MidiEvent

Struct MidiEvent 

Source
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: u4

The channel this event is to be sent to.

§message: MidiMessage

The message body.

Implementations§

Source§

impl MidiEvent

Source

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.

Source§

impl MidiEvent

Source

pub fn write<W: Write>(&self, w: &mut W) -> Result<()>

Writes a valid MIDI message to the given io::Write.

Trait Implementations§

Source§

impl Clone for MidiEvent

Source§

fn clone(&self) -> MidiEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MidiEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for MidiEvent

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MidiEvent

Source§

fn eq(&self, other: &MidiEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for MidiEvent

Source§

impl Eq for MidiEvent

Source§

impl StructuralPartialEq for MidiEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.