basic cleanup and formatting

git-svn-id: https://svn.eduke32.com/eduke32@5815 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-08-27 01:39:41 +00:00
parent a58e1ff580
commit 51992210b8

View file

@ -39,16 +39,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h" #include "compat.h"
#ifndef TRUE #ifndef TRUE
#define TRUE ( 1 == 1 ) #define TRUE (1 == 1)
#define FALSE ( !TRUE ) #define FALSE (!TRUE)
#endif #endif
#ifndef min #ifndef min
#define min(a,b) (((a)<(b))?(a):(b)) #define min(a, b) (((a) < (b)) ? (a) : (b))
#endif #endif
#ifndef max #ifndef max
# define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define max(a, b) (((a) > (b)) ? (a) : (b))
#endif #endif
int32_t MUSIC_SoundDevice = -1; int32_t MUSIC_SoundDevice = -1;
@ -58,203 +58,61 @@ static midifuncs MUSIC_MidiFunctions;
int32_t MUSIC_InitMidi(int32_t card, midifuncs *Funcs, int32_t Address); int32_t MUSIC_InitMidi(int32_t card, midifuncs *Funcs, int32_t Address);
#define MUSIC_SetErrorCode( status ) \ #define MUSIC_SetErrorCode(status) MUSIC_ErrorCode = (status);
MUSIC_ErrorCode = ( status );
/*--------------------------------------------------------------------- const char *MUSIC_ErrorString(int32_t ErrorNumber)
Function: MUSIC_ErrorString
Returns a pointer to the error message associated with an error
number. A -1 returns a pointer the current error.
---------------------------------------------------------------------*/
const char *MUSIC_ErrorString
(
int32_t ErrorNumber
)
{ {
const char *ErrorString; const char *ErrorString;
switch (ErrorNumber) switch (ErrorNumber)
{ {
case MUSIC_Warning : case MUSIC_Warning:
case MUSIC_Error : case MUSIC_Error: ErrorString = MUSIC_ErrorString(MUSIC_ErrorCode); break;
ErrorString = MUSIC_ErrorString(MUSIC_ErrorCode);
break;
case MUSIC_Ok : case MUSIC_Ok: ErrorString = "Music ok."; break;
ErrorString = "Music ok.";
break;
case MUSIC_MidiError : case MUSIC_MidiError: ErrorString = "Error playing MIDI file."; break;
ErrorString = "Error playing MIDI file.";
break;
default : default: ErrorString = "Unknown Music error code."; break;
ErrorString = "Unknown Music error code.";
break;
} }
return ErrorString; return ErrorString;
} }
/*--------------------------------------------------------------------- int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
Function: MUSIC_Init
Selects which sound device to use.
---------------------------------------------------------------------*/
int32_t MUSIC_Init
(
int32_t SoundCard,
int32_t Address
)
{ {
int32_t i; for (int i = 0; i < 128; i++)
int32_t status; MIDI_PatchMap[i] = i;
for (i = 0; i < 128; i++)
{
MIDI_PatchMap[ i ] = i;
}
MUSIC_SoundDevice = SoundCard; MUSIC_SoundDevice = SoundCard;
status = MUSIC_InitMidi(SoundCard, &MUSIC_MidiFunctions, Address); return MUSIC_InitMidi(SoundCard, &MUSIC_MidiFunctions, Address);
return status;
} }
/*--------------------------------------------------------------------- int32_t MUSIC_Shutdown(void)
Function: MUSIC_Shutdown
Terminates use of sound device.
---------------------------------------------------------------------*/
int32_t MUSIC_Shutdown
(
void
)
{ {
int32_t status;
status = MUSIC_Ok;
MIDI_StopSong(); MIDI_StopSong();
//MPU_Reset(); return MUSIC_Ok;
return status;
} }
/*--------------------------------------------------------------------- void MUSIC_SetVolume(int32_t volume)
Function: MUSIC_SetVolume
Sets the volume of music playback.
---------------------------------------------------------------------*/
void MUSIC_SetVolume
(
int32_t volume
)
{ {
volume = max(0, volume);
volume = min(volume, 255);
if (MUSIC_SoundDevice != -1) if (MUSIC_SoundDevice != -1)
{ MIDI_SetVolume(min(max(0, volume), 255));
MIDI_SetVolume(volume);
}
} }
int32_t MUSIC_GetVolume(void) { return MUSIC_SoundDevice == -1 ? 0 : MIDI_GetVolume(); }
void MUSIC_SetLoopFlag(int32_t loopflag) { MIDI_SetLoopFlag(loopflag); }
void MUSIC_Continue(void) { MIDI_ContinueSong(); }
void MUSIC_Pause(void) { MIDI_PauseSong(); }
/*--------------------------------------------------------------------- int32_t MUSIC_StopSong(void)
Function: MUSIC_GetVolume
Returns the volume of music playback.
---------------------------------------------------------------------*/
int32_t MUSIC_GetVolume
(
void
)
{
if (MUSIC_SoundDevice == -1)
{
return 0;
}
return MIDI_GetVolume();
}
/*---------------------------------------------------------------------
Function: MUSIC_SetLoopFlag
Set whether the music will loop or end when it reaches the end of
the song.
---------------------------------------------------------------------*/
void MUSIC_SetLoopFlag
(
int32_t loopflag
)
{
MIDI_SetLoopFlag(loopflag);
}
/*---------------------------------------------------------------------
Function: MUSIC_Continue
Continues playback of a paused song.
---------------------------------------------------------------------*/
void MUSIC_Continue
(
void
)
{
MIDI_ContinueSong();
}
/*---------------------------------------------------------------------
Function: MUSIC_Pause
Pauses playback of a song.
---------------------------------------------------------------------*/
void MUSIC_Pause
(
void
)
{
MIDI_PauseSong();
}
/*---------------------------------------------------------------------
Function: MUSIC_StopSong
Stops playback of current song.
---------------------------------------------------------------------*/
int32_t MUSIC_StopSong
(
void
)
{ {
MIDI_StopSong(); MIDI_StopSong();
MUSIC_SetErrorCode(MUSIC_Ok); MUSIC_SetErrorCode(MUSIC_Ok);
@ -262,42 +120,21 @@ int32_t MUSIC_StopSong
} }
/*--------------------------------------------------------------------- int32_t MUSIC_PlaySong(char *song, int32_t loopflag)
Function: MUSIC_PlaySong
Begins playback of MIDI song.
---------------------------------------------------------------------*/
int32_t MUSIC_PlaySong
(
char *song,
int32_t loopflag
)
{ {
int32_t status;
{
MUSIC_StopSong(); MUSIC_StopSong();
status = MIDI_PlaySong(song, loopflag);
if (status != MIDI_Ok) if (MIDI_PlaySong(song, loopflag) != MIDI_Ok)
{ {
MUSIC_SetErrorCode(MUSIC_MidiError); MUSIC_SetErrorCode(MUSIC_MidiError);
return MUSIC_Warning; return MUSIC_Warning;
} }
}
return MUSIC_Ok; return MUSIC_Ok;
} }
int32_t MUSIC_InitMidi int32_t MUSIC_InitMidi(int32_t card, midifuncs *Funcs, int32_t Address)
(
int32_t card,
midifuncs *Funcs,
int32_t Address
)
{ {
UNREFERENCED_PARAMETER(card); UNREFERENCED_PARAMETER(card);
UNREFERENCED_PARAMETER(Address); UNREFERENCED_PARAMETER(Address);
@ -318,11 +155,4 @@ int32_t MUSIC_InitMidi
return MIDI_Ok; return MIDI_Ok;
} }
void MUSIC_Update(void) { MIDI_UpdateMusic(); }
void MUSIC_Update(void)
{
MIDI_UpdateMusic();
}