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.

76 lines
2.1KB

  1. #include "NauModular.hpp"
  2. namespace rack_plugin_NauModular {
  3. struct S_h_it : Module{
  4. enum ParamIds{
  5. TIME_PARAM,
  6. MULT_PARAM,
  7. NUM_PARAMS
  8. };
  9. enum InputIds{
  10. VOLT_INPUT,
  11. NUM_INPUTS
  12. };
  13. enum OutputIds{
  14. VOLT_OUTPUT,
  15. NUM_OUTPUTS
  16. };
  17. enum LightIds{
  18. NUM_LIGHTS
  19. };
  20. S_h_it() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS){}
  21. void step() override;
  22. float curTime = 0.0;
  23. float lastTime = 0.0;
  24. float outVoltage = 0.0;
  25. };
  26. void S_h_it::step(){
  27. float deltaTime = 1.0 / engineGetSampleRate();
  28. curTime += deltaTime;
  29. if(!std::isfinite(curTime)) curTime = 0.0;
  30. float timeElapsed = fabs(curTime-lastTime);
  31. float timeInterval = params[TIME_PARAM].value / params[MULT_PARAM].value;
  32. if(timeElapsed >= timeInterval){
  33. outVoltage = inputs[VOLT_INPUT].value;
  34. lastTime = curTime;
  35. }
  36. outputs[VOLT_OUTPUT].value = outVoltage;
  37. }
  38. struct S_h_itWidget : ModuleWidget{
  39. S_h_itWidget(S_h_it *module);
  40. };
  41. S_h_itWidget::S_h_itWidget(S_h_it *module) : ModuleWidget(module){
  42. box.size = Vec(3*RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  43. {
  44. SVGPanel * panel = new SVGPanel();
  45. panel->box.size = box.size;
  46. panel->setBackground(SVG::load(assetPlugin(plugin, "res/sh.svg")));
  47. addChild(panel);
  48. }
  49. addChild(Widget::create<ScrewSilver>(Vec(box.size.x/2,0)));
  50. addChild(Widget::create<ScrewSilver>(Vec(box.size.x/2,365)));
  51. addParam(ParamWidget::create<Davies1900hBlackKnob>(Vec(5,150), module, S_h_it::TIME_PARAM, 0.2, 1.0, 0.5));
  52. addParam(ParamWidget::create<RoundSmallBlackKnob>(Vec(9,200), module, S_h_it::MULT_PARAM, 1.0, 50.0, 5.0));
  53. addInput(Port::create<PJ301MPort>(Vec(11,235), Port::INPUT, module, S_h_it::VOLT_INPUT));
  54. addOutput(Port::create<PJ301MPort>(Vec(11,275), Port::OUTPUT, module, S_h_it::VOLT_OUTPUT));
  55. }
  56. } // namespace rack_plugin_NauModular
  57. using namespace rack_plugin_NauModular;
  58. RACK_PLUGIN_MODEL_INIT(NauModular, S_h_it) {
  59. Model *modelS_h_it = Model::create<S_h_it, S_h_itWidget>("NauModular", "S&h(it)", "S&h(it)", SAMPLE_AND_HOLD_TAG);
  60. return modelS_h_it;
  61. }