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.

65 lines
1.4KB

  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(8),
  12. outputs(8),
  13. params(8)
  14. {
  15. }
  16. struct Param
  17. {
  18. float value = 0.0;
  19. };
  20. struct Light
  21. {
  22. /** The square of the brightness value */
  23. float value = 0.0;
  24. float getBrightness();
  25. void setBrightness(float brightness)
  26. {
  27. value = (brightness > 0.f) ? brightness * brightness : 0.f;
  28. }
  29. void setBrightnessSmooth(float brightness);
  30. };
  31. struct Input
  32. {
  33. /** Voltage of the port, zero if not plugged in. Read-only by Module */
  34. float value = 0.0;
  35. /** Whether a wire is plugged in */
  36. bool active = false;
  37. Light plugLights[2];
  38. /** Returns the value if a wire is plugged in, otherwise returns the given default value */
  39. float normalize(float normalValue)
  40. {
  41. return active ? value : normalValue;
  42. }
  43. };
  44. struct Output
  45. {
  46. /** Voltage of the port. Write-only by Module */
  47. float value = 0.0;
  48. /** Whether a wire is plugged in */
  49. bool active = false;
  50. Light plugLights[2];
  51. };
  52. std::vector<Input> inputs;
  53. std::vector<Output> outputs;
  54. std::vector<Param> params;
  55. };