Class: Webmidi::Message::System::TimeCode

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

Instance Attribute Summary collapse

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, #with

Constructor Details

#initialize(type:, value:, timestamp: nil) ⇒ TimeCode

Returns a new instance of TimeCode.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/webmidi/message/system.rb', line 58

def initialize(type:, value:, timestamp: nil)
  unless type.is_a?(Integer) && type.between?(0, 7)
    raise InvalidMessageError, "TimeCode type must be between 0 and 7, got #{type.inspect}"
  end
  unless value.is_a?(Integer) && value.between?(0, 15)
    raise InvalidMessageError, "TimeCode value must be between 0 and 15, got #{value.inspect}"
  end
  @type = type
  @value = value
  super(timestamp: timestamp)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



56
57
58
# File 'lib/webmidi/message/system.rb', line 56

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



56
57
58
# File 'lib/webmidi/message/system.rb', line 56

def value
  @value
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



74
75
76
# File 'lib/webmidi/message/system.rb', line 74

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

#to_bytesObject



70
71
72
# File 'lib/webmidi/message/system.rb', line 70

def to_bytes
  [0xF1, (@type << 4) | @value]
end