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.

89 lines
1.7KB

  1. #pragma once
  2. #include "ObjectCache.h"
  3. #include "GenerativeTriggerGenerator.h"
  4. #include "TriggerOutput.h"
  5. #include <memory>
  6. /**
  7. */
  8. template <class TBase>
  9. class GMR : public TBase
  10. {
  11. public:
  12. GMR(struct Module * module) : TBase(module), inputClockProcessing(true)
  13. {
  14. }
  15. GMR() : TBase(), inputClockProcessing(true)
  16. {
  17. }
  18. void setSampleRate(float rate)
  19. {
  20. reciprocalSampleRate = 1 / rate;
  21. }
  22. // must be called after setSampleRate
  23. void init();
  24. enum ParamIds
  25. {
  26. NUM_PARAMS
  27. };
  28. enum InputIds
  29. {
  30. CLOCK_INPUT,
  31. NUM_INPUTS
  32. };
  33. enum OutputIds
  34. {
  35. TRIGGER_OUTPUT,
  36. NUM_OUTPUTS
  37. };
  38. enum LightIds
  39. {
  40. NUM_LIGHTS
  41. };
  42. /**
  43. * Main processing entry point. Called every sample
  44. */
  45. void step() override;
  46. private:
  47. float reciprocalSampleRate = 0;
  48. std::shared_ptr<GenerativeTriggerGenerator> gtg;
  49. GateTrigger inputClockProcessing;
  50. TriggerOutput outputProcessing;
  51. };
  52. template <class TBase>
  53. inline void GMR<TBase>::init()
  54. {
  55. StochasticGrammarDictionary::Grammar grammar = StochasticGrammarDictionary::getGrammar(0);
  56. gtg = std::make_shared<GenerativeTriggerGenerator>(
  57. AudioMath::random(),
  58. grammar.rules,
  59. grammar.numRules,
  60. grammar.firstRule);
  61. }
  62. template <class TBase>
  63. inline void GMR<TBase>::step()
  64. {
  65. bool outClock = false;
  66. float inClock = TBase::inputs[CLOCK_INPUT].value;
  67. inputClockProcessing.go(inClock);
  68. if (inputClockProcessing.trigger()) {
  69. outClock = gtg->clock();
  70. }
  71. outputProcessing.go(outClock);
  72. TBase::outputs[TRIGGER_OUTPUT].value = outputProcessing.get();
  73. }