ComputerscarePolyModule.hpp (2734B)
1 #pragma once 2 3 using namespace rack; 4 5 struct AutoParamQuantity : ParamQuantity { 6 std::string getDisplayValueString() override { 7 std::string disp = Quantity::getDisplayValueString(); 8 return disp == "0" ? "Auto" : disp; 9 } 10 }; 11 12 struct ComputerscarePolyModule : Module { 13 int polyChannels = 16; 14 int polyChannelsKnobSetting = 0; 15 int counterPeriod = 64; 16 int counter = counterPeriod + 1; 17 18 virtual void checkCounter() { 19 counter++; 20 if (counter > counterPeriod) { 21 checkPoly(); 22 counter = 0; 23 } 24 } 25 26 virtual void checkPoly() {}; 27 }; 28 struct TinyChannelsSnapKnob: RoundKnob { 29 std::shared_ptr<Svg> manualChannelsSetSvg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-channels-empty-knob.svg")); 30 std::shared_ptr<Svg> autoChannelsSvg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-channels-empty-knob-auto-mode.svg")); 31 int prevSetting = -1; 32 int paramId = -1; 33 34 ComputerscarePolyModule *module; 35 36 TinyChannelsSnapKnob() { 37 setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-channels-empty-knob.svg"))); 38 shadow->opacity = 0.f; 39 snap = true; 40 RoundKnob(); 41 } 42 void draw(const DrawArgs& args) override { 43 if (module) { 44 int currentSetting = module->params[paramId].getValue();; 45 if (currentSetting != prevSetting) { 46 setSvg(currentSetting == 0 ? autoChannelsSvg : manualChannelsSetSvg); 47 prevSetting = currentSetting; 48 } 49 } 50 else { 51 52 } 53 RoundKnob::draw(args); 54 } 55 }; 56 57 struct PolyChannelsDisplay : SmallLetterDisplay 58 { 59 ComputerscarePolyModule *module; 60 bool controlled = false; 61 int prevChannels = -1; 62 int paramId = -1; 63 64 PolyChannelsDisplay(math::Vec pos) 65 { 66 box.pos = pos; 67 fontSize = 14; 68 letterSpacing = 1.f; 69 textAlign = 18; 70 textColor = BLACK; 71 breakRowWidth = 20; 72 SmallLetterDisplay(); 73 }; 74 void draw(const DrawArgs &args) 75 { 76 if (module) 77 { 78 int newChannels = module->polyChannels; 79 if (newChannels != prevChannels) { 80 std::string str = std::to_string(newChannels); 81 value = str; 82 prevChannels = newChannels; 83 } 84 85 } 86 else { 87 value = std::to_string((random::u32() % 16) + 1); 88 } 89 SmallLetterDisplay::draw(args); 90 } 91 }; 92 struct PolyOutputChannelsWidget : Widget { 93 ComputerscarePolyModule *module; 94 PolyChannelsDisplay *channelCountDisplay; 95 TinyChannelsSnapKnob *channelsKnob; 96 PolyOutputChannelsWidget(math::Vec pos, ComputerscarePolyModule *mod, int paramId) { 97 module = mod; 98 99 channelsKnob = createParam<TinyChannelsSnapKnob>(pos.plus(Vec(7, 3)), module, paramId); 100 channelsKnob->module = module; 101 channelsKnob->paramId = paramId; 102 103 channelCountDisplay = new PolyChannelsDisplay(pos); 104 105 channelCountDisplay->module = module; 106 107 addChild(channelsKnob); 108 addChild(channelCountDisplay); 109 } 110 };