Struct Process

Source
pub struct Process { /* private fields */ }

Implementations§

Source§

impl Process

Source

pub const fn steady_time(&self) -> i64

Source

pub const fn frames_count(&self) -> u32

Examples found in repository?
examples/plugin_template.rs (line 92)
89    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
90        // The `Process` API is almost entirely `const`.
91        // The methods are cheap to call in a loop on the audio thread.
92        for i in 0..process.frames_count() as usize {
93            // Get the input signal from the main input port.
94            let in_l = process.audio_inputs(0).data32(0)[i];
95            let in_r = process.audio_inputs(0).data32(1)[i];
96
97            // Process samples. Here we simply swap left and right channels.
98            let out_l = in_r;
99            let out_r = in_l;
100
101            // Write the audio signal to the main output port.
102            process.audio_outputs(0).data32(0)[i] = out_l;
103            process.audio_outputs(0).data32(1)[i] = out_r;
104        }
105        Ok(clap::Continue)
106    }
More examples
Hide additional examples
examples/gain.rs (line 124)
121    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
122        let mut gain = f64::from_bits(self.gain.load(Ordering::Relaxed));
123
124        let nframes = process.frames_count();
125        let nev = process.in_events().size();
126        let mut ev_index = 0;
127        let mut next_ev_frame = if nev > 0 { 0 } else { nframes };
128
129        let mut i = 0;
130        while i < nframes {
131            while ev_index < nev && next_ev_frame == i {
132                {
133                    let in_events = process.in_events();
134                    let header = in_events.get(ev_index);
135                    if header.time() != i {
136                        next_ev_frame = header.time();
137                        break;
138                    }
139
140                    if let Ok(param_value) = header.param_value() {
141                        gain = param_value.value();
142                        self.gain.store(gain.to_bits(), Ordering::Release);
143                    }
144                }
145
146                ev_index += 1;
147
148                if ev_index == nev {
149                    next_ev_frame = nframes;
150                    break;
151                }
152            }
153
154            {
155                let i = i as usize;
156                let gain = gain as f32;
157
158                // Get the input signal from the main input port.
159                let in_l = process.audio_inputs(0).data32(0)[i];
160                let in_r = process.audio_inputs(0).data32(1)[i];
161
162                let smoothed = self.smoothed.tick(gain);
163                let out_l = in_l * smoothed;
164                let out_r = in_r * smoothed;
165
166                // Write the audio signal to the main output port.
167                process.audio_outputs(0).data32(0)[i] = out_l;
168                process.audio_outputs(0).data32(1)[i] = out_r;
169            }
170
171            i += 1;
172        }
173        Ok(clap::Continue)
174    }
Source

pub const fn transport(&self) -> Option<Transport<'_>>

Transport info at sample 0.

If None, then this is a free running host and no transport events will be provided.

Source

pub const fn audio_inputs_count(&self) -> u32

Source

pub const fn audio_inputs(&self, n: u32) -> AudioBuffer<'_>

§Panic

This function will panic if n is greater or equal to self.audio_input_counts().

Examples found in repository?
examples/plugin_template.rs (line 94)
89    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
90        // The `Process` API is almost entirely `const`.
91        // The methods are cheap to call in a loop on the audio thread.
92        for i in 0..process.frames_count() as usize {
93            // Get the input signal from the main input port.
94            let in_l = process.audio_inputs(0).data32(0)[i];
95            let in_r = process.audio_inputs(0).data32(1)[i];
96
97            // Process samples. Here we simply swap left and right channels.
98            let out_l = in_r;
99            let out_r = in_l;
100
101            // Write the audio signal to the main output port.
102            process.audio_outputs(0).data32(0)[i] = out_l;
103            process.audio_outputs(0).data32(1)[i] = out_r;
104        }
105        Ok(clap::Continue)
106    }
More examples
Hide additional examples
examples/gain.rs (line 159)
121    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
122        let mut gain = f64::from_bits(self.gain.load(Ordering::Relaxed));
123
124        let nframes = process.frames_count();
125        let nev = process.in_events().size();
126        let mut ev_index = 0;
127        let mut next_ev_frame = if nev > 0 { 0 } else { nframes };
128
129        let mut i = 0;
130        while i < nframes {
131            while ev_index < nev && next_ev_frame == i {
132                {
133                    let in_events = process.in_events();
134                    let header = in_events.get(ev_index);
135                    if header.time() != i {
136                        next_ev_frame = header.time();
137                        break;
138                    }
139
140                    if let Ok(param_value) = header.param_value() {
141                        gain = param_value.value();
142                        self.gain.store(gain.to_bits(), Ordering::Release);
143                    }
144                }
145
146                ev_index += 1;
147
148                if ev_index == nev {
149                    next_ev_frame = nframes;
150                    break;
151                }
152            }
153
154            {
155                let i = i as usize;
156                let gain = gain as f32;
157
158                // Get the input signal from the main input port.
159                let in_l = process.audio_inputs(0).data32(0)[i];
160                let in_r = process.audio_inputs(0).data32(1)[i];
161
162                let smoothed = self.smoothed.tick(gain);
163                let out_l = in_l * smoothed;
164                let out_r = in_r * smoothed;
165
166                // Write the audio signal to the main output port.
167                process.audio_outputs(0).data32(0)[i] = out_l;
168                process.audio_outputs(0).data32(1)[i] = out_r;
169            }
170
171            i += 1;
172        }
173        Ok(clap::Continue)
174    }
Source

pub const fn audio_outputs_count(&self) -> u32

Source

pub const fn audio_outputs(&mut self, n: u32) -> AudioBufferMut<'_>

§Panic

This function will panic if n is larger or equal self.audio_output_counts().

Examples found in repository?
examples/plugin_template.rs (line 102)
89    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
90        // The `Process` API is almost entirely `const`.
91        // The methods are cheap to call in a loop on the audio thread.
92        for i in 0..process.frames_count() as usize {
93            // Get the input signal from the main input port.
94            let in_l = process.audio_inputs(0).data32(0)[i];
95            let in_r = process.audio_inputs(0).data32(1)[i];
96
97            // Process samples. Here we simply swap left and right channels.
98            let out_l = in_r;
99            let out_r = in_l;
100
101            // Write the audio signal to the main output port.
102            process.audio_outputs(0).data32(0)[i] = out_l;
103            process.audio_outputs(0).data32(1)[i] = out_r;
104        }
105        Ok(clap::Continue)
106    }
More examples
Hide additional examples
examples/gain.rs (line 167)
121    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
122        let mut gain = f64::from_bits(self.gain.load(Ordering::Relaxed));
123
124        let nframes = process.frames_count();
125        let nev = process.in_events().size();
126        let mut ev_index = 0;
127        let mut next_ev_frame = if nev > 0 { 0 } else { nframes };
128
129        let mut i = 0;
130        while i < nframes {
131            while ev_index < nev && next_ev_frame == i {
132                {
133                    let in_events = process.in_events();
134                    let header = in_events.get(ev_index);
135                    if header.time() != i {
136                        next_ev_frame = header.time();
137                        break;
138                    }
139
140                    if let Ok(param_value) = header.param_value() {
141                        gain = param_value.value();
142                        self.gain.store(gain.to_bits(), Ordering::Release);
143                    }
144                }
145
146                ev_index += 1;
147
148                if ev_index == nev {
149                    next_ev_frame = nframes;
150                    break;
151                }
152            }
153
154            {
155                let i = i as usize;
156                let gain = gain as f32;
157
158                // Get the input signal from the main input port.
159                let in_l = process.audio_inputs(0).data32(0)[i];
160                let in_r = process.audio_inputs(0).data32(1)[i];
161
162                let smoothed = self.smoothed.tick(gain);
163                let out_l = in_l * smoothed;
164                let out_r = in_r * smoothed;
165
166                // Write the audio signal to the main output port.
167                process.audio_outputs(0).data32(0)[i] = out_l;
168                process.audio_outputs(0).data32(1)[i] = out_r;
169            }
170
171            i += 1;
172        }
173        Ok(clap::Continue)
174    }
Source

pub const fn in_events(&self) -> InputEvents<'_>

Examples found in repository?
examples/state.rs (line 156)
155    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
156        let in_events = process.in_events();
157
158        for i in 0..in_events.size() {
159            let header = in_events.get(i);
160
161            if let Ok(param) = header.param_value() {
162                let value = param.value();
163                let id: usize = param.param_id().into();
164
165                if id < NUM_PARAMS {
166                    self.state[id].store(value.to_bits(), Ordering::Release);
167                }
168            }
169        }
170        Ok(clap::Continue)
171    }
More examples
Hide additional examples
examples/note_transpose.rs (line 70)
69    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
70        let in_events = process.in_events();
71        let mut out_events = process.out_events();
72
73        for i in 0..in_events.size() {
74            let header = in_events.get(i);
75
76            if let Ok(note) = header.note() {
77                use clap::EventBuilder;
78                let n = note.update().key(note.key() + 7); // Transpose notes by a perfect fifth.
79                let _ = out_events.try_push(n.event());
80            }
81
82            if let Ok(note_expr) = header.note_expression() {
83                let _ = out_events.try_push(note_expr);
84            }
85
86            if let Ok(midi) = header.midi() {
87                let _ = out_events.try_push(midi);
88            }
89
90            if let Ok(midi2) = header.midi2() {
91                let _ = out_events.try_push(midi2);
92            }
93        }
94
95        Ok(clap::Continue)
96    }
examples/gain.rs (line 125)
121    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
122        let mut gain = f64::from_bits(self.gain.load(Ordering::Relaxed));
123
124        let nframes = process.frames_count();
125        let nev = process.in_events().size();
126        let mut ev_index = 0;
127        let mut next_ev_frame = if nev > 0 { 0 } else { nframes };
128
129        let mut i = 0;
130        while i < nframes {
131            while ev_index < nev && next_ev_frame == i {
132                {
133                    let in_events = process.in_events();
134                    let header = in_events.get(ev_index);
135                    if header.time() != i {
136                        next_ev_frame = header.time();
137                        break;
138                    }
139
140                    if let Ok(param_value) = header.param_value() {
141                        gain = param_value.value();
142                        self.gain.store(gain.to_bits(), Ordering::Release);
143                    }
144                }
145
146                ev_index += 1;
147
148                if ev_index == nev {
149                    next_ev_frame = nframes;
150                    break;
151                }
152            }
153
154            {
155                let i = i as usize;
156                let gain = gain as f32;
157
158                // Get the input signal from the main input port.
159                let in_l = process.audio_inputs(0).data32(0)[i];
160                let in_r = process.audio_inputs(0).data32(1)[i];
161
162                let smoothed = self.smoothed.tick(gain);
163                let out_l = in_l * smoothed;
164                let out_r = in_r * smoothed;
165
166                // Write the audio signal to the main output port.
167                process.audio_outputs(0).data32(0)[i] = out_l;
168                process.audio_outputs(0).data32(1)[i] = out_r;
169            }
170
171            i += 1;
172        }
173        Ok(clap::Continue)
174    }
Source

pub fn out_events(&self) -> OutputEvents<'_>

Examples found in repository?
examples/note_transpose.rs (line 71)
69    fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
70        let in_events = process.in_events();
71        let mut out_events = process.out_events();
72
73        for i in 0..in_events.size() {
74            let header = in_events.get(i);
75
76            if let Ok(note) = header.note() {
77                use clap::EventBuilder;
78                let n = note.update().key(note.key() + 7); // Transpose notes by a perfect fifth.
79                let _ = out_events.try_push(n.event());
80            }
81
82            if let Ok(note_expr) = header.note_expression() {
83                let _ = out_events.try_push(note_expr);
84            }
85
86            if let Ok(midi) = header.midi() {
87                let _ = out_events.try_push(midi);
88            }
89
90            if let Ok(midi2) = header.midi2() {
91                let _ = out_events.try_push(midi2);
92            }
93        }
94
95        Ok(clap::Continue)
96    }

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