Mercurial > audlegacy-plugins
annotate src/aosd/aosd_trigger.c @ 1854:e3de567a0146
paranormal/presets -> new buildsys.
author | Jonathan Schleifer <js@h3c.de> |
---|---|
date | Mon, 24 Sep 2007 21:25:03 +0200 |
parents | 5d9fb703a7cc |
children | 2ffc6a69fcd1 |
rev | line source |
---|---|
597 | 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 "aosd_trigger.h" | |
22 #include "aosd_trigger_private.h" | |
23 #include "aosd_cfg.h" | |
24 #include <glib.h> | |
746
40fb4189fa88
[svn] - aosd: replaced other occurrencies of glib18n with audacious i18n
giacomo
parents:
637
diff
changeset
|
25 #include <audacious/i18n.h> |
597 | 26 #include <audacious/playlist.h> |
27 #include <audacious/strings.h> | |
28 #include <audacious/hook.h> | |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
29 #include <audacious/auddrct.h> |
597 | 30 |
31 | |
32 extern aosd_cfg_t * global_config; | |
33 | |
34 | |
35 /* trigger codes ( the code values do not need to be sequential ) */ | |
36 enum | |
37 { | |
38 AOSD_TRIGGER_PB_START = 0, | |
623 | 39 AOSD_TRIGGER_PB_TITLECHANGE = 1, |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
40 AOSD_TRIGGER_VOL_CHANGE = 2, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
41 AOSD_TRIGGER_PB_PAUSEON = 3, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
42 AOSD_TRIGGER_PB_PAUSEOFF = 4 |
597 | 43 }; |
44 | |
45 /* trigger codes array size */ | |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
46 #define AOSD_TRIGGER_CODES_ARRAY_SIZE 5 |
597 | 47 |
48 /* trigger codes array */ | |
49 gint aosd_trigger_codes[] = | |
50 { | |
51 AOSD_TRIGGER_PB_START, | |
623 | 52 AOSD_TRIGGER_PB_TITLECHANGE, |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
53 AOSD_TRIGGER_VOL_CHANGE, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
54 AOSD_TRIGGER_PB_PAUSEON, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
55 AOSD_TRIGGER_PB_PAUSEOFF |
597 | 56 }; |
57 | |
58 /* prototypes of trigger functions */ | |
59 static void aosd_trigger_func_pb_start_onoff ( gboolean ); | |
60 static void aosd_trigger_func_pb_start_cb ( gpointer , gpointer ); | |
623 | 61 static void aosd_trigger_func_pb_titlechange_onoff ( gboolean ); |
597 | 62 static void aosd_trigger_func_pb_titlechange_cb ( gpointer , gpointer ); |
623 | 63 static void aosd_trigger_func_vol_change_onoff ( gboolean ); |
64 static void aosd_trigger_func_vol_change_cb ( gpointer , gpointer ); | |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
65 static void aosd_trigger_func_pb_pauseon_onoff ( gboolean ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
66 static void aosd_trigger_func_pb_pauseon_cb ( gpointer , gpointer ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
67 static void aosd_trigger_func_pb_pauseoff_onoff ( gboolean ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
68 static void aosd_trigger_func_pb_pauseoff_cb ( gpointer , gpointer ); |
597 | 69 |
70 /* map trigger codes to trigger objects */ | |
71 aosd_trigger_t aosd_triggers[] = | |
72 { | |
73 [AOSD_TRIGGER_PB_START] = { N_("Playback Start") , | |
74 N_("Triggers OSD when a playlist entry is played.") , | |
75 aosd_trigger_func_pb_start_onoff , | |
76 aosd_trigger_func_pb_start_cb }, | |
77 | |
78 [AOSD_TRIGGER_PB_TITLECHANGE] = { N_("Title Change") , | |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
79 N_("Triggers OSD when, during playback, the song title changes " |
597 | 80 "but the filename is the same. This is mostly useful to display " |
81 "title changes in internet streams.") , | |
623 | 82 aosd_trigger_func_pb_titlechange_onoff , |
83 aosd_trigger_func_pb_titlechange_cb }, | |
84 | |
85 [AOSD_TRIGGER_VOL_CHANGE] = { N_("Volume Change") , | |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
86 N_("Triggers OSD when volume is changed.") , |
623 | 87 aosd_trigger_func_vol_change_onoff , |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
88 aosd_trigger_func_vol_change_cb }, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
89 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
90 [AOSD_TRIGGER_PB_PAUSEON] = { N_("Pause On") , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
91 N_("Triggers OSD when playback is paused.") , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
92 aosd_trigger_func_pb_pauseon_onoff , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
93 aosd_trigger_func_pb_pauseon_cb }, |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
94 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
95 [AOSD_TRIGGER_PB_PAUSEOFF] = { N_("Pause Off") , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
96 N_("Triggers OSD when playback is unpaused.") , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
97 aosd_trigger_func_pb_pauseoff_onoff , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
98 aosd_trigger_func_pb_pauseoff_cb } |
597 | 99 }; |
100 | |
101 | |
102 | |
103 /* TRIGGER API */ | |
104 | |
105 void | |
106 aosd_trigger_get_codes_array ( gint ** array , gint * array_size ) | |
107 { | |
108 *array = aosd_trigger_codes; | |
109 *array_size = AOSD_TRIGGER_CODES_ARRAY_SIZE; | |
110 return; | |
111 } | |
112 | |
113 | |
114 const gchar * | |
115 aosd_trigger_get_name ( gint trig_code ) | |
116 { | |
117 return aosd_triggers[trig_code].name; | |
118 } | |
119 | |
120 | |
121 const gchar * | |
122 aosd_trigger_get_desc ( gint trig_code ) | |
123 { | |
124 return aosd_triggers[trig_code].desc; | |
125 } | |
126 | |
127 | |
128 void | |
129 aosd_trigger_start ( aosd_cfg_osd_trigger_t * cfg_trigger ) | |
130 { | |
131 gint i = 0; | |
132 for ( i = 0 ; i < cfg_trigger->active->len ; i++ ) | |
133 { | |
134 gint trig_code = g_array_index( cfg_trigger->active , gint , i ); | |
135 aosd_triggers[trig_code].onoff_func( TRUE ); | |
136 } | |
137 return; | |
138 } | |
139 | |
140 | |
141 void | |
142 aosd_trigger_stop ( aosd_cfg_osd_trigger_t * cfg_trigger ) | |
143 { | |
144 gint i = 0; | |
145 for ( i = 0 ; i < cfg_trigger->active->len ; i++ ) | |
146 { | |
147 gint trig_code = g_array_index( cfg_trigger->active , gint , i ); | |
148 aosd_triggers[trig_code].onoff_func( FALSE ); | |
149 } | |
150 return; | |
151 } | |
152 | |
153 | |
893
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
154 /* HELPER FUNCTIONS */ |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
155 |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
156 static gchar * |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
157 aosd_trigger_utf8convert ( gchar * str ) |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
158 { |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
159 if ( global_config->osd->text.utf8conv_disable == FALSE ) |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
160 return str_to_utf8( str ); |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
161 else |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
162 return g_strdup( str ); |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
163 } |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
164 |
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
165 |
597 | 166 /* TRIGGER FUNCTIONS */ |
167 | |
168 static void | |
169 aosd_trigger_func_pb_start_onoff ( gboolean turn_on ) | |
170 { | |
171 if ( turn_on == TRUE ) | |
172 hook_associate( "playback begin" , aosd_trigger_func_pb_start_cb , NULL ); | |
173 else | |
174 hook_dissociate( "playback begin" , aosd_trigger_func_pb_start_cb ); | |
175 return; | |
176 } | |
177 | |
178 static void | |
179 aosd_trigger_func_pb_start_cb ( gpointer plentry_gp , gpointer unused ) | |
180 { | |
181 PlaylistEntry *pl_entry = plentry_gp; | |
598
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
182 if ( plentry_gp != NULL ) |
597 | 183 { |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
184 gchar *title, *utf8_title; |
598
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
185 if ( pl_entry->title != NULL ) |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
186 { |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
187 /* if there is a proper title, use it */ |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
188 title = g_strdup(pl_entry->title); |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
189 } |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
190 else |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
191 { |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
192 /* pick what we have as song title */ |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
193 Playlist *active = playlist_get_active(); |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
194 gint pos = playlist_get_position(active); |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
195 title = playlist_get_songtitle(active, pos); |
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
196 } |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
197 utf8_title = aosd_trigger_utf8convert( title ); |
766
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
198 if ( g_utf8_validate( utf8_title , -1 , NULL ) == TRUE ) |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
199 { |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
200 gchar *utf8_title_markup = g_markup_printf_escaped( |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
201 "<span font_desc='%s'>%s</span>" , global_config->osd->text.fonts_name[0] , utf8_title ); |
883
e6d51d079a46
[svn] - aosd: use a single ghosd object for all of the osd showups; this will be a lot gentler to XLib and should definitely help with stability
giacomo
parents:
787
diff
changeset
|
202 aosd_osd_display( utf8_title_markup , global_config->osd , FALSE ); |
766
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
203 g_free( utf8_title_markup ); |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
204 } |
597 | 205 g_free( utf8_title ); |
598
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
206 g_free( title ); |
597 | 207 } |
208 return; | |
209 } | |
210 | |
211 | |
212 | |
213 typedef struct | |
214 { | |
215 gchar *title; | |
216 gchar *filename; | |
217 } | |
218 aosd_pb_titlechange_prevs_t; | |
219 | |
220 | |
221 static void | |
623 | 222 aosd_trigger_func_pb_titlechange_onoff ( gboolean turn_on ) |
597 | 223 { |
224 static aosd_pb_titlechange_prevs_t *prevs = NULL; | |
225 | |
226 if ( turn_on == TRUE ) | |
227 { | |
228 prevs = g_malloc0(sizeof(aosd_pb_titlechange_prevs_t)); | |
229 prevs->title = NULL; | |
230 prevs->filename = NULL; | |
231 hook_associate( "playlist set info" , aosd_trigger_func_pb_titlechange_cb , prevs ); | |
232 } | |
233 else | |
234 { | |
235 hook_dissociate( "playlist set info" , aosd_trigger_func_pb_titlechange_cb ); | |
236 if ( prevs != NULL ) | |
237 { | |
238 if ( prevs->title != NULL ) g_free( prevs->title ); | |
239 if ( prevs->filename != NULL ) g_free( prevs->filename ); | |
240 g_free( prevs ); | |
241 prevs = NULL; | |
242 } | |
243 } | |
244 return; | |
245 } | |
246 | |
247 static void | |
248 aosd_trigger_func_pb_titlechange_cb ( gpointer plentry_gp , gpointer prevs_gp ) | |
249 { | |
250 if ( ip_data.playing ) | |
251 { | |
252 aosd_pb_titlechange_prevs_t *prevs = prevs_gp; | |
253 PlaylistEntry *pl_entry = plentry_gp; | |
254 | |
255 /* same filename but title changed, useful to detect http stream song changes */ | |
256 | |
257 if ( ( prevs->title != NULL ) && ( prevs->filename != NULL ) ) | |
258 { | |
598
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
259 if ( ( pl_entry->filename != NULL ) && ( !strcmp(pl_entry->filename,prevs->filename) ) ) |
597 | 260 { |
598
e83e6fb3ebfa
[svn] - aosd: stability fixes for triggers (handle situation where a plentry exists but plentry->title is null)
giacomo
parents:
597
diff
changeset
|
261 if ( ( pl_entry->title != NULL ) && ( strcmp(pl_entry->title,prevs->title) ) ) |
597 | 262 { |
263 /* string formatting is done here a.t.m. - TODO - improve this area */ | |
893
ca9907354db6
[svn] - aosd: added an option to enable/disable utf8 text conversion done by the plugin
giacomo
parents:
890
diff
changeset
|
264 gchar *utf8_title = aosd_trigger_utf8convert( pl_entry->title ); |
766
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
265 if ( g_utf8_validate( utf8_title , -1 , NULL ) == TRUE ) |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
266 { |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
267 gchar *utf8_title_markup = g_markup_printf_escaped( |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
268 "<span font_desc='%s'>%s</span>" , global_config->osd->text.fonts_name[0] , utf8_title ); |
883
e6d51d079a46
[svn] - aosd: use a single ghosd object for all of the osd showups; this will be a lot gentler to XLib and should definitely help with stability
giacomo
parents:
787
diff
changeset
|
269 aosd_osd_display( utf8_title_markup , global_config->osd , FALSE ); |
766
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
270 g_free( utf8_title_markup ); |
53f63f43663f
[svn] - extra check with g_utf8_validate to avoid the osd crash when a non-utf8 string survives the str_to_utf8 conversion
giacomo
parents:
746
diff
changeset
|
271 } |
597 | 272 g_free( utf8_title ); |
273 g_free( prevs->title ); | |
274 prevs->title = g_strdup(pl_entry->title); | |
275 } | |
276 } | |
277 else | |
278 { | |
279 g_free(prevs->filename); | |
280 prevs->filename = g_strdup(pl_entry->filename); | |
609
9b73eb35f4ff
[svn] - aosd: avoid collision between playback start trigger and titlechange trigger, that occurred when the next file in playlist was played
giacomo
parents:
598
diff
changeset
|
281 /* if filename changes, reset title as well */ |
9b73eb35f4ff
[svn] - aosd: avoid collision between playback start trigger and titlechange trigger, that occurred when the next file in playlist was played
giacomo
parents:
598
diff
changeset
|
282 if ( prevs->title != NULL ) |
9b73eb35f4ff
[svn] - aosd: avoid collision between playback start trigger and titlechange trigger, that occurred when the next file in playlist was played
giacomo
parents:
598
diff
changeset
|
283 g_free(prevs->title); |
9b73eb35f4ff
[svn] - aosd: avoid collision between playback start trigger and titlechange trigger, that occurred when the next file in playlist was played
giacomo
parents:
598
diff
changeset
|
284 prevs->title = g_strdup(pl_entry->title); |
597 | 285 } |
286 } | |
287 else | |
288 { | |
289 if ( prevs->title != NULL ) | |
290 g_free(prevs->title); | |
291 prevs->title = g_strdup(pl_entry->title); | |
292 if ( prevs->filename != NULL ) | |
293 g_free(prevs->filename); | |
294 prevs->filename = g_strdup(pl_entry->filename); | |
295 } | |
296 } | |
297 } | |
623 | 298 |
299 | |
300 static void | |
301 aosd_trigger_func_vol_change_onoff ( gboolean turn_on ) | |
302 { | |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
303 if ( turn_on == TRUE ) |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
304 hook_associate( "volume set" , aosd_trigger_func_vol_change_cb , NULL ); |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
305 else |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
306 hook_dissociate( "volume set" , aosd_trigger_func_vol_change_cb ); |
623 | 307 return; |
308 } | |
309 | |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
310 typedef struct |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
311 { |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
312 gint h_vol[2]; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
313 gint sid; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
314 } |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
315 aosd_vol_change_bucket_t; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
316 |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
317 static gboolean |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
318 aosd_trigger_func_vol_change_timeout ( gpointer bucket_gp ) |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
319 { |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
320 aosd_vol_change_bucket_t *bucket = bucket_gp; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
321 gchar *utf8_title_markup = g_markup_printf_escaped( |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
322 "<span font_desc='%s'>Volume Change - L: %i , R: %i</span>" , |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
323 global_config->osd->text.fonts_name[0] , bucket->h_vol[0] , bucket->h_vol[1] ); |
883
e6d51d079a46
[svn] - aosd: use a single ghosd object for all of the osd showups; this will be a lot gentler to XLib and should definitely help with stability
giacomo
parents:
787
diff
changeset
|
324 aosd_osd_display( utf8_title_markup , global_config->osd , FALSE ); |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
325 g_free( utf8_title_markup ); |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
326 bucket->sid = 0; /* reset source id value */ |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
327 return FALSE; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
328 } |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
329 |
623 | 330 static void |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
331 aosd_trigger_func_vol_change_cb ( gpointer h_vol_gp , gpointer unused ) |
623 | 332 { |
637
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
333 gint *h_vol = h_vol_gp; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
334 static aosd_vol_change_bucket_t bucket = { { 0 , 0 } , 0 }; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
335 |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
336 bucket.h_vol[0] = h_vol[0]; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
337 bucket.h_vol[1] = h_vol[1]; |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
338 |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
339 /* in order to avoid repeated display of osd for each volume variation, use a |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
340 timer to prevent it from appearing more than once when multiple volume |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
341 changes are performed in a short time interval (500 msec) */ |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
342 if ( bucket.sid == 0 ) |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
343 { |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
344 /* first call in the time interval */ |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
345 bucket.sid = g_timeout_add( 500 , aosd_trigger_func_vol_change_timeout , &bucket ); |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
346 } |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
347 else |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
348 { |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
349 /* another call in the same interval, reset the interval */ |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
350 g_source_remove( bucket.sid ); |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
351 bucket.sid = g_timeout_add( 500 , aosd_trigger_func_vol_change_timeout , &bucket ); |
a1687bd302ce
[svn] - aosd: completed volume change trigger, works now
giacomo
parents:
623
diff
changeset
|
352 } |
623 | 353 return; |
354 } | |
1238
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
355 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
356 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
357 static void |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
358 aosd_trigger_func_pb_pauseon_onoff ( gboolean turn_on ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
359 { |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
360 if ( turn_on == TRUE ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
361 hook_associate( "playback pause" , aosd_trigger_func_pb_pauseon_cb , NULL ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
362 else |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
363 hook_dissociate( "playback pause" , aosd_trigger_func_pb_pauseon_cb ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
364 return; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
365 } |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
366 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
367 static void |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
368 aosd_trigger_func_pb_pauseon_cb ( gpointer unused1 , gpointer unused2 ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
369 { |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
370 gchar *utf8_title_markup = g_markup_printf_escaped( |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
371 "<span font_desc='%s'>Paused</span>" , global_config->osd->text.fonts_name[0] ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
372 aosd_osd_display( utf8_title_markup , global_config->osd , FALSE ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
373 g_free( utf8_title_markup ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
374 return; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
375 } |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
376 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
377 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
378 static void |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
379 aosd_trigger_func_pb_pauseoff_onoff ( gboolean turn_on ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
380 { |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
381 if ( turn_on == TRUE ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
382 hook_associate( "playback unpause" , aosd_trigger_func_pb_pauseoff_cb , NULL ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
383 else |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
384 hook_dissociate( "playback unpause" , aosd_trigger_func_pb_pauseoff_cb ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
385 return; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
386 } |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
387 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
388 static void |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
389 aosd_trigger_func_pb_pauseoff_cb ( gpointer unused1 , gpointer unused2 ) |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
390 { |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
391 Playlist *active = playlist_get_active(); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
392 gint pos = playlist_get_position(active); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
393 gchar *title, *utf8_title, *utf8_title_markup; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
394 gint time_cur, time_tot; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
395 gint time_cur_m, time_cur_s, time_tot_m, time_tot_s; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
396 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
397 time_tot = playlist_get_songtime(active, pos) / 1000; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
398 time_cur = audacious_drct_get_time() / 1000; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
399 time_cur_s = time_cur % 60; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
400 time_cur_m = (time_cur - time_cur_s) / 60; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
401 time_tot_s = time_tot % 60; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
402 time_tot_m = (time_tot - time_tot_s) / 60; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
403 |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
404 title = playlist_get_songtitle(active, pos); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
405 utf8_title = aosd_trigger_utf8convert( title ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
406 utf8_title_markup = g_markup_printf_escaped( |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
407 "<span font_desc='%s'>%s (%i:%02i/%i:%02i)</span>" , |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
408 global_config->osd->text.fonts_name[0] , utf8_title , time_cur_m , time_cur_s , time_tot_m , time_tot_s ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
409 aosd_osd_display( utf8_title_markup , global_config->osd , FALSE ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
410 g_free( utf8_title_markup ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
411 g_free( utf8_title ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
412 g_free( title ); |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
413 return; |
5d9fb703a7cc
aosd: added triggers for pause and unpause event
Giacomo Lozito <james@develia.org>
parents:
893
diff
changeset
|
414 } |