Created
May 17, 2023 22:46
-
-
Save Xenakios/d2cafd0140048e71836ef761767d2bc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ClapNoteGenerator::process(double sr, | |
int samples_to_advance,clap::helpers::EventList& outlist) | |
{ | |
// notesendfunc is a thing that deals with actually sending the output note events onwards | |
// my code is doing that in the Clap plugin event format, so the details are not | |
// super important | |
if (mustSendNoteOffs) | |
{ | |
// we were asked to immediately stop producing notes, so just send note offs for everything and bail out | |
for (auto& e : sequence) | |
{ | |
notesendfunc(0,CLAP_EVENT_NOTE_OFF,0,e.m_actual_pitch,-1,0.0); | |
} | |
return; | |
} | |
int note_gap_samples = (60.0/m_bpm * m_note_gap) * sr; | |
for (int i=0;i<samples_to_advance;++i) | |
{ | |
if (m_step_time_counter == 0) | |
{ | |
auto& step = sequence[m_sequence_counter]; | |
int note_dur_samples = (60.0/m_bpm * m_note_gap * step.m_dur_ratio) * sr; | |
step.m_count_to_note_off = note_dur_samples; | |
int mkey = step.m_pitch+m_global_transpose; | |
step.m_actual_pitch = step.m_pitch+m_global_transpose; | |
m_cur_note = mkey; | |
notesendfunc(i,CLAP_EVENT_NOTE_ON,0,mkey,-1,step.m_velo); | |
//DBG("Sent note on at buffer pos " << i << " " << mkey); | |
++m_sequence_counter; | |
if (m_sequence_counter == sequence.size()) | |
m_sequence_counter = 0; | |
} | |
// obviously pretty inefficient but shall work for now... | |
for (int j=0;j<sequence.size();++j) | |
{ | |
auto& step = sequence[j]; | |
if (step.m_count_to_note_off>0) | |
{ | |
--step.m_count_to_note_off; | |
if (step.m_count_to_note_off==0) | |
{ | |
notesendfunc(i,CLAP_EVENT_NOTE_OFF,0,step.m_actual_pitch,-1,0.0); | |
} | |
} | |
} | |
++m_step_time_counter; | |
if (m_step_time_counter == note_gap_samples) | |
m_step_time_counter = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment