Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created April 7, 2024 00:43
Show Gist options
  • Save Xenakios/2722f150e30fc08ff74af34a16bce039 to your computer and use it in GitHub Desktop.
Save Xenakios/2722f150e30fc08ff74af34a16bce039 to your computer and use it in GitHub Desktop.
void handleNextEvent(const clap_event_header_t *nextEvent, bool is_from_ui)
{
if (nextEvent->space_id != CLAP_CORE_EVENT_SPACE_ID)
return;
switch (nextEvent->type)
{
case CLAP_EVENT_NOTE_OFF:
case CLAP_EVENT_NOTE_CHOKE:
{
auto nevt = reinterpret_cast<const clap_event_note *>(nextEvent);
m_synth.stopNote(nevt->port_index, nevt->channel, nevt->key, nevt->note_id,
nevt->velocity);
break;
}
case CLAP_EVENT_NOTE_ON:
{
auto nevt = reinterpret_cast<const clap_event_note *>(nextEvent);
m_synth.startNote(nevt->port_index, nevt->channel, nevt->key, nevt->note_id,
nevt->velocity);
break;
}
case CLAP_EVENT_NOTE_EXPRESSION:
{
auto nexp = reinterpret_cast<const clap_event_note_expression *>(nextEvent);
m_synth.applyNoteExpression(nexp->port_index, nexp->channel, nexp->key, nexp->note_id,
nexp->expression_id, nexp->value);
break;
}
case CLAP_EVENT_PARAM_VALUE:
{
auto pevt = reinterpret_cast<const clap_event_param_value *>(nextEvent);
if (pevt->param_id >= 0 && pevt->param_id < numParams)
{
paramValues[pevt->param_id] = pevt->value;
m_synth.applyParameter(pevt->port_index, pevt->channel, pevt->key, pevt->note_id,
pevt->param_id, pevt->value);
if (m_gui && !is_from_ui)
{
UiMessage msg;
msg.type = CLAP_EVENT_PARAM_VALUE;
msg.parid = pevt->param_id;
msg.values[0] = pevt->value;
m_to_ui_fifo.push(msg);
}
}
break;
}
case CLAP_EVENT_PARAM_MOD:
{
auto pevt = reinterpret_cast<const clap_event_param_mod *>(nextEvent);
m_synth.applyParameterModulation(pevt->port_index, pevt->channel, pevt->key,
pevt->note_id, pevt->param_id, pevt->amount);
break;
}
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment