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.

110 lines
3.6KB

  1. #include "QuantalAudio.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_QuantalAudio {
  4. struct DaisyChannel : Module {
  5. enum ParamIds {
  6. CH_LVL_PARAM,
  7. MUTE_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. CH_INPUT,
  12. LVL_CV_INPUT,
  13. CHAIN_INPUT,
  14. NUM_INPUTS
  15. };
  16. enum OutputIds {
  17. CH_OUTPUT,
  18. CHAIN_OUTPUT,
  19. NUM_OUTPUTS
  20. };
  21. enum LightsIds {
  22. MUTE_LIGHT,
  23. NUM_LIGHTS
  24. };
  25. // Hypothetically the max number of channels that could be chained
  26. // Needs to match the divisor in the daisy master class
  27. float DAISY_DIVISOR = 16.f;
  28. bool muted = false;
  29. SchmittTrigger muteTrigger;
  30. DaisyChannel() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  31. json_t *toJson() override {
  32. json_t *rootJ = json_object();
  33. // mute
  34. json_object_set_new(rootJ, "muted", json_boolean(muted));
  35. return rootJ;
  36. }
  37. void fromJson(json_t *rootJ) override {
  38. // mute
  39. json_t *mutedJ = json_object_get(rootJ, "muted");
  40. if (mutedJ)
  41. muted = json_is_true(mutedJ);
  42. }
  43. void step() override {
  44. if (muteTrigger.process(params[MUTE_PARAM].value)) {
  45. muted = !muted;
  46. }
  47. float ch = 0.f;
  48. if (!muted) {
  49. ch = inputs[CH_INPUT].value;
  50. ch *= powf(params[CH_LVL_PARAM].value, 2.f);
  51. if (inputs[LVL_CV_INPUT].active) {
  52. float _cv = clamp(inputs[LVL_CV_INPUT].value / 10.f, 0.f, 1.f);
  53. ch *= _cv;
  54. }
  55. }
  56. outputs[CH_OUTPUT].value = ch;
  57. // Make the voltage small to the chain by dividing by the divisor;
  58. outputs[CHAIN_OUTPUT].value = inputs[CHAIN_INPUT].value + ch / DAISY_DIVISOR;
  59. lights[MUTE_LIGHT].value = (muted);
  60. }
  61. };
  62. struct DaisyChannelWidget : ModuleWidget {
  63. DaisyChannelWidget(DaisyChannel *module) : ModuleWidget(module) {
  64. setPanel(SVG::load(assetPlugin(plugin, "res/DaisyChannel.svg")));
  65. // Screws
  66. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  67. addChild(Widget::create<ScrewSilver>(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  68. // Channel Input/Output
  69. addInput(Port::create<PJ301MPort>(Vec(RACK_GRID_WIDTH - 12.5, 50.0), Port::INPUT, module, DaisyChannel::CH_INPUT));
  70. addOutput(Port::create<PJ301MPort>(Vec(RACK_GRID_WIDTH - 12.5, 245.0), Port::OUTPUT, module, DaisyChannel::CH_OUTPUT));
  71. // Level & CV
  72. addParam(ParamWidget::create<LEDSliderGreen>(Vec(RACK_GRID_WIDTH - 10.5, 121.4), module, DaisyChannel::CH_LVL_PARAM, 0.0, 1.0, 1.0));
  73. addInput(Port::create<PJ301MPort>(Vec(RACK_GRID_WIDTH - 12.5, 89.0), Port::INPUT, module, DaisyChannel::LVL_CV_INPUT));
  74. // Mute
  75. addParam(ParamWidget::create<LEDButton>(Vec(RACK_GRID_WIDTH - 9.0, 206.0), module, DaisyChannel::MUTE_PARAM, 0.0f, 1.0f, 0.0f));
  76. addChild(ModuleLightWidget::create<MediumLight<RedLight>>(Vec(RACK_GRID_WIDTH - 4.5, 210.25f), module, DaisyChannel::MUTE_LIGHT));
  77. // Chain Input/Output
  78. addInput(Port::create<PJ301MPort>(Vec(RACK_GRID_WIDTH - 12.5, 290.5), Port::INPUT, module, DaisyChannel::CHAIN_INPUT));
  79. addOutput(Port::create<PJ301MPort>(Vec(RACK_GRID_WIDTH - 12.5, 320.0), Port::OUTPUT, module, DaisyChannel::CHAIN_OUTPUT));
  80. }
  81. };
  82. } // namespace rack_plugin_QuantalAudio
  83. using namespace rack_plugin_QuantalAudio;
  84. RACK_PLUGIN_MODEL_INIT(QuantalAudio, DaisyChannel) {
  85. Model *modelDaisyChannel = Model::create<DaisyChannel, DaisyChannelWidget>("QuantalAudio", "DaisyChannel", "Daisy Mix Channel | 2HP", MIXER_TAG);
  86. return modelDaisyChannel;
  87. }