OutputPortHandle

Struct OutputPortHandle 

Source
pub struct OutputPortHandle<SampleType> { /* private fields */ }

Implementations§

Source§

impl<SampleType> OutputPortHandle<SampleType>

Source

pub fn get_write_buffer<'a>( &self, nframes: NumFrames, _ctx: &'a CallbackContext, ) -> &'a mut [SampleType]

Get the input port’s readable buffer

Examples found in repository?
examples/thru.rs (line 36)
32    fn process(&mut self, ctx: &jack::CallbackContext, nframes: jack::NumFrames) -> i32 {
33        // for each of our inputs and outputs, copy the input buffer into the output buffer
34        for index in 0..self.inputs.len() {
35            let i = self.inputs[index].get_read_buffer(nframes, ctx);
36            let o = self.outputs[index].get_write_buffer(nframes, ctx);
37            o.clone_from_slice(i);
38        }
39
40
41        // return 0 so jack lets us keep running
42        0
43    }
More examples
Hide additional examples
examples/simple_client.rs (line 73)
71    fn process(&mut self, ctx: &jack::CallbackContext, nframes: jack::NumFrames) -> i32 {
72        // get the ports
73        let right = self.right_output.get_write_buffer(nframes, ctx);
74        let left  = self.left_output.get_write_buffer(nframes, ctx);
75
76        // for every frame, write our current progress
77        for i in 0..(nframes as usize) {
78            right[i] = self.samples[self.right_phase];
79            left[i]  = self.samples[self.left_phase];
80
81            // adjust the phases, keep left and right out of sync
82            self.right_phase = self.right_phase + 1;
83            self.left_phase  = self.left_phase + 3;
84
85            if self.right_phase >= self.samples.len() {
86                self.right_phase = 0
87            }
88
89            if self.left_phase >= self.samples.len() {
90                self.left_phase = 0
91            }
92        }
93
94        // try to update the samples, if we need to
95        match self.incoming.try_recv() {
96            Ok(samples) => self.samples = samples,
97            Err(_) => (),
98        };
99
100        0
101    }
examples/midi_sine.rs (line 99)
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<SampleType: Clone> Clone for OutputPortHandle<SampleType>

Source§

fn clone(&self) -> OutputPortHandle<SampleType>

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<SampleType: Debug> Debug for OutputPortHandle<SampleType>

Source§

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

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

impl<SampleType> Port for OutputPortHandle<SampleType>

Source§

fn get_name(&self) -> String

Gets the port’s assigned full name (including the client name and the colon)
Source§

fn get_port_flags(&self) -> PortFlags

Get the flags used to construct this port
Source§

impl<SampleType: Copy> Copy for OutputPortHandle<SampleType>

Auto Trait Implementations§

§

impl<SampleType> Freeze for OutputPortHandle<SampleType>

§

impl<SampleType> RefUnwindSafe for OutputPortHandle<SampleType>
where SampleType: RefUnwindSafe,

§

impl<SampleType> !Send for OutputPortHandle<SampleType>

§

impl<SampleType> !Sync for OutputPortHandle<SampleType>

§

impl<SampleType> Unpin for OutputPortHandle<SampleType>
where SampleType: Unpin,

§

impl<SampleType> UnwindSafe for OutputPortHandle<SampleType>
where SampleType: UnwindSafe,

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