Browse Source

Don't overwrite param handles when duplicating MIDI-Map.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
d699c2e07d
4 changed files with 33 additions and 19 deletions
  1. +1
    -1
      include/engine/Engine.hpp
  2. +24
    -14
      src/Core/MIDI_Map.cpp
  3. +1
    -0
      src/app/ParamWidget.cpp
  4. +7
    -4
      src/engine/Engine.cpp

+ 1
- 1
include/engine/Engine.hpp View File

@@ -63,7 +63,7 @@ struct Engine {
/** Sets the ParamHandle IDs and module pointer.
If the given ParamHandle is added to the engine and another ParamHandle points to the same param, unsets that one and replaces it with the given handle.
*/
void updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId);
void updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId, bool overwrite = true);
};




+ 24
- 14
src/Core/MIDI_Map.cpp View File

@@ -1,6 +1,9 @@
#include "plugin.hpp"


static const int CHANNELS = 8;


struct MIDI_Map : Module {
enum ParamIds {
NUM_PARAMS
@@ -23,17 +26,17 @@ struct MIDI_Map : Module {
/** Whether the param has been set during the learning session */
bool learnedParam;
/** The learned CC number of each channel */
int learnedCcs[8];
int learnedCcs[CHANNELS];
/** The learned param handle of each channel */
ParamHandle learnedParamHandles[8];
ParamHandle learnedParamHandles[CHANNELS];
/** The value of each CC number */
int8_t values[128];
/** The smoothing processor (normalized between 0 and 1) of each channel */
dsp::ExponentialFilter valueFilters[8];
dsp::ExponentialFilter valueFilters[CHANNELS];

MIDI_Map() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
APP->engine->addParamHandle(&learnedParamHandles[i]);
valueFilters[i].lambda = 60.f;
}
@@ -41,7 +44,7 @@ struct MIDI_Map : Module {
}

~MIDI_Map() {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
APP->engine->removeParamHandle(&learnedParamHandles[i]);
}
}
@@ -50,7 +53,7 @@ struct MIDI_Map : Module {
learningId = -1;
learnedCc = false;
learnedParam = false;
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
learnedCcs[i] = -1;
APP->engine->updateParamHandle(&learnedParamHandles[i], -1, 0);
valueFilters[i].reset();
@@ -70,7 +73,7 @@ struct MIDI_Map : Module {
float deltaTime = APP->engine->getSampleTime();

// Step channels
for (int id = 0; id < 8; id++) {
for (int id = 0; id < CHANNELS; id++) {
int cc = learnedCcs[id];
if (cc < 0)
continue;
@@ -128,7 +131,7 @@ struct MIDI_Map : Module {
learnedCc = false;
learnedParam = false;
// Find next unlearned channel
while (++learningId < 8) {
while (++learningId < CHANNELS) {
if (learnedCcs[learningId] < 0 || learnedParamHandles[learningId].moduleId < 0)
return;
}
@@ -156,7 +159,7 @@ struct MIDI_Map : Module {
}

void learnParam(int id, int moduleId, int paramId) {
APP->engine->updateParamHandle(&learnedParamHandles[id], moduleId, paramId);
APP->engine->updateParamHandle(&learnedParamHandles[id], moduleId, paramId, true);
learnedParam = true;
commitLearn();
}
@@ -172,7 +175,7 @@ struct MIDI_Map : Module {

json_t *moduleIdsJ = json_array();
json_t *paramIdsJ = json_array();
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
json_array_append_new(moduleIdsJ, json_integer(learnedParamHandles[i].moduleId));
json_array_append_new(paramIdsJ, json_integer(learnedParamHandles[i].paramId));
}
@@ -186,7 +189,7 @@ struct MIDI_Map : Module {
void dataFromJson(json_t *rootJ) override {
json_t *ccsJ = json_object_get(rootJ, "ccs");
if (ccsJ) {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
json_t *ccJ = json_array_get(ccsJ, i);
if (ccJ)
learnedCcs[i] = json_integer_value(ccJ);
@@ -196,11 +199,11 @@ struct MIDI_Map : Module {
json_t *moduleIdsJ = json_object_get(rootJ, "moduleIds");
json_t *paramIdsJ = json_object_get(rootJ, "paramIds");
if (moduleIdsJ && paramIdsJ) {
for (int i = 0; i < 8; i++) {
for (int i = 0; i < CHANNELS; i++) {
json_t *moduleIdJ = json_array_get(moduleIdsJ, i);
json_t *paramIdJ = json_array_get(paramIdsJ, i);
if (moduleIdJ && paramIdsJ)
APP->engine->updateParamHandle(&learnedParamHandles[i], json_integer_value(moduleIdJ), json_integer_value(paramIdJ));
APP->engine->updateParamHandle(&learnedParamHandles[i], json_integer_value(moduleIdJ), json_integer_value(paramIdJ), false);
}
}

@@ -335,8 +338,15 @@ struct MIDI_MapChoice : LedDisplayChoice {

struct MIDI_MapDisplay : MidiWidget {
void setModule(MIDI_Map *module) {
// ScrollWidget *scroll = new ScrollWidget;
// scroll->box.pos = channelChoice->box.getBottomLeft();
// scroll->box.size.x = box.size.x;
// scroll->box.size.y = box.size.y - scroll->box.pos.y;
// addChild(scroll);

Vec pos = channelChoice->box.getBottomLeft();
for (int i = 0; i < 8; i++) {

for (int i = 0; i < CHANNELS; i++) {
LedDisplaySeparator *separator = createWidget<LedDisplaySeparator>(pos);
separator->box.size.x = box.size.x;
addChild(separator);


+ 1
- 0
src/app/ParamWidget.cpp View File

@@ -165,6 +165,7 @@ void ParamWidget::draw(const widget::DrawContext &ctx) {
nvgFillColor(ctx.vg, color);
nvgFill(ctx.vg);
nvgStrokeColor(ctx.vg, color::mult(color, 0.5));
nvgStrokeWidth(ctx.vg, 1.0);
nvgStroke(ctx.vg);
}
}


+ 7
- 4
src/engine/Engine.cpp View File

@@ -589,7 +589,7 @@ void Engine::addParamHandle(ParamHandle *paramHandle) {
auto it = std::find(internal->paramHandles.begin(), internal->paramHandles.end(), paramHandle);
assert(it == internal->paramHandles.end());

updateParamHandle(paramHandle, paramHandle->moduleId, paramHandle->paramId);
assert(paramHandle->moduleId < 0);
internal->paramHandles.push_back(paramHandle);
}

@@ -615,7 +615,7 @@ ParamHandle *Engine::getParamHandle(Module *module, int paramId) {
return NULL;
}

void Engine::updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId) {
void Engine::updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId, bool overwrite) {
VIPLock vipLock(internal->vipMutex);
std::lock_guard<std::recursive_mutex> lock(internal->mutex);

@@ -630,12 +630,15 @@ void Engine::updateParamHandle(ParamHandle *paramHandle, int moduleId, int param
// Remove existing ParamHandles pointing to the same param
for (ParamHandle *p : internal->paramHandles) {
if (p != paramHandle && p->moduleId == moduleId && p->paramId == paramId) {
p->reset();
if (overwrite)
p->reset();
else
paramHandle->reset();
}
}
// Find module with same moduleId
for (Module *module : internal->modules) {
if (module->id == moduleId) {
if (module->id == paramHandle->moduleId) {
paramHandle->module = module;
}
}


Loading…
Cancel
Save