Class: HeadMusic::Notation::MusicXML::ClefSelector
- Inherits:
-
Object
- Object
- HeadMusic::Notation::MusicXML::ClefSelector
- Defined in:
- lib/head_music/notation/music_xml/clef_selector.rb
Overview
Chooses a clef for a voice based on the midpoint of its pitch range.
Constant Summary collapse
- MIDDLE_C_MIDI_NOTE_NUMBER =
60
Class Method Summary collapse
-
.for(voice) ⇒ Object
Returns the treble clef for a voice with no notes (rest-only or empty), and otherwise the clef whose side of middle C matches the midpoint of the voice’s lowest and highest pitches.
-
.midpoint(voice) ⇒ Object
private
Class Method Details
.for(voice) ⇒ Object
Returns the treble clef for a voice with no notes (rest-only or empty), and otherwise the clef whose side of middle C matches the midpoint of the voice’s lowest and highest pitches. A midpoint exactly on middle C is treated as treble.
11 12 13 14 15 16 17 18 19 |
# File 'lib/head_music/notation/music_xml/clef_selector.rb', line 11 def self.for(voice) return HeadMusic::Rudiment::Clef.get(:treble_clef) unless voice.lowest_pitch if midpoint(voice) < MIDDLE_C_MIDI_NOTE_NUMBER HeadMusic::Rudiment::Clef.get(:bass_clef) else HeadMusic::Rudiment::Clef.get(:treble_clef) end end |
.midpoint(voice) ⇒ Object (private)
21 22 23 |
# File 'lib/head_music/notation/music_xml/clef_selector.rb', line 21 def self.midpoint(voice) (voice.lowest_pitch.midi_note_number + voice.highest_pitch.midi_note_number) / 2.0 end |