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.

84 lines
2.2KB

  1. #include "huaba.hpp"
  2. #include "abbus.hpp"
  3. #include "math.h"
  4. namespace rack_plugin_huaba {
  5. struct ABBus : Module {
  6. enum ParamIds {
  7. SW1_PARAM,
  8. SW2_PARAM,
  9. SW3_PARAM,
  10. SW4_PARAM,
  11. SW5_PARAM,
  12. SW6_PARAM,
  13. SW7_PARAM,
  14. SW8_PARAM,
  15. NUM_PARAMS
  16. };
  17. enum InputIds {
  18. IN1_INPUT,
  19. IN2_INPUT,
  20. IN3_INPUT,
  21. IN4_INPUT,
  22. IN5_INPUT,
  23. IN6_INPUT,
  24. IN7_INPUT,
  25. IN8_INPUT,
  26. NUM_INPUTS
  27. };
  28. enum OutputIds {
  29. OUTA_OUTPUT,
  30. OUTB_OUTPUT,
  31. NUM_OUTPUTS
  32. };
  33. ABBus() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
  34. void step() override;
  35. };
  36. void ABBus::step() {
  37. float outa=0.0;
  38. float outb=0.0;
  39. for(int i=0; i<8; i++) {
  40. if(params[SW1_PARAM+i].value == 2.0)
  41. outa += inputs[IN1_INPUT+i].normalize(0.0);
  42. if(params[SW1_PARAM+i].value == 0.0)
  43. outb += inputs[IN1_INPUT+i].normalize(0.0);
  44. }
  45. outputs[OUTA_OUTPUT].value = outa;
  46. outputs[OUTB_OUTPUT].value = outb;
  47. }
  48. struct ABBusWidget : ModuleWidget {
  49. ABBusWidget(ABBus *module) : ModuleWidget(module) {
  50. setPanel(SVG::load(assetPlugin(plugin, "res/ABBus.svg")));
  51. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  52. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  53. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  54. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  55. const float offset_y = 40, delta_y = 26.5+3, offset_x=2;
  56. for( int i=0; i<8; i++) {
  57. addInput(Port::create<PJ301MPort>(Vec(offset_x, offset_y + i*delta_y), Port::INPUT, module, ABBus::IN1_INPUT+i));
  58. addParam(ParamWidget::create<dh_switch3>(Vec(offset_x+27, offset_y+6 + i*delta_y), module, ABBus::SW1_PARAM+i, 0.0, 2.0, 1.0));
  59. }
  60. addOutput(Port::create<PJ301MPort>(Vec(offset_x+1.5, 320), Port::OUTPUT, module, ABBus::OUTA_OUTPUT));
  61. addOutput(Port::create<PJ301MPort>(Vec(offset_x+29, 320), Port::OUTPUT, module, ABBus::OUTB_OUTPUT));
  62. }
  63. };
  64. } // namespace rack_plugin_huaba
  65. using namespace rack_plugin_huaba;
  66. RACK_PLUGIN_MODEL_INIT(huaba, ABBus) {
  67. Model *modelABBus = Model::create<ABBus, ABBusWidget>("huaba", "A+B Bus", "A+B Bus", UTILITY_TAG, MULTIPLE_TAG);
  68. return modelABBus;
  69. }