You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6KB

  1. #include "plugin.hpp"
  2. using simd::float_4;
  3. struct Voltio : Module {
  4. enum ParamId {
  5. OCT_PARAM,
  6. RANGE_PARAM,
  7. SEMITONES_PARAM,
  8. PARAMS_LEN
  9. };
  10. enum InputId {
  11. SUM_INPUT,
  12. INPUTS_LEN
  13. };
  14. enum OutputId {
  15. OUT_OUTPUT,
  16. OUTPUTS_LEN
  17. };
  18. enum LightId {
  19. PLUSMINUS5_LIGHT,
  20. ZEROTOTEN_LIGHT,
  21. LIGHTS_LEN
  22. };
  23. Voltio() {
  24. config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
  25. auto octParam = configParam(OCT_PARAM, 0.f, 10.f, 0.f, "Octave");
  26. octParam->snapEnabled = true;
  27. configSwitch(RANGE_PARAM, 0.f, 1.f, 0.f, "Range", {"0 to 10", "-5 to +5"});
  28. auto semitonesParam = configParam(SEMITONES_PARAM, 0.f, 11.f, 0.f, "Semitones");
  29. semitonesParam->snapEnabled = true;
  30. configInput(SUM_INPUT, "Sum");
  31. configOutput(OUT_OUTPUT, "Main");
  32. }
  33. void process(const ProcessArgs& args) override {
  34. const int channels = std::max(1, inputs[SUM_INPUT].getChannels());
  35. for (int c = 0; c < channels; c += 4) {
  36. float_4 in = inputs[SUM_INPUT].getPolyVoltageSimd<float_4>(c);
  37. float offset = params[RANGE_PARAM].getValue() ? -5.f : 0.f;
  38. in += params[SEMITONES_PARAM].getValue() / 12.f + params[OCT_PARAM].getValue() + offset;
  39. outputs[OUT_OUTPUT].setVoltageSimd<float_4>(in, c);
  40. }
  41. outputs[OUT_OUTPUT].setChannels(channels);
  42. lights[PLUSMINUS5_LIGHT].setBrightness(params[RANGE_PARAM].getValue() ? 1.f : 0.f);
  43. lights[ZEROTOTEN_LIGHT].setBrightness(params[RANGE_PARAM].getValue() ? 0.f : 1.f);
  44. }
  45. };
  46. struct VoltioWidget : ModuleWidget {
  47. VoltioWidget(Voltio* module) {
  48. setModule(module);
  49. setPanel(createPanel(asset::plugin(pluginInstance, "res/panels/Voltio.svg")));
  50. addChild(createWidget<Knurlie>(Vec(RACK_GRID_WIDTH, 0)));
  51. addChild(createWidget<Knurlie>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  52. addParam(createParamCentered<Davies1900hLargeLightGreyKnob>(mm2px(Vec(15.0, 20.828)), module, Voltio::OCT_PARAM));
  53. addParam(createParamCentered<BefacoSwitch>(mm2px(Vec(22.083, 44.061)), module, Voltio::RANGE_PARAM));
  54. auto p = createParamCentered<Davies1900hLargeLightGreyKnob>(mm2px(Vec(15.0, 67.275)), module, Voltio::SEMITONES_PARAM);
  55. p->minAngle = -0.83 * M_PI;
  56. p->maxAngle = M_PI;
  57. addParam(p);
  58. addInput(createInputCentered<BefacoInputPort>(mm2px(Vec(7.117, 111.003)), module, Voltio::SUM_INPUT));
  59. addOutput(createOutputCentered<BefacoOutputPort>(mm2px(Vec(22.661, 111.003)), module, Voltio::OUT_OUTPUT));
  60. addChild(createLightCentered<SmallLight<RedLight>>(mm2px(Vec(5.695, 41.541)), module, Voltio::PLUSMINUS5_LIGHT));
  61. addChild(createLightCentered<SmallLight<RedLight>>(mm2px(Vec(5.695, 46.633)), module, Voltio::ZEROTOTEN_LIGHT));
  62. }
  63. };
  64. Model* modelVoltio = createModel<Voltio, VoltioWidget>("Voltio");