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.

66 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(20),
  12. outputs(20),
  13. params(20),
  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. struct Input
  33. {
  34. /** Voltage of the port, zero if not plugged in. Read-only by Module */
  35. float value = 0.0;
  36. /** Whether a wire is plugged in */
  37. bool active = false;
  38. Light plugLights[2];
  39. /** Returns the value if a wire is plugged in, otherwise returns the given default value */
  40. float normalize(float normalValue)
  41. {
  42. return active ? value : normalValue;
  43. }
  44. };
  45. struct Output
  46. {
  47. /** Voltage of the port. Write-only by Module */
  48. float value = 0.0;
  49. /** Whether a wire is plugged in */
  50. bool active = false;
  51. Light plugLights[2];
  52. };
  53. std::vector<Input> inputs;
  54. std::vector<Output> outputs;
  55. std::vector<Param> params;
  56. std::vector<Light> lights;
  57. };