annotate Plugins/General/lirc/lirc.c @ 1637:5261e37b4d55 trunk

[svn] - fully working CoreAudio plugin, based on the OSS plugin and an incomplete xmms coreaudio plugin (fink)
author nenolod
date Thu, 07 Sep 2006 11:32:59 -0700
parents d77a1c5b5c13
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
1 /* Lirc plugin
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
2
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
3 Copyright (C) 2005 Audacious development team
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
4
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
5 Copyright (c) 1998-1999 Carl van Schaik (carl@leg.uct.ac.za)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
6
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
7 Copyright (C) 2000 Christoph Bartelmus (xmms@bartelmus.de)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
8
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
9 some code was stolen from:
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
10 IRman plugin for xmms by Charles Sielski (stray@teklabs.net)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
11
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
12 This program is free software; you can redistribute it and/or modify
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
13 it under the terms of the GNU General Public License as published by
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
14 the Free Software Foundation; either version 2 of the License, or
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
15 (at your option) any later version.
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
16
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
17 This program is distributed in the hope that it will be useful,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
20 GNU General Public License for more details.
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
21
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
22 You should have received a copy of the GNU General Public License
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
23 along with this program; if not, write to the Free Software
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
25 */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
26
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
27 #ifdef HAVE_CONFIG_H
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
28 # include "config.h"
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
29 #endif
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
30
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
31 #include <stdio.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
32 #include <unistd.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
33 #include <fcntl.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
34 #include <string.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
35 #include <signal.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
36 #include <stdlib.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
37 #include <ctype.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
38
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
39 #include <gtk/gtk.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
40
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
41 #include <glib.h>
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
42 #include <glib/gi18n.h>
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
43
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
44 #include "audacious/plugin.h"
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
45 #include "libaudacious/beepctrl.h"
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
46
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
47 #include <lirc/lirc_client.h>
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
48
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
49 #include "lirc.h"
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
50
628
3770123787c2 [svn] Remove config dependency, font usage and misc dead code.
chainsaw
parents: 554
diff changeset
51 const char *plugin_name="LIRC Plugin";
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
52
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
53 GeneralPlugin lirc_plugin = {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
54 NULL,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
55 NULL,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
56 -1,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
57 NULL,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
58 init,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
59 about,
628
3770123787c2 [svn] Remove config dependency, font usage and misc dead code.
chainsaw
parents: 554
diff changeset
60 NULL,
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
61 cleanup,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
62 };
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
63
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
64 GeneralPlugin *get_gplugin_info(void)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
65 {
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
66 lirc_plugin.description = g_strdup_printf(_("LIRC Plugin"));
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
67 return(&lirc_plugin);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
68 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
69
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
70 int lirc_fd=-1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
71 struct lirc_config *config=NULL;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
72 gint tracknr=0;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
73 gint mute=0; /* mute flag */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
74 gint mute_vol=0; /* holds volume before mute */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
75
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
76 gint input_tag;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
77
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
78 void init(void)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
79 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
80 int flags;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
81
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
82 if((lirc_fd=lirc_init("audacious",1))==-1)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
83 {
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
84 fprintf(stderr,_("%s: could not init LIRC support\n"),
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
85 plugin_name);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
86 return;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
87 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
88 if(lirc_readconfig(NULL,&config,NULL)==-1)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
89 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
90 lirc_deinit();
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
91 fprintf(stderr,
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
92 _("%s: could not read LIRC config file\n"
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
93 "%s: please read the documentation of LIRC\n"
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
94 "%s: how to create a proper config file\n"),
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
95 plugin_name,plugin_name,plugin_name);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
96 return;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
97 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
98 input_tag=gdk_input_add(lirc_fd,GDK_INPUT_READ,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
99 lirc_input_callback,NULL);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
100 fcntl(lirc_fd,F_SETOWN,getpid());
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
101 flags=fcntl(lirc_fd,F_GETFL,0);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
102 if(flags!=-1)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
103 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
104 fcntl(lirc_fd,F_SETFL,flags|O_NONBLOCK);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
105 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
106 fflush(stdout);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
107 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
108
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
109 void lirc_input_callback(gpointer data,gint source,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
110 GdkInputCondition condition)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
111 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
112 char *code;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
113 char *c;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
114 gint playlist_time,playlist_pos,output_time,v;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
115 int ret;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
116 char *ptr;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
117 gint balance;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
118 gboolean show_pl;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
119 int n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
120
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
121 while((ret=lirc_nextcode(&code))==0 && code!=NULL)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
122 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
123 while((ret=lirc_code2char(config,code,&c))==0 && c!=NULL)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
124 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
125 if(strcasecmp("PLAY",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
126 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
127 xmms_remote_play(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
128 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
129 else if(strcasecmp("STOP",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
130 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
131 xmms_remote_stop(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
132 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
133 else if(strcasecmp("PAUSE",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
134 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
135 xmms_remote_pause(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
136 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
137 else if(strcasecmp("PLAYPAUSE",c) == 0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
138 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
139 if(xmms_remote_is_playing(lirc_plugin.
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
140 xmms_session))
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
141 xmms_remote_pause
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
142 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
143 else
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
144 xmms_remote_play
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
145 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
146 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
147 else if(strncasecmp("NEXT",c,4)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
148 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
149 ptr=c+4;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
150 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
151 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
152
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
153 if(n<=0) n=1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
154 for(;n>0;n--)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
155 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
156 xmms_remote_playlist_next
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
157 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
158 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
159 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
160 else if(strncasecmp("PREV",c,4)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
161 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
162 ptr=c+4;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
163 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
164 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
165
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
166 if(n<=0) n=1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
167 for(;n>0;n--)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
168 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
169 xmms_remote_playlist_prev
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
170 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
171 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
172 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
173 else if(strcasecmp("SHUFFLE",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
174 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
175 xmms_remote_toggle_shuffle(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
176 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
177 else if(strcasecmp("REPEAT",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
178 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
179 xmms_remote_toggle_repeat(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
180 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
181 else if(strncasecmp("FWD",c,3)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
182 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
183 ptr=c+3;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
184 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
185 n=atoi(ptr)*1000;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
186
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
187 if(n<=0) n=5000;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
188 output_time=xmms_remote_get_output_time
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
189 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
190 playlist_pos=xmms_remote_get_playlist_pos
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
191 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
192 playlist_time=xmms_remote_get_playlist_time
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
193 (lirc_plugin.xmms_session,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
194 playlist_pos);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
195 if(playlist_time-output_time<n)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
196 output_time=playlist_time-n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
197 xmms_remote_jump_to_time
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
198 (lirc_plugin.xmms_session,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
199 output_time+n);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
200 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
201 else if(strncasecmp("BWD",c,3)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
202 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
203 ptr=c+3;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
204 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
205 n=atoi(ptr)*1000;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
206
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
207 if(n<=0) n=5000;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
208 output_time=xmms_remote_get_output_time
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
209 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
210 if(output_time<n)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
211 output_time=n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
212 xmms_remote_jump_to_time
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
213 (lirc_plugin.xmms_session,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
214 output_time-n);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
215 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
216 else if(strncasecmp("VOL_UP",c,6)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
217 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
218 ptr=c+6;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
219 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
220 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
221 if(n<=0) n=5;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
222
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
223 v = xmms_remote_get_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
224 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
225 if(v > (100-n)) v=100-n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
226 xmms_remote_set_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
227 (lirc_plugin.xmms_session,v+n);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
228 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
229 else if(strncasecmp("VOL_DOWN",c,8)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
230 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
231 ptr=c+8;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
232 while (isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
233 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
234 if(n<=0) n=5;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
235
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
236 v = xmms_remote_get_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
237 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
238 if(v<n) v=n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
239 xmms_remote_set_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
240 (lirc_plugin.xmms_session,v-n);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
241 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
242 else if(strcasecmp("QUIT",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
243 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
244 xmms_remote_quit(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
245 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
246 else if(strcasecmp("MUTE",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
247 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
248 if(mute==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
249 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
250 mute=1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
251 /* store the master volume so
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
252 we can restore it on unmute. */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
253 mute_vol = xmms_remote_get_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
254 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
255 xmms_remote_set_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
256 (lirc_plugin.xmms_session, 0);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
257 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
258 else
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
259 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
260 mute=0;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
261 xmms_remote_set_main_volume
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
262 (lirc_plugin.xmms_session,
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
263 mute_vol);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
264 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
265 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
266 else if(strncasecmp("BAL_LEFT",c,8)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
267 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
268 ptr=c+8;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
269 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
270 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
271 if(n<=0) n=5;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
272
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
273 balance=xmms_remote_get_balance
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
274 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
275 balance-=n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
276 if(balance<-100) balance=-100;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
277 xmms_remote_set_balance
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
278 (lirc_plugin.xmms_session,balance);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
279 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
280 else if(strncasecmp("BAL_RIGHT",c,9)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
281 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
282 ptr=c+9;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
283 while(isspace(*ptr)) ptr++;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
284 n=atoi(ptr);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
285 if(n<=0) n=5;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
286
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
287 balance=xmms_remote_get_balance
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
288 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
289 balance+=n;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
290 if(balance>100) balance=100;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
291 xmms_remote_set_balance
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
292 (lirc_plugin.xmms_session,balance);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
293 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
294 else if(strcasecmp("BAL_CENTER",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
295 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
296 balance=0;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
297 xmms_remote_set_balance
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
298 (lirc_plugin.xmms_session,balance);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
299 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
300 else if(strcasecmp("LIST",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
301 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
302 show_pl=xmms_remote_is_pl_win
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
303 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
304 show_pl=(show_pl) ? 0:1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
305 xmms_remote_pl_win_toggle
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
306 (lirc_plugin.xmms_session,show_pl);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
307 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
308 else if(strcasecmp("PLAYLIST_CLEAR",c)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
309 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
310 gboolean pl_visible;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
311
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
312 pl_visible=xmms_remote_is_pl_win
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
313 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
314 xmms_remote_stop(lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
315 xmms_remote_playlist_clear
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
316 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
317 /* This is to refresh window content */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
318 xmms_remote_pl_win_toggle
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
319 (lirc_plugin.xmms_session,pl_visible);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
320 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
321 else if(strncasecmp("PLAYLIST_ADD ",c,13)==0)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
322 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
323 gboolean pl_visible;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
324 GList list;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
325
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
326 pl_visible=xmms_remote_is_pl_win
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
327 (lirc_plugin.xmms_session);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
328 list.prev=list.next=NULL;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
329 list.data=c+13;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
330 xmms_remote_playlist_add
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
331 (lirc_plugin.xmms_session,&list);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
332 /* This is to refresh window content */
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
333 xmms_remote_pl_win_toggle
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
334 (lirc_plugin.xmms_session,pl_visible);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
335 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
336 else
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
337 {
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
338 fprintf(stderr,_("%s: unknown command \"%s\"\n"),
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
339 plugin_name,c);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
340 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
341 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
342 free(code);
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
343 if(ret==-1) break;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
344 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
345 if(ret==-1)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
346 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
347 /* something went badly wrong */
554
8a7a6dda6add [svn] make lirc strings translatable
nenolod
parents: 307
diff changeset
348 fprintf(stderr,_("%s: disconnected from LIRC\n"),plugin_name);
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
349 cleanup();
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
350 return;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
351 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
352 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
353
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
354 void cleanup()
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
355 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
356 if(config)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
357 {
732
d77a1c5b5c13 [svn] - crash fix at no additional charge
nenolod
parents: 628
diff changeset
358 if(input_tag)
d77a1c5b5c13 [svn] - crash fix at no additional charge
nenolod
parents: 628
diff changeset
359 gtk_input_remove(input_tag);
d77a1c5b5c13 [svn] - crash fix at no additional charge
nenolod
parents: 628
diff changeset
360
156
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
361 config=NULL;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
362 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
363 if(lirc_fd!=-1)
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
364 {
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
365 lirc_deinit();
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
366 lirc_fd=-1;
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
367 }
23726a5a74bc [svn] Add LIRC general plugin.
chainsaw
parents:
diff changeset
368 }