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.

137 lines
3.4KB

  1. #include "Squinky.hpp"
  2. #include "WidgetComposite.h"
  3. #include "Gray.h"
  4. /**
  5. */
  6. struct GrayModule : Module
  7. {
  8. public:
  9. GrayModule();
  10. /**
  11. *
  12. *
  13. * Overrides of Module functions
  14. */
  15. void step() override;
  16. Gray<WidgetComposite> gray;
  17. private:
  18. };
  19. GrayModule::GrayModule()
  20. : Module(gray.NUM_PARAMS,
  21. gray.NUM_INPUTS,
  22. gray.NUM_OUTPUTS,
  23. gray.NUM_LIGHTS),
  24. gray(this)
  25. {
  26. }
  27. void GrayModule::step()
  28. {
  29. gray.step();
  30. }
  31. ////////////////////
  32. // module widget
  33. ////////////////////
  34. struct GrayWidget : ModuleWidget
  35. {
  36. GrayWidget(GrayModule *);
  37. /**
  38. * Helper to add a text label to this widget
  39. */
  40. Label* addLabel(const Vec& v, const char* str, const NVGcolor& color = COLOR_BLACK)
  41. {
  42. Label* label = new Label();
  43. label->box.pos = v;
  44. label->text = str;
  45. label->color = color;
  46. addChild(label);
  47. return label;
  48. }
  49. private:
  50. void addBits(GrayModule *module);
  51. GrayModule* const module;
  52. };
  53. const float jackCol = 99.5;
  54. const float ledCol = 69;
  55. const float vertSpace = 31; // 31.4
  56. const float firstBitY = 64;
  57. inline void GrayWidget::addBits(GrayModule *module)
  58. {
  59. printf("add bits\n"); fflush(stdout);
  60. for (int i=0; i<8; ++i) {
  61. const Vec v(jackCol, firstBitY + i * vertSpace);
  62. addOutput(createOutputCentered<PJ301MPort>(
  63. v,
  64. module,
  65. Gray<WidgetComposite>::OUTPUT_0 + i));
  66. addChild(ModuleLightWidget::create<MediumLight<GreenLight>>(
  67. Vec(ledCol, firstBitY + i * vertSpace - 6),
  68. module,
  69. Gray<WidgetComposite>::LIGHT_0+i));
  70. }
  71. }
  72. /**
  73. * Widget constructor will describe my implementation structure and
  74. * provide meta-data.
  75. * This is not shared by all modules in the DLL, just one
  76. */
  77. GrayWidget::GrayWidget(GrayModule *module) :
  78. ModuleWidget(module),
  79. module(module)
  80. {
  81. box.size = Vec(8 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  82. {
  83. SVGPanel *panel = new SVGPanel();
  84. panel->box.size = box.size;
  85. panel->setBackground(SVG::load(assetPlugin(plugin, "res/gray.svg")));
  86. addChild(panel);
  87. }
  88. addBits(module);
  89. addInput(createInputCentered<PJ301MPort>(
  90. Vec(22, 339),
  91. module,
  92. Gray<WidgetComposite>::INPUT_CLOCK));
  93. addLabel(Vec(0, 310), "Clock");
  94. addParam(createParamCentered<CKSS>(
  95. Vec(71,33),
  96. module,
  97. Gray<WidgetComposite>::PARAM_CODE,
  98. 0.0f, 1.0f, 0.0f));
  99. addLabel(Vec(2, 27), "Balanced");
  100. addOutput(createOutputCentered<PJ301MPort>(
  101. Vec(100, 339),
  102. module,
  103. Gray<WidgetComposite>::OUTPUT_MIXED));
  104. addLabel(Vec(81, 310), "Mix", COLOR_WHITE);
  105. // screws
  106. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  107. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  108. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  109. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  110. }
  111. RACK_PLUGIN_MODEL_INIT(squinkylabs_plug1, Gray) {
  112. Model *modelGrayModule = Model::create<GrayModule,
  113. GrayWidget>("Squinky Labs",
  114. "squinkylabs-gry",
  115. "Gray Code: Eclectic clock divider", CLOCK_MODULATOR_TAG, RANDOM_TAG);
  116. return modelGrayModule;
  117. }