Class: Clef::Core::Note
- Inherits:
-
Object
- Object
- Clef::Core::Note
- Defined in:
- lib/clef/core/note.rb
Constant Summary collapse
- VALID_ARTICULATIONS =
%i[staccato tenuto accent marcato fermata].freeze
- TIE_STATES =
%i[start continue stop].freeze
Instance Attribute Summary collapse
-
#articulations ⇒ Object
Returns the value of attribute articulations.
-
#beam_end ⇒ Object
Returns the value of attribute beam_end.
-
#beam_start ⇒ Object
Returns the value of attribute beam_start.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
-
#slur_end ⇒ Object
Returns the value of attribute slur_end.
-
#slur_start ⇒ Object
Returns the value of attribute slur_start.
-
#tie_state ⇒ Object
readonly
Returns the value of attribute tie_state.
Instance Method Summary collapse
- #add_articulation(articulation) ⇒ Note
-
#initialize(pitch, duration, articulations: [], tied: false) ⇒ Note
constructor
A new instance of Note.
- #length ⇒ Rational
- #tied ⇒ Boolean
- #tied=(value) ⇒ Object
Constructor Details
#initialize(pitch, duration, articulations: [], tied: false) ⇒ Note
Returns a new instance of Note.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/clef/core/note.rb', line 17 def initialize(pitch, duration, articulations: [], tied: false) validate_pitch!(pitch) validate_duration!(duration) @pitch = pitch @duration = duration self.articulations = articulations @tie_state = normalize_tie_state(tied) @slur_start = false @slur_end = false @beam_start = false @beam_end = false end |
Instance Attribute Details
#articulations ⇒ Object
Returns the value of attribute articulations.
10 11 12 |
# File 'lib/clef/core/note.rb', line 10 def articulations @articulations end |
#beam_end ⇒ Object
Returns the value of attribute beam_end.
11 12 13 |
# File 'lib/clef/core/note.rb', line 11 def beam_end @beam_end end |
#beam_start ⇒ Object
Returns the value of attribute beam_start.
11 12 13 |
# File 'lib/clef/core/note.rb', line 11 def beam_start @beam_start end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
9 10 11 |
# File 'lib/clef/core/note.rb', line 9 def duration @duration end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
9 10 11 |
# File 'lib/clef/core/note.rb', line 9 def pitch @pitch end |
#slur_end ⇒ Object
Returns the value of attribute slur_end.
11 12 13 |
# File 'lib/clef/core/note.rb', line 11 def slur_end @slur_end end |
#slur_start ⇒ Object
Returns the value of attribute slur_start.
11 12 13 |
# File 'lib/clef/core/note.rb', line 11 def slur_start @slur_start end |
#tie_state ⇒ Object (readonly)
Returns the value of attribute tie_state.
10 11 12 |
# File 'lib/clef/core/note.rb', line 10 def tie_state @tie_state end |
Instance Method Details
#add_articulation(articulation) ⇒ Note
53 54 55 56 |
# File 'lib/clef/core/note.rb', line 53 def add_articulation(articulation) self.articulations = articulations + [articulation] self end |
#length ⇒ Rational
32 33 34 |
# File 'lib/clef/core/note.rb', line 32 def length duration.length end |
#tied ⇒ Boolean
37 38 39 |
# File 'lib/clef/core/note.rb', line 37 def tied !tie_state.nil? end |
#tied=(value) ⇒ Object
42 43 44 |
# File 'lib/clef/core/note.rb', line 42 def tied=(value) @tie_state = normalize_tie_state(value) end |