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.

193 lines
4.8KB

  1. #include "Squinky.hpp"
  2. #ifdef _CH10
  3. #include "ctrl/SqWidgets.h"
  4. #include "WidgetComposite.h"
  5. #include "CH10.h"
  6. #include "ctrl/ToggleButton.h"
  7. #include <sstream>
  8. /**
  9. */
  10. struct CH10Module : Module
  11. {
  12. public:
  13. CH10Module();
  14. /**
  15. *
  16. * Overrides of Module functions
  17. */
  18. void step() override;
  19. void onSampleRateChange() override;
  20. CH10<WidgetComposite> ch10;
  21. private:
  22. };
  23. void CH10Module::onSampleRateChange()
  24. {
  25. }
  26. CH10Module::CH10Module()
  27. : Module(CH10<WidgetComposite>::NUM_PARAMS,
  28. CH10<WidgetComposite>::NUM_INPUTS,
  29. CH10<WidgetComposite>::NUM_OUTPUTS,
  30. CH10<WidgetComposite>::NUM_LIGHTS),
  31. ch10(this)
  32. {
  33. onSampleRateChange();
  34. ch10.init();
  35. }
  36. void CH10Module::step()
  37. {
  38. ch10.step();
  39. }
  40. ////////////////////
  41. // module widget
  42. ////////////////////
  43. struct CH10Widget : ModuleWidget
  44. {
  45. CH10Widget(CH10Module *);
  46. Label* addLabel(const Vec& v, const char* str, const NVGcolor& color = COLOR_BLACK)
  47. {
  48. Label* label = new Label();
  49. label->box.pos = v;
  50. label->text = str;
  51. label->color = color;
  52. addChild(label);
  53. return label;
  54. }
  55. void makeA(CH10Module *);
  56. void makeB(CH10Module *);
  57. void makeAB(CH10Module *);
  58. void addSwitch(float x, float y, int id);
  59. void makeVCO(CH10Module*, int whichOne);
  60. };
  61. const static float gridSize = 28;
  62. const static float gridCol1 = 140;
  63. const static float gridRow1 = 300;
  64. inline void CH10Widget::makeA(CH10Module *)
  65. {
  66. for (int i = 0; i < 10; ++i) {
  67. const float x = gridCol1;
  68. const float y = gridRow1 - i * gridSize;
  69. addSwitch(x, y, CH10<Widget>::A0_PARAM + i);
  70. }
  71. }
  72. inline void CH10Widget::makeB(CH10Module *)
  73. {
  74. for (int i = 0; i < 10; ++i) {
  75. const float x = gridCol1 + gridSize * (i + 1);
  76. const float y = gridRow1 + gridSize;
  77. addSwitch(x, y, CH10<Widget>::B0_PARAM + i);
  78. }
  79. }
  80. inline void CH10Widget::makeAB(CH10Module *)
  81. {
  82. for (int row = 0; row < 10; ++row) {
  83. for (int col = 0; col < 10; ++col) {
  84. float x = gridCol1 + gridSize * (col + 1);
  85. float y = gridRow1 - row * gridSize;
  86. int id = CH10<Widget>::A0B0_PARAM +
  87. col + row * 10;
  88. addSwitch(x, y, id);
  89. }
  90. }
  91. }
  92. inline void CH10Widget::addSwitch(float x, float y, int id)
  93. {
  94. ToggleButton* tog = ParamWidget::create<ToggleButton>(
  95. Vec(x, y),
  96. module,
  97. id,
  98. 0.0f, 1, 0);
  99. tog->addSvg("res/square-button-01.svg");
  100. tog->addSvg("res/square-button-02.svg");
  101. addParam(tog);
  102. }
  103. const float rowSpacing = 40;
  104. const float vcoACol = 50;
  105. const float vcoBCol = 90;
  106. const float vcoOctRow = 60;
  107. const float vcoSemiRow = vcoOctRow + rowSpacing;
  108. const float vcoCVRow = vcoSemiRow + rowSpacing;
  109. inline void CH10Widget::makeVCO(CH10Module* module, int whichVCO)
  110. {
  111. const float x = whichVCO ? vcoBCol : vcoACol;
  112. addParam(createParamCentered<Blue30Knob>(
  113. Vec(x, vcoOctRow),
  114. module,
  115. CH10<WidgetComposite>::AOCTAVE_PARAM + whichVCO,
  116. -5.f, 4.f, 0.f));
  117. addParam(createParamCentered<Blue30SnapKnob>(
  118. Vec(x, vcoSemiRow), module,
  119. CH10<WidgetComposite>::ASEMI_PARAM + whichVCO,
  120. -11.f, 11.0f, 0.f));
  121. addInput(createInputCentered<PJ301MPort>(
  122. Vec(x, vcoCVRow),
  123. module,
  124. CH10<WidgetComposite>::ACV_INPUT + whichVCO));
  125. }
  126. /**
  127. * Widget constructor will describe my implementation structure and
  128. * provide meta-data.
  129. * This is not shared by all modules in the DLL, just one
  130. */
  131. CH10Widget::CH10Widget(CH10Module *module) : ModuleWidget(module)
  132. {
  133. box.size = Vec(35 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  134. {
  135. SVGPanel *panel = new SVGPanel();
  136. panel->box.size = box.size;
  137. panel->setBackground(SVG::load(assetPlugin(plugin, "res/ch10_panel.svg")));
  138. addChild(panel);
  139. }
  140. makeA(module);
  141. makeB(module);
  142. makeAB(module);
  143. makeVCO(module, 0);
  144. makeVCO(module, 1);
  145. addOutput(createOutputCentered<PJ301MPort>(
  146. Vec(70, 300),
  147. module,
  148. CH10<WidgetComposite>::MIXED_OUTPUT));
  149. // screws
  150. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  151. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  152. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  153. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  154. }
  155. RACK_PLUGIN_MODEL_INIT(squinkylabs_plug1, CH10) {
  156. Model *modelCH10Module = Model::create<CH10Module,
  157. CH10Widget>("Squinky Labs",
  158. "squinkylabs-ch10",
  159. "-- ch10 --", RANDOM_TAG);
  160. return modelCH10Module;
  161. }
  162. #endif