Mercurial > audlegacy-plugins
comparison src/evdev-plug/ed.c @ 422:5e46b57d1eda trunk
[svn] - added evdev-plug, written-from-scratch plugin that allows to control the player via event devices on linux systems
author | giacomo |
---|---|
date | Sun, 14 Jan 2007 17:55:24 -0800 |
parents | |
children | f757e1aa62e6 |
comparison
equal
deleted
inserted
replaced
421:1a82af4f13cf | 422:5e46b57d1eda |
---|---|
1 /* | |
2 * | |
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2007 | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License as published by the | |
7 * Free Software Foundation; either version 2 of the License, or (at your | |
8 * option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License along | |
16 * with this program; if not, write to the Free Software Foundation, Inc., | |
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 */ | |
20 | |
21 #include "ed.h" | |
22 #include "ed_types.h" | |
23 #include "ed_internals.h" | |
24 #include "ed_actions.h" | |
25 #include "ed_ui.h" | |
26 #include "ed_common.h" | |
27 #include <glib/gi18n.h> | |
28 #include <audacious/beepctrl.h> | |
29 | |
30 | |
31 GList *ed_device_listening_list = NULL; | |
32 gboolean plugin_is_active = FALSE; | |
33 | |
34 /* action callbacks */ | |
35 void ed_action_pb_play ( gpointer ); | |
36 void ed_action_pb_stop ( gpointer ); | |
37 void ed_action_pb_pause ( gpointer ); | |
38 void ed_action_pb_prev ( gpointer ); | |
39 void ed_action_pb_next ( gpointer ); | |
40 void ed_action_pb_eject ( gpointer ); | |
41 void ed_action_vol_up5 ( gpointer ); | |
42 void ed_action_vol_down5 ( gpointer ); | |
43 void ed_action_vol_up10 ( gpointer ); | |
44 void ed_action_vol_down10 ( gpointer ); | |
45 void ed_action_win_main ( gpointer ); | |
46 void ed_action_win_playlist ( gpointer ); | |
47 void ed_action_win_equalizer ( gpointer ); | |
48 void ed_action_pl_repeat ( gpointer ); | |
49 void ed_action_pl_shuffle ( gpointer ); | |
50 | |
51 /* map action codes to ed_action_t objects */ | |
52 ed_action_t player_actions[] = | |
53 { | |
54 [ED_ACTION_PB_PLAY] = { N_("Playback->Play") , ed_action_pb_play }, | |
55 [ED_ACTION_PB_STOP] = { N_("Playback->Stop") , ed_action_pb_stop }, | |
56 [ED_ACTION_PB_PAUSE] = { N_("Playback->Pause") , ed_action_pb_pause }, | |
57 [ED_ACTION_PB_PREV] = { N_("Playback->Prev") , ed_action_pb_prev }, | |
58 [ED_ACTION_PB_NEXT] = { N_("Playback->Next") , ed_action_pb_next }, | |
59 [ED_ACTION_PB_EJECT] = { N_("Playback->Eject") , ed_action_pb_eject }, | |
60 | |
61 [ED_ACTION_PL_REPEAT] = { N_("Playlist->Repeat") , ed_action_pl_repeat }, | |
62 [ED_ACTION_PL_SHUFFLE] = { N_("Playlist->Shuffle") , ed_action_pl_shuffle }, | |
63 | |
64 [ED_ACTION_VOL_UP5] = { N_("Volume->Up_5") , ed_action_vol_up5 }, | |
65 [ED_ACTION_VOL_DOWN5] = { N_("Volume->Down_5") , ed_action_vol_down5 }, | |
66 [ED_ACTION_VOL_UP10] = { N_("Volume->Up_10") , ed_action_vol_up10 }, | |
67 [ED_ACTION_VOL_DOWN10] = { N_("Volume->Down_10") , ed_action_vol_down10 }, | |
68 | |
69 [ED_ACTION_WIN_MAIN] = { N_("Window->Main") , ed_action_win_main }, | |
70 [ED_ACTION_WIN_PLAYLIST] = { N_("Window->Playlist") , ed_action_win_playlist }, | |
71 [ED_ACTION_WIN_EQUALIZER] = { N_("Window->Equalizer") , ed_action_win_equalizer } | |
72 }; | |
73 | |
74 | |
75 | |
76 /* ***************** */ | |
77 /* plug-in functions */ | |
78 | |
79 GeneralPlugin *get_gplugin_info() | |
80 { | |
81 return &ed_gp; | |
82 } | |
83 | |
84 | |
85 void | |
86 ed_init ( void ) | |
87 { | |
88 g_log_set_handler( NULL , G_LOG_LEVEL_WARNING , g_log_default_handler , NULL ); | |
89 | |
90 plugin_is_active = TRUE; /* go! */ | |
91 | |
92 /* read event devices and bindings from user | |
93 configuration and start listening for active ones */ | |
94 ed_device_start_listening_from_config(); | |
95 | |
96 return; | |
97 } | |
98 | |
99 | |
100 void | |
101 ed_cleanup ( void ) | |
102 { | |
103 /* shut down all devices being listened */ | |
104 ed_device_stop_listening_all( TRUE ); | |
105 | |
106 plugin_is_active = FALSE; /* stop! */ | |
107 | |
108 return; | |
109 } | |
110 | |
111 | |
112 void | |
113 ed_config ( void ) | |
114 { | |
115 ed_ui_config_show(); | |
116 } | |
117 | |
118 | |
119 void | |
120 ed_about ( void ) | |
121 { | |
122 ed_ui_about_show(); | |
123 } | |
124 | |
125 | |
126 | |
127 /* ************** */ | |
128 /* player actions */ | |
129 | |
130 void | |
131 ed_action_call ( gint code , gpointer param ) | |
132 { | |
133 DEBUGMSG( "Calling action; code %i ( %s )\n" , code , player_actions[code].desc ); | |
134 | |
135 /* activate callback for requested action */ | |
136 player_actions[code].callback( param ); | |
137 } | |
138 | |
139 | |
140 void | |
141 ed_action_pb_play ( gpointer param ) | |
142 { | |
143 xmms_remote_play( ed_gp.xmms_session ); | |
144 } | |
145 | |
146 void | |
147 ed_action_pb_stop ( gpointer param ) | |
148 { | |
149 xmms_remote_stop( ed_gp.xmms_session ); | |
150 } | |
151 | |
152 void | |
153 ed_action_pb_pause ( gpointer param ) | |
154 { | |
155 xmms_remote_pause( ed_gp.xmms_session ); | |
156 } | |
157 | |
158 void | |
159 ed_action_pb_prev ( gpointer param ) | |
160 { | |
161 xmms_remote_playlist_prev( ed_gp.xmms_session ); | |
162 } | |
163 | |
164 void | |
165 ed_action_pb_next ( gpointer param ) | |
166 { | |
167 xmms_remote_playlist_next( ed_gp.xmms_session ); | |
168 } | |
169 | |
170 void | |
171 ed_action_pb_eject ( gpointer param ) | |
172 { | |
173 xmms_remote_eject( ed_gp.xmms_session ); | |
174 } | |
175 | |
176 void | |
177 ed_action_pl_repeat ( gpointer param ) | |
178 { | |
179 xmms_remote_toggle_repeat( ed_gp.xmms_session ); | |
180 } | |
181 | |
182 void | |
183 ed_action_pl_shuffle ( gpointer param ) | |
184 { | |
185 xmms_remote_toggle_shuffle( ed_gp.xmms_session ); | |
186 } | |
187 | |
188 void | |
189 ed_action_vol_up5 ( gpointer param ) | |
190 { | |
191 gint vl, vr; | |
192 xmms_remote_get_volume( ed_gp.xmms_session , &vl , &vr ); | |
193 xmms_remote_set_volume( ed_gp.xmms_session , CLAMP(vl + 5, 0, 100) , CLAMP(vr + 5, 0, 100) ); | |
194 } | |
195 | |
196 void | |
197 ed_action_vol_down5 ( gpointer param ) | |
198 { | |
199 gint vl, vr; | |
200 xmms_remote_get_volume( ed_gp.xmms_session , &vl , &vr ); | |
201 xmms_remote_set_volume( ed_gp.xmms_session , CLAMP(vl - 5, 0, 100) , CLAMP(vr - 5, 0, 100) ); | |
202 } | |
203 | |
204 void | |
205 ed_action_vol_up10 ( gpointer param ) | |
206 { | |
207 gint vl, vr; | |
208 xmms_remote_get_volume( ed_gp.xmms_session , &vl , &vr ); | |
209 xmms_remote_set_volume( ed_gp.xmms_session , CLAMP(vl + 10, 0, 100) , CLAMP(vr + 10, 0, 100) ); | |
210 } | |
211 | |
212 void | |
213 ed_action_vol_down10 ( gpointer param ) | |
214 { | |
215 gint vl, vr; | |
216 xmms_remote_get_volume( ed_gp.xmms_session , &vl , &vr ); | |
217 xmms_remote_set_volume( ed_gp.xmms_session , CLAMP(vl - 10, 0, 100) , CLAMP(vr - 10, 0, 100) ); | |
218 } | |
219 | |
220 void | |
221 ed_action_win_main ( gpointer param ) | |
222 { | |
223 xmms_remote_main_win_toggle( ed_gp.xmms_session , | |
224 !xmms_remote_is_main_win ( ed_gp.xmms_session ) ); | |
225 } | |
226 | |
227 void | |
228 ed_action_win_playlist ( gpointer param ) | |
229 { | |
230 xmms_remote_pl_win_toggle( ed_gp.xmms_session , | |
231 !xmms_remote_is_pl_win ( ed_gp.xmms_session ) ); | |
232 } | |
233 | |
234 void | |
235 ed_action_win_equalizer ( gpointer param ) | |
236 { | |
237 xmms_remote_eq_win_toggle( ed_gp.xmms_session , | |
238 !xmms_remote_is_eq_win ( ed_gp.xmms_session ) ); | |
239 } |