Class: Webmidi::Message::Channel::ControlChange

Inherits:
Base
  • Object
show all
Defined in:
lib/webmidi/message/channel.rb

Constant Summary collapse

CONTROLLERS =
{
  bank_select: 0,
  modulation: 1,
  breath_controller: 2,
  foot_controller: 4,
  portamento_time: 5,
  data_entry_msb: 6,
  volume: 7,
  balance: 8,
  pan: 10,
  expression: 11,
  sustain: 64,
  portamento: 65,
  sostenuto: 66,
  soft_pedal: 67,
  legato: 68,
  hold_2: 69,
  sound_variation: 70,
  resonance: 71,
  release_time: 72,
  attack_time: 73,
  brightness: 74,
  all_sound_off: 120,
  reset_all_controllers: 121,
  local_control: 122,
  all_notes_off: 123,
  omni_off: 124,
  omni_on: 125,
  mono_on: 126,
  poly_on: 127
}.freeze
ALL_NOTES_OFF =

Instance Attribute Summary collapse

Attributes inherited from Base

#channel

Attributes inherited from Base

#timestamp

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #channel, #deconstruct, #eql?, #hash, #same_bytes?, #same_event?, #to_binary, #to_hex, #with

Constructor Details

#initialize(cc:, value:, channel: 0, timestamp: nil) ⇒ ControlChange

Returns a new instance of ControlChange.



127
128
129
130
131
132
133
134
135
136
# File 'lib/webmidi/message/channel.rb', line 127

def initialize(cc:, value:, channel: 0, timestamp: nil)
  validate_channel!(channel)
  cc = self.class.controller_number(cc)
  validate_byte!(cc, "CC")
  validate_byte!(value, "Value")
  @cc = cc
  @value = value
  @channel = channel
  super(timestamp: timestamp)
end

Instance Attribute Details

#ccObject (readonly)

Returns the value of attribute cc.



125
126
127
# File 'lib/webmidi/message/channel.rb', line 125

def cc
  @cc
end

#valueObject (readonly)

Returns the value of attribute value.



125
126
127
# File 'lib/webmidi/message/channel.rb', line 125

def value
  @value
end

Class Method Details

.controller_number(controller) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/webmidi/message/channel.rb', line 146

def self.controller_number(controller)
  return controller if controller.is_a?(Integer)

  key = controller.to_sym if controller.respond_to?(:to_sym)
  return CONTROLLERS[key] if key && CONTROLLERS.key?(key)

  raise InvalidMessageError, "Unknown control change controller: #{controller.inspect}"
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



142
143
144
# File 'lib/webmidi/message/channel.rb', line 142

def deconstruct_keys(keys)
  {cc: @cc, value: @value, channel: @channel}
end

#to_bytesObject



138
139
140
# File 'lib/webmidi/message/channel.rb', line 138

def to_bytes
  [0xB0 | @channel, @cc, @value]
end