Class: Stretto::MusicElements::ChannelPressure

Inherits:
MusicElement show all
Defined in:
lib/stretto/music_elements/channel_pressure.rb

Overview

ChannelPressure sends a MIDI message similar to applying pressure to an electronic keyboard. This event applies pressure to the whole channel, and its value can rango from 0 to 127

Constant Summary collapse

MAX_CHANNEL_PRESSURE_VALUE =
127

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) ⇒ ChannelPressure

Returns a new instance of ChannelPressure.



13
14
15
16
17
18
19
20
# File 'lib/stretto/music_elements/channel_pressure.rb', line 13

def initialize(string_or_options, pattern = nil)
  token = case string_or_options
    when String then Stretto::Parser.parse_channel_pressure!(string_or_options)
    else string_or_options
  end
  super(token[:text_value], pattern)
  @original_value = token[:value]
end

Instance Method Details

#valueObject



30
31
32
# File 'lib/stretto/music_elements/channel_pressure.rb', line 30

def value
  @value || @original_value.to_i(@pattern)
end

#value=(value) ⇒ Object

Sets value and validates in range



23
24
25
26
27
28
# File 'lib/stretto/music_elements/channel_pressure.rb', line 23

def value=(value)
  if value < 0 or value > MAX_CHANNEL_PRESSURE_VALUE
    raise Exceptions::ValueOutOfBoundsException.new("Channel pressure should be in range 0..#{MAX_CHANNEL_PRESSURE_VALUE}")
  end
  @value = value
end