Class: Webmidi::Message::UMP::Raw

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

Direct Known Subclasses

Data128, Data64, FlexData, SystemCommon, Utility

Instance Attribute Summary collapse

Attributes inherited from Base

#group, #message_type

Attributes inherited from Base

#timestamp

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(message_type:, words:, group: 0, timestamp: nil) ⇒ Raw

Returns a new instance of Raw.



134
135
136
137
138
139
140
141
142
# File 'lib/webmidi/message/ump.rb', line 134

def initialize(message_type:, words:, group: 0, timestamp: nil)
  words = normalize_words!(words)
  validate_message_type!(message_type)
  validate_word_count!(message_type, words)
  validate_range!(group, "Group", 0, 15)
  validate_word_header!(message_type, group, words.first)
  @words = words.dup.freeze
  super(message_type: message_type, group: group, timestamp: timestamp)
end

Instance Attribute Details

#wordsObject (readonly)

Returns the value of attribute words.



132
133
134
# File 'lib/webmidi/message/ump.rb', line 132

def words
  @words
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



148
149
150
# File 'lib/webmidi/message/ump.rb', line 148

def deconstruct_keys(keys)
  super.merge(words: @words)
end

#to_bytesObject



144
145
146
# File 'lib/webmidi/message/ump.rb', line 144

def to_bytes
  words_to_bytes(@words)
end

#with(**changes) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/webmidi/message/ump.rb', line 152

def with(**changes)
  changes = changes.dup
  next_timestamp = changes.key?(:timestamp) ? changes.delete(:timestamp) : @timestamp
  attributes = constructor_attributes.merge(changes)
  attributes[:words] = words_with_group(attributes[:words], attributes[:group])
  self.class.new(**attributes, timestamp: next_timestamp)
end