diff --git a/include/engine/Engine.hpp b/include/engine/Engine.hpp index 8ba19b73..08500391 100644 --- a/include/engine/Engine.hpp +++ b/include/engine/Engine.hpp @@ -26,6 +26,7 @@ struct Engine { /** Does not transfer pointer ownership. */ void addModule(Module *module); void removeModule(Module *module); + Module *getModule(int moduleId); void resetModule(Module *module); void randomizeModule(Module *module); void bypassModule(Module *module, bool bypass); diff --git a/include/engine/ParamMap.hpp b/include/engine/ParamMap.hpp index 44c61c88..7554ed05 100644 --- a/include/engine/ParamMap.hpp +++ b/include/engine/ParamMap.hpp @@ -1,7 +1,5 @@ #pragma once #include "common.hpp" -#include "math.hpp" -#include namespace rack { diff --git a/include/rack.hpp b/include/rack.hpp index 3d9a0ab7..b5233346 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -72,6 +72,7 @@ #include "engine/Module.hpp" #include "engine/Param.hpp" #include "engine/Cable.hpp" +#include "engine/ParamMap.hpp" #include "plugin/Plugin.hpp" #include "plugin/Model.hpp" diff --git a/res/Core/MIDI-Map.svg b/res/Core/MIDI-Map.svg index f136d0fa..60cc98d7 100644 --- a/res/Core/MIDI-Map.svg +++ b/res/Core/MIDI-Map.svg @@ -13,11 +13,11 @@ height="128.50069mm" viewBox="0 0 50.799999 128.50069" version="1.1" - id="svg25656" - inkscape:version="0.92.2 2405546, 2018-03-11" + id="svg22863" + inkscape:version="0.92.4 5da689c313, 2019-01-14" sodipodi:docname="MIDI-Map.svg"> + id="defs22857" /> + id="metadata22860"> @@ -59,194 +59,109 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-575.58863,33.900484)"> + transform="translate(-69.85,-117.08894)"> + d="M 69.942357,117.18265 H 120.5563 V 245.49592 H 69.942357 Z m 0,0" + id="path11771" /> + d="m 120.65,117.08894 h -50.8 v 128.50069 h 50.8 z m -0.1874,128.31328 H 70.036055 V 117.27636 H 120.4626 Z m 0,0" + id="path11773" /> - - - + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277775" + d="m 84.875617,126.36238 c 0,0.17639 0.137795,0.3197 0.314184,0.3197 0.176389,0 0.319722,-0.14331 0.319722,-0.3197 v -1.47174 l 0.567761,0.8654 c 0.06615,0.10473 0.148802,0.16537 0.270087,0.16537 0.115746,0 0.20394,-0.0606 0.270086,-0.16537 l 0.573264,-0.88194 v 1.47725 c 0,0.18191 0.143334,0.33073 0.319723,0.33073 0.181892,0 0.32519,-0.14882 0.32519,-0.33073 v -2.35368 c 0,-0.18191 -0.143298,-0.32522 -0.32519,-0.32522 h -0.07168 c -0.132291,0 -0.225989,0.0551 -0.292135,0.16536 l -0.793755,1.28985 -0.788247,-1.28433 c -0.0551,-0.0992 -0.15434,-0.17088 -0.292135,-0.17088 h -0.07165 c -0.181892,0 -0.325226,0.14331 -0.325226,0.32522 z m 0,0" + id="path21896" /> + d="m 88.621306,126.35135 c 0,0.18191 0.143333,0.33073 0.325225,0.33073 0.181893,0 0.325226,-0.14882 0.325226,-0.33073 v -2.3592 c 0,-0.1819 -0.143333,-0.32521 -0.325226,-0.32521 -0.181892,0 -0.325225,0.14331 -0.325225,0.32521 z m 0,0" + id="path21892" /> + d="m 90.050408,126.32931 c 0,0.1819 0.143334,0.32521 0.325226,0.32521 h 0.826841 c 0.931545,0 1.576458,-0.65043 1.576458,-1.48277 v -0.005 c 0,-0.83784 -0.644913,-1.47725 -1.576458,-1.47725 h -0.826841 c -0.181892,0 -0.325226,0.14882 -0.325226,0.33073 z m 0.650452,-0.26459 v -1.78593 h 0.501615 c 0.53467,0 0.892951,0.36931 0.892951,0.89296 v 0.011 c 0,0.52366 -0.358281,0.88195 -0.892951,0.88195 z m 0,0" + id="path21888" /> + d="m 93.396153,126.35135 c 0,0.18191 0.143298,0.33073 0.32519,0.33073 0.181928,0 0.325226,-0.14882 0.325226,-0.33073 v -2.3592 c 0,-0.1819 -0.143298,-0.32521 -0.325226,-0.32521 -0.181892,0 -0.32519,0.14331 -0.32519,0.32521 z m 0,0" + id="path21884" /> + d="m 95.007924,125.65131 h 0.733107 c 0.170886,0 0.314184,-0.1378 0.314184,-0.30868 0,-0.17088 -0.143298,-0.30868 -0.314184,-0.30868 h -0.733107 c -0.170886,0 -0.308681,0.1378 -0.308681,0.30868 0,0.17088 0.137795,0.30868 0.308681,0.30868 z m 0,0" + id="path21880" /> + d="m 96.693427,126.36238 c 0,0.17639 0.137829,0.3197 0.314219,0.3197 0.176387,0 0.319685,-0.14331 0.319685,-0.3197 v -1.47174 l 0.567762,0.8654 c 0.06615,0.10473 0.148836,0.16537 0.270086,0.16537 0.115748,0 0.203941,-0.0606 0.270087,-0.16537 l 0.573265,-0.88194 v 1.47725 c 0,0.18191 0.143332,0.33073 0.319722,0.33073 0.181891,0 0.325226,-0.14882 0.325226,-0.33073 v -2.35368 c 0,-0.18191 -0.143335,-0.32522 -0.325226,-0.32522 h -0.07165 c -0.132292,0 -0.226026,0.0551 -0.292171,0.16536 l -0.793749,1.28985 -0.788213,-1.28433 c -0.05514,-0.0992 -0.154339,-0.17088 -0.292168,-0.17088 h -0.07165 c -0.181893,0 -0.325225,0.14331 -0.325225,0.32522 z m 0,0" + id="path21872" /> + d="m 100.13439,126.3734 c 0,0.17088 0.12678,0.30868 0.29767,0.30868 0.13779,0 0.24804,-0.0772 0.30314,-0.20394 l 0.20398,-0.49059 h 1.30637 l 0.19843,0.46854 c 0.0606,0.13229 0.15985,0.22599 0.31419,0.22599 0.17088,0 0.30868,-0.14331 0.30868,-0.31419 0,-0.0441 -0.0109,-0.0882 -0.0332,-0.13229 l -1.03629,-2.33164 c -0.0717,-0.15985 -0.19843,-0.25907 -0.37482,-0.25907 h -0.0386 c -0.17639,0 -0.30869,0.0992 -0.38033,0.25907 l -1.03079,2.33164 c -0.0219,0.0441 -0.0386,0.0937 -0.0386,0.1378 z m 1.04732,-0.95911 0.41339,-0.97565 0.40791,0.97565 z m 0,0" + id="path21876" /> + d="m 103.54924,126.35135 c 0,0.18191 0.14333,0.33073 0.32522,0.33073 0.18189,0 0.32523,-0.14882 0.32523,-0.33073 v -0.58428 h 0.49607 c 0.66146,0 1.19617,-0.35829 1.19617,-1.0418 v -0.011 c 0,-0.60633 -0.42997,-1.02526 -1.13552,-1.02526 h -0.88195 c -0.18189,0 -0.32522,0.14883 -0.32522,0.33073 z m 0.65045,-1.16306 v -0.9095 h 0.50161 c 0.32519,0 0.52917,0.15985 0.52917,0.45199 v 0.005 c 0,0.25356 -0.18743,0.452 -0.51816,0.452 z m 0,0" + id="path21868" /> + style="fill:#ffd714;fill-opacity:1;stroke:none;stroke-width:0.35277775" + d="" + id="path21860" /> + id="path21804" /> + id="path21824" /> + id="path21756" /> + + + + diff --git a/src/Core/CV_CC.cpp b/src/Core/CV_CC.cpp index 7027eb91..4cf4b0df 100644 --- a/src/Core/CV_CC.cpp +++ b/src/Core/CV_CC.cpp @@ -148,4 +148,3 @@ struct CV_CCWidget : ModuleWidget { Model *modelCV_CC = createModel("CV-CC"); - diff --git a/src/Core/CV_Gate.cpp b/src/Core/CV_Gate.cpp index a96b262d..c46bb88d 100644 --- a/src/Core/CV_Gate.cpp +++ b/src/Core/CV_Gate.cpp @@ -212,4 +212,3 @@ struct CV_GateWidget : ModuleWidget { Model *modelCV_Gate = createModel("CV-Gate"); - diff --git a/src/Core/MIDI_Map.cpp b/src/Core/MIDI_Map.cpp index c4b28488..00777d22 100644 --- a/src/Core/MIDI_Map.cpp +++ b/src/Core/MIDI_Map.cpp @@ -12,15 +12,12 @@ struct MIDI_Map : Module { NUM_OUTPUTS }; enum LightIds { - ENUMS(MAP_LIGHTS, 16), NUM_LIGHTS }; midi::InputQueue midiInput; int8_t values[128]; - int learningId = -1; - int learnedCcs[16] = {}; - bool mapped[16] = {}; + dsp::ExponentialFilter valueFilters[8]; MIDI_Map() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -28,47 +25,40 @@ struct MIDI_Map : Module { } void onReset() override { - for (int i = 0; i < 128; i++) { - values[i] = 0; - } - for (int i = 0; i < 16; i++) { - learnedCcs[i] = i; - } - learningId = -1; midiInput.reset(); } void step() override { - for (int i = 0; i < 16; i++) { - lights[MAP_LIGHTS + i].setBrightness(mapped[i]); - } } }; -struct CKD6Button : SvgButton { +struct MIDI_MapChoice : LedDisplayChoice { MIDI_Map *module; - int id; - CKD6Button() { - addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_0.svg"))); - addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_1.svg"))); + void setModule(MIDI_Map *module) { + this->module = module; } +}; + - void onAction(const event::Action &e) override { - module->mapped[id] ^= true; +struct MIDI_MapDisplay : MidiWidget { + void setModule(MIDI_Map *module) { + Vec pos = channelChoice->box.getBottomLeft(); + for (int i = 0; i < 8; i++) { + LedDisplaySeparator *separator = createWidget(pos); + separator->box.size.x = box.size.x; + addChild(separator); + + MIDI_MapChoice *choice = createWidget(pos); + choice->box.size.x = box.size.x; + choice->setModule(module); + addChild(choice); + pos = choice->box.getBottomLeft(); + } } }; -template -TWidget *createMapButtonCentered(math::Vec pos, MIDI_Map *module, int id) { - TWidget *o = new TWidget; - o->box.pos = pos.minus(o->box.size.div(2));; - o->module = module; - o->id = id; - return o; -} - struct MIDI_MapWidget : ModuleWidget { MIDI_MapWidget(MIDI_Map *module) { @@ -80,43 +70,8 @@ struct MIDI_MapWidget : ModuleWidget { addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addChild(createMapButtonCentered(mm2px(Vec(8, 77)), module, 0)); - addChild(createMapButtonCentered(mm2px(Vec(20, 77)), module, 1)); - addChild(createMapButtonCentered(mm2px(Vec(31, 77)), module, 2)); - addChild(createMapButtonCentered(mm2px(Vec(43, 77)), module, 3)); - addChild(createMapButtonCentered(mm2px(Vec(8, 89)), module, 4)); - addChild(createMapButtonCentered(mm2px(Vec(20, 89)), module, 5)); - addChild(createMapButtonCentered(mm2px(Vec(31, 89)), module, 6)); - addChild(createMapButtonCentered(mm2px(Vec(43, 89)), module, 7)); - addChild(createMapButtonCentered(mm2px(Vec(8, 101)), module, 8)); - addChild(createMapButtonCentered(mm2px(Vec(20, 101)), module, 9)); - addChild(createMapButtonCentered(mm2px(Vec(31, 101)), module, 10)); - addChild(createMapButtonCentered(mm2px(Vec(43, 101)), module, 11)); - addChild(createMapButtonCentered(mm2px(Vec(8, 112)), module, 12)); - addChild(createMapButtonCentered(mm2px(Vec(20, 112)), module, 13)); - addChild(createMapButtonCentered(mm2px(Vec(31, 112)), module, 14)); - addChild(createMapButtonCentered(mm2px(Vec(43, 112)), module, 15)); - - addChild(createLightCentered>(mm2px(Vec(8, 77)), module, MIDI_Map::MAP_LIGHTS + 0)); - addChild(createLightCentered>(mm2px(Vec(20, 77)), module, MIDI_Map::MAP_LIGHTS + 1)); - addChild(createLightCentered>(mm2px(Vec(31, 77)), module, MIDI_Map::MAP_LIGHTS + 2)); - addChild(createLightCentered>(mm2px(Vec(43, 77)), module, MIDI_Map::MAP_LIGHTS + 3)); - addChild(createLightCentered>(mm2px(Vec(8, 89)), module, MIDI_Map::MAP_LIGHTS + 4)); - addChild(createLightCentered>(mm2px(Vec(20, 89)), module, MIDI_Map::MAP_LIGHTS + 5)); - addChild(createLightCentered>(mm2px(Vec(31, 89)), module, MIDI_Map::MAP_LIGHTS + 6)); - addChild(createLightCentered>(mm2px(Vec(43, 89)), module, MIDI_Map::MAP_LIGHTS + 7)); - addChild(createLightCentered>(mm2px(Vec(8, 101)), module, MIDI_Map::MAP_LIGHTS + 8)); - addChild(createLightCentered>(mm2px(Vec(20, 101)), module, MIDI_Map::MAP_LIGHTS + 9)); - addChild(createLightCentered>(mm2px(Vec(31, 101)), module, MIDI_Map::MAP_LIGHTS + 10)); - addChild(createLightCentered>(mm2px(Vec(43, 101)), module, MIDI_Map::MAP_LIGHTS + 11)); - addChild(createLightCentered>(mm2px(Vec(8, 112)), module, MIDI_Map::MAP_LIGHTS + 12)); - addChild(createLightCentered>(mm2px(Vec(20, 112)), module, MIDI_Map::MAP_LIGHTS + 13)); - addChild(createLightCentered>(mm2px(Vec(31, 112)), module, MIDI_Map::MAP_LIGHTS + 14)); - addChild(createLightCentered>(mm2px(Vec(43, 112)), module, MIDI_Map::MAP_LIGHTS + 15)); - - typedef Grid16MidiWidget> TMidiWidget; - TMidiWidget *midiWidget = createWidget(mm2px(Vec(3.399621, 14.837339))); - midiWidget->box.size = mm2px(Vec(44, 54.667)); + MIDI_MapDisplay *midiWidget = createWidget(mm2px(Vec(3.4, 14.839))); + midiWidget->box.size = mm2px(Vec(43.999, 102.664)); if (module) midiWidget->midiIO = &module->midiInput; midiWidget->setModule(module); @@ -126,4 +81,3 @@ struct MIDI_MapWidget : ModuleWidget { Model *modelMIDI_Map = createModel("MIDI-Map"); - diff --git a/src/Core/plugin.hpp b/src/Core/plugin.hpp index b71ae29e..060b0eb1 100644 --- a/src/Core/plugin.hpp +++ b/src/Core/plugin.hpp @@ -23,21 +23,27 @@ struct Grid16MidiWidget : MidiWidget { LedDisplaySeparator *vSeparators[4]; TChoice *choices[4][4]; - Grid16MidiWidget() { + template + void setModule(TModule *module) { Vec pos = channelChoice->box.getBottomLeft(); // Add vSeparators for (int x = 1; x < 4; x++) { vSeparators[x] = createWidget(pos); + vSeparators[x]->box.pos.x = box.size.x / 4 * x; addChild(vSeparators[x]); } // Add hSeparators and choice widgets for (int y = 0; y < 4; y++) { hSeparators[y] = createWidget(pos); + hSeparators[y]->box.size.x = box.size.x; addChild(hSeparators[y]); for (int x = 0; x < 4; x++) { choices[x][y] = new TChoice; choices[x][y]->box.pos = pos; choices[x][y]->setId(4*y + x); + choices[x][y]->box.size.x = box.size.x / 4; + choices[x][y]->box.pos.x = box.size.x / 4 * x; + choices[x][y]->setModule(module); addChild(choices[x][y]); } pos = choices[0][y]->box.getBottomLeft(); @@ -46,29 +52,6 @@ struct Grid16MidiWidget : MidiWidget { vSeparators[x]->box.size.y = pos.y - vSeparators[x]->box.pos.y; } } - - void step() override { - MidiWidget::step(); - for (int x = 1; x < 4; x++) { - vSeparators[x]->box.pos.x = box.size.x / 4 * x; - } - for (int y = 0; y < 4; y++) { - hSeparators[y]->box.size.x = box.size.x; - for (int x = 0; x < 4; x++) { - choices[x][y]->box.size.x = box.size.x / 4; - choices[x][y]->box.pos.x = box.size.x / 4 * x; - } - } - } - - template - void setModule(TModule *module) { - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 4; x++) { - choices[x][y]->module = module; - } - } - } }; @@ -83,6 +66,10 @@ struct CcChoice : LedDisplayChoice { textOffset.y -= 4; } + void setModule(TModule *module) { + this->module = module; + } + void setId(int id) { this->id = id; } @@ -162,6 +149,10 @@ struct NoteChoice : LedDisplayChoice { this->id = id; } + void setModule(TModule *module) { + this->module = module; + } + void step() override { if (!module) return; diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index fd383425..d2890d94 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -193,6 +193,7 @@ void RackWidget::clear() { ModuleWidget *moduleWidget = dynamic_cast(w); assert(moduleWidget); removeModule(moduleWidget); + delete moduleWidget; } } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 85f6b1cf..95e72d63 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -425,8 +425,17 @@ void Engine::removeModule(Module *module) { assert(it != internal->modules.end()); // Remove the module internal->modules.erase(it); - // Remove id - module->id = -1; +} + +Module *Engine::getModule(int moduleId) { + VIPLock vipLock(internal->vipMutex); + std::lock_guard lock(internal->mutex); + // Find module + for (Module *module : internal->modules) { + if (module->id == moduleId) + return module; + } + return NULL; } void Engine::resetModule(Module *module) { @@ -527,8 +536,6 @@ void Engine::removeCable(Cable *cable) { // Remove the cable internal->cables.erase(it); Engine_updateConnected(this); - // Remove ID - cable->id = -1; } void Engine::setParam(Module *module, int paramId, float value) {