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.

198 lines
6.4KB

  1. /******************************************************************************
  2. * Copyright 2017-2018 Valerio Orlandini / Sonus Dept. <sonusdept@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *****************************************************************************/
  17. #include "sonusmodular.hpp"
  18. namespace rack_plugin_SonusModular {
  19. struct Scramblase : Module
  20. {
  21. enum ParamIds
  22. {
  23. THRESHOLD,
  24. NUM_PARAMS
  25. };
  26. enum InputIds
  27. {
  28. IN_A,
  29. IN_B,
  30. IN_C,
  31. THRESHOLD_CV,
  32. NUM_INPUTS
  33. };
  34. enum OutputIds
  35. {
  36. OUT_A1,
  37. OUT_A2,
  38. OUT_A3,
  39. OUT_A4,
  40. OUT_B1,
  41. OUT_B2,
  42. OUT_B3,
  43. OUT_B4,
  44. OUT_C1,
  45. OUT_C2,
  46. OUT_C3,
  47. OUT_C4,
  48. NUM_OUTPUTS
  49. };
  50. enum LightIds
  51. {
  52. NUM_LIGHTS
  53. };
  54. Scramblase() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  55. void step() override;
  56. float threshold = 0.0;
  57. };
  58. void Scramblase::step()
  59. {
  60. float in_a = inputs[IN_A].value / 5.0;
  61. float in_b = inputs[IN_B].value / 5.0;
  62. float in_c = inputs[IN_C].value / 5.0;
  63. float out_a1, out_a2, out_a3, out_a4;
  64. float out_b1, out_b2, out_b3, out_b4;
  65. float out_c1, out_c2, out_c3, out_c4;
  66. threshold = params[THRESHOLD].value + inputs[THRESHOLD_CV].value / 5.0;
  67. if (threshold > 1.0)
  68. {
  69. threshold = 1.0;
  70. }
  71. if (threshold < 0.0)
  72. {
  73. threshold = 0.0;
  74. }
  75. if (fabs(in_a) > threshold)
  76. {
  77. out_a1 = (fabs(in_a) - 2.0 * (fabs(in_a) - threshold)) * copysign(1.0, in_a);
  78. out_a2 = threshold * copysign (1.0, in_a);
  79. out_a3 = 1.0 * copysign (1.0, in_a);
  80. out_a4 = (fabs(in_a) - 2.0 * (fabs(in_a) - threshold)) * copysign(1.0, in_a);
  81. }
  82. else
  83. {
  84. out_a1 = in_a;
  85. out_a2 = in_a;
  86. out_a3 = in_a;
  87. out_a4 = 1.0 * copysign(1.0, in_a);
  88. }
  89. if (fabs(in_b) > threshold)
  90. {
  91. out_b1 = (fabs(in_b) - 2.0 * (fabs(in_b) - threshold)) * copysign(1.0, in_b);
  92. out_b2 = threshold * copysign (1.0, in_b);
  93. out_b3 = 1.0 * copysign (1.0, in_b);
  94. out_b4 = (fabs(in_b) - 2.0 * (fabs(in_b) - threshold)) * copysign(1.0, in_b);
  95. }
  96. else
  97. {
  98. out_b1 = in_b;
  99. out_b2 = in_b;
  100. out_b3 = in_b;
  101. out_b4 = 1.0 * copysign(1.0, in_b);
  102. }
  103. if (fabs(in_c) > threshold)
  104. {
  105. out_c1 = (fabs(in_c) - 2.0 * (fabs(in_c) - threshold)) * copysign(1.0, in_c);
  106. out_c2 = threshold * copysign (1.0, in_c);
  107. out_c3 = 1.0 * copysign (1.0, in_c);
  108. out_c4 = (fabs(in_c) - 2.0 * (fabs(in_c) - threshold)) * copysign(1.0, in_c);
  109. }
  110. else
  111. {
  112. out_c1 = in_c;
  113. out_c2 = in_c;
  114. out_c3 = in_c;
  115. out_c4 = 1.0 * copysign(1.0, in_c);
  116. }
  117. outputs[OUT_A1].value = out_a1 * 5.0;
  118. outputs[OUT_A2].value = out_a2 * 5.0;
  119. outputs[OUT_A3].value = out_a3 * 5.0;
  120. outputs[OUT_A4].value = out_a4 * 5.0;
  121. outputs[OUT_B1].value = out_b1 * 5.0;
  122. outputs[OUT_B2].value = out_b2 * 5.0;
  123. outputs[OUT_B3].value = out_b3 * 5.0;
  124. outputs[OUT_B4].value = out_b4 * 5.0;
  125. outputs[OUT_C1].value = out_c1 * 5.0;
  126. outputs[OUT_C2].value = out_c2 * 5.0;
  127. outputs[OUT_C3].value = out_c3 * 5.0;
  128. outputs[OUT_C4].value = out_c4 * 5.0;
  129. }
  130. struct ScramblaseWidget : ModuleWidget
  131. {
  132. ScramblaseWidget(Scramblase *module);
  133. };
  134. ScramblaseWidget::ScramblaseWidget(Scramblase *module) : ModuleWidget(module)
  135. {
  136. box.size = Vec(15 * 8, 380);
  137. {
  138. SVGPanel *panel = new SVGPanel();
  139. panel->box.size = box.size;
  140. panel->setBackground(SVG::load(assetPlugin(plugin, "res/scramblase.svg")));
  141. addChild(panel);
  142. }
  143. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  144. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  145. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  146. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  147. addInput(Port::create<PJ301MPort>(Vec(12, 67), Port::INPUT, module, Scramblase::IN_A));
  148. addOutput(Port::create<PJ301MPort>(Vec(12, 121), Port::OUTPUT, module, Scramblase::OUT_A1));
  149. addOutput(Port::create<PJ301MPort>(Vec(12, 150), Port::OUTPUT, module, Scramblase::OUT_A2));
  150. addOutput(Port::create<PJ301MPort>(Vec(12, 179), Port::OUTPUT, module, Scramblase::OUT_A3));
  151. addOutput(Port::create<PJ301MPort>(Vec(12, 208), Port::OUTPUT, module, Scramblase::OUT_A4));
  152. addInput(Port::create<PJ301MPort>(Vec(47, 67), Port::INPUT, module, Scramblase::IN_B));
  153. addOutput(Port::create<PJ301MPort>(Vec(47, 120), Port::OUTPUT, module, Scramblase::OUT_B1));
  154. addOutput(Port::create<PJ301MPort>(Vec(47, 150), Port::OUTPUT, module, Scramblase::OUT_B2));
  155. addOutput(Port::create<PJ301MPort>(Vec(47, 179), Port::OUTPUT, module, Scramblase::OUT_B3));
  156. addOutput(Port::create<PJ301MPort>(Vec(47, 208), Port::OUTPUT, module, Scramblase::OUT_B4));
  157. addInput(Port::create<PJ301MPort>(Vec(83, 67), Port::INPUT, module, Scramblase::IN_C));
  158. addOutput(Port::create<PJ301MPort>(Vec(83, 121), Port::OUTPUT, module, Scramblase::OUT_C1));
  159. addOutput(Port::create<PJ301MPort>(Vec(83, 150), Port::OUTPUT, module, Scramblase::OUT_C2));
  160. addOutput(Port::create<PJ301MPort>(Vec(83, 179), Port::OUTPUT, module, Scramblase::OUT_C3));
  161. addOutput(Port::create<PJ301MPort>(Vec(83, 208), Port::OUTPUT, module, Scramblase::OUT_C4));
  162. addInput(Port::create<PJ301MPort>(Vec(12, 290), Port::INPUT, module, Scramblase::THRESHOLD_CV));
  163. addParam(ParamWidget::create<SonusBigKnob>(Vec(53, 275), module, Scramblase::THRESHOLD, 0.0, 1.0, 1.0));
  164. }
  165. } // namespace rack_plugin_SonusModular
  166. using namespace rack_plugin_SonusModular;
  167. RACK_PLUGIN_MODEL_INIT(SonusModular, Scramblase) {
  168. Model *modelScramblase = Model::create<Scramblase, ScramblaseWidget>("Sonus Modular", "Scramblase", "Scramblase | Waveshaper", WAVESHAPER_TAG, EFFECT_TAG);
  169. return modelScramblase;
  170. }