Hymn to Beauty
C++ 3D Engine
SoundSource.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "SuperComponent.hpp"
4#include <string>
5#include <miniaudio.h>
6
7class SoundManager;
8
9namespace Component {
12 friend class ::SoundManager;
13
14 public:
17
20
21 void Serialize(Json::Value& node, bool load) override;
22
24
27 void SetPath(const std::string& path);
28
30
33 const std::string& GetPath() const;
34
36 void Play();
37
39 void Pause();
40
42 void Stop();
43
45 float pitch = 1.0f;
46
48 float gain = 1.0f;
49
51 bool loop = false;
52
53 private:
54 void FreeSound();
55 void ReloadSound();
56
57 ma_engine* engine;
58 ma_sound sound;
59 std::string path = "";
60
61 bool shouldPlay = false;
62 bool shouldPause = false;
63 bool shouldStop = false;
64
65 bool soundInitialized = false;
66};
67} // namespace Component
Component describing a sound source.
Definition: SoundSource.hpp:11
const std::string & GetPath() const
Get the path to the sound file to play.
Definition: SoundSource.cpp:35
float gain
Gain.
Definition: SoundSource.hpp:48
void SetPath(const std::string &path)
Set the path to the sound file to play.
Definition: SoundSource.cpp:30
void Serialize(Json::Value &node, bool load) override
Save or load component values to/from JSON.
Definition: SoundSource.cpp:19
void Play()
Play the sound.
Definition: SoundSource.cpp:39
SoundSource()
Create new sound source.
Definition: SoundSource.cpp:11
~SoundSource()
Destructor.
Definition: SoundSource.cpp:15
void Stop()
Stop the sound.
Definition: SoundSource.cpp:47
void Pause()
Pause the sound.
Definition: SoundSource.cpp:43
float pitch
Pitch.
Definition: SoundSource.hpp:45
bool loop
Whether the sound should loop.
Definition: SoundSource.hpp:51
Component which all components inherit.
Definition: SuperComponent.hpp:9
Handles sound.
Definition: SoundManager.hpp:12
Definition: BoxShapeEditor.hpp:5