169 lines
3.3 KiB
C
169 lines
3.3 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"
|
|
|
|
static int xmms_loop = 1;
|
|
static int xmms_track;
|
|
|
|
static qboolean xmms_playing = false;
|
|
static qboolean xmms_wasplaying = false;
|
|
static qboolean xmmsctl_initialized = false;
|
|
|
|
void Tracker_Play(byte track, qboolean looping)
|
|
{
|
|
char buffer [32];
|
|
sprintf(buffer, "xmms-ctl -track-set %i", (int) track);
|
|
system(buffer);
|
|
system("xmms-ctl -play");
|
|
|
|
xmms_loop = looping == true ? 1 : 0;
|
|
xmms_track = (int) track;
|
|
xmms_playing = true;
|
|
|
|
Con_Printf("XMMS: Now playing song %i, looping %i\n", xmms_track, xmms_loop);
|
|
}
|
|
|
|
void Tracker_Stop(void)
|
|
{
|
|
system("xmms-ctl -stop");
|
|
xmms_wasplaying = false;
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Track %i stopped\n", xmms_track);
|
|
}
|
|
|
|
|
|
void Tracker_Pause(void)
|
|
{
|
|
system("xmms-ctl -pause");
|
|
xmms_wasplaying = xmms_playing;
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Track %i paused\n", xmms_track);
|
|
}
|
|
|
|
|
|
void Tracker_Resume(void)
|
|
{
|
|
if (!xmms_wasplaying)
|
|
return;
|
|
system("xmms-ctl -play");
|
|
xmms_playing = false;
|
|
|
|
Con_Printf("XMMS: Resuming track %i\n", xmms_track);
|
|
}
|
|
|
|
// DO NOTHING
|
|
void Tracker_Update(void)
|
|
{
|
|
#if 0
|
|
if(!xmmsctl_initialized)
|
|
return;
|
|
|
|
if(xmms_loop)
|
|
{
|
|
int current_track;
|
|
FILE *fp;
|
|
char buffer [32];
|
|
|
|
fp = popen("/usr/local/bin/xmms-ctl -track-get", "r");
|
|
|
|
if (fp == NULL)
|
|
{
|
|
Con_Printf("Can't get track listing from XMMS\n" );
|
|
return;
|
|
}
|
|
while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
|
|
current_track = atoi(buffer);
|
|
}
|
|
|
|
if(current_track != xmms_track)
|
|
{
|
|
sprintf(buffer, "xmms-ctl -track-set %i", xmms_track);
|
|
system(buffer);
|
|
Con_Printf("XMMS: looping track %i\n", xmms_track);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
static void XMMS_f (void)
|
|
{
|
|
char *command;
|
|
int i;
|
|
|
|
if (Cmd_Argc() < 2)
|
|
return;
|
|
|
|
command = Cmd_Argv (1);
|
|
|
|
if (Q_strcasecmp(command, "play") == 0)
|
|
{
|
|
Tracker_Play((byte)Q_atoi(Cmd_Argv (2)), false);
|
|
return;
|
|
}
|
|
|
|
if (Q_strcasecmp(command, "stop") == 0)
|
|
{
|
|
Tracker_Stop();
|
|
return;
|
|
}
|
|
|
|
if (Q_strcasecmp(command, "pause") == 0)
|
|
{
|
|
Tracker_Pause();
|
|
return;
|
|
}
|
|
|
|
if (Q_strcasecmp(command, "resume") == 0)
|
|
{
|
|
Tracker_Resume();
|
|
return;
|
|
}
|
|
|
|
if (Q_strcasecmp(command, "quit") == 0)
|
|
{
|
|
system("xmms-ctl -quit");
|
|
return;
|
|
}
|
|
}
|
|
|
|
int Tracker_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;
|
|
Cmd_AddCommand ("xmms", XMMS_f); // link DUMB
|
|
return 1;
|
|
}
|
|
|
|
|
|
void Tracker_Shutdown(void)
|
|
{
|
|
Tracker_Stop(); // Because requested
|
|
}
|