Class: Stretto::MusicElements::MusicElement

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Attributes included from Node

#next, #prev

Instance Method Summary collapse

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_stringString? (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

Returns:



20
21
22
# File 'lib/stretto/music_elements/music_element.rb', line 20

def original_string
  @original_string
end

#patternPattern?

The pattern to where this element belongs. Used to make calculations about key signatures, ties, instruments, voices, etc. that may modify the element itself.

Returns:



26
27
28
# File 'lib/stretto/music_elements/music_element.rb', line 26

def pattern
  @pattern
end

Instance Method Details

#build_music_stringObject

This method is abstract.
TODO:

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

#durationObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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_sObject Also known as: inspect

TODO:

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.

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