Class: Stretto::MusicElements::Instrument
- Inherits:
-
MusicElement
- Object
- MusicElement
- Stretto::MusicElements::Instrument
- Defined in:
- lib/stretto/music_elements/instrument.rb
Overview
Represent an instrument change by the MIDI specification.
The sound played depends on the soundbank installed by the synthesizer, the MIDI standard defines 128 standard instruments (see Variables::INSTRUMENT_VARIABLES) that are reflected by JFugue with predefined variables.
Constant Summary collapse
- MAX_INSTRUMENT_VALUE =
127
Instance Attribute Summary
Attributes inherited from MusicElement
Attributes included from Node
Class Method Summary collapse
-
.default_instrument(pattern = nil) ⇒ Object
Returns an instrument with value 0 (piano).
Instance Method Summary collapse
-
#initialize(string_or_options, pattern = nil) ⇒ Instrument
constructor
A new instance of Instrument.
-
#value ⇒ Number
Returns or calculates the value for the instrument.
-
#value=(value) ⇒ Object
Sets and validates value (0…127).
Methods inherited from MusicElement
#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #to_s
Constructor Details
#initialize(string_or_options, pattern = nil) ⇒ Instrument
Returns a new instance of Instrument.
25 26 27 28 29 30 31 32 |
# File 'lib/stretto/music_elements/instrument.rb', line 25 def initialize(, pattern = nil) token = case when String then Stretto::Parser.parse_instrument!() else end super(token[:text_value], pattern ) @original_value = token[:value] end |
Class Method Details
.default_instrument(pattern = nil) ⇒ Object
Returns an instrument with value 0 (piano)
17 18 19 20 21 22 23 |
# File 'lib/stretto/music_elements/instrument.rb', line 17 def self.default_instrument(pattern = nil) params = { :text_value => '', :value => Value.new(Value::NumericValue.new(0)) } new(params, pattern) end |
Instance Method Details
#value ⇒ Number
Returns or calculates the value for the instrument
44 45 46 |
# File 'lib/stretto/music_elements/instrument.rb', line 44 def value @value || @original_value.to_i(@pattern) end |
#value=(value) ⇒ Object
Sets and validates value (0…127)
35 36 37 38 39 40 |
# File 'lib/stretto/music_elements/instrument.rb', line 35 def value=(value) if value < 0 or value > MAX_INSTRUMENT_VALUE raise Exceptions::ValueOutOfBoundsException.new("Instrument value should be in range 0..#{MAX_INSTRUMENT_VALUE}") end @value = value end |