Trait helgoboss_midi::ShortMessageFactory
source · [−]pub trait ShortMessageFactory: ShortMessage + Sized {
Show 25 methods
unsafe fn from_bytes_unchecked(bytes: (u8, U7, U7)) -> Self;
fn from_bytes(bytes: (u8, U7, U7)) -> Result<Self, FromBytesError> { ... }
fn from_other(msg: &impl ShortMessage) -> Self { ... }
fn channel_message(
type: ShortMessageType,
channel: Channel,
data_1: U7,
data_2: U7
) -> Self { ... }
fn system_common_message(
type: ShortMessageType,
data_1: U7,
data_2: U7
) -> Self { ... }
fn system_real_time_message(type: ShortMessageType) -> Self { ... }
fn note_on(channel: Channel, key_number: KeyNumber, velocity: U7) -> Self { ... }
fn note_off(channel: Channel, key_number: KeyNumber, velocity: U7) -> Self { ... }
fn control_change(
channel: Channel,
controller_number: ControllerNumber,
control_value: U7
) -> Self { ... }
fn program_change(channel: Channel, program_number: U7) -> Self { ... }
fn polyphonic_key_pressure(
channel: Channel,
key_number: KeyNumber,
pressure_amount: U7
) -> Self { ... }
fn channel_pressure(channel: Channel, pressure_amount: U7) -> Self { ... }
fn pitch_bend_change(channel: Channel, pitch_bend_value: U14) -> Self { ... }
fn system_exclusive_start() -> Self { ... }
fn time_code_quarter_frame(frame: TimeCodeQuarterFrame) -> Self { ... }
fn song_position_pointer(position: U14) -> Self { ... }
fn song_select(song_number: U7) -> Self { ... }
fn tune_request() -> Self { ... }
fn system_exclusive_end() -> Self { ... }
fn timing_clock() -> Self { ... }
fn start() -> Self { ... }
fn continue() -> Self { ... }
fn stop() -> Self { ... }
fn active_sensing() -> Self { ... }
fn system_reset() -> Self { ... }
}
Expand description
Static methods for creating short MIDI messages.
This trait is supposed to be implemented for structs that represent a short MIDI message and also support their creation. Only one method needs to be implemented, the rest is done by default methods.
Required Methods
Creates a MIDI message from the given bytes without checking the status byte. The tuple consists of the status byte, data byte 1 and data byte 2 in exactly this order.
Safety
Callers must make sure that the given status byte is valid, otherwise an invalid MIDI message will be created.
Implementations can therefore assume that the given status byte is valid. This method is
usually called by from_bytes
, which checks the necessary preconditions.
Provided Methods
fn from_bytes(bytes: (u8, U7, U7)) -> Result<Self, FromBytesError>
fn from_bytes(bytes: (u8, U7, U7)) -> Result<Self, FromBytesError>
Creates a MIDI message from the given bytes. The tuple consists of the status byte, data byte 1 and data byte 2 in exactly this order.
Errors
If the given status byte is invalid, an error will be returned.
Design
Although one could argue that calling such a function with illegal input values is a
violation of its contract, this function returns a result rather than panicking. It’s
because - unlike the functions in test_util
- this function is primarily intended
to be used in real-world situations where the bytes come from somewhere else (e.g. from a
DAW) and therefore acts a bit like a parse function where client code should be able to
recover from wrong input.
fn from_other(msg: &impl ShortMessage) -> Self
fn from_other(msg: &impl ShortMessage) -> Self
Creates this message from a MIDI message of another type.
fn channel_message(
type: ShortMessageType,
channel: Channel,
data_1: U7,
data_2: U7
) -> Self
fn channel_message(
type: ShortMessageType,
channel: Channel,
data_1: U7,
data_2: U7
) -> Self
Creates a Channel message.
Panics
This function panics if the given type is not a channel message type.
fn system_common_message(type: ShortMessageType, data_1: U7, data_2: U7) -> Self
fn system_common_message(type: ShortMessageType, data_1: U7, data_2: U7) -> Self
Creates a System Common message.
Panics
This function panics if the given type is not a System Common message type.
fn system_real_time_message(type: ShortMessageType) -> Self
fn system_real_time_message(type: ShortMessageType) -> Self
Creates a System Real Time message.
Panics
This function panics if the given type is not a System Real Time message type.
Creates a Note On message.
Creates a Note Off message.
fn control_change(
channel: Channel,
controller_number: ControllerNumber,
control_value: U7
) -> Self
fn control_change(
channel: Channel,
controller_number: ControllerNumber,
control_value: U7
) -> Self
Creates a Control Change message.
fn program_change(channel: Channel, program_number: U7) -> Self
fn program_change(channel: Channel, program_number: U7) -> Self
Creates a Program Change message.
fn polyphonic_key_pressure(
channel: Channel,
key_number: KeyNumber,
pressure_amount: U7
) -> Self
fn polyphonic_key_pressure(
channel: Channel,
key_number: KeyNumber,
pressure_amount: U7
) -> Self
Creates a Polyphonic Key Pressure message.
fn channel_pressure(channel: Channel, pressure_amount: U7) -> Self
fn channel_pressure(channel: Channel, pressure_amount: U7) -> Self
Creates a Channel Pressure message.
fn pitch_bend_change(channel: Channel, pitch_bend_value: U14) -> Self
fn pitch_bend_change(channel: Channel, pitch_bend_value: U14) -> Self
Creates a Pitch Bend Change message.
fn system_exclusive_start() -> Self
fn system_exclusive_start() -> Self
Creates the start of a System Exclusive message.
fn time_code_quarter_frame(frame: TimeCodeQuarterFrame) -> Self
fn time_code_quarter_frame(frame: TimeCodeQuarterFrame) -> Self
Creates a MIDI Time Code Quarter Frame message.
fn song_position_pointer(position: U14) -> Self
fn song_position_pointer(position: U14) -> Self
Creates a Song Position Pointer message.
fn song_select(song_number: U7) -> Self
fn song_select(song_number: U7) -> Self
Creates a Song Select message.
fn tune_request() -> Self
fn tune_request() -> Self
Creates a Tune Request message.
fn system_exclusive_end() -> Self
fn system_exclusive_end() -> Self
Creates the end of a System Exclusive message.
fn timing_clock() -> Self
fn timing_clock() -> Self
Creates a Timing Clock message.
fn active_sensing() -> Self
fn active_sensing() -> Self
Creates an Active Sensing message.
fn system_reset() -> Self
fn system_reset() -> Self
Creates a System Reset message.