Class: Webmidi::Message::Channel::PitchBend
- Inherits:
-
Base
- Object
- Base
- Base
- Webmidi::Message::Channel::PitchBend
show all
- Defined in:
- lib/webmidi/message/channel.rb
Constant Summary
collapse
- MIN =
0
- CENTER =
8192
- MAX =
16_383
- SIGNED_MIN =
-8192
- SIGNED_MAX =
8191
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(value:, channel: 0, timestamp: nil) ⇒ PitchBend
Returns a new instance of PitchBend.
205
206
207
208
209
210
211
212
213
|
# File 'lib/webmidi/message/channel.rb', line 205
def initialize(value:, channel: 0, timestamp: nil)
validate_channel!(channel)
unless value.is_a?(Integer) && value.between?(MIN, MAX)
raise InvalidMessageError, "Pitch bend value must be between #{MIN} and #{MAX}, got #{value.inspect}"
end
@value = value
@channel = channel
super(timestamp: timestamp)
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
203
204
205
|
# File 'lib/webmidi/message/channel.rb', line 203
def value
@value
end
|
Class Method Details
.from_signed(value, channel: 0, timestamp: nil) ⇒ Object
227
228
229
230
231
232
233
234
|
# File 'lib/webmidi/message/channel.rb', line 227
def self.from_signed(value, channel: 0, timestamp: nil)
unless value.is_a?(Integer) && value.between?(SIGNED_MIN, SIGNED_MAX)
raise InvalidMessageError,
"Signed pitch bend value must be between #{SIGNED_MIN} and #{SIGNED_MAX}, got #{value.inspect}"
end
new(value: value + CENTER, channel: channel, timestamp: timestamp)
end
|
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
219
220
221
|
# File 'lib/webmidi/message/channel.rb', line 219
def deconstruct_keys(keys)
{value: @value, channel: @channel}
end
|
#signed_value ⇒ Object
223
224
225
|
# File 'lib/webmidi/message/channel.rb', line 223
def signed_value
@value - CENTER
end
|
#to_bytes ⇒ Object
215
216
217
|
# File 'lib/webmidi/message/channel.rb', line 215
def to_bytes
[0xE0 | @channel, @value & 0x7F, (@value >> 7) & 0x7F]
end
|