ngunix/tracker/tracker_xmms.c

138 lines
3.2 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"
#include <xmms/xmmsctrl.h>
unsigned int xmms_session = 0;
static int xmms_loop = 1;
static int xmms_track;
static qboolean xmms_playing = false;
static qboolean xmms_wasplaying = false;
void Tracker_Play(byte track, qboolean looping)
{
xmms_remote_set_playlist_pos(xmms_session, (int) track);
xmms_remote_play(xmms_session);
xmms_loop = looping == true ? 0 : 1;
xmms_track = (int) track;
xmms_playing = true;
}
void Tracker_Stop(void)
{
xmms_remote_stop(xmms_session);
xmms_wasplaying = false;
xmms_playing = false;
}
void Tracker_Pause(void)
{
xmms_remote_pause(xmms_session);
xmms_wasplaying = xmms_playing;
xmms_playing = false;
}
void Tracker_Resume(void)
{
if (!xmms_wasplaying)
return;
xmms_remote_play(xmms_session);
xmms_playing = false;
}
// DO NOTHING
void Tracker_Update(void)
{
if(xmms_loop)
if(xmms_remote_get_playlist_pos(xmms_session) != xmms_track)
xmms_remote_set_playlist_pos(xmms_session, xmms_track);
}
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)
{
xmms_remote_quit(xmms_session);
return;
}
if (Q_strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", xmms_remote_get_playlist_length(xmms_session));
if (xmms_playing)
Con_Printf("Currently %s track %u (%s)\n", xmms_loop ? "looping" : "playing", xmms_track, xmms_remote_get_playlist_title(xmms_session, xmms_track));
else if (xmms_wasplaying)
Con_Printf("Paused %s track %u (%s)\n", xmms_loop ? "looping" : "playing", xmms_track, xmms_remote_get_playlist_title(xmms_session, xmms_track));
Con_Printf("Volume is %f\n", xmms_remote_get_main_volume(xmms_session));
return;
}
if(Q_strcasecmp(command, "tracks") == 0)
for(i = 0; i < xmms_remote_get_playlist_length(xmms_session); i++)
Con_Printf("#%i %s\n", i, xmms_remote_get_playlist_title(xmms_session, i));
}
int Tracker_Init(void)
{
Cmd_AddCommand ("xmms", XMMS_f); // link DUMB
return 1;
}
void Tracker_Shutdown(void)
{
}