Skip to main content

MidiEvent

Struct MidiEvent 

Source
pub struct MidiEvent {
    pub frame: u64,
    pub kind: MidiEventKind,
}
Expand description

One MIDI event at an absolute sample frame of the render.

Fields§

§frame: u64§kind: MidiEventKind

Implementations§

Source§

impl MidiEvent

Source

pub fn note_on(frame: u64, channel: u8, key: u8, velocity: f32) -> MidiEvent

Examples found in repository?
examples/render_note.rs (line 24)
10fn main() {
11    let args: Vec<String> = std::env::args().skip(1).collect();
12    if args.len() < 2 {
13        eprintln!("usage: render_note <plugin> <out.wav> [midi key] [param=value ...]");
14        std::process::exit(2);
15    }
16    let plugin = PluginRef::resolve(&args[0], &[]).unwrap_or_else(|e| {
17        eprintln!("{e}");
18        std::process::exit(e.exit_code)
19    });
20    let key: u8 = args.get(2).and_then(|k| k.parse().ok()).unwrap_or(60);
21    let params =
22        args.iter().skip(3).filter_map(|kv| kv.split_once('=').map(|(k, v)| (k.to_string(), v.to_string()))).collect();
23    let sr = 48000u32;
24    let events = [MidiEvent::note_on(sr as u64 / 10, 0, key, 0.8), MidiEvent::note_off(sr as u64, 0, key)];
25    let opts = PluginOptions { params, ..Default::default() };
26    match render_instrument_with(&plugin, &events, sr, 2.0, &opts) {
27        Ok(run) => {
28            let a = &run.audio;
29            let onset = a.data[0].iter().position(|v| v.abs() > 1e-4);
30            println!(
31                "{} ({}): {} frames, peak {:.3}, first sound at frame {:?} (note at {}), latency {}",
32                plugin.name,
33                plugin.format,
34                a.frames(),
35                a.peak(),
36                onset,
37                sr / 10,
38                run.latency
39            );
40            std::fs::write(&args[1], ferraus_core::wav::encode(a, 32, true).expect("encode")).expect("write");
41        }
42        Err(e) => {
43            eprintln!("{e}");
44            std::process::exit(e.exit_code);
45        }
46    }
47}
Source

pub fn note_off(frame: u64, channel: u8, key: u8) -> MidiEvent

Examples found in repository?
examples/render_note.rs (line 24)
10fn main() {
11    let args: Vec<String> = std::env::args().skip(1).collect();
12    if args.len() < 2 {
13        eprintln!("usage: render_note <plugin> <out.wav> [midi key] [param=value ...]");
14        std::process::exit(2);
15    }
16    let plugin = PluginRef::resolve(&args[0], &[]).unwrap_or_else(|e| {
17        eprintln!("{e}");
18        std::process::exit(e.exit_code)
19    });
20    let key: u8 = args.get(2).and_then(|k| k.parse().ok()).unwrap_or(60);
21    let params =
22        args.iter().skip(3).filter_map(|kv| kv.split_once('=').map(|(k, v)| (k.to_string(), v.to_string()))).collect();
23    let sr = 48000u32;
24    let events = [MidiEvent::note_on(sr as u64 / 10, 0, key, 0.8), MidiEvent::note_off(sr as u64, 0, key)];
25    let opts = PluginOptions { params, ..Default::default() };
26    match render_instrument_with(&plugin, &events, sr, 2.0, &opts) {
27        Ok(run) => {
28            let a = &run.audio;
29            let onset = a.data[0].iter().position(|v| v.abs() > 1e-4);
30            println!(
31                "{} ({}): {} frames, peak {:.3}, first sound at frame {:?} (note at {}), latency {}",
32                plugin.name,
33                plugin.format,
34                a.frames(),
35                a.peak(),
36                onset,
37                sr / 10,
38                run.latency
39            );
40            std::fs::write(&args[1], ferraus_core::wav::encode(a, 32, true).expect("encode")).expect("write");
41        }
42        Err(e) => {
43            eprintln!("{e}");
44            std::process::exit(e.exit_code);
45        }
46    }
47}

Trait Implementations§

Source§

impl Clone for MidiEvent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for MidiEvent

Source§

impl Debug for MidiEvent

Source§

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

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

impl PartialEq for MidiEvent

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.