Class: Stretto::MusicElements::PitchBend

Inherits:
MusicElement show all
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

#original_string, #pattern

Attributes included from Node

#next, #prev

Instance Method Summary collapse

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(string_or_options, pattern = nil)
  token = case string_or_options
    when String then Stretto::Parser.parse_pitch_bend!(string_or_options)
    else string_or_options
  end
  super(token[:text_value], pattern)
  @original_value = token[:value]
end

Instance Method Details

#valueObject



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