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.

116 lines
3.4KB

  1. #include "21kHz.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_21kHz {
  4. struct D_Inf : Module {
  5. enum ParamIds {
  6. OCTAVE_PARAM,
  7. COARSE_PARAM,
  8. HALF_SHARP_PARAM,
  9. INVERT_PARAM,
  10. GATE_PARAM,
  11. INVERT_TRIG_PARAM,
  12. NUM_PARAMS
  13. };
  14. enum InputIds {
  15. TRIG_INPUT,
  16. A_INPUT,
  17. NUM_INPUTS
  18. };
  19. enum OutputIds {
  20. A_OUTPUT,
  21. NUM_OUTPUTS
  22. };
  23. enum LightIds {
  24. NUM_LIGHTS
  25. };
  26. bool transpose = true;
  27. SchmittTrigger transposeTrigger;
  28. D_Inf() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  29. void step() override;
  30. // For more advanced Module features, read Rack's engine.hpp header file
  31. // - toJson, fromJson: serialization of internal data
  32. // - onSampleRateChange: event triggered by a change of sample rate
  33. // - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu
  34. };
  35. void D_Inf::step() {
  36. if (!inputs[TRIG_INPUT].active) {
  37. transpose = true;
  38. }
  39. else {
  40. if (params[GATE_PARAM].value == 0) {
  41. if (transposeTrigger.process(inputs[TRIG_INPUT].value)) {
  42. transpose = !transpose;
  43. }
  44. }
  45. else {
  46. if (inputs[TRIG_INPUT].value >= 5.0f) {
  47. transpose = true;
  48. }
  49. else {
  50. transpose = false;
  51. }
  52. }
  53. }
  54. float output = inputs[A_INPUT].value;
  55. if (transpose) {
  56. if (params[INVERT_PARAM].value == 1) {
  57. output *= -1.0f;
  58. }
  59. output += params[OCTAVE_PARAM].value + 0.083333 * params[COARSE_PARAM].value + 0.041667 * params[HALF_SHARP_PARAM].value;
  60. }
  61. else {
  62. if (params[INVERT_TRIG_PARAM].value == 0) {
  63. if (params[INVERT_PARAM].value == 1) {
  64. output *= -1.0f;
  65. }
  66. }
  67. }
  68. outputs[A_OUTPUT].value = output;
  69. }
  70. struct D_InfWidget : ModuleWidget {
  71. D_InfWidget(D_Inf *module) : ModuleWidget(module) {
  72. setPanel(SVG::load(assetPlugin(plugin, "res/Panels/D_Inf.svg")));
  73. addChild(Widget::create<kHzScrew>(Vec(RACK_GRID_WIDTH, 0)));
  74. addChild(Widget::create<kHzScrew>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  75. addParam(ParamWidget::create<kHzKnobSmallSnap>(Vec(14, 40), module, D_Inf::OCTAVE_PARAM, -4, 4, 0));
  76. addParam(ParamWidget::create<kHzKnobSmallSnap>(Vec(14, 96), module, D_Inf::COARSE_PARAM, -7, 7, 0));
  77. addParam(ParamWidget::create<kHzButton>(Vec(10, 150), module, D_Inf::HALF_SHARP_PARAM, 0, 1, 0));
  78. addParam(ParamWidget::create<kHzButton>(Vec(36, 150), module, D_Inf::INVERT_PARAM, 0, 1, 0));
  79. addParam(ParamWidget::create<kHzButton>(Vec(10, 182), module, D_Inf::GATE_PARAM, 0, 1, 0));
  80. addParam(ParamWidget::create<kHzButton>(Vec(36, 182), module, D_Inf::INVERT_TRIG_PARAM, 0, 1, 0));
  81. addInput(Port::create<kHzPort>(Vec(17, 234), Port::INPUT, module, D_Inf::TRIG_INPUT));
  82. addInput(Port::create<kHzPort>(Vec(17, 276), Port::INPUT, module, D_Inf::A_INPUT));
  83. addOutput(Port::create<kHzPort>(Vec(17, 318), Port::OUTPUT, module, D_Inf::A_OUTPUT));
  84. }
  85. };
  86. } // namespace rack_plugin_21kHz
  87. using namespace rack_plugin_21kHz;
  88. RACK_PLUGIN_MODEL_INIT(21kHz, D_Inf) {
  89. Model *modelD_Inf = Model::create<D_Inf, D_InfWidget>("21kHz", "kHzD_Inf", "Dāˆž — pitch tools — 4hp", TUNER_TAG, UTILITY_TAG);
  90. return modelD_Inf;
  91. }
  92. // history
  93. // 0.6.1
  94. // create