JA_GetMusicState & JA_GetChannelState replace paused ones

This commit is contained in:
2021-02-07 22:06:21 +01:00
parent f94d9294eb
commit 852710d15d
3 changed files with 13 additions and 13 deletions

View File

@@ -9,8 +9,6 @@ struct JA_Sound_t {
Uint8* buffer {NULL};
};
enum JA_Channel_state { JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
struct JA_Channel_t {
JA_Sound sound;
int pos {0};
@@ -18,8 +16,6 @@ struct JA_Channel_t {
JA_Channel_state state { JA_CHANNEL_FREE };
};
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
struct JA_Music_t {
int samples {0};
int pos {0};
@@ -127,8 +123,9 @@ void JA_StopMusic() {
current_music->state = JA_MUSIC_STOPPED;
}
bool JA_IsMusicPlaying() {
return current_music != NULL && current_music->state == JA_MUSIC_PLAYING;
JA_Music_state JA_GetMusicState() {
if (current_music == NULL) return JA_MUSIC_INVALID;
return current_music->state;
}
void JA_DeleteMusic(JA_Music music) {
@@ -209,8 +206,8 @@ void JA_StopChannel(const int channel) {
}
}
bool JA_IsChannelPlaying(const int channel) {
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return false;
return channels[channel].state == JA_CHANNEL_PLAYING;
JA_Channel_state JA_GetChannelState(const int channel) {
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
return channels[channel].state;
}

View File

@@ -1,6 +1,9 @@
#pragma once
#include <SDL2/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
typedef struct JA_Sound_t *JA_Sound;
typedef struct JA_Music_t *JA_Music;
@@ -11,7 +14,7 @@ void JA_PlayMusic(JA_Music music, const int loop = -1);
void JA_PauseMusic();
void JA_ResumeMusic();
void JA_StopMusic();
bool JA_IsMusicPlaying();
JA_Music_state JA_GetMusicState();
void JA_DeleteMusic(JA_Music music);
JA_Sound JA_LoadSound(const char* filename);
@@ -19,5 +22,5 @@ int JA_PlaySound(JA_Sound sound, const int loop = 0);
void JA_PauseChannel(const int channel);
void JA_ResumeChannel(const int channel);
void JA_StopChannel(const int channel);
bool JA_IsChannelPlaying(const int channel);
JA_Channel_state JA_GetChannelState(const int channel);
void JA_DeleteSound(JA_Sound sound);

View File

@@ -24,7 +24,7 @@ int main(int argc, char **argv) {
if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.scancode) {
case SDL_SCANCODE_1: // Si pulsem la tecla '1' pausem o despausem la música
if (JA_IsMusicPlaying()) { JA_PauseMusic(); } else { JA_ResumeMusic(); }
if (JA_GetMusicState() == JA_MUSIC_PLAYING) { JA_PauseMusic(); } else { JA_ResumeMusic(); }
break;
case SDL_SCANCODE_2: // Si pulsem la tecla '2' sona el wav 1 vegada
JA_PlaySound(peiv);
@@ -36,7 +36,7 @@ int main(int argc, char **argv) {
channel = JA_PlaySound(peiv, -1);
break;
case SDL_SCANCODE_5: // Si pulsem la tecla '5' pausem o despausem el wav que sonaba infinitament
if (JA_IsChannelPlaying(channel)) { JA_PauseChannel(channel); } else { JA_ResumeChannel(channel); }
if (JA_GetChannelState(channel) == JA_CHANNEL_PLAYING) { JA_PauseChannel(channel); } else { JA_ResumeChannel(channel); }
break;
case SDL_SCANCODE_6: // Si pulsem la tecla '6' stopem definitivament el wav infinit
JA_StopChannel(channel);