Class: GabcPitchReader
- Inherits:
-
Object
- Object
- GabcPitchReader
- 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
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#clef ⇒ Object
readonly
Returns the value of attribute clef.
-
#clef_position ⇒ Object
readonly
Returns the value of attribute clef_position.
Instance Method Summary collapse
-
#initialize(clef = :c, clef_position = 4) ⇒ GabcPitchReader
constructor
A new instance of GabcPitchReader.
-
#pitch(visual_note) ⇒ Object
gets a gabc visual pitch, returns a RbMusicTheory::Note.
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
23 24 25 |
# File 'lib/lygre/gabcpitchreader.rb', line 23 def base @base end |
#clef ⇒ Object (readonly)
Returns the value of attribute clef.
23 24 25 |
# File 'lib/lygre/gabcpitchreader.rb', line 23 def clef @clef end |
#clef_position ⇒ Object (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 |