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.

111 lines
3.1KB

  1. #include "HetrickCV.hpp"
  2. namespace rack_plugin_HetrickCV {
  3. struct Contrast : Module
  4. {
  5. enum ParamIds
  6. {
  7. AMOUNT_PARAM,
  8. SCALE_PARAM,
  9. RANGE_PARAM,
  10. NUM_PARAMS
  11. };
  12. enum InputIds
  13. {
  14. MAIN_INPUT,
  15. AMOUNT_INPUT,
  16. NUM_INPUTS
  17. };
  18. enum OutputIds
  19. {
  20. MAIN_OUTPUT,
  21. NUM_OUTPUTS
  22. };
  23. Contrast() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS)
  24. {
  25. }
  26. void step() override;
  27. // For more advanced Module features, read Rack's engine.hpp header file
  28. // - toJson, fromJson: serialization of internal data
  29. // - onSampleRateChange: event triggered by a change of sample rate
  30. // - reset, randomize: implements special behavior when user clicks these from the context menu
  31. };
  32. void Contrast::step()
  33. {
  34. float input = inputs[MAIN_INPUT].value;
  35. bool mode5V = (params[RANGE_PARAM].value == 0.0f);
  36. if(mode5V) input = clampf(input, -5.0f, 5.0f) * 0.2f;
  37. else input = clampf(input, -10.0f, 10.0f) * 0.1f;
  38. float contrast = params[AMOUNT_PARAM].value + (inputs[AMOUNT_INPUT].value * params[SCALE_PARAM].value);
  39. contrast = clampf(contrast, 0.0f, 5.0f) * 0.2f;
  40. const float factor1 = input * 1.57143;
  41. const float factor2 = sinf(input * 6.28571) * contrast;
  42. float output = sinf(factor1 + factor2);
  43. if(mode5V) output *= 5.0f;
  44. else output *= 10.0f;
  45. outputs[MAIN_OUTPUT].value = output;
  46. }
  47. struct CKSSRot : SVGSwitch, ToggleSwitch {
  48. CKSSRot() {
  49. addFrame(SVG::load(assetPlugin(plugin, "res/CKSS_rot_0.svg")));
  50. addFrame(SVG::load(assetPlugin(plugin, "res/CKSS_rot_1.svg")));
  51. sw->wrap();
  52. box.size = sw->box.size;
  53. }
  54. };
  55. struct ContrastWidget : ModuleWidget { ContrastWidget(Contrast *module); };
  56. ContrastWidget::ContrastWidget(Contrast *module) : ModuleWidget(module)
  57. {
  58. box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  59. {
  60. auto *panel = new SVGPanel();
  61. panel->box.size = box.size;
  62. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Contrast.svg")));
  63. addChild(panel);
  64. }
  65. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  66. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 0)));
  67. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  68. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 365)));
  69. //////PARAMS//////
  70. addParam(ParamWidget::create<Davies1900hBlackKnob>(Vec(27, 62), module, Contrast::AMOUNT_PARAM, 0, 5.0, 0.0));
  71. addParam(ParamWidget::create<Trimpot>(Vec(36, 112), module, Contrast::SCALE_PARAM, -1.0, 1.0, 1.0));
  72. addParam(ParamWidget::create<CKSSRot>(Vec(35, 200), module, Contrast::RANGE_PARAM, 0.0, 1.0, 0.0));
  73. //////INPUTS//////
  74. addInput(Port::create<PJ301MPort>(Vec(33, 235), Port::INPUT, module, Contrast::MAIN_INPUT));
  75. addInput(Port::create<PJ301MPort>(Vec(33, 145), Port::INPUT, module, Contrast::AMOUNT_INPUT));
  76. //////OUTPUTS//////
  77. addOutput(Port::create<PJ301MPort>(Vec(33, 285), Port::OUTPUT, module, Contrast::MAIN_OUTPUT));
  78. }
  79. } // namespace rack_plugin_HetrickCV
  80. using namespace rack_plugin_HetrickCV;
  81. RACK_PLUGIN_MODEL_INIT(HetrickCV, Contrast) {
  82. Model *modelContrast = Model::create<Contrast, ContrastWidget>("HetrickCV", "Contrast", "Contrast", EFFECT_TAG);
  83. return modelContrast;
  84. }