Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output parameters in DPF #155

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
Next Release
-----

* Core: add attributes and send type to send params
* DPF: add "read only" outputParameter type based on send params
* JS Bugfix: printHook and sendHook for AudioWorklet; mention emsdk limitations in docs
* Bugfix: stripnote missing right inlet

Expand Down
2 changes: 2 additions & 0 deletions hvcc/core/hv2ir/HIrSend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def get_ir_control_list(self) -> List:
on_message_list = [x for o in receive_objs for x in o.get_ir_on_message(inlet_index=0)]
return [{
"id": self.id,
"type": "send",
"onMessage": [on_message_list],
"extern": self.args["extern"],
"attributes": self.args["attributes"],
"hash": self.args["hash"],
"display": self.args["name"],
"name": ((f"_{self.args['name']}") if re.match(r"\d", self.args["name"]) else self.args["name"])
Expand Down
7 changes: 4 additions & 3 deletions hvcc/generators/c2dpf/c2dpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def compile(

out_dir = os.path.join(out_dir, "plugin")
receiver_list = externs['parameters']['in']
sender_list = externs["parameters"]["out"]

if patch_meta:
patch_name = patch_meta.get("name", patch_name)
Expand Down Expand Up @@ -87,6 +88,7 @@ def compile(
num_input_channels=num_input_channels,
num_output_channels=num_output_channels,
receivers=receiver_list,
senders=sender_list,
copyright=copyright_c))
dpf_cpp_path = os.path.join(source_dir, f"HeavyDPF_{patch_name}.cpp")
with open(dpf_cpp_path, "w") as f:
Expand All @@ -97,6 +99,7 @@ def compile(
num_input_channels=num_input_channels,
num_output_channels=num_output_channels,
receivers=receiver_list,
senders=sender_list,
pool_sizes_kb=externs["memoryPoolSizesKb"],
copyright=copyright_c))
if dpf_meta.get("enable_ui"):
Expand All @@ -106,9 +109,8 @@ def compile(
name=patch_name,
meta=dpf_meta,
class_name=f"HeavyDPF_{patch_name}",
num_input_channels=num_input_channels,
num_output_channels=num_output_channels,
receivers=receiver_list,
senders=sender_list,
copyright=copyright_c))
dpf_h_path = os.path.join(source_dir, "DistrhoPluginInfo.h")
with open(dpf_h_path, "w") as f:
Expand All @@ -118,7 +120,6 @@ def compile(
class_name=f"HeavyDPF_{patch_name}",
num_input_channels=num_input_channels,
num_output_channels=num_output_channels,
receivers=receiver_list,
pool_sizes_kb=externs["memoryPoolSizesKb"],
copyright=copyright_c))

Expand Down
84 changes: 27 additions & 57 deletions hvcc/generators/c2dpf/templates/HeavyDPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <set>


#define HV_LV2_NUM_PARAMETERS {{receivers|length}}
#define HV_DPF_NUM_PARAMETER {{receivers|length + senders|length}}

#define HV_HASH_NOTEIN 0x67E37CA3
#define HV_HASH_CTLIN 0x41BE0f9C
Expand Down Expand Up @@ -55,6 +55,7 @@ static void hvSendHookFunc(HeavyContextInterface *c, const char *sendName, uint3
{{class_name}}* plugin = ({{class_name}}*)c->getUserData();
if (plugin != nullptr)
{
plugin->setOutputParameter(sendHash, m);
{%- if meta.midi_output is defined and meta.midi_output == 1 %}
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
plugin->handleMidiSend(sendHash, m);
Expand All @@ -78,9 +79,9 @@ static void hvPrintHookFunc(HeavyContextInterface *c, const char *printLabel, co
// Main DPF plugin class

{{class_name}}::{{class_name}}()
: Plugin(HV_LV2_NUM_PARAMETERS, 0, 0)
: Plugin(HV_DPF_NUM_PARAMETER, 0, 0)
{
{% for k, v in receivers -%}
{% for k, v in receivers + senders -%}
_parameters[{{loop.index-1}}] = {{v.attributes.default}}f;
{% endfor %}

Expand All @@ -91,7 +92,7 @@ static void hvPrintHookFunc(HeavyContextInterface *c, const char *printLabel, co

{% if receivers|length > 0 %}
// ensure that the new context has the current parameters
for (int i = 0; i < HV_LV2_NUM_PARAMETERS; ++i) {
for (int i = 0; i < HV_DPF_NUM_PARAMETER; ++i) {
setParameterValue(i, _parameters[i]);
}
{%- endif %}
Expand All @@ -102,62 +103,18 @@ static void hvPrintHookFunc(HeavyContextInterface *c, const char *printLabel, co
}

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

void {{class_name}}::initParameter(uint32_t index, Parameter& parameter)
{
{%- if receivers|length > 0 -%}
{%- if (receivers|length > 0) or (senders|length > 0) -%}
// initialise parameters with defaults
switch (index)
{
{% for k, v in receivers -%}
case param{{v.display}}:
parameter.name = "{{v.display.replace('_', ' ')}}";
parameter.symbol = "{{v.display|lower}}";
{%- if v.attributes.type == 'db': %}
parameter.unit = "dB";
{%- elif v.attributes.type in ['hz', 'log_hz']: %}
parameter.unit = "Hz";
{%- endif %}
parameter.hints = kParameterIsAutomatable
{%- if v.attributes.type == 'bool': %}
| kParameterIsBoolean
{%- elif v.attributes.type == 'trig': -%}
| kParameterIsTrigger
{%- elif v.attributes.type == 'int': -%}
| kParameterIsInteger
{%- elif v.attributes.type in ['log', 'log_hz']: -%}
| kParameterIsLogarithmic
{%- endif %};
parameter.ranges.min = {{v.attributes.min}}f;
parameter.ranges.max = {{v.attributes.max}}f;
parameter.ranges.def = {{v.attributes.default}}f;
{%- if v.attributes.type == 'db' and not (meta.enumerators is defined and meta.enumerators[v.display] is defined): %}
{
ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[1];
enumValues[0].value = {{v.attributes.min}}f;
enumValues[0].label = "-inf";
parameter.enumValues.count = 1;
parameter.enumValues.values = enumValues;
}
{%- endif %}
{%- if meta.enumerators is defined and meta.enumerators[v.display] is defined %}
{% set enums = meta.enumerators[v.display] %}
{% set enumlen = enums|length %}
if (ParameterEnumerationValue *values = new ParameterEnumerationValue[{{enumlen}}])
{
parameter.enumValues.restrictedMode = true;
{% for i in enums -%}
values[{{loop.index - 1}}].value = {{loop.index - 1}}.0f;
values[{{loop.index - 1}}].label = "{{i}}";
{% endfor -%}
parameter.enumValues.count = {{enumlen}};
parameter.enumValues.values = values;
}
{%- endif %}
break;
{% endfor %}
{% for k, v in receivers + senders %}
{% include 'initParameter.cpp' %}
{% endfor -%}
}
{% endif %}
}
Expand All @@ -167,7 +124,7 @@ void {{class_name}}::initParameter(uint32_t index, Parameter& parameter)

float {{class_name}}::getParameterValue(uint32_t index) const
{
{%- if receivers|length > 0 %}
{%- if (receivers|length > 0) or (senders|length > 0) %}
return _parameters[index];
{% else %}
return 0.0f;
Expand All @@ -194,6 +151,19 @@ void {{class_name}}::setParameterValue(uint32_t index, float value)
{%- endif %}
}

void {{class_name}}::setOutputParameter(uint32_t sendHash, const HvMessage *m)
{
{%- if senders|length > 0 %}
switch (sendHash) {
{% for k, v in senders -%}
case {{v.hash}}: // {{v.display}}
_parameters[param{{v.display}}] = hv_msg_getFloat(m, 0);
break;
{% endfor %}
}
{%- endif %}
}


// -------------------------------------------------------------------
// Process
Expand All @@ -210,13 +180,13 @@ void {{class_name}}::setParameterValue(uint32_t index, float value)

{%- if meta.midi_input is defined and meta.midi_input == 1 %}
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
{% include 'HeavyDPF_MIDI_Input.cpp' %}
{% include 'midiInput.cpp' %}
#endif
{% endif %}

{%- if meta.midi_output is defined and meta.midi_output == 1 %}
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
{% include 'HeavyDPF_MIDI_Output.cpp' %}
{% include 'midiOutput.cpp' %}
#endif
{% endif %}

Expand Down Expand Up @@ -254,7 +224,7 @@ void {{class_name}}::sampleRateChanged(double newSampleRate)

{% if receivers|length > 0 -%}
// ensure that the new context has the current parameters
for (int i = 0; i < HV_LV2_NUM_PARAMETERS; ++i) {
for (int i = 0; i < HV_DPF_NUM_PARAMETER; ++i) {
setParameterValue(i, _parameters[i]);
}
{%- endif %}
Expand Down
8 changes: 6 additions & 2 deletions hvcc/generators/c2dpf/templates/HeavyDPF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class {{class_name}} : public Plugin
{% for k, v in receivers -%}
param{{v.display}},
{% endfor %}
{% for k, v in senders -%}
param{{v.display}},
{% endfor %}
};

{% if meta.port_groups is defined %}
Expand All @@ -44,6 +47,7 @@ class {{class_name}} : public Plugin

void handleMidiInput(uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount);
void handleMidiSend(uint32_t sendHash, const HvMessage *m);
void setOutputParameter(uint32_t sendHash, const HvMessage *m);

protected:
// -------------------------------------------------------------------
Expand Down Expand Up @@ -135,9 +139,9 @@ class {{class_name}} : public Plugin
// -------------------------------------------------------------------

private:
{%- if receivers|length > 0 %}
{%- if (receivers|length > 0) or senders|length > 0 %}
// parameters
float _parameters[{{receivers|length}}]; // in range of [0,1]
float _parameters[{{receivers|length + senders|length}}]; // in range of [0,1]
{%- endif %}

// transport values
Expand Down
16 changes: 9 additions & 7 deletions hvcc/generators/c2dpf/templates/HeavyDPF_UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
START_NAMESPACE_DISTRHO

// --------------------------------------------------------------------------------------------------------------------
{%- if receivers|length > 0 %}
{%- if (receivers|length > 0) or (senders|length > 0) %}
enum HeavyParams {
{%- for k, v in receivers %}
{%- for k, v in receivers + senders -%}
{{v.display|upper}},
{%- endfor %}
};
{%- endif %}

class ImGuiPluginUI : public UI
{
{% for k, v in receivers -%}
{% for k, v in receivers + senders -%}
{%- if v.attributes.type == 'bool': %}
bool f{{v.display|lower}} = {{v.attributes.default}}f != 0.0f;
{%- elif v.attributes.type == 'int': %}
Expand Down Expand Up @@ -56,9 +56,9 @@ class ImGuiPluginUI : public UI
*/
void parameterChanged(uint32_t index, float value) override
{
{%- if receivers|length > 0 %}
{%- if (receivers|length > 0) or (senders|length > 0) %}
switch (index) {
{% for k, v in receivers -%}
{% for k, v in receivers + senders -%}
case {{v.display|upper}}:
{%- if v.attributes.type == 'bool': %}
f{{v.display|lower}} = value != 0.0f;
Expand Down Expand Up @@ -92,7 +92,7 @@ class ImGuiPluginUI : public UI

if (ImGui::Begin("{{name.replace('_', ' ')}}", nullptr, ImGuiWindowFlags_NoResize + ImGuiWindowFlags_NoCollapse))
{
{%- for k, v in receivers %}
{%- for k, v in receivers + senders %}
{%- set v_display = v.display|lower %}
{%- if meta.enumerators is defined and meta.enumerators[v.display] is defined -%}
{%- set enums = meta.enumerators[v.display] -%}
Expand Down Expand Up @@ -130,17 +130,19 @@ class ImGuiPluginUI : public UI
if (ImGui::SliderFloat("{{v.display.replace('_', ' ')}}", &f{{v_display}}, {{v.attributes.min}}f, {{v.attributes.max}}f))
{%- endif %}
{
{%- if not v.type == "send" %}
if (ImGui::IsItemActivated())
{
editParameter({{v.display|upper}}, true);
}
setParameterValue({{v.display|upper}}, f{{v_display}});
{%- endif %}
}
{%- endif %}
{% endfor %}
if (ImGui::IsItemDeactivated())
{
{%- for k, v in receivers -%}
{% for k, v in receivers + senders -%}
editParameter({{v.display|upper}}, false);
{% endfor -%}
}
Expand Down
49 changes: 49 additions & 0 deletions hvcc/generators/c2dpf/templates/initParameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
case param{{v.display}}:
parameter.name = "{{v.display.replace('_', ' ')}}";
parameter.symbol = "{{v.display|lower}}";
{%- if v.attributes.type == 'db': %}
parameter.unit = "dB";
{%- elif v.attributes.type in ['hz', 'log_hz']: %}
parameter.unit = "Hz";
{%- endif %}
{%- if v.type == "send" %}
parameter.hints = kParameterIsOutput
{%- else %}
parameter.hints = kParameterIsAutomatable
{%- endif %}
{%- if v.attributes.type == 'bool': %}
| kParameterIsBoolean
{%- elif v.attributes.type == 'trig': -%}
| kParameterIsTrigger
{%- elif v.attributes.type == 'int': -%}
| kParameterIsInteger
{%- elif v.attributes.type in ['log', 'log_hz']: -%}
| kParameterIsLogarithmic
{%- endif %};
parameter.ranges.min = {{v.attributes.min}}f;
parameter.ranges.max = {{v.attributes.max}}f;
parameter.ranges.def = {{v.attributes.default}}f;
{%- if v.attributes.type == 'db' and not (meta.enumerators is defined and meta.enumerators[v.display] is defined): %}
{
ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[1];
enumValues[0].value = {{v.attributes.min}}f;
enumValues[0].label = "-inf";
parameter.enumValues.count = 1;
parameter.enumValues.values = enumValues;
}
{%- endif %}
{%- if meta.enumerators is defined and meta.enumerators[v.display] is defined %}
{% set enums = meta.enumerators[v.display] %}
{% set enumlen = enums|length %}
if (ParameterEnumerationValue *values = new ParameterEnumerationValue[{{enumlen}}])
{
parameter.enumValues.restrictedMode = true;
{% for i in enums -%}
values[{{loop.index - 1}}].value = {{loop.index - 1}}.0f;
values[{{loop.index - 1}}].label = "{{i}}";
{% endfor -%}
parameter.enumValues.count = {{enumlen}};
parameter.enumValues.values = values;
}
{%- endif %}
break;
Loading
Loading