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.

192 lines
4.4KB

  1. #include "cf.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_cf {
  4. struct DISTO : Module {
  5. enum ParamIds {
  6. FOLD_PARAM,
  7. GAIN_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. IN_INPUT,
  12. GAIN_INPUT,
  13. FOLD_INPUT,
  14. NUM_INPUTS
  15. };
  16. enum OutputIds {
  17. X_OUTPUT,
  18. NUM_OUTPUTS
  19. };
  20. float x = 0;
  21. float y = 0;
  22. int length = 0;
  23. float fold_gain ;
  24. int fold_affi ;
  25. float gain_gain ;
  26. int gain_affi ;
  27. DISTO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
  28. void step() override;
  29. };
  30. void DISTO::step() {
  31. if (inputs[FOLD_INPUT].active) {
  32. fold_affi =true; fold_gain = clamp(inputs[FOLD_INPUT].value,-0.001,10.001) ;}
  33. else {fold_affi =false; fold_gain = params[FOLD_PARAM].value ;}
  34. if (inputs[GAIN_INPUT].active) {
  35. gain_affi =true; gain_gain = clamp(inputs[GAIN_INPUT].value,-0.001,10.001) ;}
  36. else {gain_affi =false; gain_gain = params[GAIN_PARAM].value ;}
  37. //////////DISTO
  38. x=inputs[IN_INPUT].value*5.0f*gain_gain;
  39. if (abs(x)>5) y = clamp((abs(x)-5)/2.2f,0.0f,58.0f); else y=0;
  40. for (int i =0; i<100; i++) {
  41. if (x<-5.0f) x=-5.0f+(-x-5.0f)*fold_gain/5.0;
  42. if (x>5.0f) x=5.0f-(x-5.0f)*fold_gain/5.0;
  43. if ((x>=-5.0) & (x<=5.0)) i=1000;
  44. if (i==99) x=0;
  45. }
  46. outputs[X_OUTPUT].value=clamp(x,-5.0f,5.0f);
  47. }
  48. struct cachecl : SVGScrew {
  49. cachecl() {
  50. sw->setSVG(SVG::load(assetPlugin(plugin, "res/distocach.svg")));
  51. box.size = sw->box.size;
  52. }
  53. };
  54. struct DISTODisplay : TransparentWidget {
  55. float *xxxx;
  56. int *llll;
  57. float bu[5] = {};
  58. int ind = 0;
  59. DISTODisplay() {
  60. }
  61. void draw(NVGcontext *vg) {
  62. bu[ind] = *xxxx ;
  63. for (int i = 0 ; i<5 ; i++){
  64. {//nvgStrokeColor(vg, nvgRGBA(0x28, 0xb0, 0xf3, 0xff));
  65. nvgBeginPath(vg);
  66. nvgCircle(vg, 0,0, bu[i]);
  67. nvgFillColor(vg, nvgRGBA(0x28, 0xb0, 0xf3, 0xff));
  68. nvgGlobalCompositeOperation(vg, NVG_LIGHTER);
  69. nvgFill(vg);
  70. nvgClosePath(vg);
  71. }
  72. }
  73. //nvgStroke(vg);
  74. if (ind<4) ind = ind +1; else ind = 0;
  75. }
  76. };
  77. struct MOTORPOTDisplay : TransparentWidget {
  78. float d;
  79. float *gainX ;
  80. int *affich;
  81. MOTORPOTDisplay() {
  82. }
  83. void draw(NVGcontext *vg) {
  84. if (*affich==1) {
  85. float xx = d*sin(-(*gainX*0.17+0.15)*M_PI) ;
  86. float yy = d*cos((*gainX*0.17+0.15)*M_PI) ;
  87. nvgBeginPath(vg);
  88. nvgCircle(vg, 0,0, d);
  89. nvgFillColor(vg, nvgRGBA(0x00, 0x00, 0x00, 0xff));
  90. nvgFill(vg);
  91. nvgStrokeWidth(vg,1.2);
  92. nvgStrokeColor(vg, nvgRGBA(0xff, 0xff, 0xff, 0xff));
  93. {
  94. nvgBeginPath(vg);
  95. nvgMoveTo(vg, 0,0);
  96. nvgLineTo(vg, xx,yy);
  97. nvgClosePath(vg);
  98. }
  99. nvgStroke(vg);
  100. }
  101. }
  102. };
  103. struct DISTOWidget : ModuleWidget {
  104. DISTOWidget(DISTO *module);
  105. };
  106. DISTOWidget::DISTOWidget(DISTO *module) : ModuleWidget(module) {
  107. setPanel(SVG::load(assetPlugin(plugin, "res/DISTO.svg")));
  108. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  109. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  110. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  111. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  112. {
  113. DISTODisplay *distdisplay = new DISTODisplay();
  114. distdisplay->box.pos = Vec(60, 170);
  115. distdisplay->xxxx = &module->y ;
  116. distdisplay->llll = &module->length ;
  117. addChild(distdisplay);
  118. }
  119. addInput(Port::create<PJ301MPort>(Vec(15, 321), Port::INPUT, module, DISTO::IN_INPUT));
  120. addInput(Port::create<PJ301MPort>(Vec(47, 321), Port::INPUT, module, DISTO::GAIN_INPUT));
  121. addParam(ParamWidget::create<Trimpot>(Vec(50.4, 284), module, DISTO::GAIN_PARAM, 0.0f, 10.0f, 0.2f));
  122. {
  123. MOTORPOTDisplay *gaindisplay = new MOTORPOTDisplay();
  124. gaindisplay->box.pos = Vec(59.8, 293.2);
  125. gaindisplay->d = 9.3;
  126. gaindisplay->gainX = &module->gain_gain;
  127. gaindisplay->affich = &module->gain_affi;
  128. addChild(gaindisplay);
  129. }
  130. addInput(Port::create<PJ301MPort>(Vec(80, 321), Port::INPUT, module, DISTO::FOLD_INPUT));
  131. addParam(ParamWidget::create<Trimpot>(Vec(83.4, 284), module, DISTO::FOLD_PARAM, 0.0f, 10.0f, 0.0f));
  132. {
  133. MOTORPOTDisplay *folddisplay = new MOTORPOTDisplay();
  134. folddisplay->box.pos = Vec(92.8, 293.2);
  135. folddisplay->d = 9.3;
  136. folddisplay->gainX = &module->fold_gain;
  137. folddisplay->affich = &module->fold_affi;
  138. addChild(folddisplay);
  139. }
  140. addOutput(Port::create<PJ301MPort>(Vec(80, 31), Port::OUTPUT, module, DISTO::X_OUTPUT));
  141. addChild(Widget::create<cachecl>(Vec(0, 0)));
  142. }
  143. } // namespace rack_plugin_cf
  144. using namespace rack_plugin_cf;
  145. RACK_PLUGIN_MODEL_INIT(cf, DISTO) {
  146. Model *modelDISTO = Model::create<DISTO, DISTOWidget>("cf", "DISTO", "Disto", DISTORTION_TAG);
  147. return modelDISTO;
  148. }