Class: Diatone::Strat

Inherits:
Object
  • Object
show all
Defined in:
lib/diatone.rb

Class Method Summary collapse

Class Method Details

.blisters(choice = nil, strings = self.standard_tuning, scale = nil) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/diatone.rb', line 369

def self.blisters (choice=nil,strings=self.standard_tuning,scale=nil)
  blisters = {}
  if choice == nil
    return blisters.to_json
  end
  tonic = Note.key(choice[0],true)%12
    colors = $chordcolors[tonic]
  6.times do |s|
    blisterstr = []
    st = strings[s]
    t = Note.fix st
    $numfrets.times do |f|
      n = Note.key(t,false)
      i = choice.rindex {|a| a == n}
      if i
        color = colors[i]
        if i == 0 then rad = 7 else rad = 5 end
        if f == 0
          blister = {
            'type' => 'circle',
            'cx' => $boardmargin+s*$boardstep,
            'cy' => $dists[f]+8,
            'r' => rad-1,
            'count' => Note.ord2tone(t.to_i),
            'coord' => [s,f],
            'index' => i,
            'stroke' => color,
            'stroke-width' => 3,
            'fill' => 'black'
          }
          blisterstr.push blister
        else
          xc = ($dists[f]/460.0)
          blister = {
            'type' => 'circle',
            'cx' => $boardmargin-xc*2.5+s*($boardstep+xc),
            'cy' => $dists[f],
            'r' => rad,
            'count' => Note.ord2tone(t.to_i),
            'coord' => [s,f],
            'index' => i,
            'fill' => color,
            #'fill-opacity' => 1.2-f/($numfrets*1.0),
            'stroke' => 'none'
          }
          blisterstr.push blister
        end
      end
      t += 1
    end
    blisters[s] = blisterstr
  end
  legend = []
  ords = []
  choice.length.times do |c|
    nt = choice[c]
    cl = colors[c]
    o = Note.fix(nt+'4').to_i
    if c > 0 and o < ords[c-1]
      o += 12
    end
    ords.push o
    legend.push(nt+','+cl+','+o.to_s)
  end
  blisters['legend'] = (legend.join(';'))
  return blisters
end

.fretboardObject



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/diatone.rb', line 252

def self.fretboard ()
  y = $firstfretwidth;
  yy = 0;
  board = []
  head = {
    'type' => 'path',
    'path' => "m 0,0 c 0.67553,-13.141072 -4.48542,-17.874924 -30.62047,-25.353202 l 93.57286,-287.670447 c 13.79673,-28.33919 54.14057,-31.93149 75.04833,-12.57035 9.11046,9.06332 20.55453,35.78224 9.28602,60.61698 -5.45523,12.0228 -17.15423,23.82984 -36.50441,32.19232 0,0 -2.81387,3.53158 -1.91422,9.86513 4.11709,28.98438 32.13336,129.84242 24.99516,141.72309 -7.13821,11.880669 -48.15894,10.032667 -52.87363,81.339695 z",
    'stroke' =>  'none',
    'fill' => '90-#8b512e-#cd8f69:10-#c07040'
  }
  board.push(head)


  body = {
    'type' => 'path',
    'path' => "m -4,770 c -4.5242,43.39873 -83.3941,32.78475 -108.7634,-11.67981 -20.7376,-36.34659 5.2806,-91.30037 -19.9816,-102.2859 -30.8976,-13.43602 -80.1227,35.57216 -72.3811,129.47097 7.3335,88.948316 57.1253,131.731505 44.9389,217.090413 -12.1864,85.358817 -110.4576,200.116007 -85.1837,318.218047 25.2739,118.10213 162.8277,135.95354 274.3877,145.03181 111.5601,9.07826 263.55221,6.37368 287.47455,-128.09349 24.6158,-138.36507 -67.0671,-209.42944 -74.31643,-304.36328 -3.18581,-41.719804 14.39068,-62.103376 22.96767,-88.367288 8.5803,-26.274115 25.80111,-44.13946 23.04036,-96.234742 -4.57647,-86.35794 -45.45078,-70.88739 -48.67796,-70.97081 -27.19304,7.98078 -15.26175,59.28649 -42.35049,85.685817 -8.8064,8.582202 -30.3951,18.925638 -49.5918,18.485334 -60.499,-1.387536 -54.4462,-20.583252 -61.4426,-35.736221 -8.599,-18.62415 -90.1201,-76.25085 -90.1201,-76.25085 z",
    'stroke' =>  'none',
    'fill' => 'maroon'
  }
  board.push(body)
  white = {
    'type' => 'path',
    'path' => "m -96,1140 c 0.098,7.01566 0.8747,14.03337 2.4142,21.22344 8.7356,48.54034 40.2199,58.7572 74.4886,53.05809 40.0337,1.66041 95.5773,-7.43657 154.943,7.6553 50.2963,12.78628 73.79222,31.93169 94.91923,51.95945 17.53567,15.74884 37.64893,32.96362 55.5543,23.46872 30.22696,-20.56269 -2.85821,-89.94559 -13.0125,-115.40769 -21.34736,-53.00201 -47.47667,-93.35326 -50.38964,-150.820522 -2.42253,-47.791858 16.95174,-74.49973817 24.01244,-96.120565 10.32302,-31.610493 24.49009,-41.3072 21.99337,-88.420203 -2.10544,-39.72965 -11.89005,-48.9677 -14.67067,-50.69193 -1.3903,-0.86212 -2.28921,-0.9382 -3.72532,-0.90891 -0.71806,0.0145 -1.44538,0.0977 -2.28269,0.24145 -0.18297,0.031 -0.46873,0.0898 -0.67735,0.12887 -0.0684,0.19233 -0.14486,0.42621 -0.76059,1.67448 -1.49359,3.02792 -3.37982,9.69246 -5.23772,18.05192 -3.60708,16.22961 -7.38026,39.85959 -25.58263,58.765547 l 0.0275,0.02835 c -0.50003,0.606339 -1.06013,1.131786 -1.57707,1.716489 -11.46688,12.97011 -26.98306,22.595111 -42.57546,25.085465 -16.2953,2.602665 -32.6136,-1.418191 -48.8761,-5.556621 -32.5252,-8.276954 -65.6194,-25.061756 -95.7875,-39.87163 -30.1681,-14.80978 -58.4564,-27.17844 -71.6229,-28.67619 -6.5833,-0.74888 -6.5511,0.23292 -6.2433,-0.0811 0.2923,-0.29824 -2.0298,2.90505 -2.0368,13.55084 15.6979,74.226032 12.888,128.553187 -6.4573,178.417869 -18.2156,46.953021 -37.3243,86.480971 -36.8373,121.528471 z",
    'stroke' =>  'none',
    'fill' => 'White'
  }
  board.push(white)
  fboard = {
      'type' => 'path',
      'path' => 'M 0 0 L 80 0 L 85 910 C 87 930 -7 930 -5 910 Z',
      'stroke' => 'none',
      'fill' => 'Black'
    }
  board.push(fboard)
  $numfrets.times do |t|
    i = [5,7,9,15,17,19,21].rindex {|a| a == t}
    if i
      circle = {
          'type' => 'circle',
          'cx' => 40,
          'cy' => yy-y/2,
          'r' => 5,
          'fill' => 'Silver'
      }
      board.push circle
    elsif t == 12
      board.push ( {
          'type' => 'circle',
          'cx' => 16,
          'cy' => yy-y/2,
          'r' => 5,
          'fill' => 'Silver'
      })
      board.push ( {
          'type' => 'circle',
          'cx' => 63,
          'cy' => yy-y/2,
          'r' => 5,
          'fill' => 'Silver'
      })
    end
    if t == 0 then w = 9 else w = 3 end
    fret = {
      'type' => 'path',
      'path' => 'M'+(-yy/184).to_s+' '+(yy).to_s+' H'+(80+yy/184).to_s,
      'stroke-width' => w,
      'stroke' => 'Gainsboro'
    }
    board.push fret
    $dists.push (yy-8)
    y /= STEP
    yy += y.round
  end
  tresh = {
      'type' => 'path',
      'path' => 'M 0 0 L 80 0 L 80 -10 L 0 -10 Z',
      'stroke' => 'none',
      'fill' => 'Black',
      'fill-opacity' => 0.6
    }
  #board.push(tresh)
  $dists.push (yy-8)
  6.times do |h|
    x = ($boardmargin + h * $boardstep).to_s
    xx = (3+h*15)
    yx = (-68-h*44)
    l = {
      'type' => 'path',
      'path' => 'M'+x+' 0 L '+(xx+5).to_s+' '+yx.to_s,
      'stroke-width' => 2.5-h/3.0,
      'stroke' => 'Silver',
    }
    board.push(l)
    c = {
      'type' => 'circle',
      'cx' => xx.to_s,
      'cy' => yx.to_s,
      'r' => 8,
      'stroke' => 'none',
      'fill' => 'r(.8,.4)#666-#ddd',
    }
    board.push(c)
  end
  6.times do |s|
    x = ($boardmargin + s * $boardstep).to_s
    xx = (s * 17 - 3).to_s
    string = {
      'type' => 'path',
      'path' => 'M'+x+' 0 L '+xx+' 1280',
      'stroke-width' => 2.5-s/3.0,
      'stroke' => 'Silver'
    }
    board.push string
  end
  return board
end

.handles(st = self.standard_tuning) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/diatone.rb', line 231

def self.handles(st=self.standard_tuning)
  handles = []
  6.times do |h|
    x = ($boardmargin + h * $boardstep).to_s
    xx = (3+h*15)
    yx = (-68-h*44)
    t = {
      'type' => 'text',
      'x' => (xx-36).to_s,
      'y' => (yx-12).to_s,
      'text' => st[h],
      'count' => h,
      'fill' => '#666',
      'font' =>  "bold 18px 'Georgia'",
      'transform' => 'R -79',
    }
    handles.push(t)
  end
  return handles
end

.standard_tuningObject



227
228
229
# File 'lib/diatone.rb', line 227

def self.standard_tuning
  ['E2','A2','D3','G3','B3','E4']
end