Skip to content

Commit

Permalink
set heavy context after hw.init()
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Jun 13, 2024
1 parent 551586c commit 11140f6
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions hvcc/generators/c2daisy/templates/HeavyDaisy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace daisy;

json2daisy::Daisy{{ class_name|capitalize }} hardware;

Heavy_{{patch_name}} hv(SAMPLE_RATE, {{pool_sizes_kb.internal}}, {{pool_sizes_kb.inputQueue}}, {{pool_sizes_kb.outputQueue}});
Heavy_{{patch_name}}* hv;

void audiocallback(daisy::AudioHandle::InputBuffer in, daisy::AudioHandle::OutputBuffer out, size_t size);
static void sendHook(HeavyContextInterface *c, const char *receiverName, uint32_t receiverHash, const HvMessage * m);
Expand All @@ -50,8 +50,8 @@ daisy::MidiUsbHandler midiusb;
{% endif %}
// int midiOutCount;
// uint8_t* midiOutData;
void CallbackWriteIn(Heavy_{{patch_name}}& hv);
void LoopWriteIn(Heavy_{{patch_name}}& hv);
void CallbackWriteIn(HeavyContext& hv);
void LoopWriteIn(HeavyContext& hv);
void CallbackWriteOut();
void LoopWriteOut();
void PostProcess();
Expand Down Expand Up @@ -100,7 +100,7 @@ DaisyHvParamOut DaisyOutputParameters[DaisyNumOutputParameters] = {
void HandleMidiMessage(MidiEvent m)
{
for (int i = 0; i <= 2; ++i) {
hv.sendMessageToReceiverV(HV_HASH_MIDIIN, 0, "ff",
hv->sendMessageToReceiverV(HV_HASH_MIDIIN, 0, "ff",
(float) m.data[i],
(float) m.channel);
}
Expand Down Expand Up @@ -132,52 +132,52 @@ void HandleMidiMessage(MidiEvent m)
break;
}

hv.sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, "ff",
hv->sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, "ff",
(float) srtType);
break;
}
case NoteOff: {
NoteOnEvent p = m.AsNoteOn();
hv.sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
hv->sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
(float) p.note, // pitch
(float) 0, // velocity
(float) p.channel);
break;
}
case NoteOn: {
NoteOnEvent p = m.AsNoteOn();
hv.sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
hv->sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
(float) p.note, // pitch
(float) p.velocity, // velocity
(float) p.channel);
break;
}
case PolyphonicKeyPressure: { // polyphonic aftertouch
PolyphonicKeyPressureEvent p = m.AsPolyphonicKeyPressure();
hv.sendMessageToReceiverV(HV_HASH_POLYTOUCHIN, 0, "fff",
hv->sendMessageToReceiverV(HV_HASH_POLYTOUCHIN, 0, "fff",
(float) p.pressure, // pressure
(float) p.note, // note
(float) p.channel);
break;
}
case ControlChange: {
ControlChangeEvent p = m.AsControlChange();
hv.sendMessageToReceiverV(HV_HASH_CTLIN, 0, "fff",
hv->sendMessageToReceiverV(HV_HASH_CTLIN, 0, "fff",
(float) p.value, // value
(float) p.control_number, // cc number
(float) p.channel);
break;
}
case ProgramChange: {
ProgramChangeEvent p = m.AsProgramChange();
hv.sendMessageToReceiverV(HV_HASH_PGMIN, 0, "ff",
hv->sendMessageToReceiverV(HV_HASH_PGMIN, 0, "ff",
(float) p.program,
(float) p.channel);
break;
}
case ChannelPressure: {
ChannelPressureEvent p = m.AsChannelPressure();
hv.sendMessageToReceiverV(HV_HASH_TOUCHIN, 0, "ff",
hv->sendMessageToReceiverV(HV_HASH_TOUCHIN, 0, "ff",
(float) p.pressure,
(float) p.channel);
break;
Expand All @@ -186,7 +186,7 @@ void HandleMidiMessage(MidiEvent m)
PitchBendEvent p = m.AsPitchBend();
// combine 7bit lsb and msb into 32bit int
hv_uint32_t value = (((hv_uint32_t) m.data[1]) << 7) | ((hv_uint32_t) m.data[0]);
hv.sendMessageToReceiverV(HV_HASH_BENDIN, 0, "ff",
hv->sendMessageToReceiverV(HV_HASH_BENDIN, 0, "ff",
(float) value,
(float) p.channel);
break;
Expand All @@ -200,6 +200,8 @@ void HandleMidiMessage(MidiEvent m)
int main(void)
{
hardware.Init(true);
hv = new Heavy_{{patch_name}}(SAMPLE_RATE, {{pool_sizes_kb.internal}}, {{pool_sizes_kb.inputQueue}}, {{pool_sizes_kb.outputQueue}});

{% if samplerate %}
hardware.SetAudioSampleRate({{samplerate}});
{% endif %}
Expand All @@ -220,12 +222,12 @@ int main(void)
hardware.StartAudio(audiocallback);
{% if debug_printing %}
hardware.som.StartLog();
hv.setPrintHook(printHook);
hv->setPrintHook(printHook);

uint32_t now = System::GetNow();
uint32_t log_time = System::GetNow();
{% endif %}
hv.setSendHook(sendHook);
hv->setSendHook(sendHook);

for(;;)
{
Expand All @@ -250,7 +252,7 @@ int main(void)
{% endif %}
Display();
{% if loop_write_in|length > 0 %}
LoopWriteIn(hv);
LoopWriteIn(*hv);
{% endif %}
{% if output_parameters|length > 0 %}
LoopWriteOut();
Expand Down Expand Up @@ -286,9 +288,9 @@ void audiocallback(daisy::AudioHandle::InputBuffer in, daisy::AudioHandle::Outpu
{% endif %}
{% if parameters|length > 0 %}
hardware.ProcessAllControls();
CallbackWriteIn(hv);
CallbackWriteIn(*hv);
{% endif %}
hv.process((float**)in, (float**)out, size);
hv->process((float**)in, (float**)out, size);
{% if output_parameters|length > 0 %}
CallbackWriteOut();
{% endif %}
Expand Down Expand Up @@ -472,7 +474,7 @@ static void printHook(HeavyContextInterface *c, const char *printLabel, const ch
/** Sends signals from the Daisy hardware to the PD patch via the receive objects during the main loop
*
*/
void LoopWriteIn(Heavy_{{patch_name}}& hv)
void LoopWriteIn(HeavyContext& hv)
{
{% for param in loop_write_in %}
{% if param.bool %}
Expand All @@ -487,7 +489,7 @@ void LoopWriteIn(Heavy_{{patch_name}}& hv)
/** Sends signals from the Daisy hardware to the PD patch via the receive objects during the audio callback
*
*/
void CallbackWriteIn(Heavy_{{patch_name}}& hv)
void CallbackWriteIn(HeavyContext& hv)
{
{% for param in callback_write_in %}
{% if param.bool %}
Expand Down

0 comments on commit 11140f6

Please sign in to comment.