Class: Sergovia::Transcriber

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tuning: [:e2, :a2, :d3, :g3, :b3, :e4], frets: 24) ⇒ Transcriber

Returns a new instance of Transcriber.



6
7
8
9
10
# File 'lib/sergovia/transcriber.rb', line 6

def initialize(tuning:[:e2, :a2, :d3, :g3, :b3, :e4], frets: 24)
  @tuning = tuning
  @frets = frets
  build_fretboard
end

Instance Attribute Details

#fretboardObject (readonly)

Returns the value of attribute fretboard.



4
5
6
# File 'lib/sergovia/transcriber.rb', line 4

def fretboard
  @fretboard
end

#fretsObject (readonly)

Returns the value of attribute frets.



4
5
6
# File 'lib/sergovia/transcriber.rb', line 4

def frets
  @frets
end

#tuningObject (readonly)

Returns the value of attribute tuning.



4
5
6
# File 'lib/sergovia/transcriber.rb', line 4

def tuning
  @tuning
end

Instance Method Details

#fingerings(pitch_sting) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sergovia/transcriber.rb', line 12

def fingerings(pitch_sting)
  in_theory = theoretical_fingerings(pitch_sting)
  ret = in_theory.reject do |v| 
    grouped_by_string = {}
    v.notes.each do |n|
      grouped_by_string[n.string] ||= []
      grouped_by_string[n.string] << n
    end
    grouped_by_string.any? { |k,v| v.size > 1 }
  end
  ret.map do |fingering|
    Fingering.new(notes:fingering.notes, playability: Scorers::Stretch.new(fingering).score)
  end.sort_by(&:playability).reverse
end

#increment(pitch) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sergovia/transcriber.rb', line 49

def increment(pitch)
  pitch_string = pitch.to_s.downcase
  match = /([a-z][#]?[b]?)([0-9])/.match(pitch_string)
  note = match[1].to_sym
  octave = match[2].to_i
  note = to_sharp_key_notation(note) 
  if note == :b
    octave += 1
  end
  res_note = pitch_inc_map[note]
  return :"#{res_note}#{octave}"
end

#locations_for(pitch) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sergovia/transcriber.rb', line 34

def locations_for(pitch)
  original_pitch_name = pitch.to_sym
  pitch = to_sharp_key_notation(original_pitch_name)

  locations = []
  fretboard.each_with_index do |string, string_num|
    string.each_with_index do |note, fret_num|
      if note == pitch
        locations << Note.new(string: string_num + 1, fret: fret_num, pitch: original_pitch_name)
      end
    end
  end
  locations
end

#theoretical_fingerings(pitch_string) ⇒ Object



27
28
29
30
31
32
# File 'lib/sergovia/transcriber.rb', line 27

def theoretical_fingerings(pitch_string)
  groups = pitch_string.split(",").map do |pitch|
    locations_for(pitch)
  end
  groups.first.product(*groups[1..-1]).map { |n| Fingering.new(notes: n) }
end