diff options
Diffstat (limited to 'src/audio/music.c')
| -rw-r--r-- | src/audio/music.c | 165 |
1 files changed, 79 insertions, 86 deletions
diff --git a/src/audio/music.c b/src/audio/music.c index cf3db24..f2ac6e1 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -6,9 +6,7 @@ #include "main.h" #include "list.h" #include "storage.h" - #include "interface.h" - #include "audio.h" #include "music.h" @@ -17,199 +15,194 @@ static list_t *listStorage; static bool_t isMusicInit = FALSE; static bool_t var_isMusicActive = TRUE; static Mix_Music *currentMusic; - +/* + * Return state of music initialization + */ bool_t isMusicInicialized() { return isMusicInit; } - +/* + * Initialize music + */ void initMusic() { - if( isAudioInicialized() == FALSE ) - { + if (isAudioInicialized() == FALSE) { isMusicInit = FALSE; return; } - listStorage = newStorage(); currentMusic = NULL; - isMusicInit = TRUE; var_isMusicActive = TRUE; - - if( isParamFlag("--nomusic") ) - { + if (isParamFlag("--nomusic")) setMusicActive(FALSE); - } - - if( isParamFlag("--music") ) - { + if (isParamFlag("--music")) setMusicActive(TRUE); - } - - printf("init music..\n"); +#ifdef DEBUG + printf(_("Initializing music...\n")); +#endif } - +/* + * Load music file and returns it + */ static Mix_Music* loadMixMusic(char *file) { - Mix_Music *new; + Mix_Music *mixer; char str[STR_PATH_SIZE]; - - - printf("load music %s..\n", file); +#ifdef DEBUG + printf(_("Loading music file: %s\n"), file); +#endif sprintf(str, PATH_MUSIC "%s", file); - accessExistFile(str); - - new = Mix_LoadMUS(str); - - if( new == NULL ) - { - fprintf(stderr, "Nepodarilo sa nacitat hudbu %s\n", file); + mixer = Mix_LoadMUS(str); + if( mixer == NULL ) { + fprintf(stderr, _("Unable to load music from file: %s\n"), file); return NULL; } - return new; + return mixer; } - +/* + * Prepare music mixer + */ static void playMixMusic() { - if( currentMusic != NULL ) - { + if (currentMusic != NULL) Mix_PlayMusic(currentMusic, 1000); - } } - +/* + * Free memory of music + */ static void destroyMusic(void *p) { Mix_FreeMusic((Mix_Music *)p); } - +/* + * Add file to list with music + */ void addMusic(char *file, char *name, char *group) { Mix_Music *new; - - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } assert( file != NULL ); assert( name != NULL ); assert( group != NULL ); new = loadMixMusic(file); - addItemToStorage(listStorage, group, name, new ); } - +/* + * Disable music and stop playback + */ void stopMusic() { - if( isMusicInit == FALSE || - var_isMusicActive == FALSE ) - { + if (isMusicInit == FALSE || + var_isMusicActive == FALSE) return; - } - if( currentMusic != NULL ) - { - printf("stop music..\n"); + if (currentMusic != NULL) { +#ifdef DEBUG + printf(_("Stopping music...\n")); +#endif Mix_HaltMusic(); currentMusic = NULL; } } - +/* + * start music playback + */ void playMusic(char *name, char *group) { static char currentMusic_group[STR_SIZE]; static char currentMusic_name[STR_SIZE]; static int isStrInit = 0; - if( isStrInit == 0 ) - { + if (isStrInit == 0) { strcpy(currentMusic_group, "none"); strcpy(currentMusic_name, "none"); isStrInit = 1; } - if( isMusicInit == FALSE || - var_isMusicActive == FALSE ) - { + if (isMusicInit == FALSE || + var_isMusicActive == FALSE) return; - } - if( currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0 ) - { + if (currentMusic != NULL && + strcmp(currentMusic_group, group) == 0 && + strcmp(currentMusic_name, name) == 0) { return; } - if( currentMusic != NULL ) - { + if (currentMusic != NULL) stopMusic(); - } currentMusic = getItemFromStorage(listStorage, group, name); strcpy(currentMusic_group, group); strcpy(currentMusic_name, name); - if( currentMusic != NULL ) - { - printf("play music %s\n", name); + if( currentMusic != NULL ) { +#ifdef DEBUG + printf(_("Playing music file %s\n"), name); +#endif playMixMusic(); } } - +/* + * Set music active/deactivated + */ void setMusicActive(bool_t n) { static Mix_Music *music = NULL; - if( n == FALSE ) - { + if (n == FALSE) { music = currentMusic; stopMusic(); } - - if( n == TRUE ) - { + if (n == TRUE) { currentMusic = music; playMixMusic(); } var_isMusicActive = n; } - +/* + * Return status of music + */ bool_t isMusicActive() { return var_isMusicActive; } - +/* + * TOCOMMENT + */ char* getCurrentMusic() { return "unknown"; } - +/* + * TOCOMMENT + */ void delAllMusicInGroup(char *group) { - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } - delAllItemFromStorage(listStorage, group, destroyMusic); } - +/* + * Deactivate all what is ment for music + */ void quitMusic() { - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } stopMusic(); destroyStorage(listStorage, destroyMusic); isMusicInit = FALSE; - - printf("quit music..\n"); +#ifdef DEBUG + printf(_("Quitting music...\n")); +#endif } |