Class: Webmidi::Message::System::SongPosition

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(position:, timestamp: nil) ⇒ SongPosition

Returns a new instance of SongPosition.



82
83
84
85
86
87
88
# File 'lib/webmidi/message/system.rb', line 82

def initialize(position:, timestamp: nil)
  unless position.is_a?(Integer) && position.between?(0, 16383)
    raise InvalidMessageError, "Song position must be between 0 and 16383, got #{position.inspect}"
  end
  @position = position
  super(timestamp: timestamp)
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



80
81
82
# File 'lib/webmidi/message/system.rb', line 80

def position
  @position
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



94
95
96
# File 'lib/webmidi/message/system.rb', line 94

def deconstruct_keys(keys)
  {position: @position}
end

#to_bytesObject



90
91
92
# File 'lib/webmidi/message/system.rb', line 90

def to_bytes
  [0xF2, @position & 0x7F, (@position >> 7) & 0x7F]
end