179 lines
4 KiB
C
179 lines
4 KiB
C
/*
|
|
Copyright (C) 2015 Marco "eukara" Hladik
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
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
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include "globaldef.h"
|
|
|
|
#ifdef XMMSCTL
|
|
static int xmms_loop = 1;
|
|
static int xmms_track;
|
|
|
|
static qboolean xmms_playing = false;
|
|
static qboolean xmms_wasplaying = false;
|
|
static qboolean xmmsctl_initialized = false;
|
|
|
|
static int xmms_old_repeat;
|
|
static int xmms_old_shuffle;
|
|
static int xmms_old_advance;
|
|
static float xmms_volume;
|
|
|
|
int XMMS_GetValue(char *parm)
|
|
{
|
|
FILE *fp;
|
|
char buffer[32];
|
|
int value;
|
|
|
|
sprintf(buffer, "/usr/local/bin/xmms-ctl %s", parm);
|
|
fp = popen(buffer, "r");
|
|
|
|
if (fp == NULL)
|
|
{
|
|
Con_Printf("Can't get info from XMMS\n" );
|
|
return;
|
|
}
|
|
while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
|
|
value = atoi(buffer);
|
|
}
|
|
|
|
pclose(fp);
|
|
return value;
|
|
}
|
|
|
|
void XMMS_Play(byte track, qboolean looping)
|
|
{
|
|
char buffer [32];
|
|
int ctltemp;
|
|
sprintf(buffer, "xmms-ctl -set-track %i", (int) track);
|
|
system(buffer);
|
|
system("xmms-ctl -play");
|
|
|
|
xmms_loop = looping == true ? 1 : 0;
|
|
xmms_track = (int) track;
|
|
xmms_playing = true;
|
|
xmms_volume = bgmvolume->value;
|
|
|
|
if(xmms_loop)
|
|
{
|
|
if(XMMS_GetValue("-get-advance"))
|
|
system("xmms-ctl -set-advance");
|
|
if(!XMMS_GetValue("-get-repeat"))
|
|
system("xmms-ctl -set-repeat");
|
|
}
|
|
else
|
|
{
|
|
if(XMMS_GetValue("-get-repeat"))
|
|
system("xmms-ctl -set-repeat");
|
|
}
|
|
|
|
system("xmms-ctl -set-volume %s" xmms_volume);
|
|
Con_Printf("XMMS: Now playing song %i, looping %i\n", xmms_track, xmms_loop);
|
|
}
|
|
|
|
void XMMS_Stop(void)
|
|
{
|
|
system("xmms-ctl -stop");
|
|
xmms_wasplaying = false;
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Track %i stopped\n", xmms_track);
|
|
}
|
|
|
|
|
|
void XMMS_Pause(void)
|
|
{
|
|
system("xmms-ctl -pause");
|
|
xmms_wasplaying = xmms_playing;
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Track %i paused\n", xmms_track);
|
|
}
|
|
|
|
|
|
void XMMS_Resume(void)
|
|
{
|
|
if (!xmms_wasplaying)
|
|
return;
|
|
system("xmms-ctl -play");
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Resuming track %i\n", xmms_track);
|
|
}
|
|
|
|
void XMMS_Update(void)
|
|
{
|
|
if(xmms_volume != bgmvolume->value)
|
|
{
|
|
xmms_volume = bgmvolume->value;
|
|
system("xmms-ctl -set-volume %s" bgmvolume->value);
|
|
}
|
|
}
|
|
|
|
static void XMMS_f (void)
|
|
{
|
|
char *command;
|
|
int i;
|
|
|
|
if (Cmd_Argc() < 2)
|
|
return;
|
|
|
|
command = Cmd_Argv (1);
|
|
|
|
if (Q_strcasecmp(command, "play") == 0)
|
|
XMMS_Play((byte)Q_atoi(Cmd_Argv (2)), false);
|
|
else if (Q_strcasecmp(command, "stop") == 0)
|
|
XMMS_Stop();
|
|
else if (Q_strcasecmp(command, "pause") == 0)
|
|
XMMS_Pause();
|
|
else if (Q_strcasecmp(command, "resume") == 0)
|
|
XMMS_Resume();
|
|
else if (Q_strcasecmp(command, "quit") == 0)
|
|
system("xmms-ctl -quit");
|
|
}
|
|
|
|
int XMMS_Init(void)
|
|
{
|
|
FILE *fp;
|
|
fp = popen("/usr/local/bin/xmms-ctl", "r");
|
|
|
|
if (fp == NULL)
|
|
{
|
|
Con_Printf("XMMS: Cannot find XMMS-CTL!\n" );
|
|
return 0;
|
|
}
|
|
|
|
xmmsctl_initialized = true;
|
|
xmms_old_repeat = XMMS_GetValue("-get-repeat");
|
|
xmms_old_advance = XMMS_GetValue("-get-advance");
|
|
xmms_old_shuffle = XMMS_GetValue("-get-shuffle");
|
|
|
|
Cmd_AddCommand ("xmms", XMMS_f);
|
|
return 1;
|
|
}
|
|
|
|
|
|
void XMMS_Shutdown(void)
|
|
{
|
|
if(XMMS_GetValue("-get-advance") != xmms_old_advance)
|
|
system("xmms-ctl -set-advance");
|
|
if(!XMMS_GetValue("-get-repeat") != xmms_old_repeat)
|
|
system("xmms-ctl -set-repeat");
|
|
|
|
XMMS_Stop(); // Because requested
|
|
}
|
|
#endif
|