CSound.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <optional>
  3. #include "WallpaperEngine/Audio/AudioStream.h"
  4. #include "WallpaperEngine/Render/CObject.h"
  5. using namespace WallpaperEngine;
  6. namespace WallpaperEngine::Render::Wallpapers {
  7. class CScene;
  8. }
  9. namespace WallpaperEngine::Render::Objects {
  10. using namespace WallpaperEngine::Data::Model;
  11. class CSound final : public CObject {
  12. public:
  13. CSound (Wallpapers::CScene& scene, const Sound& sound);
  14. ~CSound () override;
  15. void render () override;
  16. /** Overrides the volume (0-128) this sound's streams mix at instead of the global volume; nullopt = global */
  17. void setVolumeOverride (std::optional<int> volume);
  18. /** Script-facing playback control (thisScene.getLayer(<sound name>).play()/stop()/pause()) */
  19. void play ();
  20. void stop ();
  21. [[nodiscard]] bool isPlaying () const { return this->m_playing; }
  22. protected:
  23. void load ();
  24. private:
  25. void applyEffectiveVolume ();
  26. std::map<int, Audio::AudioStream*> m_audioStreams = {};
  27. const Sound& m_sound;
  28. /** Screen-level mute/ambient-volume policy from CScene::setAudioPolicy; nullopt = no override */
  29. std::optional<int> m_screenVolumeOverride;
  30. bool m_playing = true;
  31. };
  32. } // namespace WallpaperEngine::Render::Objects