Class: NoteFactory
- Inherits:
-
Object
- Object
- NoteFactory
- Defined in:
- lib/lygre/gabcpitchreader.rb
Overview
an interface to create RBMusicTheory::Notes using lilypond notation
Class Method Summary collapse
-
.create(notesym) ⇒ Object
(also: create_note, [])
notesym is a String - absolute pitch in the lilypond format.
-
.lily_abs_pitch(note) ⇒ Object
returns a lilypond absolute pitch for the given RbMusicTheory::Note.
Class Method Details
.create(notesym) ⇒ Object Also known as: create_note, []
notesym is a String - absolute pitch in the lilypond format. (currently alterations are not supported, as they are not necessary for our dealing with Gregorian chant.) returns a coresponding RBMusicTheory::Note
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lygre/gabcpitchreader.rb', line 48 def create(notesym) unless notesym =~ /^[a-g]('+|,+)?$/i raise ArgumentError.new('#{notesym} is not a valid lilypond absolute pitch') end note = notesym[0] octaves = notesym[1..-1] sign = 0 octave = 0 if octaves then sign = (octaves[0] == ',' ? -1 : 1) octave += (octaves.size * sign) end return MusicTheory::Note.new note.to_sym, octave end |
.lily_abs_pitch(note) ⇒ Object
returns a lilypond absolute pitch for the given RbMusicTheory::Note
this method doesn’t fit well in a factory, but #create translates lilypond pitch to Note and #lily_abs_pitch does the reverse translation, so maybe just the class should be renamed
73 74 75 76 |
# File 'lib/lygre/gabcpitchreader.rb', line 73 def lily_abs_pitch(note) octave_signs = (note.octave >= 0 ? "'" : ",") * note.octave.abs note.pitch.to_s + octave_signs end |