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.

115 lines
3.8KB

  1. #include <string.h>
  2. #include "AudibleInstruments.hpp"
  3. #include "warps/dsp/modulator.h"
  4. struct Warps : Module {
  5. enum ParamIds {
  6. ALGORITHM_PARAM,
  7. TIMBRE_PARAM,
  8. STATE_PARAM,
  9. LEVEL1_PARAM,
  10. LEVEL2_PARAM,
  11. NUM_PARAMS
  12. };
  13. enum InputIds {
  14. LEVEL1_INPUT,
  15. LEVEL2_INPUT,
  16. ALGORITHM_INPUT,
  17. TIMBRE_INPUT,
  18. CARRIER_INPUT,
  19. MODULATOR_INPUT,
  20. NUM_INPUTS
  21. };
  22. enum OutputIds {
  23. MODULATOR_OUTPUT,
  24. AUX_OUTPUT,
  25. NUM_OUTPUTS
  26. };
  27. int frame = 0;
  28. warps::Modulator modulator;
  29. warps::ShortFrame inputFrames[60] = {};
  30. warps::ShortFrame outputFrames[60] = {};
  31. float lights[1] = {};
  32. Warps();
  33. void step();
  34. };
  35. Warps::Warps() {
  36. params.resize(NUM_PARAMS);
  37. inputs.resize(NUM_INPUTS);
  38. outputs.resize(NUM_OUTPUTS);
  39. memset(&modulator, 0, sizeof(modulator));
  40. modulator.Init(96000.0f);
  41. }
  42. void Warps::step() {
  43. if (++frame >= 60) {
  44. frame = 0;
  45. warps::Parameters *p = modulator.mutable_parameters();
  46. p->channel_drive[0] = clampf(params[LEVEL1_PARAM] + getf(inputs[LEVEL1_INPUT]) / 5.0, 0.0, 1.0);
  47. p->channel_drive[1] = clampf(params[LEVEL2_PARAM] + getf(inputs[LEVEL2_INPUT]) / 5.0, 0.0, 1.0);
  48. p->modulation_algorithm = clampf(params[ALGORITHM_PARAM] / 8.0 + getf(inputs[ALGORITHM_PARAM]) / 5.0, 0.0, 1.0);
  49. p->modulation_parameter = clampf(params[TIMBRE_PARAM] + getf(inputs[TIMBRE_INPUT]) / 5.0, 0.0, 1.0);
  50. p->frequency_shift_pot = params[ALGORITHM_PARAM] / 8.0;
  51. p->frequency_shift_cv = clampf(getf(inputs[ALGORITHM_INPUT]) / 5.0, -1.0, 1.0);
  52. p->phase_shift = p->modulation_algorithm;
  53. p->note = 60.0 * params[LEVEL1_PARAM] + 12.0 * getf(inputs[LEVEL1_INPUT], 2.0) + 12.0;
  54. p->note += log2f(96000.0 / gSampleRate) * 12.0;
  55. float state = roundf(params[STATE_PARAM]);
  56. p->carrier_shape = (int32_t)state;
  57. lights[0] = state - 1.0;
  58. modulator.Process(inputFrames, outputFrames, 60);
  59. }
  60. inputFrames[frame].l = clampf(getf(inputs[CARRIER_INPUT]) / 16.0 * 0x8000, -0x8000, 0x7fff);
  61. inputFrames[frame].r = clampf(getf(inputs[MODULATOR_INPUT]) / 16.0 * 0x8000, -0x8000, 0x7fff);
  62. setf(outputs[MODULATOR_OUTPUT], (float)outputFrames[frame].l / 0x8000 * 5.0);
  63. setf(outputs[AUX_OUTPUT], (float)outputFrames[frame].r / 0x8000 * 5.0);
  64. }
  65. WarpsWidget::WarpsWidget() {
  66. Warps *module = new Warps();
  67. setModule(module);
  68. box.size = Vec(15*10, 380);
  69. {
  70. Panel *panel = new LightPanel();
  71. panel->backgroundImage = Image::load("plugins/AudibleInstruments/res/Warps.png");
  72. panel->box.size = box.size;
  73. addChild(panel);
  74. }
  75. addChild(createScrew<SilverScrew>(Vec(15, 0)));
  76. addChild(createScrew<SilverScrew>(Vec(120, 0)));
  77. addChild(createScrew<SilverScrew>(Vec(15, 365)));
  78. addChild(createScrew<SilverScrew>(Vec(120, 365)));
  79. addParam(createParam<Rogan6PSWhite>(Vec(30, 53), module, Warps::ALGORITHM_PARAM, 0.0, 8.0, 0.0));
  80. addParam(createParam<Rogan1PSWhite>(Vec(95, 173), module, Warps::TIMBRE_PARAM, 0.0, 1.0, 0.5));
  81. addParam(createParam<MediumToggleSwitch>(Vec(17, 182), module, Warps::STATE_PARAM, 0.0, 3.0, 0.0));
  82. addParam(createParam<Trimpot>(Vec(15, 214), module, Warps::LEVEL1_PARAM, 0.0, 1.0, 1.0));
  83. addParam(createParam<Trimpot>(Vec(54, 214), module, Warps::LEVEL2_PARAM, 0.0, 1.0, 1.0));
  84. addInput(createInput<PJ3410Port>(Vec(5, 270), module, Warps::LEVEL1_INPUT));
  85. addInput(createInput<PJ3410Port>(Vec(41, 270), module, Warps::LEVEL2_INPUT));
  86. addInput(createInput<PJ3410Port>(Vec(77, 270), module, Warps::ALGORITHM_INPUT));
  87. addInput(createInput<PJ3410Port>(Vec(113, 270), module, Warps::TIMBRE_INPUT));
  88. addInput(createInput<PJ3410Port>(Vec(5, 313), module, Warps::CARRIER_INPUT));
  89. addInput(createInput<PJ3410Port>(Vec(41, 313), module, Warps::MODULATOR_INPUT));
  90. addOutput(createOutput<PJ3410Port>(Vec(77, 313), module, Warps::MODULATOR_OUTPUT));
  91. addOutput(createOutput<PJ3410Port>(Vec(113, 313), module, Warps::AUX_OUTPUT));
  92. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(20, 167), &module->lights[0]));
  93. }