Class: Stretto::MusicElements::MusicElement
- Inherits:
-
Object
- Object
- 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)
-
- (String?) original_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)
- - (Object) build_music_string abstract
-
- (Object) duration
By default, duration is 0.
-
- (Boolean) end_of_tie?
By default, it is true, so we can tie notes with elements in between.
-
- (MusicElement) initialize(original_string, pattern = nil)
constructor
Stores the original string and an optional pattern.
-
- (Boolean) start_of_tie?
By default, it is true, so we can tie notes with elements in between.
-
- (Object) substitute_variables!
Called whenever an element is attached to a pattern, and its attributes need to be recalculated / validated (because of variables, key signatures, ties, etc.).
-
- (Object) to_s
(also: #inspect)
The string representation of the element.
Constructor Details
- (MusicElement) initialize(original_string, pattern = nil)
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
- (String?) original_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
- (Object) build_music_string
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 |
- (Object) duration
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 |
- (Boolean) end_of_tie?
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 |
- (Boolean) start_of_tie?
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 |
- (Object) substitute_variables!
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 |
- (Object) to_s 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
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 |