/*
 * tbzmusic.h: music for the fredygames.com browser build of TecnoballZ (Emscripten).
 *
 * The game plays parts of one ProTracker module at a time: it jumps to a song position
 * (Mix_SetMusicPosition, which SDL_mixer's MikMod backend maps to the order number) and watches the
 * position MikMod is playing (MODULE->sngpos, ->patpos, ->numpos), which it reads from SDL_mixer's
 * internal structures. SDL2_mixer in Emscripten has no MikMod, and its modplug backend seeks in
 * milliseconds, so this file plays the music itself with libmodplug (which can seek to an order and
 * report the order and row being played), through Mix_HookMusic. The sound effects stay on SDL2_mixer.
 *
 * Copyright (C) 2026 FredyGames. GNU GPL version 3 or later, like TecnoballZ.
 */
#ifndef TBZ_MUSIC_H
#define TBZ_MUSIC_H

#include <SDL.h>
#include <SDL_mixer.h>

#ifdef __cplusplus
extern "C" {
#endif

/* the fields of MikMod's MODULE that the game reads */
typedef struct
{
  int sngpos;   /* order (song position) being played */
  int patpos;   /* row being played in that pattern */
  int numpos;   /* number of orders in the song */
} MODULE;

Mix_Music *tbz_LoadMUS (const char *file);
void tbz_FreeMusic (Mix_Music * music);
int tbz_PlayMusic (Mix_Music * music, int loops);
int tbz_HaltMusic (void);
int tbz_SetMusicPosition (double position);
int tbz_VolumeMusic (int volume);
MODULE *tbz_music_module (Mix_Music * music);
int Player_Paused (void);
void Player_TogglePause (void);
void Player_Stop (void);

#ifndef TBZ_MUSIC_IMPLEMENTATION
#define Mix_LoadMUS tbz_LoadMUS
#define Mix_FreeMusic tbz_FreeMusic
#define Mix_PlayMusic tbz_PlayMusic
#define Mix_HaltMusic tbz_HaltMusic
#define Mix_SetMusicPosition tbz_SetMusicPosition
#define Mix_VolumeMusic tbz_VolumeMusic
#endif

#ifdef __cplusplus
}
#endif

#endif
