Skip to main content

NoteEvent

Enum NoteEvent 

Source
#[non_exhaustive]
pub enum NoteEvent<S> {
Show 18 variants NoteOn { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, velocity: f32, }, NoteOff { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, velocity: f32, }, Choke { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, }, VoiceTerminated { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, }, PolyModulation { timing: u32, voice_id: i32, poly_modulation_id: u32, normalized_offset: f32, }, MonoAutomation { timing: u32, poly_modulation_id: u32, normalized_value: f32, }, PolyPressure { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, pressure: f32, }, PolyVolume { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, gain: f32, }, PolyPan { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, pan: f32, }, PolyTuning { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, tuning: f32, }, PolyVibrato { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, vibrato: f32, }, PolyExpression { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, expression: f32, }, PolyBrightness { timing: u32, voice_id: Option<i32>, channel: u8, note: u8, brightness: f32, }, MidiChannelPressure { timing: u32, channel: u8, pressure: f32, }, MidiPitchBend { timing: u32, channel: u8, value: f32, }, MidiCC { timing: u32, channel: u8, cc: u8, value: f32, }, MidiProgramChange { timing: u32, channel: u8, program: u8, }, MidiSysEx { timing: u32, message: S, },
}
Expand description

Event for (incoming) notes. The set of supported note events depends on the value of [Plugin::MIDI_INPUT. Also check out the util module for convenient conversion functions.

S is a MIDI SysEx message type that needs to implement SysExMessage to allow converting this NoteEvent to and from raw MIDI data. () is provided as a default implementing for plugins that don’t use SysEx.

All of the timings are sample offsets within the current buffer. Out of bound timings are clamped to the current buffer’s length. All sample, channel and note numbers are zero-indexed.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

NoteOn

A note on event, available on MidiConfig::Basic and up.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§velocity: f32

The note’s velocity, in [0, 1]. Some plugin APIs may allow higher precision than the 128 levels available in MIDI.

§

NoteOff

A note off event, available on MidiConfig::Basic and up. Bitwig Studio does not provide a voice ID for this event.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§velocity: f32

The note’s velocity, in [0, 1]. Some plugin APIs may allow higher precision than the 128 levels available in MIDI.

§

Choke

A note choke event, available on MidiConfig::Basic and up. When the host sends this to the plugin, it indicates that a voice or all sound associated with a note should immediately stop playing.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§

VoiceTerminated

Sent by the plugin to the host to indicate that a voice has ended. This needs to be sent when a voice terminates when using polyphonic modulation. Otherwise you can ignore this event.

Fields

§timing: u32
§voice_id: Option<i32>

The voice’s unique identifier. Setting this allows a single voice to be terminated if the plugin allows multiple overlapping voices for a single key.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§

PolyModulation

A polyphonic modulation event, available on MidiConfig::Basic and up. This will only be sent for parameters that were decorated with the .with_poly_modulation_id() modifier, and only by supported hosts. This event contains a normalized offset value for the parameter’s current, unmodulated value. That is, an offset for the current value before monophonic modulation is applied, as polyphonic modulation overrides monophonic modulation. There are multiple ways to incorporate this polyphonic modulation into a synthesizer, but a simple way to incorporate this would work as follows:

  • By default, a voice uses the parameter’s global value, which may or may not include monophonic modulation. This is parameter.value for unsmoothed parameters, and smoothed parameters should use block smoothing so the smoothed values can be reused by multiple voices.
  • If a PolyModulation event is emitted for the voice, that voice should use the the normalized offset contained within the event to compute the voice’s modulated value and use that in place of the global value.
    • This value can be obtained by calling param.preview_plain(param.normalized_value() + event.normalized_offset). These functions automatically clamp the values as necessary.
    • If the parameter uses smoothing, then the parameter’s smoother can be copied to the voice. Smoother::set_target() can then be used to have the smoother use the modulated value.
    • One caveat with smoothing is that copying the smoother like this only works correctly if it last produced a value during the sample before the PolyModulation event. Otherwise there may still be an audible jump in parameter values. A solution for this would be to first call the Smoother::reset() with the current sample’s global value before calling set_target().
    • Finally, if the polyphonic modulation happens on the same sample as the NoteOn event, then the smoothing should not start at the current global value. In this case, reset() should be called with the voice’s modulated value.
  • If a MonoAutomation event is emitted for a parameter, then the values or target values (if the parameter uses smoothing) for all voices must be updated. The normalized value from the MonoAutomation and the voice’s normalized modulation offset must be added and converted back to a plain value. This value can be used directly for unsmoothed parameters, or passed to set_target() for smoothed parameters. The global value will have already been updated, so this event only serves as a notification to update polyphonic modulation.
  • When a voice ends, either because the amplitude envelope has hit zero or because the voice was stolen, the plugin must send a VoiceTerminated to the host to let it know that it can reuse the resources it used to modulate the value.

Fields

§timing: u32
§voice_id: i32

The identifier of the voice this polyphonic modulation event should affect. This voice should use the values from this and subsequent polyphonic modulation events instead of the global value.

§poly_modulation_id: u32

The ID that was set for the modulated parameter using the .with_poly_modulation_id() method.

§normalized_offset: f32

The normalized offset value. See the event’s docstring for more information.

§

MonoAutomation

A notification to inform the plugin that a polyphonically modulated parameter has received a new automation value. This is used in conjunction with the PolyModulation event. See that event’s documentation for more details. The parameter’s global value has already been updated when this event is emitted.

Fields

§timing: u32
§poly_modulation_id: u32

The ID that was set for the modulated parameter using the .with_poly_modulation_id() method.

§normalized_value: f32

The parameter’s new normalized value. This needs to be added to a voice’s normalized offset to get that voice’s modulated normalized value. See the PolyModulation event’s docstring for more information.

§

PolyPressure

A polyphonic note pressure/aftertouch event, available on MidiConfig::Basic and up. Not all hosts may support polyphonic aftertouch.

§Note

When implementing MPE support you should use MIDI channel pressure instead as polyphonic key pressure + MPE is undefined as per the MPE specification. Or as a more generic catch all, you may manually combine the polyphonic key pressure and MPE channel pressure.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§pressure: f32

The note’s pressure, in [0, 1].

§

PolyVolume

A volume expression event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§gain: f32

The note’s voltage gain ratio, where 1.0 is unity gain.

§

PolyPan

A panning expression event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§pan: f32

The note’s panning from, in [-1, 1], with -1 being panned hard left, and 1 being panned hard right.

§

PolyTuning

A tuning expression event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§tuning: f32

The note’s tuning in semitones, in [-128, 128].

§

PolyVibrato

A vibrato expression event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§vibrato: f32

The note’s vibrato amount, in [0, 1].

§

PolyExpression

A expression expression (yes, expression expression) event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§expression: f32

The note’s expression amount, in [0, 1].

§

PolyBrightness

A brightness expression event, available on MidiConfig::Basic and up. Not all hosts may support these expressions.

Fields

§timing: u32
§voice_id: Option<i32>

A unique identifier for this note, if available. Using this to refer to a note is required when allowing overlapping voices for CLAP plugins.

§channel: u8

The note’s channel, in 0..16.

§note: u8

The note’s MIDI key number, in 0..128.

§brightness: f32

The note’s brightness amount, in [0, 1].

§

MidiChannelPressure

A MIDI channel pressure event, available on MidiConfig::MidiCCs and up.

Fields

§timing: u32
§channel: u8

The affected channel, in 0..16.

§pressure: f32

The pressure, normalized to [0, 1] to match the poly pressure event.

§

MidiPitchBend

A MIDI pitch bend, available on MidiConfig::MidiCCs and up.

Fields

§timing: u32
§channel: u8

The affected channel, in 0..16.

§value: f32

The pressure, normalized to [0, 1]. 0.5 means no pitch bend.

§

MidiCC

A MIDI control change event, available on MidiConfig::MidiCCs and up.

§Note

The wrapper does not perform any special handling for two message 14-bit CCs (where the CC number is in 0..32, and the next CC is that number plus 32) or for four message RPN messages. For now you will need to handle these CCs yourself.

Fields

§timing: u32
§channel: u8

The affected channel, in 0..16.

§cc: u8

The control change number. See control_change for a list of CC numbers.

§value: f32

The CC’s value, normalized to [0, 1]. Multiply by 127 to get the original raw value.

§

MidiProgramChange

A MIDI program change event, available on MidiConfig::MidiCCs and up. VST3 plugins cannot receive these events.

Fields

§timing: u32
§channel: u8

The affected channel, in 0..16.

§program: u8

The program number, in 0..128.

§

MidiSysEx

A MIDI SysEx message supported by the plugin’s SysExMessage type, available on MidiConfig::Basic and up. If the conversion from the raw byte array fails (e.g. the plugin doesn’t support this kind of message), then this will be logged during debug builds of the plugin, and no event is emitted.

Fields

§timing: u32
§message: S

Implementations§

Source§

impl<S> NoteEvent<S>

Source

pub fn timing(&self) -> u32

Returns the sample within the current buffer this event belongs to.

Source

pub fn voice_id(&self) -> Option<i32>

Returns the event’s voice ID, if it has any.

Source

pub fn channel(&self) -> Option<u8>

Returns the event’s channel, if it has any.

Source§

impl<S: SysExMessage> NoteEvent<S>

Source

pub fn from_midi(timing: u32, midi_data: &[u8]) -> Result<Self, u8>

Parse MIDI into a NoteEvent. Supports both basic three bytes messages as well as SysEx. Will return Err(event_type) if the parsing failed.

Source

pub fn as_midi(self) -> Option<MidiResult<S>>

Create a MIDI message from this note event. Returns None if this even does not have a direct MIDI equivalent. PolyPressure will be converted to polyphonic key pressure, but the other polyphonic note expression types will not be converted to MIDI CC messages.

Source

pub fn subtract_timing(&mut self, samples: u32)

Subtract a sample offset from this event’s timing, needed to compensate for the block splitting in the VST3 wrapper implementation because all events have to be read upfront.

Trait Implementations§

Source§

impl<S: Clone> Clone for NoteEvent<S>

Source§

fn clone(&self) -> NoteEvent<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for NoteEvent<S>

Source§

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

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

impl<S: PartialEq> PartialEq for NoteEvent<S>

Source§

fn eq(&self, other: &NoteEvent<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<S: Copy> Copy for NoteEvent<S>

Source§

impl<S> StructuralPartialEq for NoteEvent<S>

Auto Trait Implementations§

§

impl<S> Freeze for NoteEvent<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for NoteEvent<S>
where S: RefUnwindSafe,

§

impl<S> Send for NoteEvent<S>
where S: Send,

§

impl<S> Sync for NoteEvent<S>
where S: Sync,

§

impl<S> Unpin for NoteEvent<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for NoteEvent<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for NoteEvent<S>
where S: 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.