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.

175 lines
4.9KB

  1. #include "SubmarineFree.hpp"
  2. namespace rack_plugin_SubmarineFree {
  3. struct SS_112 : Module {
  4. static constexpr int deviceCount = 12;
  5. SS_112() : Module(0, deviceCount, 0, 0) {}
  6. };
  7. struct SS112 : ModuleWidget {
  8. SS112(SS_112 *module) : ModuleWidget(module) {
  9. setPanel(SVG::load(assetPlugin(plugin, "res/SS-112.svg")));
  10. for (int i = 0; i < SS_112::deviceCount; i++) {
  11. addInput(Port::create<SilverPort>(Vec(2.5,19 + i * 29), Port::INPUT, module, i));
  12. }
  13. }
  14. };
  15. struct SS_208 : Module {
  16. static constexpr int deviceCount = 8;
  17. SS_208() : Module(0, 0, deviceCount, 0) {
  18. outputs[0].value = M_PI;
  19. outputs[1].value = 2 * M_PI;
  20. outputs[2].value = M_E;
  21. outputs[3].value = M_SQRT1_2;
  22. outputs[4].value = M_SQRT2;
  23. outputs[5].value = powf(3.0f, 0.5f);
  24. outputs[6].value = powf(5.0f, 0.5f);
  25. outputs[7].value = powf(7.0f, 0.5f);
  26. }
  27. };
  28. struct SS208 : ModuleWidget {
  29. SS208(SS_208 *module) : ModuleWidget(module) {
  30. setPanel(SVG::load(assetPlugin(plugin, "res/SS-208.svg")));
  31. for (int i = 0; i < SS_208::deviceCount; i++) {
  32. addOutput(Port::create<SilverPort>(Vec(2.5,19 + 43 * i), Port::OUTPUT, module, i));
  33. }
  34. }
  35. };
  36. struct SS_212 : Module {
  37. static constexpr int deviceCount = 12;
  38. int v = 0;
  39. void setValues() {
  40. for (int i = 0; i < deviceCount; i++) {
  41. outputs[i].value = v + 1.0f * i / 12.0f;
  42. }
  43. }
  44. SS_212() : Module(0, 0, deviceCount, 0) {
  45. setValues();
  46. }
  47. json_t *toJson() override {
  48. json_t *rootJ = json_object();
  49. json_object_set_new(rootJ, "octave", json_integer(v));
  50. return rootJ;
  51. }
  52. void fromJson(json_t *rootJ) override {
  53. json_t *intJ = json_object_get(rootJ, "octave");
  54. if (intJ)
  55. v = json_integer_value(intJ);
  56. setValues();
  57. }
  58. };
  59. struct SS212 : ModuleWidget {
  60. SS212(SS_212 *module) : ModuleWidget(module) {
  61. setPanel(SVG::load(assetPlugin(plugin, "res/SS-212.svg")));
  62. for (int i = 0; i < SS_212::deviceCount; i++) {
  63. addOutput(Port::create<SilverPort>(Vec(2.5,19 + i * 29), Port::OUTPUT, module, i));
  64. }
  65. }
  66. void appendContextMenu(Menu *menu) override;
  67. };
  68. struct SSMenuItem : MenuItem {
  69. SS_212 *ss_212;
  70. int v;
  71. void onAction(EventAction &e) override {
  72. ss_212->v = v;
  73. ss_212->setValues();
  74. }
  75. void step() override {
  76. rightText = CHECKMARK(ss_212->v == v);
  77. }
  78. };
  79. void SS212::appendContextMenu(Menu *menu) {
  80. char label[20];
  81. menu->addChild(MenuEntry::create());
  82. SS_212 *ss_212 = dynamic_cast<SS_212*>(this->module);
  83. assert(ss_212);
  84. for (int i = -5; i < 5; i++) {
  85. sprintf(label, "Octave %d", i);
  86. SSMenuItem *menuItem = MenuItem::create<SSMenuItem>(label);
  87. menuItem->ss_212 = ss_212;
  88. menuItem->v = i;
  89. menu->addChild(menuItem);
  90. }
  91. }
  92. struct SS_221 : Module {
  93. static constexpr int deviceCount = 21;
  94. SS_221() : Module(0, 0, deviceCount, 0) {
  95. for (int i = 0; i < deviceCount; i++) {
  96. outputs[i].value = 10.0f - i;
  97. }
  98. }
  99. };
  100. struct SS221 : ModuleWidget {
  101. SS221(SS_221 *module) : ModuleWidget(module) {
  102. setPanel(SVG::load(assetPlugin(plugin, "res/SS-221.svg")));
  103. for (int i = 0; i < SS_221::deviceCount; i++) {
  104. addOutput(Port::create<SilverPort>(Vec(2.5 + 45 * (i % 2),19 + i * 16), Port::OUTPUT, module, i));
  105. }
  106. }
  107. };
  108. struct SS_220 : Module {
  109. static constexpr int deviceCount = 12;
  110. static constexpr int deviceSetCount = 10;
  111. SS_220() : Module(0, 0, deviceCount * deviceSetCount, 0) {
  112. for (int j = 0; j < deviceSetCount; j++) {
  113. for (int i = 0; i < deviceCount; i++) {
  114. outputs[j * deviceCount + i].value = (j - 5.0f) + 1.0f * i / 12.0f;
  115. }
  116. }
  117. }
  118. };
  119. struct SS220 : ModuleWidget {
  120. SS220(SS_220 *module) : ModuleWidget(module) {
  121. setPanel(SVG::load(assetPlugin(plugin, "res/SS-220.svg")));
  122. for (int j = 0; j < SS_220::deviceSetCount; j++) {
  123. for (int i = 0; i < SS_220::deviceCount; i++) {
  124. addOutput(Port::create<SilverPort>(Vec(2.5 + 30 * j, 19 + i * 29), Port::OUTPUT, module, j * SS_220::deviceCount + i));
  125. }
  126. }
  127. }
  128. };
  129. } // namespace rack_plugin_SubmarineFree
  130. using namespace rack_plugin_SubmarineFree;
  131. RACK_PLUGIN_MODEL_INIT(SubmarineFree, SS112) {
  132. Model *modelSS112 = Model::create<SS_112, SS112>("Submarine (Free)", "SS-112", "SS-112 12 Input Sinks", UTILITY_TAG);
  133. return modelSS112;
  134. }
  135. RACK_PLUGIN_MODEL_INIT(SubmarineFree, SS208) {
  136. Model *modelSS208 = Model::create<SS_208, SS208>("Submarine (Free)", "SS-208", "SS-208 8 Irrational Output Voltage Sources", UTILITY_TAG);
  137. return modelSS208;
  138. }
  139. RACK_PLUGIN_MODEL_INIT(SubmarineFree, SS212) {
  140. Model *modelSS212 = Model::create<SS_212, SS212>("Submarine (Free)", "SS-212", "SS-212 12 Chromatic Output Voltage Sources", UTILITY_TAG);
  141. return modelSS212;
  142. }
  143. RACK_PLUGIN_MODEL_INIT(SubmarineFree, SS220) {
  144. Model *modelSS220 = Model::create<SS_220, SS220>("Submarine (Free)", "SS-220", "SS-220 120 Chromatic Output Voltage Sources", UTILITY_TAG);
  145. return modelSS220;
  146. }
  147. RACK_PLUGIN_MODEL_INIT(SubmarineFree, SS221) {
  148. Model *modelSS221 = Model::create<SS_221, SS221>("Submarine (Free)", "SS-221", "SS-221 21 Output Voltage Sources", UTILITY_TAG);
  149. return modelSS221;
  150. }