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.

117 lines
3.7KB

  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 Harmony : Module
  20. {
  21. enum ParamIds
  22. {
  23. NUM_PARAMS
  24. };
  25. enum InputIds
  26. {
  27. PITCH,
  28. NUM_INPUTS
  29. };
  30. enum OutputIds
  31. {
  32. m2,
  33. M2,
  34. m3,
  35. M3,
  36. P4,
  37. TT,
  38. P5,
  39. m6,
  40. M6,
  41. m7,
  42. M7,
  43. P8,
  44. NUM_OUTPUTS
  45. };
  46. enum LightIds
  47. {
  48. NUM_LIGHTS
  49. };
  50. Harmony() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  51. void step() override;
  52. const float semitone = 1.0 / 12.0;
  53. };
  54. void Harmony::step()
  55. {
  56. float pitch = inputs[PITCH].value;
  57. for (int s = 0; s < 12; s++)
  58. {
  59. outputs[s].value = pitch + (semitone * (s + 1));
  60. }
  61. }
  62. struct HarmonyWidget : ModuleWidget
  63. {
  64. HarmonyWidget(Harmony *module);
  65. };
  66. HarmonyWidget::HarmonyWidget(Harmony *module) : ModuleWidget(module)
  67. {
  68. box.size = Vec(15 * 12, 380);
  69. {
  70. SVGPanel *panel = new SVGPanel();
  71. panel->box.size = box.size;
  72. panel->setBackground(SVG::load(assetPlugin(plugin, "res/harmony.svg")));
  73. addChild(panel);
  74. }
  75. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  76. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  77. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  78. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  79. addInput(Port::create<PJ301MPort>(Vec(78, 67), Port::INPUT, module, Harmony::PITCH));
  80. addOutput(Port::create<PJ301MPort>(Vec(20, 132), Port::OUTPUT, module, Harmony::m2));
  81. addOutput(Port::create<PJ301MPort>(Vec(58, 132), Port::OUTPUT, module, Harmony::M2));
  82. addOutput(Port::create<PJ301MPort>(Vec(96, 132), Port::OUTPUT, module, Harmony::m3));
  83. addOutput(Port::create<PJ301MPort>(Vec(134, 132), Port::OUTPUT, module, Harmony::M3));
  84. addOutput(Port::create<PJ301MPort>(Vec(20, 197), Port::OUTPUT, module, Harmony::P4));
  85. addOutput(Port::create<PJ301MPort>(Vec(58, 197), Port::OUTPUT, module, Harmony::TT));
  86. addOutput(Port::create<PJ301MPort>(Vec(96, 197), Port::OUTPUT, module, Harmony::P5));
  87. addOutput(Port::create<PJ301MPort>(Vec(134, 197), Port::OUTPUT, module, Harmony::m6));
  88. addOutput(Port::create<PJ301MPort>(Vec(20, 262), Port::OUTPUT, module, Harmony::M6));
  89. addOutput(Port::create<PJ301MPort>(Vec(58, 262), Port::OUTPUT, module, Harmony::m7));
  90. addOutput(Port::create<PJ301MPort>(Vec(96, 262), Port::OUTPUT, module, Harmony::M7));
  91. addOutput(Port::create<PJ301MPort>(Vec(134, 262), Port::OUTPUT, module, Harmony::P8));
  92. }
  93. } // namespace rack_plugin_SonusModular
  94. using namespace rack_plugin_SonusModular;
  95. RACK_PLUGIN_MODEL_INIT(SonusModular, Harmony) {
  96. Model *modelHarmony = Model::create<Harmony, HarmonyWidget>("Sonus Modular", "Harmony", "Harmony | Chord Tool", TUNER_TAG, UTILITY_TAG);
  97. return modelHarmony;
  98. }