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: MidiEventKindImplementations§
Source§impl MidiEvent
impl MidiEvent
Sourcepub fn note_on(frame: u64, channel: u8, key: u8, velocity: f32) -> MidiEvent
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}Sourcepub fn note_off(frame: u64, channel: u8, key: u8) -> MidiEvent
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§
impl Copy for MidiEvent
impl StructuralPartialEq for MidiEvent
Auto Trait Implementations§
impl Forget for MidiEvent
impl Freeze for MidiEvent
impl Move for MidiEvent
impl RefUnwindSafe for MidiEvent
impl Send for MidiEvent
impl Sync for MidiEvent
impl Unpin for MidiEvent
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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