computerscare-vcv-modules

ComputerScare modules for VCV Rack
Log | Files | Refs

ComputerscareKnolyPobs.cpp (5270B)


      1 #include "Computerscare.hpp"
      2 #include "ComputerscarePolyModule.hpp"
      3 
      4 struct ComputerscareKnolyPobs;
      5 
      6 const int numKnobs = 16;
      7 const int numToggles = 16;
      8 
      9 
     10 struct ComputerscareKnolyPobs : ComputerscarePolyModule {
     11 	ComputerscareSVGPanel* panelRef;
     12 	enum ParamIds {
     13 		KNOB,
     14 		TOGGLES = KNOB + numKnobs,
     15 		POLY_CHANNELS = TOGGLES + numToggles,
     16 		GLOBAL_SCALE,
     17 		GLOBAL_OFFSET,
     18 		NUM_PARAMS
     19 
     20 	};
     21 	enum InputIds {
     22 		CHANNEL_INPUT,
     23 		NUM_INPUTS
     24 	};
     25 	enum OutputIds {
     26 		POLY_OUTPUT,
     27 		NUM_OUTPUTS
     28 	};
     29 	enum LightIds {
     30 		NUM_LIGHTS
     31 	};
     32 
     33 
     34 	ComputerscareKnolyPobs()  {
     35 
     36 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
     37 
     38 		for (int i = 0; i < numKnobs; i++) {
     39 			configParam(KNOB + i, 0.f, 10.f, 0.f, "Channel " + std::to_string(i + 1));
     40 		}
     41 		configParam(POLY_CHANNELS, 1.f, 16.f, 16.f, "Poly Channels");
     42 		configParam(GLOBAL_SCALE, -2.f, 2.f, 1.f, "Scale");
     43 		configParam(GLOBAL_OFFSET, -10.f, 10.f, 0.f, "Offset", " volts");
     44 
     45 		getParamQuantity(POLY_CHANNELS)->randomizeEnabled = false;
     46 		getParamQuantity(POLY_CHANNELS)->resetEnabled = false;
     47 		getParamQuantity(GLOBAL_SCALE)->randomizeEnabled = false;
     48 		getParamQuantity(GLOBAL_OFFSET)->randomizeEnabled = false;
     49 
     50 		configOutput(POLY_OUTPUT, "Main");
     51 
     52 	}
     53 	void process(const ProcessArgs &args) override {
     54 		ComputerscarePolyModule::checkCounter();
     55 		float trim = params[GLOBAL_SCALE].getValue();
     56 		float offset = params[GLOBAL_OFFSET].getValue();
     57 		for (int i = 0; i < polyChannels; i++) {
     58 			outputs[POLY_OUTPUT].setVoltage(params[KNOB + i].getValue()*trim + offset, i);
     59 		}
     60 	}
     61 	void checkPoly() override {
     62 		polyChannels = params[POLY_CHANNELS].getValue();
     63 		if (polyChannels == 0) {
     64 			polyChannels = 16;
     65 			params[POLY_CHANNELS].setValue(16);
     66 		}
     67 		outputs[POLY_OUTPUT].setChannels(polyChannels);
     68 	}
     69 };
     70 
     71 struct NoRandomSmallKnob : SmallKnob {
     72 	NoRandomSmallKnob() {
     73 		SmallKnob();
     74 	};
     75 };
     76 struct NoRandomMediumSmallKnob : RoundKnob {
     77 	std::shared_ptr<Svg> enabledSvg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-small-knob.svg"));
     78 
     79 	NoRandomMediumSmallKnob() {
     80 		setSvg(enabledSvg);
     81 		RoundKnob();
     82 	};
     83 };
     84 
     85 struct DisableableSmoothKnob : RoundKnob {
     86 	std::shared_ptr<Svg> enabledSvg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-small-knob.svg"));
     87 	std::shared_ptr<Svg> disabledSvg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-small-knob-disabled.svg"));
     88 
     89 	int channel = 0;
     90 	bool disabled = false;
     91 	ComputerscarePolyModule *module;
     92 
     93 	DisableableSmoothKnob() {
     94 		setSvg(enabledSvg);
     95 		shadow->box.size = math::Vec(0, 0);
     96 		shadow->opacity = 0.f;
     97 	}
     98 	void step() override {
     99 		if (module) {
    100 			bool candidate = channel > module->polyChannels - 1;
    101 			if (disabled != candidate) {
    102 				setSvg(candidate ? disabledSvg : enabledSvg);
    103 				onChange(*(new event::Change()));
    104 				fb->dirty = true;
    105 				disabled = candidate;
    106 			}
    107 		}
    108 		else {
    109 		}
    110 		RoundKnob::step();
    111 	}
    112 };
    113 
    114 struct ComputerscareKnolyPobsWidget : ModuleWidget {
    115 	ComputerscareKnolyPobsWidget(ComputerscareKnolyPobs *module) {
    116 
    117 		setModule(module);
    118 		//setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg")));
    119 		box.size = Vec(4 * 15, 380);
    120 		{
    121 			ComputerscareSVGPanel *panel = new ComputerscareSVGPanel();
    122 			panel->box.size = box.size;
    123 			panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg")));
    124 			addChild(panel);
    125 		}
    126 		channelWidget = new PolyOutputChannelsWidget(Vec(1, 24), module, ComputerscareKnolyPobs::POLY_CHANNELS);
    127 		addOutput(createOutput<PointingUpPentagonPort>(Vec(30, 22), module, ComputerscareKnolyPobs::POLY_OUTPUT));
    128 
    129 		addChild(channelWidget);
    130 
    131 
    132 
    133 		addParam(createParam<NoRandomSmallKnob>(Vec(11, 54), module, ComputerscareKnolyPobs::GLOBAL_SCALE));
    134 		addParam(createParam<NoRandomMediumSmallKnob>(Vec(32, 57), module, ComputerscareKnolyPobs::GLOBAL_OFFSET));
    135 
    136 
    137 		float xx;
    138 		float yy;
    139 		float yInitial = 86;
    140 		float ySpacing =  34;
    141 		float yRightColumnOffset = 14.3 / 8;
    142 		for (int i = 0; i < numKnobs; i++) {
    143 			xx = 1.4f + 24.3 * (i - i % 8) / 8;
    144 			yy = yInitial + ySpacing * (i % 8) +  yRightColumnOffset * (i - i % 8) ;
    145 			addLabeledKnob(std::to_string(i + 1), xx, yy, module, i, (i - i % 8) * 1.2 - 3 + (i == 8 ? 5 : 0), 2);
    146 		}
    147 
    148 	}
    149 	void addLabeledKnob(std::string label, int x, int y, ComputerscareKnolyPobs *module, int index, float labelDx, float labelDy) {
    150 
    151 		smallLetterDisplay = new SmallLetterDisplay();
    152 		smallLetterDisplay->box.size = Vec(5, 10);
    153 		smallLetterDisplay->fontSize = 18;
    154 		smallLetterDisplay->value = label;
    155 		smallLetterDisplay->textAlign = 1;
    156 
    157 		ParamWidget* pob =  createParam<DisableableSmoothKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index);
    158 
    159 		DisableableSmoothKnob* fader = dynamic_cast<DisableableSmoothKnob*>(pob);
    160 
    161 		fader->module = module;
    162 		fader->channel = index;
    163 
    164 		addParam(fader);
    165 
    166 
    167 		smallLetterDisplay->box.pos = Vec(x + labelDx, y - 12 + labelDy);
    168 
    169 
    170 		addChild(smallLetterDisplay);
    171 
    172 	}
    173 	PolyOutputChannelsWidget* channelWidget;
    174 	PolyChannelsDisplay* channelDisplay;
    175 	DisableableSmoothKnob* fader;
    176 	SmallLetterDisplay* smallLetterDisplay;
    177 };
    178 
    179 Model *modelComputerscareKnolyPobs = createModel<ComputerscareKnolyPobs, ComputerscareKnolyPobsWidget>("computerscare-knolypobs");