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.

112 lines
3.6KB

  1. #include "Bidoo.hpp"
  2. #include "BidooComponents.hpp"
  3. #include "dsp/digital.hpp"
  4. using namespace std;
  5. namespace rack_plugin_Bidoo {
  6. struct BISTROT : Module {
  7. enum ParamIds {
  8. LINK_PARAM,
  9. NUM_PARAMS
  10. };
  11. enum InputIds {
  12. INPUT,
  13. ADCCLOCK_INPUT,
  14. DACCLOCK_INPUT,
  15. BIT_INPUT,
  16. NUM_INPUTS = BIT_INPUT + 8
  17. };
  18. enum OutputIds {
  19. OUTPUT,
  20. BIT_OUTPUT,
  21. NUM_OUTPUTS = BIT_OUTPUT + 8
  22. };
  23. enum LightIds {
  24. LINK_LIGHT,
  25. BIT_INPUT_LIGHTS,
  26. BIT_OUTPUT_LIGHTS = BIT_INPUT_LIGHTS + 8,
  27. NUM_LIGHTS = BIT_OUTPUT_LIGHTS + 8
  28. };
  29. SchmittTrigger linkTrigger, acdClockTrigger, dacClockTrigger;
  30. unsigned char in = 0;
  31. unsigned char out = 0;
  32. BISTROT() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  33. }
  34. ~BISTROT() {
  35. }
  36. void step() override;
  37. };
  38. void BISTROT::step() {
  39. if ((!inputs[ADCCLOCK_INPUT].active) || (acdClockTrigger.process(inputs[ADCCLOCK_INPUT].value)))
  40. {
  41. in = roundf(clamp(clamp(inputs[INPUT].value,-10.0f,10.0f) / 20.0f + 0.5f, 0.0f, 1.0f) * 255);
  42. }
  43. for (int i = 0 ; i != 8 ; i++)
  44. {
  45. int bitValue = ((in & (1U << i)) != 0);
  46. lights[BIT_INPUT_LIGHTS+i].value = 1-bitValue;
  47. outputs[BIT_OUTPUT+i].value = (1-bitValue) * 10;
  48. }
  49. if ((!inputs[DACCLOCK_INPUT].active) || (dacClockTrigger.process(inputs[DACCLOCK_INPUT].value)))
  50. {
  51. for (int i = 0 ; i != 8 ; i++)
  52. {
  53. if ((inputs[BIT_INPUT+i].active) && (inputs[BIT_INPUT+i].value != 0)) {
  54. out |= 1U << i;
  55. }
  56. else {
  57. out &= ~(1U << i);
  58. }
  59. lights[BIT_OUTPUT_LIGHTS+i].value = (out >> i) & 1U;
  60. }
  61. }
  62. outputs[OUTPUT].value = -1.0f * clamp(((((float)out/255.0f))-0.5f)*10.0f,-10.0f,10.0f);
  63. }
  64. struct BISTROTWidget : ModuleWidget {
  65. BISTROTWidget(BISTROT *module) : ModuleWidget(module) {
  66. setPanel(SVG::load(assetPlugin(plugin, "res/BISTROT.svg")));
  67. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  68. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  69. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  70. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  71. addInput(Port::create<PJ301MPort>(Vec(29.0f, 46.0f), Port::INPUT, module, BISTROT::ADCCLOCK_INPUT));
  72. addInput(Port::create<PJ301MPort>(Vec(67.0f, 46.0f), Port::INPUT, module, BISTROT::DACCLOCK_INPUT));
  73. for (int i = 0; i<8; i++) {
  74. addChild(ModuleLightWidget::create<SmallLight<RedLight>>(Vec(18.0f, 97.5f + 26.0f * i), module, BISTROT::BIT_INPUT_LIGHTS + i));
  75. addOutput(Port::create<TinyPJ301MPort>(Vec(34.0f, 93.0f + 26.0f * i), Port::OUTPUT, module, BISTROT::BIT_OUTPUT + i));
  76. addInput(Port::create<TinyPJ301MPort>(Vec(72.0f, 93.0f + 26.0f * i), Port::INPUT, module, BISTROT::BIT_INPUT + i));
  77. addChild(ModuleLightWidget::create<SmallLight<BlueLight>>(Vec(95.0f, 97.5f + 26.0f * i), module, BISTROT::BIT_OUTPUT_LIGHTS + i));
  78. }
  79. addInput(Port::create<PJ301MPort>(Vec(29.0f, 320.0f), Port::INPUT, module, BISTROT::INPUT));
  80. // addInput(Port::create<TinyPJ301MPort>(Vec(24.0f, 339.0f), Port::INPUT, module, BISTROT::R_INPUT));
  81. addOutput(Port::create<PJ301MPort>(Vec(67.0f, 320.0f),Port::OUTPUT, module, BISTROT::OUTPUT));
  82. // addOutput(Port::create<TinyPJ301MPort>(Vec(78.0f, 339.0f),Port::OUTPUT, module, BISTROT::R_OUTPUT));
  83. }
  84. };
  85. } // namespace rack_plugin_Bidoo
  86. using namespace rack_plugin_Bidoo;
  87. RACK_PLUGIN_MODEL_INIT(Bidoo, BISTROT) {
  88. Model *modelBISTROT = Model::create<BISTROT, BISTROTWidget>("Bidoo", "BISTROT", "BISTROT bit crusher", EFFECT_TAG, DIGITAL_TAG, DISTORTION_TAG);
  89. return modelBISTROT;
  90. }