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.

88 lines
1.7KB

  1. #include "ML_modules.hpp"
  2. namespace rack_plugin_ML_modules {
  3. struct Sum8mk2 : Module {
  4. enum ParamIds {
  5. POLARITY_PARAM,
  6. NUM_PARAMS = POLARITY_PARAM + 8
  7. };
  8. enum InputIds {
  9. IN_INPUT,
  10. NUM_INPUTS = IN_INPUT + 8
  11. };
  12. enum OutputIds {
  13. OUT_OUTPUT,
  14. NUM_OUTPUTS
  15. };
  16. enum LightIds {
  17. NUM_LIGHTS
  18. };
  19. Sum8mk2() : Module( NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS ) {};
  20. void step() override;
  21. };
  22. void Sum8mk2::step() {
  23. float out=0.0;
  24. for(int i=0; i<8; i++) out += inputs[IN_INPUT+i].normalize(0.0) * (2*params[POLARITY_PARAM+i].value - 1.0);
  25. outputs[OUT_OUTPUT].value = out;
  26. };
  27. struct Sum8mk2Widget : ModuleWidget {
  28. Sum8mk2Widget(Sum8mk2 *module);
  29. };
  30. Sum8mk2Widget::Sum8mk2Widget(Sum8mk2 *module) : ModuleWidget(module) {
  31. box.size = Vec(15*5, 380);
  32. {
  33. SVGPanel *panel = new SVGPanel();
  34. panel->box.size = box.size;
  35. panel->setBackground(SVG::load(assetPlugin(plugin,"res/Sum8mk2.svg")));
  36. addChild(panel);
  37. }
  38. addChild(Widget::create<MLScrew>(Vec(15, 0)));
  39. addChild(Widget::create<MLScrew>(Vec(15, 365)));
  40. const float offset_y = 70, delta_y = 26.5, offset_x=9.5;
  41. for( int i=0; i<8; i++) {
  42. addInput(Port::create<MLPort>(Vec(offset_x, offset_y + i*delta_y ), Port::INPUT, module, Sum8mk2::IN_INPUT+i));
  43. addParam(ParamWidget::create<POLSWITCH>( Vec(offset_x + 37, offset_y + i*delta_y + 2 ), module, Sum8mk2::POLARITY_PARAM + i, 0.0, 1.0, 1.0));
  44. }
  45. addOutput(Port::create<MLPort>(Vec(offset_x, 320), Port::OUTPUT, module, Sum8mk2::OUT_OUTPUT));
  46. }
  47. } // namespace rack_plugin_ML_modules
  48. using namespace rack_plugin_ML_modules;
  49. RACK_PLUGIN_MODEL_INIT(ML_modules, Sum8mk2) {
  50. Model *modelSum8mk2 = Model::create<Sum8mk2, Sum8mk2Widget>("ML modules", "Sum8mk2", "Sum8 MkII", UTILITY_TAG, MIXER_TAG);
  51. return modelSum8mk2;
  52. }