clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 5d1f16b64aa2f9f0beddafe975c79adfd770e1ba
parent 8beec77e3944b1fc29d44ca4bc15eac69d531d97
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Sun,  4 Dec 2022 15:51:14 +0100

Merge pull request #229 from Trinitou/f/pluginActions

Triggers extension 
Diffstat:
Minclude/clap/events.h | 18++++++++++++++++++
Ainclude/clap/ext/draft/triggers.h | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/include/clap/events.h b/include/clap/events.h @@ -113,6 +113,10 @@ enum { CLAP_EVENT_MIDI, // raw midi event; clap_event_midi CLAP_EVENT_MIDI_SYSEX, // raw midi sysex event; clap_event_midi_sysex CLAP_EVENT_MIDI2, // raw midi 2 event; clap_event_midi2 + + // Represents a trigger. + // Uses clap_event_trigger. + CLAP_EVENT_TRIGGER, }; // Note on, off, end and choke events. @@ -259,6 +263,20 @@ typedef struct clap_event_midi2 { uint32_t data[4]; } clap_event_midi2_t; +typedef struct clap_event_trigger { + clap_event_header_t header; + + // target trigger + clap_id trigger_id; // @ref clap_trigger_info.id + void *cookie; // @ref clap_trigger_info.cookie + + // target a specific note_id, port, key and channel, -1 for global + int32_t note_id; + int16_t port_index; + int16_t channel; + int16_t key; +} clap_event_trigger_t; + // Input event list, events must be sorted by time. typedef struct clap_input_events { void *ctx; // reserved pointer for the list diff --git a/include/clap/ext/draft/triggers.h b/include/clap/ext/draft/triggers.h @@ -0,0 +1,113 @@ +#pragma once + +#include "../../plugin.h" +#include "../string-sizes.h" + +static CLAP_CONSTEXPR const char CLAP_EXT_TRIGGERS[] = "clap.triggers.draft/0"; + +#ifdef __cplusplus +extern "C" { +#endif + +/// @page Trigger events +/// +/// This extension enables the plugin to expose a set of triggers to the host. +/// +/// Some examples for triggers: +/// - start recording into a plugin-internal audio/note buffer +/// - trigger a retrospective audio/note looper +/// - trigger a sample-and-hold unit (maybe even per-voice) +/// - trigger an envelope during voice lifetime + +enum { + // Does this trigger support per note automations? + CLAP_TRIGGER_IS_AUTOMATABLE_PER_NOTE_ID = 1 << 0, + + // Does this trigger support per key automations? + CLAP_TRIGGER_IS_AUTOMATABLE_PER_KEY = 1 << 1, + + // Does this trigger support per channel automations? + CLAP_TRIGGER_IS_AUTOMATABLE_PER_CHANNEL = 1 << 2, + + // Does this trigger support per port automations? + CLAP_TRIGGER_IS_AUTOMATABLE_PER_PORT = 1 << 3, +}; +typedef uint32_t clap_trigger_info_flags; + +/* This describes a trigger */ +typedef struct clap_trigger_info { + // stable trigger identifier, it must never change. + clap_id id; + + clap_trigger_info_flags flags; + + // in analogy to clap_param_info.cookie + void *cookie; + + // displayable name + char name[CLAP_NAME_SIZE]; + + // the module path containing the trigger, eg:"sequencers/seq1" + // '/' will be used as a separator to show a tree like structure. + char module[CLAP_PATH_SIZE]; +} clap_trigger_info_t; + +typedef struct clap_plugin_triggers { + // Returns the number of triggers. + // [main-thread] + uint32_t(CLAP_ABI *count)(const clap_plugin_t *plugin); + + // Copies the trigger's info to trigger_info and returns true on success. + // Returns true on success. + // [main-thread] + bool(CLAP_ABI *get_info)(const clap_plugin_t *plugin, + uint32_t index, + clap_trigger_info_t *trigger_info); +} clap_plugin_triggers_t; + +enum { + // The trigger info did change, use this flag for: + // - name change + // - module change + // New info takes effect immediately. + CLAP_TRIGGER_RESCAN_INFO = 1 << 0, + + // Invalidates everything the host knows about triggers. + // It can only be used while the plugin is deactivated. + // If the plugin is activated use clap_host->restart() and delay any change until the host calls + // clap_plugin->deactivate(). + // + // You must use this flag if: + // - some triggers were added or removed. + // - some triggers had critical changes: + // - is_per_note (flag) + // - is_per_key (flag) + // - is_per_channel (flag) + // - is_per_port (flag) + // - cookie + CLAP_TRIGGER_RESCAN_ALL = 1 << 1, +}; +typedef uint32_t clap_trigger_rescan_flags; + +enum { + // Clears all possible references to a trigger + CLAP_TRIGGER_CLEAR_ALL = 1 << 0, + + // Clears all automations to a trigger + CLAP_TRIGGER_CLEAR_AUTOMATIONS = 1 << 1, +}; +typedef uint32_t clap_trigger_clear_flags; + +typedef struct clap_host_triggers { + // Rescan the full list of triggers according to the flags. + // [main-thread] + void(CLAP_ABI *rescan)(const clap_host_t *host, clap_trigger_rescan_flags flags); + + // Clears references to a trigger. + // [main-thread] + void(CLAP_ABI *clear)(const clap_host_t *host, clap_id trigger_id, clap_trigger_clear_flags flags); +} clap_host_triggers_t; + +#ifdef __cplusplus +} +#endif