@@ -14,75 +14,75 @@ static int oldLoopStatus = -1;
1414static int oldShuffleStatus = -1 ;
1515
1616static int onStart () {
17- oldLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , 0 );
18- oldShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
19- mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
17+ oldLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , 0 );
18+ oldShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
19+ mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
2020
2121#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 32 )
22- mprisThread = g_thread_create (startServer , (void * )& mprisData , TRUE, NULL );
22+ mprisThread = g_thread_create (startServer , (void * )& mprisData , TRUE, NULL );
2323#else
24- mprisThread = g_thread_new ("mpris-listener" , startServer , (void * )& mprisData );
24+ mprisThread = g_thread_new ("mpris-listener" , startServer , (void * )& mprisData );
2525#endif
26- return 0 ;
26+ return 0 ;
2727}
2828
2929static int onStop () {
30- stopServer ();
30+ stopServer ();
3131
3232#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 32 )
33- g_thread_join (mprisThread );
33+ g_thread_join (mprisThread );
3434#else
35- g_thread_unref (mprisThread );
35+ g_thread_unref (mprisThread );
3636#endif
3737
38- if (mprisData .artworkData .artwork ) {
39- free (mprisData .artworkData .path );
40- free (mprisData .artworkData .default_path );
41- mprisData .artworkData .path = NULL ;
42- mprisData .artworkData .default_path = NULL ;
43- }
38+ if (mprisData .artworkData .artwork ) {
39+ free (mprisData .artworkData .path );
40+ free (mprisData .artworkData .default_path );
41+ mprisData .artworkData .path = NULL ;
42+ mprisData .artworkData .default_path = NULL ;
43+ }
4444
45- return 0 ;
45+ return 0 ;
4646}
4747
4848static int onDisconnect () {
49- if (mprisData .artworkData .artwork ) {
50- mprisData .artworkData .artwork -> cancel_queries_with_source_id (mprisData .artworkData .source_id );
51- }
49+ if (mprisData .artworkData .artwork ) {
50+ mprisData .artworkData .artwork -> cancel_queries_with_source_id (mprisData .artworkData .source_id );
51+ }
5252 return 0 ;
5353}
5454
5555static int onConnect () {
56- mprisData .prevOrRestart = NULL ;
57-
58- ddb_artwork_plugin_t * artworkPlugin = (ddb_artwork_plugin_t * )mprisData .deadbeef -> plug_get_for_id ("artwork2" );
59-
60- if (artworkPlugin != NULL ) {
61- debug ("artwork plugin detected... album art support enabled\n" );
62- if (artworkPlugin ) {
63- mprisData .artworkData .artwork = artworkPlugin ;
64- mprisData .artworkData .source_id = artworkPlugin -> allocate_source_id ();
65- mprisData .artworkData .path = NULL ;
66- mprisData .artworkData .default_path = malloc (PATH_MAX );
67- if (mprisData .artworkData .default_path ) {
68- strcpy (mprisData .artworkData .default_path ,"file://" );
69- size_t offset = strlen ("file://" );
70- artworkPlugin -> default_image_path (mprisData .artworkData .default_path + offset , PATH_MAX - offset );
71- }
72- }
73- } else {
74- debug ("artwork plugin not detected... album art support disabled\n" );
75- }
76-
77- DB_plugin_t * hotkeysPlugin = mprisData .deadbeef -> plug_get_for_id ("hotkeys" );
56+ mprisData .prevOrRestart = NULL ;
57+
58+ ddb_artwork_plugin_t * artworkPlugin = (ddb_artwork_plugin_t * )mprisData .deadbeef -> plug_get_for_id ("artwork2" );
59+
60+ if (artworkPlugin != NULL ) {
61+ debug ("artwork plugin detected... album art support enabled\n" );
62+ if (artworkPlugin ) {
63+ mprisData .artworkData .artwork = artworkPlugin ;
64+ mprisData .artworkData .source_id = artworkPlugin -> allocate_source_id ();
65+ mprisData .artworkData .path = NULL ;
66+ mprisData .artworkData .default_path = malloc (PATH_MAX );
67+ if (mprisData .artworkData .default_path ) {
68+ strcpy (mprisData .artworkData .default_path ,"file://" );
69+ size_t offset = strlen ("file://" );
70+ artworkPlugin -> default_image_path (mprisData .artworkData .default_path + offset , PATH_MAX - offset );
71+ }
72+ }
73+ } else {
74+ debug ("artwork plugin not detected... album art support disabled\n" );
75+ }
76+
77+ DB_plugin_t * hotkeysPlugin = mprisData .deadbeef -> plug_get_for_id ("hotkeys" );
7878 DB_plugin_t * * plugins = mprisData .deadbeef -> plug_get_list ();
7979 for (int i = 0 ; plugins [i ]; i ++ ) {
80- for (DB_plugin_action_t * dbaction = plugins [i ]-> get_actions (NULL ); dbaction ; dbaction = dbaction -> next ) {
81- if (strcmp (dbaction -> name , "prev_or_restart" ) == 0 ) {
82- debug ("prev_or_restart command detected... previous or restart support enabled\n" );
83- mprisData .prevOrRestart = dbaction ;
84- break ;
85- }
80+ for (DB_plugin_action_t * dbaction = plugins [i ]-> get_actions (NULL ); dbaction ; dbaction = dbaction -> next ) {
81+ if (strcmp (dbaction -> name , "prev_or_restart" ) == 0 ) {
82+ debug ("prev_or_restart command detected... previous or restart support enabled\n" );
83+ mprisData .prevOrRestart = dbaction ;
84+ break ;
85+ }
8686 }
8787
8888 if (mprisData .prevOrRestart != NULL ) {
@@ -95,7 +95,7 @@ static int onConnect() {
9595 debug ("prev_or_restart command not detected... previous or restart support disabled\n" );
9696 }
9797
98- return 0 ;
98+ return 0 ;
9999}
100100
101101//***********************
@@ -108,117 +108,117 @@ static int onConnect() {
108108//* - Shuffle status *
109109//***********************
110110static int handleEvent (uint32_t id , uintptr_t ctx , uint32_t p1 , uint32_t p2 ) {
111- DB_functions_t * deadbeef = mprisData .deadbeef ;
112-
113- switch (id ) {
114- case DB_EV_SEEKED :
115- debug ("DB_EV_SEEKED event received\n" );
116- emitSeeked (((ddb_event_playpos_t * ) ctx )-> playpos );
117- break ;
118- case DB_EV_TRACKINFOCHANGED :
119- debug ("DB_EV_TRACKINFOCHANGED event received\n" );
120- emitMetadataChanged (-1 , & mprisData );
121- emitCanGoChanged (& mprisData );
122- emitSeeked (deadbeef -> streamer_get_playpos ());
123- break ;
124- case DB_EV_SELCHANGED :
125- case DB_EV_PLAYLISTSWITCHED :
126- emitCanGoChanged (& mprisData );
127- break ;
128- case DB_EV_SONGSTARTED :
129- debug ("DB_EV_SONGSTARTED event received\n" );
130- emitMetadataChanged (-1 , & mprisData );
131- emitPlaybackStatusChanged (OUTPUT_STATE_PLAYING , & mprisData );
132- break ;
133- case DB_EV_PAUSED :
134- debug ("DB_EV_PAUSED event received\n" );
135- emitPlaybackStatusChanged (p1 ? OUTPUT_STATE_PAUSED : OUTPUT_STATE_PLAYING , & mprisData );
136- break ;
137- case DB_EV_STOP :
138- debug ("DB_EV_STOP event received\n" );
139- emitPlaybackStatusChanged (OUTPUT_STATE_STOPPED , & mprisData );
140- break ;
141- case DB_EV_VOLUMECHANGED :
142- debug ("DB_EV_VOLUMECHANGED event received\n" );
143- emitVolumeChanged (deadbeef -> volume_get_db ());
144- break ;
145- case DB_EV_CONFIGCHANGED :
146- debug ("DB_EV_CONFIGCHANGED event received\n" );
147- if (oldShuffleStatus != -1 ) {
148- int newLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , PLAYBACK_MODE_LOOP_ALL );
149- int newShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
150-
151- if (newLoopStatus != oldLoopStatus ) {
152- debug ("LoopStatus changed %d\n" , newLoopStatus );
153- emitLoopStatusChanged (oldLoopStatus = newLoopStatus );
154- } if (newShuffleStatus != oldShuffleStatus ) {
155- debug ("ShuffleStatus changed %d\n" , newShuffleStatus );
156- emitShuffleStatusChanged (oldShuffleStatus = newShuffleStatus );
157- }
158-
159- mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
160- }
111+ DB_functions_t * deadbeef = mprisData .deadbeef ;
112+
113+ switch (id ) {
114+ case DB_EV_SEEKED :
115+ debug ("DB_EV_SEEKED event received\n" );
116+ emitSeeked (((ddb_event_playpos_t * ) ctx )-> playpos );
117+ break ;
118+ case DB_EV_TRACKINFOCHANGED :
119+ debug ("DB_EV_TRACKINFOCHANGED event received\n" );
120+ emitMetadataChanged (-1 , & mprisData );
121+ emitCanGoChanged (& mprisData );
122+ emitSeeked (deadbeef -> streamer_get_playpos ());
123+ break ;
124+ case DB_EV_SELCHANGED :
125+ case DB_EV_PLAYLISTSWITCHED :
126+ emitCanGoChanged (& mprisData );
127+ break ;
128+ case DB_EV_SONGSTARTED :
129+ debug ("DB_EV_SONGSTARTED event received\n" );
130+ emitMetadataChanged (-1 , & mprisData );
131+ emitPlaybackStatusChanged (OUTPUT_STATE_PLAYING , & mprisData );
132+ break ;
133+ case DB_EV_PAUSED :
134+ debug ("DB_EV_PAUSED event received\n" );
135+ emitPlaybackStatusChanged (p1 ? OUTPUT_STATE_PAUSED : OUTPUT_STATE_PLAYING , & mprisData );
136+ break ;
137+ case DB_EV_STOP :
138+ debug ("DB_EV_STOP event received\n" );
139+ emitPlaybackStatusChanged (OUTPUT_STATE_STOPPED , & mprisData );
140+ break ;
141+ case DB_EV_VOLUMECHANGED :
142+ debug ("DB_EV_VOLUMECHANGED event received\n" );
143+ emitVolumeChanged (deadbeef -> volume_get_db ());
144+ break ;
145+ case DB_EV_CONFIGCHANGED :
146+ debug ("DB_EV_CONFIGCHANGED event received\n" );
147+ if (oldShuffleStatus != -1 ) {
148+ int newLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , PLAYBACK_MODE_LOOP_ALL );
149+ int newShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
150+
151+ if (newLoopStatus != oldLoopStatus ) {
152+ debug ("LoopStatus changed %d\n" , newLoopStatus );
153+ emitLoopStatusChanged (oldLoopStatus = newLoopStatus );
154+ } if (newShuffleStatus != oldShuffleStatus ) {
155+ debug ("ShuffleStatus changed %d\n" , newShuffleStatus );
156+ emitShuffleStatusChanged (oldShuffleStatus = newShuffleStatus );
157+ }
158+
159+ mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
160+ }
161161 if (deadbeef -> conf_get_int ("mpris.trace" , 0 )) {
162162 plugin .plugin .flags |= DDB_PLUGIN_FLAG_LOGGING ;
163163 }
164164 else {
165165 plugin .plugin .flags &= ~DDB_PLUGIN_FLAG_LOGGING ;
166166 }
167- break ;
168- default :
169- break ;
170- }
167+ break ;
168+ default :
169+ break ;
170+ }
171171
172- return 0 ;
172+ return 0 ;
173173}
174174
175175#define STR (x ) #x
176176#define XSTR (x ) STR(x)
177177
178178static const char settings_dlg [] =
179- "property \"\\\"Previous\\\" action behavior\" select[2] " SETTING_PREVIOUS_ACTION " " XSTR (PREVIOUS_ACTION_PREV_OR_RESTART ) " \"Previous\" \"Previous or restart current track\";"
179+ "property \"\\\"Previous\\\" action behavior\" select[2] " SETTING_PREVIOUS_ACTION " " XSTR (PREVIOUS_ACTION_PREV_OR_RESTART ) " \"Previous\" \"Previous or restart current track\";"
180180 "property \"Enable logging\" checkbox mpris.trace 0;\n"
181181 "property \"Disable shuffle and repeat\" checkbox mpris.disable_shuffle_repeat 0;\n"
182182;
183183
184184
185185DB_misc_t plugin = {
186- .plugin .api_vmajor = 1 ,
187- .plugin .api_vminor = DDB_API_LEVEL ,
188- .plugin .type = DB_PLUGIN_MISC ,
189- .plugin .version_major = PLUGIN_VERSION_MAJOR ,
190- .plugin .version_minor = PLUGIN_VERSION_MINOR ,
191- .plugin .id = "mpris" ,
192- .plugin .name = "MPRISv2 plugin" ,
193- .plugin .descr = "Communicate with other applications using D-Bus." ,
194- .plugin .copyright =
195- "Copyright (C) 2014 Peter Lamby <[email protected] >\n" 196- "\n"
197- "This program is free software; you can redistribute it and/or\n"
198- "modify it under the terms of the GNU General Public License\n"
199- "as published by the Free Software Foundation; either version 2\n"
200- "of the License, or (at your option) any later version.\n"
201- "\n"
202- "This program is distributed in the hope that it will be useful,\n"
203- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
204- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
205- "GNU General Public License for more details.\n"
206- "\n"
207- "You should have received a copy of the GNU General Public License\n"
208- "along with this program; if not, write to the Free Software\n"
209- "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
210- ,
211- .plugin .website = "https://github.com/DeaDBeeF-Player/deadbeef-mpris2-plugin" ,
212- .plugin .start = onStart ,
213- .plugin .stop = onStop ,
214- .plugin .connect = onConnect ,
215- .plugin .disconnect = onDisconnect ,
216- .plugin .configdialog = settings_dlg ,
217- .plugin .message = handleEvent ,
186+ .plugin .api_vmajor = 1 ,
187+ .plugin .api_vminor = DDB_API_LEVEL ,
188+ .plugin .type = DB_PLUGIN_MISC ,
189+ .plugin .version_major = PLUGIN_VERSION_MAJOR ,
190+ .plugin .version_minor = PLUGIN_VERSION_MINOR ,
191+ .plugin .id = "mpris" ,
192+ .plugin .name = "MPRISv2 plugin" ,
193+ .plugin .descr = "Communicate with other applications using D-Bus." ,
194+ .plugin .copyright =
195+ "Copyright (C) 2014 Peter Lamby <[email protected] >\n" 196+ "\n"
197+ "This program is free software; you can redistribute it and/or\n"
198+ "modify it under the terms of the GNU General Public License\n"
199+ "as published by the Free Software Foundation; either version 2\n"
200+ "of the License, or (at your option) any later version.\n"
201+ "\n"
202+ "This program is distributed in the hope that it will be useful,\n"
203+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
204+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
205+ "GNU General Public License for more details.\n"
206+ "\n"
207+ "You should have received a copy of the GNU General Public License\n"
208+ "along with this program; if not, write to the Free Software\n"
209+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
210+ ,
211+ .plugin .website = "https://github.com/DeaDBeeF-Player/deadbeef-mpris2-plugin" ,
212+ .plugin .start = onStart ,
213+ .plugin .stop = onStop ,
214+ .plugin .connect = onConnect ,
215+ .plugin .disconnect = onDisconnect ,
216+ .plugin .configdialog = settings_dlg ,
217+ .plugin .message = handleEvent ,
218218};
219219
220220DB_plugin_t * mpris_load (DB_functions_t * ddb ) {
221- deadbeef = mprisData .deadbeef = ddb ;
221+ deadbeef = mprisData .deadbeef = ddb ;
222222
223- return DB_PLUGIN (& plugin );
223+ return DB_PLUGIN (& plugin );
224224}
0 commit comments