Class: Stretto::MusicElements::PitchBend
- Inherits:
-
MusicElement
- Object
- MusicElement
- Stretto::MusicElements::PitchBend
- Defined in:
- lib/stretto/music_elements/pitch_bend.rb
Overview
Pitch bend, according to MIDI spacification, changes the tone of a note in steps of hundredth of a note. The full range can go from 0 to 16383, being 8192 the middle pitch, that is, no variation.
Pitch bends are represented with a & symbol before, for example &16000
Constant Summary collapse
- MAX_PITCH_BEND_VALUE =
16383
Instance Attribute Summary
Attributes inherited from MusicElement
Attributes included from Node
Instance Method Summary collapse
-
#initialize(string_or_options, pattern = nil) ⇒ PitchBend
constructor
A new instance of PitchBend.
- #value ⇒ Object
-
#value=(value) ⇒ Object
Sets value and validates it is in range.
Methods inherited from MusicElement
#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #to_s
Constructor Details
#initialize(string_or_options, pattern = nil) ⇒ PitchBend
Returns a new instance of PitchBend.
15 16 17 18 19 20 21 22 |
# File 'lib/stretto/music_elements/pitch_bend.rb', line 15 def initialize(, pattern = nil) token = case when String then Stretto::Parser.parse_pitch_bend!() else end super(token[:text_value], pattern) @original_value = token[:value] end |
Instance Method Details
#value ⇒ Object
32 33 34 |
# File 'lib/stretto/music_elements/pitch_bend.rb', line 32 def value @value || @original_value.to_i(@pattern) end |
#value=(value) ⇒ Object
Sets value and validates it is in range
25 26 27 28 29 30 |
# File 'lib/stretto/music_elements/pitch_bend.rb', line 25 def value=(value) if value < 0 or value > MAX_PITCH_BEND_VALUE raise Exceptions::ValueOutOfBoundsException.new("Pitch bend should be in range 0..#{MAX_PITCH_BEND_VALUE}") end @value = value end |