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.

220 lines
5.8KB

  1. #include <sstream>
  2. #include "Squinky.hpp"
  3. #include "WidgetComposite.h"
  4. #ifdef _EV
  5. #include "EvenVCO.h"
  6. /**
  7. */
  8. struct EVModule : Module
  9. {
  10. public:
  11. EVModule();
  12. /**
  13. *
  14. * Overrides of Module functions
  15. */
  16. void step() override;
  17. void onSampleRateChange() override;
  18. EvenVCO<WidgetComposite> vco;
  19. private:
  20. };
  21. void EVModule::onSampleRateChange()
  22. {
  23. }
  24. EVModule::EVModule()
  25. : Module(vco.NUM_PARAMS,
  26. vco.NUM_INPUTS,
  27. vco.NUM_OUTPUTS,
  28. vco.NUM_LIGHTS),
  29. vco(this)
  30. {
  31. onSampleRateChange();
  32. }
  33. void EVModule::step()
  34. {
  35. vco.step();
  36. }
  37. ////////////////////
  38. // module widget
  39. ////////////////////
  40. struct EVWidget : ModuleWidget
  41. {
  42. EVWidget(EVModule *);
  43. Label* addLabel(const Vec& v, const char* str, const NVGcolor& color = COLOR_BLACK)
  44. {
  45. Label* label = new Label();
  46. label->box.pos = v;
  47. label->text = str;
  48. label->color = color;
  49. addChild(label);
  50. return label;
  51. }
  52. void draw(NVGcontext *vg) override;
  53. void addPWM(EVModule *, float verticalShift);
  54. void addMiddle(EVModule *, float verticalShift);
  55. void addOutputs(EVModule *, float verticalShift);
  56. Label* octaveLabel;
  57. ParamWidget* octaveKnob;
  58. int lastOctave = -100;
  59. };
  60. void EVWidget::draw(NVGcontext *vg)
  61. {
  62. float value = octaveKnob->value;
  63. int oct = roundf(value);
  64. if (oct != lastOctave) {
  65. const char * val = "yy";
  66. switch (oct) {
  67. case -5:
  68. val = "32'";
  69. break;
  70. case -4:
  71. val = "16'";
  72. break;
  73. case -3:
  74. val = "8'";
  75. break;
  76. case -2:
  77. val = "4'";
  78. break;
  79. case -1:
  80. val = "2'";
  81. break;
  82. case 0:
  83. val = "1'";
  84. break;
  85. case 1:
  86. val = "1/2'";
  87. break;
  88. case 2:
  89. val = "1/4'";
  90. break;
  91. case 3:
  92. val = "1/8'";
  93. break;
  94. case 4:
  95. val = "1/16'";
  96. break;
  97. }
  98. octaveLabel->text = val;
  99. }
  100. ModuleWidget::draw(vg);
  101. }
  102. void EVWidget::addPWM(EVModule * module, float verticalShift)
  103. {
  104. addInput(Port::create<PJ301MPort>(Vec(72, 236 + verticalShift),
  105. Port::INPUT, module, module->vco.PWM_INPUT));
  106. addParam(ParamWidget::create<Rogan1PBlue>(Vec(16, 212 + verticalShift),
  107. module, module->vco.PWM_PARAM, -1.0, 1.0, 0.0));
  108. addLabel(Vec(30, 246 + verticalShift), "pwm");
  109. }
  110. void EVWidget::addMiddle(EVModule * module, float verticalShift)
  111. {
  112. addParam(ParamWidget::create<Rogan1PBlue>(Vec(73, 125 + verticalShift),
  113. module, module->vco.TUNE_PARAM, -7.0, 7.0, 0.0));
  114. addLabel(Vec(69, 164 + verticalShift), "tune");
  115. addInput(Port::create<PJ301MPort>(Vec(10, 124 + verticalShift),
  116. Port::INPUT, module, module->vco.PITCH1_INPUT));
  117. addInput(Port::create<PJ301MPort>(Vec(34, 160 + verticalShift),
  118. Port::INPUT, module, module->vco.PITCH2_INPUT));
  119. addLabel(Vec(6, 164 + verticalShift), "cv");
  120. addInput(Port::create<PJ301MPort>(Vec(62, 194 + verticalShift),
  121. Port::INPUT, module, module->vco.FM_INPUT));
  122. addLabel(Vec(84, 200 + verticalShift), "fm");
  123. // addInput(Port::create<PJ301MPort>(Vec(86, 189), Port::INPUT, module, module->vco.SYNC_INPUT));
  124. }
  125. void EVWidget::addOutputs(EVModule * module, float verticalShift)
  126. {
  127. const float penultimateRow = 273 + verticalShift;
  128. const float penultimateLabelRow = penultimateRow + 24;
  129. addOutput(Port::create<PJ301MPort>(Vec(10, penultimateRow), Port::OUTPUT, module, module->vco.TRI_OUTPUT));
  130. addLabel(Vec(8, penultimateLabelRow), "tri");
  131. addOutput(Port::create<PJ301MPort>(Vec(87, penultimateRow), Port::OUTPUT, module, module->vco.SINE_OUTPUT));
  132. addLabel(Vec(84, penultimateLabelRow), "sin");
  133. const float bottomRow = 317 + verticalShift; // 320 -> 317 to make room?
  134. const float bottomLabelRow = bottomRow + 24;
  135. addOutput(Port::create<PJ301MPort>(Vec(48, bottomRow), Port::OUTPUT, module, module->vco.EVEN_OUTPUT));
  136. addLabel(Vec(38, bottomLabelRow), "even");
  137. addOutput(Port::create<PJ301MPort>(Vec(10, bottomRow), Port::OUTPUT, module, module->vco.SAW_OUTPUT));
  138. addLabel(Vec(4, bottomLabelRow), "saw");
  139. addOutput(Port::create<PJ301MPort>(Vec(87, bottomRow), Port::OUTPUT, module, module->vco.SQUARE_OUTPUT));
  140. addLabel(Vec(83, bottomLabelRow), "sqr");
  141. }
  142. /**
  143. * Widget constructor will describe my implementation structure and
  144. * provide meta-data.
  145. * This is not shared by all modules in the DLL, just one
  146. */
  147. EVWidget::EVWidget(EVModule *module) : ModuleWidget(module)
  148. {
  149. box.size = Vec(8 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  150. {
  151. SVGPanel *panel = new SVGPanel();
  152. panel->box.size = box.size;
  153. panel->setBackground(SVG::load(assetPlugin(plugin, "res/blank_panel.svg")));
  154. addChild(panel);
  155. }
  156. addPWM(module, -10);
  157. addMiddle(module, -14);
  158. addOutputs(module, -12);
  159. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  160. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  161. addChild(Widget::create<ScrewSilver>(Vec(15 * 6, 0)));
  162. addChild(Widget::create<ScrewSilver>(Vec(15 * 6, 365)));
  163. octaveKnob = ParamWidget::create<Rogan3PSBlue>(Vec(34, 32),
  164. module, module->vco.OCTAVE_PARAM, -5.0, 4.0, 0.0);
  165. addParam(octaveKnob);
  166. addLabel(Vec(20, 88), "octave:");
  167. //label->fontSize = 16;
  168. octaveLabel = addLabel(Vec(70, 90), "xx");
  169. }
  170. RACK_PLUGIN_MODEL_INIT(squinkylabs_plug1, EV) {
  171. Model *modelEVModule = Model::create<EVModule,
  172. EVWidget>("Squinky Labs",
  173. "squinkylabs-evco",
  174. "EvilVCO", OSCILLATOR_TAG);
  175. return modelEVModule;
  176. }
  177. #endif