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.

129 lines
3.8KB

  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 Bitter : Module
  20. {
  21. enum ParamIds
  22. {
  23. BIT_1,
  24. BIT_2,
  25. BIT_3,
  26. BIT_4,
  27. BIT_5,
  28. BIT_6,
  29. BIT_7,
  30. BIT_8,
  31. NUM_PARAMS
  32. };
  33. enum InputIds
  34. {
  35. INPUT,
  36. NUM_INPUTS
  37. };
  38. enum OutputIds
  39. {
  40. OUTPUT,
  41. NUM_OUTPUTS
  42. };
  43. enum LightIds
  44. {
  45. NUM_LIGHTS
  46. };
  47. Bitter() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  48. void step() override;
  49. };
  50. inline void clear_bit(unsigned char &number, unsigned int bit)
  51. {
  52. number &= ~(1 << bit);
  53. }
  54. inline void toggle_bit(unsigned char &number, unsigned int bit)
  55. {
  56. number ^= 1 << bit;
  57. }
  58. void Bitter::step()
  59. {
  60. unsigned char in = (unsigned char)round((1.0 + (inputs[INPUT].value / 5.0)) * 0.5 * 255.0);
  61. for (int b = 0; b < 8; b++)
  62. {
  63. if ((int)roundf(params[b].value) == 1)
  64. {
  65. clear_bit(in, b);
  66. }
  67. if ((int)roundf(params[b].value) == 0)
  68. {
  69. toggle_bit(in, b);
  70. }
  71. }
  72. float out = (((float)in / 255.0) * 2.0) - 1.0;
  73. outputs[OUTPUT].value = out * 5.0;
  74. }
  75. struct BitterWidget : ModuleWidget
  76. {
  77. BitterWidget(Bitter *module);
  78. };
  79. BitterWidget::BitterWidget(Bitter *module) : ModuleWidget(module)
  80. {
  81. box.size = Vec(15 * 8, 380);
  82. {
  83. SVGPanel *panel = new SVGPanel();
  84. panel->box.size = box.size;
  85. panel->setBackground(SVG::load(assetPlugin(plugin, "res/bitter.svg")));
  86. addChild(panel);
  87. }
  88. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  89. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  90. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  91. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  92. addInput(Port::create<PJ301MPort>(Vec(16, 67), Port::INPUT, module, Bitter::INPUT));
  93. addOutput(Port::create<PJ301MPort>(Vec(80, 67), Port::OUTPUT, module, Bitter::OUTPUT));
  94. addParam(ParamWidget::create<NKK>(Vec(12, 133), module, Bitter::BIT_1, 0.0, 2.0, 2.0));
  95. addParam(ParamWidget::create<NKK>(Vec(12, 183), module, Bitter::BIT_2, 0.0, 2.0, 2.0));
  96. addParam(ParamWidget::create<NKK>(Vec(12, 233), module, Bitter::BIT_3, 0.0, 2.0, 2.0));
  97. addParam(ParamWidget::create<NKK>(Vec(12, 283), module, Bitter::BIT_4, 0.0, 2.0, 2.0));
  98. addParam(ParamWidget::create<NKK>(Vec(76, 133), module, Bitter::BIT_5, 0.0, 2.0, 2.0));
  99. addParam(ParamWidget::create<NKK>(Vec(76, 183), module, Bitter::BIT_6, 0.0, 2.0, 2.0));
  100. addParam(ParamWidget::create<NKK>(Vec(76, 233), module, Bitter::BIT_7, 0.0, 2.0, 2.0));
  101. addParam(ParamWidget::create<NKK>(Vec(76, 283), module, Bitter::BIT_8, 0.0, 2.0, 2.0));
  102. }
  103. } // namespace rack_plugin_SonusModular
  104. using namespace rack_plugin_SonusModular;
  105. RACK_PLUGIN_MODEL_INIT(SonusModular, Bitter) {
  106. Model *modelBitter = Model::create<Bitter, BitterWidget>("Sonus Modular", "Bitter", "Bitter | Bit Manipulator", DISTORTION_TAG, EFFECT_TAG);
  107. return modelBitter;
  108. }