Class: HeadMusic::Note
- Inherits:
-
Object
- Object
- HeadMusic::Note
- Defined in:
- lib/head_music/content/note.rb
Overview
A note is a pitch with a duration.
Note quacks like a placement, but requires a different set of construction arguments
- always has a pitch
- receives a voice and position if unspecified
Instance Attribute Summary collapse
-
#pitch ⇒ Object
Returns the value of attribute pitch.
-
#position ⇒ Object
Returns the value of attribute position.
-
#rhythmic_value ⇒ Object
Returns the value of attribute rhythmic_value.
-
#voice ⇒ Object
Returns the value of attribute voice.
Instance Method Summary collapse
-
#initialize(pitch, rhythmic_value, voice = nil, position = nil) ⇒ Note
constructor
A new instance of Note.
- #method_missing(method_name, *args, &block) ⇒ Object
- #placement ⇒ Object
- #respond_to_missing?(method_name, *_args) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(pitch, rhythmic_value, voice = nil, position = nil) ⇒ Note
Returns a new instance of Note.
11 12 13 14 15 16 |
# File 'lib/head_music/content/note.rb', line 11 def initialize(pitch, rhythmic_value, voice = nil, position = nil) @pitch = HeadMusic::Pitch.get(pitch) @rhythmic_value = HeadMusic::RhythmicValue.get(rhythmic_value) @voice = voice || HeadMusic::Voice.new @position = position || HeadMusic::Position.new(@voice.composition, "1:1") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
26 27 28 |
# File 'lib/head_music/content/note.rb', line 26 def method_missing(method_name, *args, &block) respond_to_missing?(method_name) ? placement.send(method_name, *args, &block) : super end |
Instance Attribute Details
#pitch ⇒ Object
Returns the value of attribute pitch.
9 10 11 |
# File 'lib/head_music/content/note.rb', line 9 def pitch @pitch end |
#position ⇒ Object
Returns the value of attribute position.
9 10 11 |
# File 'lib/head_music/content/note.rb', line 9 def position @position end |
#rhythmic_value ⇒ Object
Returns the value of attribute rhythmic_value.
9 10 11 |
# File 'lib/head_music/content/note.rb', line 9 def rhythmic_value @rhythmic_value end |
#voice ⇒ Object
Returns the value of attribute voice.
9 10 11 |
# File 'lib/head_music/content/note.rb', line 9 def voice @voice end |
Instance Method Details
#placement ⇒ Object
18 19 20 |
# File 'lib/head_music/content/note.rb', line 18 def placement @placement ||= HeadMusic::Placement.new(voice, position, rhythmic_value, pitch) end |
#respond_to_missing?(method_name, *_args) ⇒ Boolean
30 31 32 |
# File 'lib/head_music/content/note.rb', line 30 def respond_to_missing?(method_name, *_args) placement.respond_to?(method_name) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/head_music/content/note.rb', line 22 def to_s "#{pitch} at #{position}" end |