Browse Source

Add midi learn to CC/Trigger module (hold down right mouse button on

text field and turn knob/press button)
tags/v0.5.0
ben 7 years ago
parent
commit
7b41fe9d52
2 changed files with 75 additions and 1 deletions
  1. +37
    -1
      src/core/MidiCCToCV.cpp
  2. +38
    -0
      src/core/MidiTriggerToCV.cpp

+ 37
- 1
src/core/MidiCCToCV.cpp View File

@@ -22,11 +22,13 @@ struct MIDICCToCVInterface : MidiIO, Module {
int cc[NUM_OUTPUTS]; int cc[NUM_OUTPUTS];
int ccNum[NUM_OUTPUTS]; int ccNum[NUM_OUTPUTS];
bool ccNumInited[NUM_OUTPUTS]; bool ccNumInited[NUM_OUTPUTS];
bool onFocus[NUM_OUTPUTS];


MIDICCToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { MIDICCToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
for (int i = 0; i < NUM_OUTPUTS; i++) { for (int i = 0; i < NUM_OUTPUTS; i++) {
cc[i] = 0; cc[i] = 0;
ccNum[i] = i; ccNum[i] = i;
onFocus[i] = false;
} }
} }


@@ -103,11 +105,15 @@ void MIDICCToCVInterface::processMidi(std::vector<unsigned char> msg) {
return; return;


if (status == 0xb) { if (status == 0xb) {
for (int i = 0; i < NUM_OUTPUTS; i++) {
if (onFocus[i]) {
this->ccNum[i] = data1;
}
}
for (int i = 0; i < NUM_OUTPUTS; i++) { for (int i = 0; i < NUM_OUTPUTS; i++) {
if (data1 == ccNum[i]) { if (data1 == ccNum[i]) {
this->cc[i] = data2; this->cc[i] = data2;
} }

} }
} }
} }
@@ -117,8 +123,15 @@ struct CCTextField : TextField {


void draw(NVGcontext *vg); void draw(NVGcontext *vg);


void onMouseDownOpaque(int button);

void onMouseUpOpaque(int button);

void onMouseLeave();

int *ccNum; int *ccNum;
bool *inited; bool *inited;
bool *onFocus;
}; };


void CCTextField::draw(NVGcontext *vg) { void CCTextField::draw(NVGcontext *vg) {
@@ -129,9 +142,31 @@ void CCTextField::draw(NVGcontext *vg) {
text = std::to_string(*ccNum); text = std::to_string(*ccNum);
} }


if (*onFocus) {
text = std::to_string(*ccNum);
}

TextField::draw(vg); TextField::draw(vg);
} }


void CCTextField::onMouseUpOpaque(int button) {
if (button == 1) {
*onFocus = false;
}

}

void CCTextField::onMouseDownOpaque(int button) {
if (button == 1) {
*onFocus = true;
}
}

void CCTextField::onMouseLeave() {
*onFocus = false;
}


void CCTextField::onTextChange() { void CCTextField::onTextChange() {
if (text.size() > 0) { if (text.size() > 0) {
try { try {
@@ -209,6 +244,7 @@ MIDICCToCVWidget::MIDICCToCVWidget() {
CCTextField *ccNumChoice = new CCTextField(); CCTextField *ccNumChoice = new CCTextField();
ccNumChoice->ccNum = &module->ccNum[i]; ccNumChoice->ccNum = &module->ccNum[i];
ccNumChoice->inited = &module->ccNumInited[i]; ccNumChoice->inited = &module->ccNumInited[i];
ccNumChoice->onFocus = &module->onFocus[i];
ccNumChoice->text = std::to_string(module->ccNum[i]); ccNumChoice->text = std::to_string(module->ccNum[i]);
ccNumChoice->box.pos = Vec(11 + (i % 4) * (63), yPos); ccNumChoice->box.pos = Vec(11 + (i % 4) * (63), yPos);
ccNumChoice->box.size.x = 29; ccNumChoice->box.size.x = 29;


+ 38
- 0
src/core/MidiTriggerToCV.cpp View File

@@ -25,11 +25,13 @@ struct MIDITriggerToCVInterface : MidiIO, Module {
int trigger[NUM_OUTPUTS]; int trigger[NUM_OUTPUTS];
int triggerNum[NUM_OUTPUTS]; int triggerNum[NUM_OUTPUTS];
bool triggerNumInited[NUM_OUTPUTS]; bool triggerNumInited[NUM_OUTPUTS];
bool onFocus[NUM_OUTPUTS];


MIDITriggerToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { MIDITriggerToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
for (int i = 0; i < NUM_OUTPUTS; i++) { for (int i = 0; i < NUM_OUTPUTS; i++) {
trigger[i] = 0; trigger[i] = 0;
triggerNum[i] = i; triggerNum[i] = i;
onFocus[i] = false;
} }
} }


@@ -117,6 +119,12 @@ void MIDITriggerToCVInterface::processMidi(std::vector<unsigned char> msg) {
} }


if (status == 0x9) { // note on if (status == 0x9) { // note on
for (int i = 0; i < NUM_OUTPUTS; i++) {
if (onFocus[i]) {
this->triggerNum[i] = data1;
}
}

for (int i = 0; i<NUM_OUTPUTS; i++) { for (int i = 0; i<NUM_OUTPUTS; i++) {
if (data1 == triggerNum[i]) { if (data1 == triggerNum[i]) {
trigger[i] = data2; trigger[i] = data2;
@@ -131,8 +139,16 @@ struct TriggerTextField : TextField {


void draw(NVGcontext *vg); void draw(NVGcontext *vg);


void onMouseDownOpaque(int button);

void onMouseUpOpaque(int button);

void onMouseLeave();


int *triggerNum; int *triggerNum;
bool *inited; bool *inited;
bool *onFocus;
}; };


void TriggerTextField::draw(NVGcontext *vg) { void TriggerTextField::draw(NVGcontext *vg) {
@@ -143,6 +159,10 @@ void TriggerTextField::draw(NVGcontext *vg) {
text = std::to_string(*triggerNum); text = std::to_string(*triggerNum);
} }


if (*onFocus) {
text = std::to_string(*triggerNum);
}

TextField::draw(vg); TextField::draw(vg);
} }


@@ -164,6 +184,23 @@ void TriggerTextField::onTextChange() {
}; };
} }


void TriggerTextField::onMouseUpOpaque(int button) {
if (button == 1) {
*onFocus = false;
}

}

void TriggerTextField::onMouseDownOpaque(int button) {
if (button == 1) {
*onFocus = true;
}
}

void TriggerTextField::onMouseLeave() {
*onFocus = false;
}

MIDITriggerToCVWidget::MIDITriggerToCVWidget() { MIDITriggerToCVWidget::MIDITriggerToCVWidget() {
MIDITriggerToCVInterface *module = new MIDITriggerToCVInterface(); MIDITriggerToCVInterface *module = new MIDITriggerToCVInterface();
setModule(module); setModule(module);
@@ -223,6 +260,7 @@ MIDITriggerToCVWidget::MIDITriggerToCVWidget() {
TriggerTextField *triggerNumChoice = new TriggerTextField(); TriggerTextField *triggerNumChoice = new TriggerTextField();
triggerNumChoice->triggerNum = &module->triggerNum[i]; triggerNumChoice->triggerNum = &module->triggerNum[i];
triggerNumChoice->inited = &module->triggerNumInited[i]; triggerNumChoice->inited = &module->triggerNumInited[i];
triggerNumChoice->onFocus = &module->onFocus[i];
triggerNumChoice->text = std::to_string(module->triggerNum[i]); triggerNumChoice->text = std::to_string(module->triggerNum[i]);
triggerNumChoice->box.pos = Vec(11 + (i % 4) * (63), yPos); triggerNumChoice->box.pos = Vec(11 + (i % 4) * (63), yPos);
triggerNumChoice->box.size.x = 29; triggerNumChoice->box.size.x = 29;


Loading…
Cancel
Save