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.

82 lines
1.6KB

  1. #pragma once
  2. #include <vector>
  3. /**
  4. * Base class for composites embeddable in a unit test
  5. * Isolates test from VCV.
  6. */
  7. class TestComposite
  8. {
  9. public:
  10. TestComposite() :
  11. inputs(40),
  12. outputs(40),
  13. params(40),
  14. lights(20)
  15. {
  16. }
  17. struct Param
  18. {
  19. float value = 0.0;
  20. };
  21. struct Light
  22. {
  23. /** The square of the brightness value */
  24. float value = 0.0;
  25. float getBrightness();
  26. void setBrightness(float brightness)
  27. {
  28. value = (brightness > 0.f) ? brightness * brightness : 0.f;
  29. }
  30. void setBrightnessSmooth(float brightness)
  31. {
  32. }
  33. };
  34. struct Input
  35. {
  36. /** Voltage of the port, zero if not plugged in. Read-only by Module */
  37. float value = 0.0;
  38. /** Whether a wire is plugged in */
  39. bool active = false;
  40. Light plugLights[2];
  41. /** Returns the value if a wire is plugged in, otherwise returns the given default value */
  42. float normalize(float normalValue)
  43. {
  44. return active ? value : normalValue;
  45. }
  46. };
  47. struct Output
  48. {
  49. /** Voltage of the port. Write-only by Module */
  50. float value = 0.0;
  51. /** Whether a wire is plugged in */
  52. bool active = true;
  53. Light plugLights[2];
  54. };
  55. std::vector<Input> inputs;
  56. std::vector<Output> outputs;
  57. std::vector<Param> params;
  58. std::vector<Light> lights;
  59. float engineGetSampleTime()
  60. {
  61. return 1.0f / 44100.0f;
  62. }
  63. float engineGetSampleRate()
  64. {
  65. return 44100.f;
  66. }
  67. virtual void step()
  68. {
  69. }
  70. };