Class: GabcPitchReader

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

Overview

responsible for converting the ‘visual pitch’ information contained in gabc to absolute musical pitch

Constant Summary collapse

CLEFS =
{:c => "c''", :f => "f'"}
CLEF_POSITIONS =
1..4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clef = :c, clef_position = 4) ⇒ GabcPitchReader

Returns a new instance of GabcPitchReader.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lygre/gabcpitchreader.rb', line 9

def initialize(clef=:c, clef_position=4)
  unless CLEFS.include? clef
    raise ArgumentError.new "#{clef} is not a valid clef"
  end
  unless CLEF_POSITIONS.include? clef_position
    raise ArgumentError.new "#{clef_position} is not a valid clef position"
  end

  @clef = clef
  @clef_position = clef_position

  init_base
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



23
24
25
# File 'lib/lygre/gabcpitchreader.rb', line 23

def base
  @base
end

#clefObject (readonly)

Returns the value of attribute clef.



23
24
25
# File 'lib/lygre/gabcpitchreader.rb', line 23

def clef
  @clef
end

#clef_positionObject (readonly)

Returns the value of attribute clef_position.



23
24
25
# File 'lib/lygre/gabcpitchreader.rb', line 23

def clef_position
  @clef_position
end

Instance Method Details

#pitch(visual_note) ⇒ Object

gets a gabc visual pitch, returns a RbMusicTheory::Note



26
27
28
29
# File 'lib/lygre/gabcpitchreader.rb', line 26

def pitch(visual_note)
  hnote = visual_note.to_s.ord - 'a'.ord # steps from a - the lowest writable gabc note
  return @base.diatonic_steps(hnote)
end