2010-05-25 10:56:00 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2009-07-28 06:32:58 +00:00
|
|
|
/*
|
2010-05-25 10:56:00 +00:00
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
2009-07-28 06:32:58 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
This file is part of EDuke32.
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
2009-07-28 06:32:58 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-07-28 06:32:58 +00:00
|
|
|
*/
|
2010-05-25 10:56:00 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
/*
|
|
|
|
* A reimplementation of Jim Dose's FX_MAN routines, using SDL_mixer 1.2.
|
|
|
|
* Whee. FX_MAN is also known as the "Apogee Sound System", or "ASS" for
|
|
|
|
* short. How strangely appropriate that seems.
|
|
|
|
*/
|
|
|
|
|
2013-10-13 09:08:31 +00:00
|
|
|
#define _NEED_SDLMIXER 1
|
|
|
|
|
2015-02-11 05:22:48 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
#include "duke3d.h"
|
|
|
|
#include "cache1d.h"
|
|
|
|
|
2014-07-06 00:11:32 +00:00
|
|
|
#include "sdlayer.h"
|
2009-07-28 06:32:58 +00:00
|
|
|
#include "music.h"
|
|
|
|
|
2012-05-01 12:40:08 +00:00
|
|
|
#if !defined _WIN32 && !defined(GEKKO)
|
2013-11-16 18:47:23 +00:00
|
|
|
//# define FORK_EXEC_MIDI 1
|
2010-11-09 21:10:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined FORK_EXEC_MIDI // fork/exec based external midi player
|
2010-07-19 15:14:00 +00:00
|
|
|
#include <signal.h>
|
2010-06-27 10:08:58 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
static char **external_midi_argv;
|
|
|
|
static pid_t external_midi_pid=-1;
|
|
|
|
static int8_t external_midi_restart=0;
|
|
|
|
#endif
|
2014-03-22 09:25:51 +00:00
|
|
|
|
|
|
|
#ifdef __ANDROID__ //TODO fix
|
2016-01-12 10:30:48 +00:00
|
|
|
static char const *external_midi_tempfn = "eduke32-music.mid";
|
2014-03-22 09:25:51 +00:00
|
|
|
#else
|
2016-01-12 10:30:48 +00:00
|
|
|
static char const *external_midi_tempfn = "/tmp/eduke32-music.mid";
|
2014-03-22 09:25:51 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-27 10:08:58 +00:00
|
|
|
static int32_t external_midi = 0;
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
int32_t MUSIC_ErrorCode = MUSIC_Ok;
|
|
|
|
|
2016-03-07 11:22:07 +00:00
|
|
|
static char warningMessage[80];
|
2009-07-28 06:32:58 +00:00
|
|
|
static char errorMessage[80];
|
|
|
|
|
|
|
|
static int32_t music_initialized = 0;
|
|
|
|
static int32_t music_context = 0;
|
2016-03-07 11:22:07 +00:00
|
|
|
static int32_t music_loopflag = MUSIC_PlayOnce;
|
2009-07-28 06:32:58 +00:00
|
|
|
static Mix_Music *music_musicchunk = NULL;
|
|
|
|
|
|
|
|
static void setErrorMessage(const char *msg)
|
|
|
|
{
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(errorMessage, msg, sizeof(errorMessage));
|
|
|
|
}
|
2009-07-28 06:32:58 +00:00
|
|
|
|
|
|
|
// The music functions...
|
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *MUSIC_ErrorString(int32_t ErrorNumber)
|
2009-07-28 06:32:58 +00:00
|
|
|
{
|
|
|
|
switch (ErrorNumber)
|
|
|
|
{
|
2016-03-07 11:22:07 +00:00
|
|
|
case MUSIC_Warning:
|
2016-06-21 00:34:41 +00:00
|
|
|
return warningMessage;
|
2016-03-07 11:22:07 +00:00
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
case MUSIC_Error:
|
2016-06-21 00:34:41 +00:00
|
|
|
return errorMessage;
|
2009-07-28 06:32:58 +00:00
|
|
|
|
|
|
|
case MUSIC_Ok:
|
2016-06-21 00:34:41 +00:00
|
|
|
return "OK; no error.";
|
2016-03-07 11:22:07 +00:00
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
case MUSIC_MidiError:
|
2016-06-21 00:34:41 +00:00
|
|
|
return "MIDI error.";
|
2016-03-07 11:22:07 +00:00
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
default:
|
2016-06-21 00:34:41 +00:00
|
|
|
return "Unknown error.";
|
2009-07-28 06:32:58 +00:00
|
|
|
} // switch
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return NULL;
|
2009-07-28 06:32:58 +00:00
|
|
|
} // MUSIC_ErrorString
|
|
|
|
|
2016-03-07 11:22:07 +00:00
|
|
|
int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
|
2009-07-28 06:32:58 +00:00
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
music_initialized = 1;
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2014-04-15 19:02:48 +00:00
|
|
|
#endif
|
2009-07-28 06:32:58 +00:00
|
|
|
// Use an external MIDI player if the user has specified to do so
|
|
|
|
char *command = getenv("EDUKE32_MUSIC_CMD");
|
|
|
|
const SDL_version *linked = Mix_Linked_Version();
|
|
|
|
|
2011-10-17 18:42:10 +00:00
|
|
|
UNREFERENCED_PARAMETER(SoundCard);
|
2016-03-07 11:22:07 +00:00
|
|
|
UNREFERENCED_PARAMETER(Address);
|
2011-10-17 18:42:10 +00:00
|
|
|
|
2010-06-27 10:08:58 +00:00
|
|
|
if (music_initialized)
|
|
|
|
{
|
|
|
|
setErrorMessage("Music system is already initialized.");
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Error;
|
2010-06-27 10:08:58 +00:00
|
|
|
} // if
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
if (SDL_VERSIONNUM(linked->major,linked->minor,linked->patch) < MIX_REQUIREDVERSION)
|
|
|
|
{
|
|
|
|
// reject running with SDL_Mixer versions older than what is stated in sdl_inc.h
|
|
|
|
initprintf("You need at least v%d.%d.%d of SDL_mixer for music\n",SDL_MIXER_MIN_X,SDL_MIXER_MIN_Y,SDL_MIXER_MIN_Z);
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Error;
|
2009-07-28 06:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
external_midi = (command != NULL && command[0] != 0);
|
|
|
|
|
2010-02-13 21:46:42 +00:00
|
|
|
if (external_midi)
|
|
|
|
{
|
2012-11-24 09:13:29 +00:00
|
|
|
#if defined FORK_EXEC_MIDI
|
2012-11-08 22:09:30 +00:00
|
|
|
int32_t ws=1, numargs=0, pagesize=sysconf(_SC_PAGE_SIZE);
|
|
|
|
char *c, *cmd;
|
|
|
|
size_t sz;
|
2012-11-24 09:13:29 +00:00
|
|
|
#endif
|
2012-11-08 22:09:30 +00:00
|
|
|
|
2010-09-27 21:52:04 +00:00
|
|
|
initprintf("Setting music command to \"%s\".\n", command);
|
2010-06-27 10:08:58 +00:00
|
|
|
|
2010-11-09 21:10:26 +00:00
|
|
|
#if !defined FORK_EXEC_MIDI
|
2010-02-13 21:46:42 +00:00
|
|
|
if (Mix_SetMusicCMD(command)==-1)
|
2010-06-27 10:08:58 +00:00
|
|
|
{
|
2010-02-13 21:46:42 +00:00
|
|
|
perror("Mix_SetMusicCMD");
|
2010-06-27 10:08:58 +00:00
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (pagesize==-1)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
for (c=command; *c; c++)
|
|
|
|
{
|
|
|
|
if (isspace(*c))
|
|
|
|
ws = 1;
|
|
|
|
else if (ws)
|
|
|
|
{
|
|
|
|
ws = 0;
|
|
|
|
numargs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numargs==0)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
sz = (numargs+2)*sizeof(char *) + (c-command+1);
|
2010-08-16 13:56:49 +00:00
|
|
|
sz = ((sz+pagesize-1)/pagesize)*pagesize;
|
2013-08-20 21:49:44 +00:00
|
|
|
#if defined(__APPLE__) || defined(__ANDROID__)
|
2014-05-30 00:02:19 +00:00
|
|
|
external_midi_argv = Xcalloc(1,sz+pagesize);
|
2010-12-17 14:22:15 +00:00
|
|
|
external_midi_argv = (char **)((intptr_t)external_midi_argv + (pagesize-(((intptr_t)external_midi_argv)&(pagesize-1))));
|
2012-03-09 07:43:49 +00:00
|
|
|
#else
|
2010-11-09 21:10:26 +00:00
|
|
|
if (posix_memalign((void **)&external_midi_argv, pagesize, sz))
|
|
|
|
goto fallback;
|
2012-03-09 07:43:49 +00:00
|
|
|
#endif
|
2010-06-27 10:08:58 +00:00
|
|
|
cmd = (char *)external_midi_argv + (numargs+2)*sizeof(char *);
|
|
|
|
Bmemcpy(cmd, command, c-command+1);
|
|
|
|
|
|
|
|
ws = 1;
|
|
|
|
numargs = 0;
|
|
|
|
for (c=cmd; *c; c++)
|
|
|
|
{
|
|
|
|
if (isspace(*c))
|
|
|
|
{
|
|
|
|
ws = 1;
|
|
|
|
*c = 0;
|
|
|
|
}
|
|
|
|
else if (ws)
|
|
|
|
{
|
|
|
|
ws = 0;
|
|
|
|
external_midi_argv[numargs++] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
external_midi_argv[numargs] = external_midi_tempfn;
|
|
|
|
external_midi_argv[numargs+1] = NULL;
|
|
|
|
|
|
|
|
if (mprotect(external_midi_argv, sz, PROT_READ)==-1) // make argv and command string read-only
|
|
|
|
{
|
|
|
|
perror("MUSIC_Init: mprotect");
|
|
|
|
goto fallback;
|
|
|
|
}
|
2013-11-16 18:47:23 +00:00
|
|
|
# if 0
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
initprintf("----Music argv:\n");
|
|
|
|
for (i=0; i<numargs+1; i++)
|
|
|
|
initprintf(" %s\n", external_midi_argv[i]);
|
|
|
|
initprintf("----\n");
|
|
|
|
}
|
|
|
|
# endif
|
2010-06-27 10:08:58 +00:00
|
|
|
#endif
|
|
|
|
music_initialized = 1;
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2010-06-27 10:08:58 +00:00
|
|
|
|
|
|
|
fallback:
|
|
|
|
initprintf("Error setting music command, falling back to timidity.\n");
|
2010-02-13 21:46:42 +00:00
|
|
|
}
|
2010-06-27 10:08:58 +00:00
|
|
|
|
2016-02-02 00:21:12 +00:00
|
|
|
{
|
2016-03-07 11:22:07 +00:00
|
|
|
static const char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" };
|
|
|
|
FILE *fp;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i = ARRAY_SIZE(s)-1; i>=0; i--)
|
2009-07-28 06:32:58 +00:00
|
|
|
{
|
2016-03-07 11:22:07 +00:00
|
|
|
fp = Bfopen(s[i], "r");
|
|
|
|
if (fp == NULL)
|
2009-07-28 06:32:58 +00:00
|
|
|
{
|
2016-03-07 11:22:07 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
initprintf("Error: couldn't open any of the following files:\n");
|
|
|
|
for (i = ARRAY_SIZE(s)-1; i>=0; i--)
|
|
|
|
initprintf("%s\n",s[i]);
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Error;
|
2016-03-07 11:22:07 +00:00
|
|
|
}
|
|
|
|
continue;
|
2009-07-28 06:32:58 +00:00
|
|
|
}
|
2016-03-07 11:22:07 +00:00
|
|
|
else break;
|
2009-07-28 06:32:58 +00:00
|
|
|
}
|
2016-03-07 11:22:07 +00:00
|
|
|
Bfclose(fp);
|
2009-07-28 06:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
music_initialized = 1;
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2009-07-28 06:32:58 +00:00
|
|
|
} // MUSIC_Init
|
|
|
|
|
|
|
|
|
|
|
|
int32_t MUSIC_Shutdown(void)
|
|
|
|
{
|
|
|
|
// TODO - make sure this is being called from the menu -- SA
|
2010-11-09 21:10:26 +00:00
|
|
|
#if !defined FORK_EXEC_MIDI
|
2009-07-28 06:32:58 +00:00
|
|
|
if (external_midi)
|
|
|
|
Mix_SetMusicCMD(NULL);
|
2010-06-27 10:08:58 +00:00
|
|
|
#endif
|
2009-07-28 06:32:58 +00:00
|
|
|
|
|
|
|
MUSIC_StopSong();
|
|
|
|
music_context = 0;
|
|
|
|
music_initialized = 0;
|
2016-03-07 11:22:07 +00:00
|
|
|
music_loopflag = MUSIC_PlayOnce;
|
2009-07-28 06:32:58 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2009-07-28 06:32:58 +00:00
|
|
|
} // MUSIC_Shutdown
|
|
|
|
|
|
|
|
|
2016-03-07 11:22:07 +00:00
|
|
|
void MUSIC_SetMaxFMMidiChannel(int32_t channel)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(channel);
|
|
|
|
} // MUSIC_SetMaxFMMidiChannel
|
|
|
|
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
void MUSIC_SetVolume(int32_t volume)
|
|
|
|
{
|
|
|
|
volume = max(0, volume);
|
|
|
|
volume = min(volume, 255);
|
|
|
|
|
|
|
|
Mix_VolumeMusic(volume >> 1); // convert 0-255 to 0-128.
|
|
|
|
} // MUSIC_SetVolume
|
|
|
|
|
|
|
|
|
2016-03-07 11:22:07 +00:00
|
|
|
int32_t MUSIC_GetVolume(void)
|
|
|
|
{
|
2016-06-21 00:34:41 +00:00
|
|
|
return (Mix_VolumeMusic(-1) << 1); // convert 0-128 to 0-255.
|
2016-03-07 11:22:07 +00:00
|
|
|
} // MUSIC_GetVolume
|
|
|
|
|
|
|
|
|
|
|
|
void MUSIC_SetLoopFlag(int32_t loopflag)
|
|
|
|
{
|
|
|
|
music_loopflag = loopflag;
|
|
|
|
} // MUSIC_SetLoopFlag
|
|
|
|
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
void MUSIC_Continue(void)
|
|
|
|
{
|
|
|
|
if (Mix_PausedMusic())
|
|
|
|
Mix_ResumeMusic();
|
|
|
|
} // MUSIC_Continue
|
|
|
|
|
|
|
|
|
|
|
|
void MUSIC_Pause(void)
|
|
|
|
{
|
|
|
|
Mix_PauseMusic();
|
|
|
|
} // MUSIC_Pause
|
|
|
|
|
|
|
|
int32_t MUSIC_StopSong(void)
|
|
|
|
{
|
2010-11-09 21:10:26 +00:00
|
|
|
#if defined FORK_EXEC_MIDI
|
2010-06-27 10:08:58 +00:00
|
|
|
if (external_midi)
|
|
|
|
{
|
|
|
|
if (external_midi_pid > 0)
|
|
|
|
{
|
|
|
|
int32_t ret;
|
2011-09-15 17:04:37 +00:00
|
|
|
struct timespec ts;
|
2010-06-27 10:08:58 +00:00
|
|
|
|
|
|
|
external_midi_restart = 0; // make SIGCHLD handler a no-op
|
|
|
|
|
2011-09-15 17:04:37 +00:00
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 5000000; // sleep 5ms at most
|
|
|
|
|
2010-06-27 10:08:58 +00:00
|
|
|
kill(external_midi_pid, SIGTERM);
|
2011-09-15 17:04:37 +00:00
|
|
|
nanosleep(&ts, NULL);
|
2010-06-27 10:08:58 +00:00
|
|
|
ret = waitpid(external_midi_pid, NULL, WNOHANG|WUNTRACED);
|
|
|
|
// printf("(%d)", ret);
|
|
|
|
|
|
|
|
if (ret != external_midi_pid)
|
|
|
|
{
|
|
|
|
if (ret==-1)
|
|
|
|
perror("waitpid");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we tried to be nice, but no...
|
|
|
|
kill(external_midi_pid, SIGKILL);
|
|
|
|
initprintf("%s: wait for SIGTERM timed out.\n", __func__);
|
|
|
|
if (waitpid(external_midi_pid, NULL, WUNTRACED)==-1)
|
|
|
|
perror("waitpid (2)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
external_midi_pid = -1;
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2010-06-27 10:08:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
//if (!fx_initialized)
|
|
|
|
if (!Mix_QuerySpec(NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
setErrorMessage("Need FX system initialized, too. Sorry.");
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Error;
|
2009-07-28 06:32:58 +00:00
|
|
|
} // if
|
|
|
|
|
|
|
|
if ((Mix_PlayingMusic()) || (Mix_PausedMusic()))
|
|
|
|
Mix_HaltMusic();
|
|
|
|
|
|
|
|
if (music_musicchunk)
|
|
|
|
Mix_FreeMusic(music_musicchunk);
|
|
|
|
|
|
|
|
music_musicchunk = NULL;
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return MUSIC_Ok;
|
2009-07-28 06:32:58 +00:00
|
|
|
} // MUSIC_StopSong
|
|
|
|
|
2010-11-09 21:10:26 +00:00
|
|
|
#if defined FORK_EXEC_MIDI
|
2010-06-27 10:08:58 +00:00
|
|
|
static void playmusic()
|
|
|
|
{
|
|
|
|
pid_t pid = vfork();
|
|
|
|
|
|
|
|
if (pid==-1) // error
|
|
|
|
{
|
|
|
|
initprintf("%s: vfork: %s\n", __func__, strerror(errno));
|
|
|
|
}
|
|
|
|
else if (pid==0) // child
|
|
|
|
{
|
2013-11-16 18:47:23 +00:00
|
|
|
// exec without PATH lookup
|
|
|
|
if (execv(external_midi_argv[0], external_midi_argv) < 0)
|
2010-06-27 10:08:58 +00:00
|
|
|
{
|
|
|
|
perror("execv");
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // parent
|
|
|
|
{
|
|
|
|
external_midi_pid = pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sigchld_handler(int signo)
|
|
|
|
{
|
|
|
|
if (signo==SIGCHLD && external_midi_restart)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2011-09-15 17:04:37 +00:00
|
|
|
if (external_midi_pid > 0)
|
2010-06-27 10:08:58 +00:00
|
|
|
{
|
2011-09-15 17:04:37 +00:00
|
|
|
if (waitpid(external_midi_pid, &status, WUNTRACED)==-1)
|
|
|
|
perror("waitpid (3)");
|
|
|
|
|
|
|
|
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
|
|
|
{
|
|
|
|
// loop ...
|
|
|
|
playmusic();
|
|
|
|
}
|
2010-06-27 10:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
// Duke3D-specific. --ryan.
|
|
|
|
// void MUSIC_PlayMusic(char *_filename)
|
|
|
|
int32_t MUSIC_PlaySong(char *song, int32_t loopflag)
|
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
// initprintf("MUSIC_PlaySong");
|
2009-07-28 06:32:58 +00:00
|
|
|
MUSIC_StopSong();
|
2010-02-13 21:46:42 +00:00
|
|
|
|
|
|
|
if (external_midi)
|
|
|
|
{
|
2010-06-27 10:08:58 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
2010-11-09 21:10:26 +00:00
|
|
|
#if defined FORK_EXEC_MIDI
|
2010-06-27 10:08:58 +00:00
|
|
|
static int32_t sigchld_handler_set = 0;
|
|
|
|
|
|
|
|
if (!sigchld_handler_set)
|
|
|
|
{
|
2012-11-05 02:49:08 +00:00
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler=sigchld_handler;
|
|
|
|
sa.sa_flags=0;
|
2010-06-27 10:08:58 +00:00
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
|
|
|
if (sigaction(SIGCHLD, &sa, NULL)==-1)
|
|
|
|
initprintf("%s: sigaction: %s\n", __func__, strerror(errno));
|
|
|
|
|
|
|
|
sigchld_handler_set = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fp = Bfopen(external_midi_tempfn, "wb");
|
2010-02-13 21:46:42 +00:00
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
fwrite(song, 1, g_musicSize, fp);
|
|
|
|
Bfclose(fp);
|
2010-06-27 10:08:58 +00:00
|
|
|
|
2010-11-09 21:10:26 +00:00
|
|
|
#if defined FORK_EXEC_MIDI
|
2010-06-27 10:08:58 +00:00
|
|
|
external_midi_restart = loopflag;
|
|
|
|
playmusic();
|
|
|
|
#else
|
|
|
|
music_musicchunk = Mix_LoadMUS(external_midi_tempfn);
|
2010-02-13 21:46:42 +00:00
|
|
|
if (!music_musicchunk)
|
|
|
|
initprintf("Mix_LoadMUS: %s\n", Mix_GetError());
|
2010-06-27 10:08:58 +00:00
|
|
|
#endif
|
2010-02-13 21:46:42 +00:00
|
|
|
}
|
2010-06-27 10:08:58 +00:00
|
|
|
else initprintf("%s: fopen: %s\n", __func__, strerror(errno));
|
2010-02-13 21:46:42 +00:00
|
|
|
}
|
|
|
|
else
|
2015-05-25 18:58:31 +00:00
|
|
|
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem(song, g_musicSize)
|
2013-10-06 07:49:53 +00:00
|
|
|
#if (SDL_MAJOR_VERSION > 1)
|
|
|
|
, SDL_FALSE
|
|
|
|
#endif
|
|
|
|
);
|
2009-07-28 06:32:58 +00:00
|
|
|
|
|
|
|
if (music_musicchunk != NULL)
|
2010-02-13 21:46:42 +00:00
|
|
|
if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1)
|
|
|
|
initprintf("Mix_PlayMusic: %s\n", Mix_GetError());
|
2009-07-31 11:45:29 +00:00
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
return MUSIC_Ok;
|
|
|
|
}
|
|
|
|
|
2016-03-07 11:22:07 +00:00
|
|
|
|
2009-07-28 06:32:58 +00:00
|
|
|
void MUSIC_Update(void)
|
|
|
|
{}
|