Class: Stretto::MusicElements::MusicElement
- Includes:
- Node
- Defined in:
- lib/stretto/music_elements/music_element.rb
Overview
Superclass of all music elements in Stretto.
These are all the elements than can be added to a pattern, most of them represent some data to be sent to a MIDI channel, or are some notation element to aid in the composition.
Direct Known Subclasses
ChannelPressure, Chord, ControllerChange, Harmony, Instrument, KeySignature, LayerChange, Measure, Melody, Note, PitchBend, PolyphonicPressure, Rest, Tempo, Timing, Variable, VoiceChange
Instance Attribute Summary collapse
-
#original_string ⇒ String?
readonly
In the case of parsed element, this is the originating string.
-
#pattern ⇒ Pattern?
The pattern to where this element belongs.
Attributes included from Node
Instance Method Summary collapse
- #build_music_string ⇒ Object abstract
-
#duration ⇒ Object
By default, duration is 0.
-
#end_of_tie? ⇒ Boolean
By default, it is true, so we can tie notes with elements in between.
-
#initialize(original_string, pattern = nil) ⇒ MusicElement
constructor
Stores the original string and an optional pattern.
-
#start_of_tie? ⇒ Boolean
By default, it is true, so we can tie notes with elements in between.
-
#substitute_variables! ⇒ Object
Called whenever an element is attached to a pattern, and its attributes need to be recalculated / validated (because of variables, key signatures, ties, etc.).
-
#to_s ⇒ Object
(also: #inspect)
The string representation of the element.
Constructor Details
#initialize(original_string, pattern = nil) ⇒ MusicElement
Stores the original string and an optional pattern
29 30 31 32 |
# File 'lib/stretto/music_elements/music_element.rb', line 29 def initialize(original_string, pattern = nil) @original_string = original_string # TODO: Validates always an original string? @pattern = pattern end |
Instance Attribute Details
#original_string ⇒ String? (readonly)
In the case of parsed element, this is the originating string. In the case of calculated elements, this should be an empty string, and its string representation must be provided by the element
20 21 22 |
# File 'lib/stretto/music_elements/music_element.rb', line 20 def original_string @original_string end |
#pattern ⇒ Pattern?
The pattern to where this element belongs. Used to make calculations about key signatures, ties, instruments, voices, etc. that may modify the element itself.
26 27 28 |
# File 'lib/stretto/music_elements/music_element.rb', line 26 def pattern @pattern end |
Instance Method Details
#build_music_string ⇒ Object
Not yet implemented
43 44 45 |
# File 'lib/stretto/music_elements/music_element.rb', line 43 def build_music_string raise "build_music_string not implemented in #{self.class}" end |
#duration ⇒ Object
By default, duration is 0
The correct duration should be overriden by subclasses
62 63 64 |
# File 'lib/stretto/music_elements/music_element.rb', line 62 def duration 0 end |
#end_of_tie? ⇒ Boolean
By default, it is true, so we can tie notes with elements in between
55 56 57 |
# File 'lib/stretto/music_elements/music_element.rb', line 55 def end_of_tie? true end |
#start_of_tie? ⇒ Boolean
By default, it is true, so we can tie notes with elements in between
50 51 52 |
# File 'lib/stretto/music_elements/music_element.rb', line 50 def start_of_tie? true end |
#substitute_variables! ⇒ Object
Called whenever an element is attached to a pattern, and its attributes need to be recalculated / validated (because of variables, key signatures, ties, etc.)
Each element class must override this class to provide the callback when the element is added to a pattern.
73 74 75 |
# File 'lib/stretto/music_elements/music_element.rb', line 73 def substitute_variables! # TODO: Big TODO - Change this method's name for a callback. end |
#to_s ⇒ Object Also known as: inspect
No specs for this. Ideally, its string representation should be one that can be parsed again to retrieve the same element
Returns The string representation of the element.
37 38 39 |
# File 'lib/stretto/music_elements/music_element.rb', line 37 def to_s original_string || build_music_string end |