Class: Webmidi::Message::UMP::ChannelVoice32

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

Instance Attribute Summary collapse

Attributes inherited from Base

#group, #message_type

Attributes inherited from Base

#timestamp

Instance Method Summary collapse

Methods inherited from Base

#with

Methods inherited from Base

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

Constructor Details

#initialize(status:, channel: 0, data1: 0, data2: 0, group: 0, timestamp: nil) ⇒ ChannelVoice32

Returns a new instance of ChannelVoice32.



442
443
444
445
446
447
448
449
450
451
452
# File 'lib/webmidi/message/ump.rb', line 442

def initialize(status:, channel: 0, data1: 0, data2: 0, group: 0, timestamp: nil)
  validate_status!(status)
  validate_range!(channel, "Channel", 0, 15)
  validate_range!(data1, "Data byte 1", 0, 127)
  validate_range!(data2, "Data byte 2", 0, 127)
  @status = status
  @channel = channel
  @data1 = data1
  @data2 = data2
  super(message_type: :channel_voice_32, group: group, timestamp: timestamp)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



440
441
442
# File 'lib/webmidi/message/ump.rb', line 440

def channel
  @channel
end

#data1Object (readonly)

Returns the value of attribute data1.



440
441
442
# File 'lib/webmidi/message/ump.rb', line 440

def data1
  @data1
end

#data2Object (readonly)

Returns the value of attribute data2.



440
441
442
# File 'lib/webmidi/message/ump.rb', line 440

def data2
  @data2
end

#statusObject (readonly)

Returns the value of attribute status.



440
441
442
# File 'lib/webmidi/message/ump.rb', line 440

def status
  @status
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



465
466
467
# File 'lib/webmidi/message/ump.rb', line 465

def deconstruct_keys(keys)
  super.merge(status: @status, channel: @channel, data1: @data1, data2: @data2)
end

#to_bytesObject



454
455
456
457
458
459
460
461
462
463
# File 'lib/webmidi/message/ump.rb', line 454

def to_bytes
  word = (MESSAGE_TYPES[:channel_voice_32] << 28) |
    (@group << 24) |
    (status_nibble << 20) |
    (@channel << 16) |
    (@data1 << 8) |
    @data2

  [(word >> 24) & 0xFF, (word >> 16) & 0xFF, (word >> 8) & 0xFF, word & 0xFF]
end