Skip to content
Snippets Groups Projects
Commit 18744e88 authored by Joakim Hunskaar's avatar Joakim Hunskaar
Browse files

simpler audio API

parent d82861eb
No related branches found
No related tags found
1 merge request!15Add sdl mixer
......@@ -132,6 +132,6 @@ class AnimationWindow {
float get_delta_mouse_wheel() const;
//
void play_audio(TDT4102::Audio& audio, bool loop = false, int repeat = 0);
void play_audio(TDT4102::Audio& audio, int loops = 0);
};
} // namespace TDT4102
......@@ -24,6 +24,6 @@ namespace TDT4102 {
std::filesystem::path src = "non existent file";
void load();
void play(bool loop, int repeat); // 0 is for play once and stop
void play(int loops = 0);
};
}
......@@ -416,7 +416,7 @@ void TDT4102::AnimationWindow::setBackgroundColor(TDT4102::Color newBackgroundCo
SDL_RenderClear(rendererHandle);
}
void TDT4102::AnimationWindow::play_audio(TDT4102::Audio& audio, bool loop, int repeat) {
audio.play(loop, repeat);
void TDT4102::AnimationWindow::play_audio(TDT4102::Audio& audio, int loops) {
audio.play(loops);
}
......@@ -35,15 +35,19 @@ void TDT4102::Audio::load() {
}
void TDT4102::Audio::play(bool loop, int repeat) {
void TDT4102::Audio::play(int loops) {
if (loops < 0) {
throw std::runtime_error("Number of loops must be positive!");
}
if(!ready) {
load();
}
if (isMusic) {
Mix_PlayMusic(mus, loop ? -1 : repeat);
Mix_PlayMusic(mus, loops == 0 ? loops : loops--);
} else {
Mix_PlayChannel(-1, sfx, loop ? -1 : repeat);
Mix_PlayChannel(-1, sfx, loops == 0 ? loops-- : loops);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment