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

Feature/owl polytouch #167

Merged
merged 6 commits into from
Feb 23, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=====

Next Release
-----

* OWL: add Polytouchin and Polytouchout

0.11.0
-----

Expand Down
110 changes: 58 additions & 52 deletions hvcc/generators/c2owl/templates/HeavyOwl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#define HV_HASH_NOTEIN 0x67E37CA3
#define HV_HASH_CTLIN 0x41BE0f9C
#define HV_HASH_POLYTOUCHIN 0xBC530F59
#define HV_HASH_PGMIN 0x2E1EA03D
#define HV_HASH_TOUCHIN 0x553925BD
#define HV_HASH_BENDIN 0x3083F0F7
Expand All @@ -29,6 +30,7 @@

#define HV_HASH_NOTEOUT 0xD1D4AC2
#define HV_HASH_CTLOUT 0xE5e2A040
#define HV_HASH_POLYTOUCHOUT 0xD5ACA9D1
#define HV_HASH_PGMOUT 0x8753E39E
#define HV_HASH_TOUCHOUT 0x476D4387
#define HV_HASH_BENDOUT 0xE8458013
Expand All @@ -50,10 +52,7 @@ extern "C" {
else
getProgramVector()->buttons &= ~(1<<bid);
}
static void owlPrintHook(HeavyContextInterface* ctxt,
const char *printLabel,
const char *msgString,
const HvMessage *m) {
static void owlPrintHook(HeavyContextInterface* ctxt, const char *printLabel, const char *msgString, const HvMessage *m) {
char buf[64];
char* dst = buf;
int len = strnlen(printLabel, 48);
Expand All @@ -62,19 +61,13 @@ extern "C" {
dst = stpncpy(dst, msgString, 63-len);
debugMessage(buf);
}
static void owlSendHook(HeavyContextInterface* ctxt,
const char *receiverName,
uint32_t sendHash,
const HvMessage *m);
static void owlSendHook(HeavyContextInterface* ctxt, const char *receiverName, uint32_t sendHash, const HvMessage *m);
}

class HeavyPatch : public Patch {
public:
HeavyPatch() {
context = new Heavy_owl(getSampleRate(),
HEAVY_MESSAGE_POOL_SIZE,
HEAVY_MESSAGE_IN_QUEUE_SIZE,
HEAVY_MESSAGE_OUT_QUEUE_SIZE);
context = new Heavy_owl(getSampleRate(), HEAVY_MESSAGE_POOL_SIZE, HEAVY_MESSAGE_IN_QUEUE_SIZE, HEAVY_MESSAGE_OUT_QUEUE_SIZE);
context->setUserData(this);
context->setPrintHook(&owlPrintHook);
context->setSendHook(&owlSendHook);
Expand Down Expand Up @@ -103,6 +96,7 @@ class HeavyPatch : public Patch {
uint8_t note = hv_msg_getFloat(m, 0);
uint8_t velocity = hv_msg_getFloat(m, 1);
uint8_t ch = hv_msg_getFloat(m, 2);
ch %= 16; // drop any pd "ports"
// debugMessage("noteout", note, velocity, ch);
sendMidi(MidiMessage::note(ch, note, velocity));
}
Expand All @@ -112,6 +106,7 @@ class HeavyPatch : public Patch {
uint8_t value = hv_msg_getFloat(m, 0);
uint8_t cc = hv_msg_getFloat(m, 1);
uint8_t ch = hv_msg_getFloat(m, 2);
ch %= 16;
// debugMessage("ctlout", value, cc, ch);
sendMidi(MidiMessage::cc(ch, cc, value));
}
Expand All @@ -120,27 +115,41 @@ class HeavyPatch : public Patch {
{
uint16_t value = hv_msg_getFloat(m, 0);
uint8_t ch = hv_msg_getFloat(m, 1);
ch %= 16;
// debugMessage("bendout", value, ch);
sendMidi(MidiMessage::pb(ch, value));
}
break;
case HV_HASH_POLYTOUCHOUT:
uint8_t value = hv_msg_getFloat(m, 0);
uint8_t note = hv_msg_getFloat(m, 1);
uint8_t ch = hv_msg_getFloat(m, 2);
ch %= 16;
sendMidi(MidiMessage::kp(ch, note, value));
break;
case HV_HASH_TOUCHOUT:
sendMidi(MidiMessage::cp((uint8_t)hv_msg_getFloat(m, 1), (uint8_t)hv_msg_getFloat(m, 0)));
uint8_t value = hv_msg_getFloat(m, 0);
uint8_t ch = hv_msg_getFloat(m, 1);
ch %= 16;
sendMidi(MidiMessage::cp(ch, value));
break;
case HV_HASH_PGMOUT:
sendMidi(MidiMessage::pc((uint8_t)hv_msg_getFloat(m, 1), (uint8_t)hv_msg_getFloat(m, 0)));
uint8_t value = hv_msg_getFloat(m, 0);
uint8_t ch = hv_msg_getFloat(m, 1);
ch %= 16;
sendMidi(MidiMessage::pc(ch, value));
break;
{% for param, name, typ, namehash, minvalue, maxvalue, defvalue, button in jdata if typ == 'SEND'%}
{% if button == True %}
// Button {{name}}
case HV_HASH_{{typ}}_CHANNEL_{{param}}:
setButton(BUTTON_{{param}}, (hv_msg_getFloat(m, 0)-HV_MIN_CHANNEL_{{param}})/
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}}) > 0.5);
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}}) > 0.5);
{% else %}
// Parameter {{name}}
case HV_HASH_{{typ}}_CHANNEL_{{param}}:
setParameterValue(PARAMETER_{{param}}, (hv_msg_getFloat(m, 0)-HV_MIN_CHANNEL_{{param}})/
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}}));
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}}));
{% endif %}
break;
{% endfor %}
Expand All @@ -153,43 +162,43 @@ class HeavyPatch : public Patch {
// sendMessageToReceiverV parses format and loops over args, see HeavyContext.cpp
switch(msg.getStatus()){
case CONTROL_CHANGE:
context->sendMessageToReceiverV
(HV_HASH_CTLIN, 0, "fff",
(float)msg.getControllerValue(), // value
(float)msg.getControllerNumber(), // controller number
(float)msg.getChannel());
context->sendMessageToReceiverV(HV_HASH_CTLIN, 0, "fff",
(float)msg.getControllerValue(), // value
(float)msg.getControllerNumber(), // controller number
(float)msg.getChannel());
break;
case NOTE_ON:
context->sendMessageToReceiverV
(HV_HASH_NOTEIN, 0, "fff",
(float)msg.getNote(), // pitch
(float)msg.getVelocity(), // velocity
(float)msg.getChannel());
context->sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
(float)msg.getNote(), // pitch
(float)msg.getVelocity(), // velocity
(float)msg.getChannel());
break;
case NOTE_OFF:
context->sendMessageToReceiverV
(HV_HASH_NOTEIN, 0, "fff",
(float)msg.getNote(), // pitch
0.0f, // velocity
(float)msg.getChannel());
break;
context->sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
(float)msg.getNote(), // pitch
0.0f, // velocity
(float)msg.getChannel());
break;
case POLY_KEY_PRESSURE:
context->sendMessageToReceiverV(HV_HASH_POLYTOUCHIN, 0, "fff"
(float)msg.getPolyKeyPressure(),
(float)msg.getNote(),
(float)msg.getChannel());
break
case CHANNEL_PRESSURE:
context->sendMessageToReceiverV
(HV_HASH_TOUCHIN, 0, "ff",
(float)msg.getChannelPressure(),
(float)msg.getChannel());
context->sendMessageToReceiverV(HV_HASH_TOUCHIN, 0, "ff",
(float)msg.getChannelPressure(),
(float)msg.getChannel());
break;
case PITCH_BEND_CHANGE:
context->sendMessageToReceiverV
(HV_HASH_BENDIN, 0, "ff",
(float)msg.getPitchBend(),
(float)msg.getChannel());
context->sendMessageToReceiverV(HV_HASH_BENDIN, 0, "ff",
(float)msg.getPitchBend(),
(float)msg.getChannel());
break;
case PROGRAM_CHANGE:
context->sendMessageToReceiverV
(HV_HASH_PGMIN, 0, "ff",
(float)msg.getProgramChange(),
(float)msg.getChannel());
context->sendMessageToReceiverV(HV_HASH_PGMIN, 0, "ff",
(float)msg.getProgramChange(),
(float)msg.getChannel());
break;
default:
break;
Expand All @@ -204,7 +213,7 @@ class HeavyPatch : public Patch {
// {{name}}
case BUTTON_{{param}}:
context->sendFloatToReceiver(HV_HASH_{{typ}}_CHANNEL_{{param}}, isButtonPressed(BUTTON_{{param}})*
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}})+HV_MIN_CHANNEL_{{param}});
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}})+HV_MIN_CHANNEL_{{param}});
break;
{% endfor %}
default:
Expand All @@ -217,7 +226,7 @@ class HeavyPatch : public Patch {
{% for param, name, typ, namehash, minvalue, maxvalue, defvalue, button in jdata if typ == 'RECV' and button == False %}
// {{name}}
context->sendFloatToReceiver(HV_HASH_{{typ}}_CHANNEL_{{param}}, getParameterValue(PARAMETER_{{param}})*
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}})+HV_MIN_CHANNEL_{{param}});
(HV_MAX_CHANNEL_{{param}}-HV_MIN_CHANNEL_{{param}})+HV_MIN_CHANNEL_{{param}});
{% endfor %}

_msgLock = false;
Expand All @@ -229,12 +238,9 @@ class HeavyPatch : public Patch {
HeavyContext* context;
};

static void owlSendHook(HeavyContextInterface* ctxt,
const char *receiverName,
uint32_t sendHash,
const HvMessage *m){
HeavyPatch* patch = (HeavyPatch*)ctxt->getUserData();
patch->sendCallback(sendHash, m);
static void owlSendHook(HeavyContextInterface* ctxt, const char *receiverName, uint32_t sendHash, const HvMessage *m){
HeavyPatch* patch = (HeavyPatch*)ctxt->getUserData();
patch->sendCallback(sendHash, m);
}

#endif // __HeavyPatch_hpp__
Loading