Struct MidiEventRef

Source
pub struct MidiEventRef<'a> { /* private fields */ }
Expand description

A reference to a midi event contained in a MidiEventBuf These references do actually perform some logic, so a plain &MidiEvent would not be sufficient for our binding needs

Implementations§

Source§

impl<'a> MidiEventRef<'a>

Source

pub fn raw_midi_bytes(&self) -> &[u8]

Returns the raw midi data corresponding to this event

Examples found in repository?
examples/midi_sine.rs (line 111)
98    fn process(&mut self, ctx: &jack::CallbackContext, nframes: jack::NumFrames) -> i32 {
99        let output_buffer = self.output.get_write_buffer(nframes, &ctx);
100        let input_buffer  = self.input.get_read_buffer(nframes, &ctx);
101
102        let mut event_index = 0;
103        let event_count = input_buffer.len();
104
105        for i in 0..(nframes as usize) {
106            if event_index < event_count {
107                let event = input_buffer.get(event_index);
108
109                println!("evi={} evt={}, i={}", event_index, event.get_jack_time(), i);
110                if event.get_jack_time() == i as jack::NumFrames {
111                    let buf = event.raw_midi_bytes();
112
113                    if buf[0] & 0x90 == 0x90 {
114                        println!("note on!");
115                        self.note    = buf[1];
116                        self.note_on = 1.0;
117                    } else if buf[0] & 0x90 == 0x80 {
118                        println!("note off!");
119                        self.note    = buf[1];
120                        self.note_on = 0.0;
121                    }
122                    event_index += 1;
123                    if event_index < event_count {
124                        event_index += 1;
125                    }
126                }
127            }
128
129            self.ramp += self.note_freqs[self.note as usize];
130            self.ramp = if self.ramp > 1.0 { self.ramp - 2.0 } else { self.ramp };
131
132            let s = (2.0 * (consts::PI) * self.ramp).sin();
133            output_buffer[i] = self.note_on*s;
134            // println!("output_buffer[{}] = {}", i, output_buffer[i]);
135        }
136
137        match self.incoming.try_recv() {
138            Ok(freqs) => self.note_freqs = freqs,
139            Err(_) => (),
140        };
141
142        0
143    }
Source

pub fn get_jack_time(&self) -> NumFrames

Examples found in repository?
examples/midi_sine.rs (line 109)
98    fn process(&mut self, ctx: &jack::CallbackContext, nframes: jack::NumFrames) -> i32 {
99        let output_buffer = self.output.get_write_buffer(nframes, &ctx);
100        let input_buffer  = self.input.get_read_buffer(nframes, &ctx);
101
102        let mut event_index = 0;
103        let event_count = input_buffer.len();
104
105        for i in 0..(nframes as usize) {
106            if event_index < event_count {
107                let event = input_buffer.get(event_index);
108
109                println!("evi={} evt={}, i={}", event_index, event.get_jack_time(), i);
110                if event.get_jack_time() == i as jack::NumFrames {
111                    let buf = event.raw_midi_bytes();
112
113                    if buf[0] & 0x90 == 0x90 {
114                        println!("note on!");
115                        self.note    = buf[1];
116                        self.note_on = 1.0;
117                    } else if buf[0] & 0x90 == 0x80 {
118                        println!("note off!");
119                        self.note    = buf[1];
120                        self.note_on = 0.0;
121                    }
122                    event_index += 1;
123                    if event_index < event_count {
124                        event_index += 1;
125                    }
126                }
127            }
128
129            self.ramp += self.note_freqs[self.note as usize];
130            self.ramp = if self.ramp > 1.0 { self.ramp - 2.0 } else { self.ramp };
131
132            let s = (2.0 * (consts::PI) * self.ramp).sin();
133            output_buffer[i] = self.note_on*s;
134            // println!("output_buffer[{}] = {}", i, output_buffer[i]);
135        }
136
137        match self.incoming.try_recv() {
138            Ok(freqs) => self.note_freqs = freqs,
139            Err(_) => (),
140        };
141
142        0
143    }

Trait Implementations§

Source§

impl<'a> Debug for MidiEventRef<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MidiEventRef<'a>

§

impl<'a> RefUnwindSafe for MidiEventRef<'a>

§

impl<'a> !Send for MidiEventRef<'a>

§

impl<'a> !Sync for MidiEventRef<'a>

§

impl<'a> Unpin for MidiEventRef<'a>

§

impl<'a> UnwindSafe for MidiEventRef<'a>

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> 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, 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.