Skip to content

Commit

Permalink
first tests with DPF CV ports
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Oct 11, 2023
1 parent 4fbaa17 commit 317cbe5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 46 deletions.
13 changes: 9 additions & 4 deletions hvcc/generators/c2dpf/templates/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#pragma once

#define HVCC_NUM_AUDIO_INPUTS {{num_input_channels - meta.cv.input|length if meta.cv is defined and meta.cv.input|length > 0 else num_input_channels }}
#define HVCC_NUM_AUDIO_OUTPUTS {{num_output_channels - meta.cv.output|length if meta.cv is defined and meta.cv.output|length > 0 else num_output_channels }}
#define HVCC_NUM_CV_INPUTS {{meta.cv.input|length if meta.cv is defined and meta.cv.input|length > 0 else 0 }}
#define HVCC_NUM_CV_OUTPUTS {{meta.cv.output|length if meta.cv is defined and meta.cv.output|length > 0 else 0 }}

#define DISTRHO_PLUGIN_NAME "{{name.replace('_', ' ')}}"
{%- if meta.plugin_uri is defined %}
#define DISTRHO_PLUGIN_URI "{{meta.plugin_uri}}"
Expand All @@ -13,17 +18,17 @@
{% else %}
#define DISTRHO_PLUGIN_CLAP_ID "urn.hvcc.{{name}}"
{%- endif %}
#define DISTRHO_PLUGIN_NUM_INPUTS {{num_input_channels}}
#define DISTRHO_PLUGIN_NUM_OUTPUTS {{num_output_channels}}
#define DISTRHO_PLUGIN_NUM_INPUTS HVCC_NUM_AUDIO_INPUTS + HVCC_NUM_CV_INPUTS
#define DISTRHO_PLUGIN_NUM_OUTPUTS HVCC_NUM_AUDIO_OUTPUTS + HVCC_NUM_CV_OUTPUTS
#define DISTRHO_PLUGIN_IS_SYNTH {{1 if num_output_channels > 0 and meta.midi_input is defined and meta.midi_input > 0 else 0}}
#define DISTRHO_PLUGIN_HAS_UI {{1 if meta.enable_ui is defined and meta.enable_ui is sameas true else 0}}
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_WANT_PROGRAMS 0
#define DISTRHO_PLUGIN_WANT_STATE 0
#define DISTRHO_PLUGIN_WANT_TIMEPOS 1
#define DISTRHO_PLUGIN_WANT_FULL_STATE 0
#define DISTRHO_PLUGIN_WANT_MIDI_INPUT {{meta.midi_input if meta.midi_input is defined else 1}}
#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT {{meta.midi_output if meta.midi_output is defined else 1}}
#define DISTRHO_PLUGIN_WANT_MIDI_INPUT {{meta.midi_input if meta.midi_input is defined and meta.midi_input > 0 else 0}}
#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT {{meta.midi_output if meta.midi_output is defined and meta.midi_output > 0 else 0}}
{%- if meta.lv2_info is defined %}
#define DISTRHO_PLUGIN_LV2_CATEGORY "{{meta.lv2_info}}"
{%- endif %}
Expand Down
10 changes: 6 additions & 4 deletions hvcc/generators/c2dpf/templates/HeavyDPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ static void hvPrintHookFunc(HeavyContextInterface *c, const char *printLabel, co
hv_{{name}}_free(_context);
}

{%- if meta.port_groups is defined %}

{%- if meta.port_groups is defined or meta.cv is defined %}
{% include 'HeavyDPF_PortGroups.cpp' %}
{%- endif %}


void {{class_name}}::initParameter(uint32_t index, Parameter& parameter)
{
{%- if receivers|length > 0 -%}
Expand Down Expand Up @@ -225,14 +227,14 @@ void {{class_name}}::setParameterValue(uint32_t index, float value)
// -------------------------------------------------------------------
// DPF Plugin run() loop

#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
{%- if meta.midi_input is defined and meta.midi_input == 1 %}
void {{class_name}}::run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount)
{
handleMidiInput(frames, midiEvents, midiEventCount);
#else
{% else %}
void {{class_name}}::run(const float** inputs, float** outputs, uint32_t frames)
{
#endif
{% endif %}
const TimePosition& timePos(getTimePosition());
if (timePos.playing && timePos.bbt.valid)
_context->sendMessageToReceiverV(HV_HASH_DPF_BPM, 0, "f", timePos.bbt.beatsPerMinute);
Expand Down
8 changes: 7 additions & 1 deletion hvcc/generators/c2dpf/templates/HeavyDPF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class {{class_name}} : public Plugin
{{class_name}}();
~{{class_name}}() override;

{%- if meta.midi_input is defined and meta.midi_input == 1 %}
void handleMidiInput(uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount);
{% endif %}
{%- if meta.midi_output is defined and meta.midi_output == 1 %}
void handleMidiSend(uint32_t sendHash, const HvMessage *m);
{% endif %}

protected:
// -------------------------------------------------------------------
Expand Down Expand Up @@ -104,8 +108,10 @@ class {{class_name}} : public Plugin
// Init

void initParameter(uint32_t index, Parameter& parameter) override;
{% if meta.port_groups is defined %}
{% if meta.port_groups is defined or meta.cv is defined %}
void initAudioPort(bool input, uint32_t index, AudioPort& port) override;
{%- endif %}
{% if meta.port_groups is defined %}
void initPortGroup(uint32_t groupId, PortGroup& portGroup) override;
{%- endif %}

Expand Down
89 changes: 52 additions & 37 deletions hvcc/generators/c2dpf/templates/HeavyDPF_PortGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ void {{class_name}}::initAudioPort(bool input, uint32_t index, AudioPort& port)

if (input)
{
switch (index)
{
{%- if meta.port_groups.input|length %}
{%- for group, gConfig in meta.port_groups.input.items() %}
{%- for port, value in gConfig.items() %}
switch (index)
{
{%- if meta.port_groups is defined %}
{%- if meta.port_groups.input|length %}
{%- for group, gConfig in meta.port_groups.input.items() %}
{%- for port, value in gConfig.items() %}
case {{value}}:
port.name = "Output {{port}} ({{group}})";
port.symbol = "out_{{port|lower}}_{{group|lower}}";
port.name = "Input {{port}} ({{group}})";
port.symbol = "in_{{port|lower}}_{{group|lower}}";
port.groupId = kPortGroup{{group}};
{%- if meta.cv is defined %}
{%- if meta.cv.input is defined and value in meta.cv.input %}
port.hints = kAudioPortIsCV | kCVPortHasPositiveUnipolarRange | kCVPortHasScaledRange | kCVPortIsOptional;
{%- endif %}
{%- endif %}
break;
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- else %}
{%- if num_input_channels == 2 %}
{%- else %}
{%- if num_input_channels == 2 %}
case 0:
port.name = "Input Left";
port.symbol = "in_left";
Expand All @@ -27,26 +33,33 @@ void {{class_name}}::initAudioPort(bool input, uint32_t index, AudioPort& port)
port.symbol = "in_right";
break;
port.groupId = kPortGroupStereo;
{%- endif %}
{%- endif %}
{%- endif %}
}
}
}
else
{
switch (index)
{
{%- if meta.port_groups.output|length %}
{%- for group, gConfig in meta.port_groups.output.items() %}
{%- for port, value in gConfig.items() %}
switch (index)
{
{%- if meta.port_groups is defined %}
{%- if meta.port_groups.output|length %}
{%- for group, gConfig in meta.port_groups.output.items() %}
{%- for port, value in gConfig.items() %}
case {{value}}:
port.name = "Output {{port}} ({{group}})";
port.symbol = "out_{{port|lower}}_{{group|lower}}";
port.groupId = kPortGroup{{group}};
{%- if meta.cv is defined %}
{%- if meta.cv.output is defined and value in meta.cv.output %}
port.hints = kAudioPortIsCV | kCVPortHasPositiveUnipolarRange | kCVPortHasScaledRange | kCVPortIsOptional;
{%- endif %}
{%- endif %}
break;
{%- endfor %}
{%- endfor %}
{%- endfor %}
{% else %}
{%- if num_output_channels == 2 %}
{% else %}
{%- if num_output_channels == 2 %}
case 0:
port.name = "Output Left";
port.symbol = "out_left";
Expand All @@ -55,34 +68,36 @@ void {{class_name}}::initAudioPort(bool input, uint32_t index, AudioPort& port)
port.name = "Output Right";
port.symbol = "out_right";
break;
}
port.groupId = kPortGroupStereo;
{%- endif %}
{%- endif %}
{%- endif %}
}
}
}
}


{%- if meta.port_groups is defined %}
void {{class_name}}::initPortGroup(uint32_t groupId, PortGroup& portGroup)
{
switch (groupId)
{
{%- if meta.port_groups.input|length %}
{%- for group, value in meta.port_groups.input.items() %}
case kPortGroup{{group}}:
portGroup.name = "{{group}}";
portGroup.symbol = "{{group|lower}}";
break;
{%- endfor %}
{%- endif %}
{%- if meta.port_groups.output|length %}
{%- for group, value in meta.port_groups.output.items() %}
case kPortGroup{{group}}:
portGroup.name = "{{group}}";
portGroup.symbol = "{{group|lower}}";
break;
{%- endfor %}
{%- endif %}
{%- if meta.port_groups.input|length %}
{%- for group, value in meta.port_groups.input.items() %}
case kPortGroup{{group}}:
portGroup.name = "{{group}}";
portGroup.symbol = "{{group|lower}}";
break;
{%- endfor %}
{%- endif %}
{%- if meta.port_groups.output|length %}
{%- for group, value in meta.port_groups.output.items() %}
case kPortGroup{{group}}:
portGroup.name = "{{group}}";
portGroup.symbol = "{{group|lower}}";
break;
{%- endfor %}
{%- endif %}
}
}
{%- endif %}

0 comments on commit 317cbe5

Please sign in to comment.