pub struct MidiEvent {
pub channel: u4,
pub message: MidiMessage,
}Expand description
Represents a MIDI message. An instance of this type can sometimes be converted from a TrackEventKind with the TryFrom trait. This type can be fed to a synthesizer.
§Examples
ⓘ
// An instance of this type can be sent to a synthesizer like this.
let msg: MidiEvent = /* ... */;
let mut buf = Vec::new();
msg.write(&mut buf)?;
// Now `buf` contains a valid MIDI message, send it to a MIDI api like `midir::MidiOutputConnection`.Fields§
§channel: u4The channel this event is to be sent to.
message: MidiMessageThe message body.
Implementations§
Source§impl MidiEvent
impl MidiEvent
Sourcepub fn transposed(self, shift: i8, transpose_ch9: bool) -> Option<Self>
pub fn transposed(self, shift: i8, transpose_ch9: bool) -> Option<Self>
Transposes self shift amount of half-steps.
Only MIDI events with keys are transposed, others are left as is.
§Notes
Normally MIDI channel 10 (index 9) is reserved for drums and MIDI keys on that channel mean not pitch but instrument/timber.
So transposing them is often not desirable.
If you still want to transpose the channel 9, set transpose_ch9 to true.
§Return Value
This function is lossy: MIDI notes can’t exceed 127 or go below 0 so when that happens, this function returns None, otherwise it returns the transposed event.
Trait Implementations§
impl Copy for MidiEvent
impl Eq for MidiEvent
impl StructuralPartialEq for MidiEvent
Auto Trait Implementations§
impl Freeze for MidiEvent
impl RefUnwindSafe for MidiEvent
impl Send for MidiEvent
impl Sync for MidiEvent
impl Unpin for MidiEvent
impl UnwindSafe for MidiEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more