Class: Stretto::MusicElements::Variable
- Inherits:
-
MusicElement
- Object
- MusicElement
- Stretto::MusicElements::Variable
- Defined in:
- lib/stretto/music_elements/variable.rb
Overview
Holds a value, identified by a name, that can be used in some elements in the pattern.
The syntax for setting a value is $name=vaue
For example, in a pattern
$SOME_VARIABLE=80 [SOME_VARIABLE]
the note will have a picth of 80, as defined by the variable SOME_VARIABLE
Value can be either a numeric value or another variable. Note that predefined variables are not constants; they can be overriden at any time, and the elements after the new definition will take its most recent value.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from MusicElement
Attributes included from Node
Instance Method Summary collapse
-
#initialize(string_or_options, pattern = nil) ⇒ Variable
constructor
A new instance of Variable.
- #to_f ⇒ Float?
- #to_i ⇒ Integer?
Methods inherited from MusicElement
#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #substitute_variables!, #to_s
Constructor Details
#initialize(string_or_options, pattern = nil) ⇒ Variable
Returns a new instance of Variable.
26 27 28 29 30 31 32 33 34 |
# File 'lib/stretto/music_elements/variable.rb', line 26 def initialize(, pattern = nil) token = case when String then Stretto::Parser.parse_variable!() else end super(token[:text_value], pattern) @value = token[:value] @name = token[:name] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/stretto/music_elements/variable.rb', line 24 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
24 25 26 |
# File 'lib/stretto/music_elements/variable.rb', line 24 def value @value end |
Instance Method Details
#to_f ⇒ Float?
42 43 44 |
# File 'lib/stretto/music_elements/variable.rb', line 42 def to_f @value.to_f(@pattern) end |
#to_i ⇒ Integer?
37 38 39 |
# File 'lib/stretto/music_elements/variable.rb', line 37 def to_i @value.to_i(@pattern) end |