Voice.hpp 815 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <SFML/Audio.hpp>
  3. #include <SFML/Graphics.hpp>
  4. #include <queue>
  5. class Voice {
  6. public:
  7. Voice();
  8. ~Voice();
  9. void addLine(std::string filename, float timer, bool pitch = false);
  10. void addSubtitle(float timer, float duration, std::string text, sf::Color color = sf::Color(172, 50, 50));
  11. void update(float dt);
  12. bool isFree() const {
  13. return m_lines.empty() && m_subs.empty();
  14. }
  15. void clear() {
  16. while(!m_lines.empty())
  17. m_lines.pop();
  18. m_sound.stop();
  19. }
  20. private:
  21. sf::Sound m_sound;
  22. sf::Text m_text;
  23. struct Line {
  24. float clock{ 0.f };
  25. float timer;
  26. bool pitch;
  27. std::string filename;
  28. bool played{ false };
  29. };
  30. struct Sub {
  31. float clock{ 0.f };
  32. float timer;
  33. float duration;
  34. sf::Color color;
  35. std::string text;
  36. };;
  37. std::queue<Line> m_lines;
  38. std::queue<Sub> m_subs;
  39. };