diff --git a/dependencies/subprojects/animationwindow/include/AnimationWindow.h b/dependencies/subprojects/animationwindow/include/AnimationWindow.h index 77d299ac8c9c1049d01e622f9cf465b14ce34c79..7fcde363734aa1d700897f5917d9bef300100537 100644 --- a/dependencies/subprojects/animationwindow/include/AnimationWindow.h +++ b/dependencies/subprojects/animationwindow/include/AnimationWindow.h @@ -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 diff --git a/dependencies/subprojects/animationwindow/include/Audio.h b/dependencies/subprojects/animationwindow/include/Audio.h index c4c2579e15059c651caca74c1d86a5a7c9d1bc26..44324bb624b8852a73e5779fb5009b9bc85fdae2 100644 --- a/dependencies/subprojects/animationwindow/include/Audio.h +++ b/dependencies/subprojects/animationwindow/include/Audio.h @@ -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); }; } diff --git a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp index 37e4650b8baa3d2fd7fea31a6729509d6fd8b697..ea8158e9a2919b1cd3d9b8b0f6130db61a54fec9 100644 --- a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp +++ b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp @@ -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); } diff --git a/dependencies/subprojects/animationwindow/src/Audio.cpp b/dependencies/subprojects/animationwindow/src/Audio.cpp index 056251ac1d7b81177d931171d8edf96ce685f239..b3352100aa106b9c88592f34e63ecb880d0e1e2c 100644 --- a/dependencies/subprojects/animationwindow/src/Audio.cpp +++ b/dependencies/subprojects/animationwindow/src/Audio.cpp @@ -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); }