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.

48 lines
790B

  1. #include "LightControl.hpp"
  2. #include <engine.hpp>
  3. LightControl::LightControl()
  4. {
  5. setState<StateOff>();
  6. }
  7. void LightControl::step()
  8. {
  9. m_currentValue = m_currentState->step();
  10. }
  11. float LightControl::lightValue()const
  12. {
  13. return m_currentValue;
  14. }
  15. float LightControl::StateOff::step()
  16. {
  17. return 0.f;
  18. }
  19. float LightControl::StateOn::step()
  20. {
  21. return 1.f;
  22. }
  23. LightControl::StateBlink::StateBlink(float blinkTime, bool initialLightState) :
  24. m_blinkTime(blinkTime),
  25. m_timeCounter(0.f),
  26. m_lightState(initialLightState)
  27. {
  28. }
  29. float LightControl::StateBlink::step()
  30. {
  31. auto const timeStep = 1.f / rack::engineGetSampleRate();
  32. m_timeCounter += timeStep;
  33. if (m_timeCounter > m_blinkTime)
  34. {
  35. m_timeCounter -= m_blinkTime;
  36. m_lightState = !m_lightState;
  37. }
  38. return m_lightState ? 1.0f : 0.f;
  39. }