Class: Vissen::Input::Message::PitchBendChange

Inherits:
Base
  • Object
show all
Defined in:
lib/vissen/input/message/pitch_bend_change.rb

Overview

From the MIDI Association:

This message is sent to indicate a change in the pitch bender (wheel or lever, typically). The pitch bender is measured by a fourteen bit value. Center (no pitch change) is 2000H. Sensitivity is a function of the receiver, but may be set using RPN 0.

Constant Summary collapse

STATUS =
0xE0
CENTER_VALUE =

Center value is defined as the the offset that should be removed from the 14 bit pitch bend value to center it around zero.

0x2000

Constants inherited from Base

Base::DATA_LENGTH

Constants included from Vissen::Input::Message

CHANNEL_MASK, DATA_LENGTH, STATUS_MASK

Instance Attribute Summary

Attributes included from Vissen::Input::Message

#data, #timestamp

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

[], factory, match, match?, matcher, #valid?

Methods included from Vissen::Input::Message

#channel, #fetch, #initialize, #status, #to_h, #valid?

Class Method Details

.create(value = 0.0, **args) ⇒ PitchBendChange

TODO: Check the range on value.

Parameters:

  • value (Float) (defaults to: 0.0)

    the pitch bend value in the range (-1..1).

Returns:



36
37
38
39
40
# File 'lib/vissen/input/message/pitch_bend_change.rb', line 36

def create(value = 0.0, **args)
  bin_value = (value.to_f * CENTER_VALUE).round + CENTER_VALUE

  super(bin_value & 0xFF, bin_value >> 7, **args)
end

Instance Method Details

#rawInteger

Returns the integer pitch bend value.

Returns:

  • (Integer)

    the integer pitch bend value.



21
22
23
# File 'lib/vissen/input/message/pitch_bend_change.rb', line 21

def raw
  (data[2] << 7) + data[1] - CENTER_VALUE
end

#valueFloat

Returns the pitch bend value normalized to the range (-1..1).

Returns:

  • (Float)

    the pitch bend value normalized to the range (-1..1).



26
27
28
# File 'lib/vissen/input/message/pitch_bend_change.rb', line 26

def value
  raw.to_f / CENTER_VALUE
end