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.

69 lines
2.2KB

  1. #include "Offset.hpp"
  2. void Offset::step() {
  3. float offset = knobValue(params[OFFSET_PARAM], inputs[OFFSET_INPUT]);
  4. float scale = knobValue(params[SCALE_PARAM], inputs[SCALE_INPUT]);
  5. scale = scale < 0.0f ? -pow(scale, 2.0f) : pow(scale, 2.0f);
  6. scale *= 10.0;
  7. float out = inputs[IN_INPUT].value;
  8. out += 10.0f * offset;
  9. out *= scale;
  10. if (!_disableOutputLimit) {
  11. out = clamp(out, -12.0f, 12.0f);
  12. }
  13. outputs[OUT_OUTPUT].value = out;
  14. }
  15. float Offset::knobValue(const Param& knob, const Input& cv) const {
  16. float v = knob.value;
  17. if (cv.active) {
  18. v *= clamp(cv.value / 10.0f, -1.0f, 1.0f);
  19. }
  20. return v;
  21. }
  22. struct OffsetWidget : DisableOutputLimitModuleWidget {
  23. static constexpr int hp = 3;
  24. OffsetWidget(Offset* module) : DisableOutputLimitModuleWidget(module) {
  25. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  26. {
  27. SVGPanel *panel = new SVGPanel();
  28. panel->box.size = box.size;
  29. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Offset.svg")));
  30. addChild(panel);
  31. }
  32. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  33. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  34. // generated by svg_widgets.rb
  35. auto offsetParamPosition = Vec(8.0, 40.0);
  36. auto scaleParamPosition = Vec(8.0, 152.0);
  37. auto offsetInputPosition = Vec(10.5, 81.0);
  38. auto scaleInputPosition = Vec(10.5, 193.0);
  39. auto inInputPosition = Vec(10.5, 243.0);
  40. auto outOutputPosition = Vec(10.5, 281.0);
  41. // end generated by svg_widgets.rb
  42. addParam(ParamWidget::create<Knob29>(offsetParamPosition, module, Offset::OFFSET_PARAM, -1.0, 1.0, 0.0));
  43. addParam(ParamWidget::create<Knob29>(scaleParamPosition, module, Offset::SCALE_PARAM, -1.0, 1.0, 0.316));
  44. addInput(Port::create<Port24>(offsetInputPosition, Port::INPUT, module, Offset::OFFSET_INPUT));
  45. addInput(Port::create<Port24>(scaleInputPosition, Port::INPUT, module, Offset::SCALE_INPUT));
  46. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Offset::IN_INPUT));
  47. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Offset::OUT_OUTPUT));
  48. }
  49. };
  50. RACK_PLUGIN_MODEL_INIT(Bogaudio, Offset) {
  51. Model *modelOffset = createModel<Offset, OffsetWidget>("Bogaudio-Offset", "Offset", "CV offset and scaler", ATTENUATOR_TAG);
  52. return modelOffset;
  53. }