Struct Header

Source
pub struct Header(/* private fields */);

Implementations§

Source§

impl Header

Source

pub const unsafe fn new_unchecked(header: &clap_event_header) -> &Self

§Safety

The reference must point to a valid header of a CLAP event. i.e.

  1. The header’s field: size must indicate the correct size of the event.
  2. The header’s field: type must indicate the correct type of the event.
  3. The entire memory block of size header.size, starting from the address of header must hold a properly initialized and aligned object whose type is inferred from header.type.

This is to make possible to cast &raw const *header pointer to a pointer to the concrete event type.

Source

pub const fn as_clap_event_header(&self) -> &clap_event_header

Source

pub const fn flags(&self) -> u32

Source

pub const fn size(&self) -> u32

Source

pub const fn space_id(&self) -> u16

Source

pub const fn time(&self) -> u32

Examples found in repository?
examples/gain.rs (line 135)
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 type(&self) -> u16

Source

pub const unsafe fn note_unchecked(&self) -> Note<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: note.

Source

pub const fn note(&self) -> Result<Note<'_>, Error>

Examples found in repository?
examples/note_transpose.rs (line 76)
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    }
Source

pub const unsafe fn note_expression_unchecked(&self) -> NoteExpression<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: note_expression.

Source

pub const fn note_expression(&self) -> Result<NoteExpression<'_>, Error>

Examples found in repository?
examples/note_transpose.rs (line 82)
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    }
Source

pub const unsafe fn param_value_unchecked(&self) -> ParamValue<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: param_value.

Source

pub const fn param_value(&self) -> Result<ParamValue<'_>, Error>

Examples found in repository?
examples/state.rs (line 161)
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/gain.rs (line 140)
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 unsafe fn param_mod_unchecked(&self) -> ParamMod<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: param_mod.

Source

pub const fn param_mod(&self) -> Result<ParamMod<'_>, Error>

Source

pub const unsafe fn transport_unchecked(&self) -> Transport<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: transport.

Source

pub const fn transport(&self) -> Result<Transport<'_>, Error>

Source

pub const unsafe fn midi_unchecked(&self) -> Midi<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: midi.

Source

pub const fn midi(&self) -> Result<Midi<'_>, Error>

Examples found in repository?
examples/note_transpose.rs (line 86)
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    }
Source

pub const unsafe fn midi2_unchecked(&self) -> Midi2<'_>

§Safety

The caller must ensure that this Header has correct size and type to contain the header and the payload of event of the returned type: midi2.

Source

pub const fn midi2(&self) -> Result<Midi2<'_>, Error>

Examples found in repository?
examples/note_transpose.rs (line 90)
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    }

Trait Implementations§

Source§

impl Debug for Header

Source§

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

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

impl PartialEq for Header

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl !Sized for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

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