Merge lp:~grawity/beat-box/mpris into lp:beat-box

Proposed by Mantas Mikulėnas
Status: Rejected
Rejected by: Scott Ringwelski
Proposed branch: lp:~grawity/beat-box/mpris
Merge into: lp:beat-box
Diff against target: 178 lines (+37/-39)
2 files modified
src/Core/LibraryWindow.vala (+0/-5)
src/DBus/MPRIS/MPRIS.vala (+37/-34)
To merge this branch: bzr merge lp:~grawity/beat-box/mpris
Reviewer Review Type Date Requested Status
Scott Ringwelski Disapprove
Review via email: mp+113800@code.launchpad.net

Description of the change

This removes MPRIS dependency on libindicate/libdbusmenu, which are hard to come by on non-Ubuntu systems, and fixes a few other issues (primarily broken PropertiesChanged signals).

To post a comment you must log in.
Revision history for this message
Kurt Smolderen (kurt.smolderen) wrote :

Mantas,

Thanks for submitting some ideas to improve the code. However, some questions...
- When removing precompiler checks such as '#if HAVE_DBUS', you should make sure to also update the CMakeList.txt file to force the dependency on dbus. THe debus dependency remains required for MPRIS, even for non-Ubuntu users
- Playlists are still managed by libunity (if available at compile time). We are planning to suppoty these via MPRIS as well (although I think there are some limitations, but I'm going to post a comment on that in the original bug report)
- You should make sure Beatbox also triggers playPauseChanged when MprisPlayer.Stop() is called. Without doing so, Beatbox will stop playing music but for instance the Gnome3 media indicator applet still thinks music is playing...

What I want to propose: I've been working on this issue as well. Basic playlist support is implemented and I will probably push my revision this evening... I will incorpotate the addition of the track_id in the metadata if this is required by MPRIS...

Please let me know your thoughts on this and thanks for your input!

Kurt

lp:~grawity/beat-box/mpris updated
676. By Mantas Mikulėnas

MPRIS: Update PlaybackStatus on playback_stopped signal

Revision history for this message
Mantas Mikulėnas (grawity) wrote :

Thanks for your feedback.

> - When removing precompiler checks such as '#if HAVE_DBUS', you should make
> sure to also update the CMakeList.txt file to force the dependency on dbus.
> THe debus dependency remains required for MPRIS, even for non-Ubuntu users

HAVE_DBUS was never present in the first place, since BeatBox already depends on GLib and Gio and uses their internal DBus support (gdbus).

My patches only remove HAVE_DBUSMENU (libdbusmenu, a different library) from code that never required libdbusmenu.

> - You should make sure Beatbox also triggers playPauseChanged when
> MprisPlayer.Stop() is called. Without doing so, Beatbox will stop playing
> music but for instance the Gnome3 media indicator applet still thinks music is
> playing...

Should be fixed in revision 676.

(I wonder why playPauseChanged is part of LibraryWindow, but playback_stopped is in LibraryManager.)

> What I want to propose: I've been working on this issue as well. Basic
> playlist support is implemented and I will probably push my revision this
> evening... I will incorpotate the addition of the track_id in the metadata if
> this is required by MPRIS...

Good to hear that.

Yes, mpris:trackid is required, although mpristester[1] is probably the only program that will complain about its absence – unless you're also implementing the TrackList interface, but I'm not sure if there are any programs that actually make use of it.

[1]: https://github.com/randomguy3/mpristester/

Revision history for this message
Scott Ringwelski (sgringwe) wrote :

Mantas, thanks for the input you provided with the branch. It was (all?) used in Kurt's branch and was very helpful. Kurt's branch was just merged.

Thanks again!

review: Disapprove
Revision history for this message
Mantas Mikulėnas (grawity) wrote :

Thanks for the review.

There's one comment I still have, regarding build dependencies. One of Kurt's commits adds "dbusmenu-glib-0.4" to CMakeLists as a required dependency, noting that "DBUS is required dependency". However, as far as I know, the "dbusmenu" library is NOT required here as it only deals with the global Unity menubar and is practically useless on other distributions than Ubuntu. The support for DBus itself is already provided by "glib-2.0", and was sufficient for my branch on Arch Linux.

Revision history for this message
Mantas Mikulėnas (grawity) wrote :

Hmm, I had hoped that my rev 674 would get picked up too. Without it, BeatBox doesn't send out change signals at all.

Revision history for this message
Scott Ringwelski (sgringwe) wrote :

Thanks for your comments.

I added your rev 674 change. Out of curiousity, why is null preferred?
I also removed dbusmenu-glib-0.4 as removing that dependency worked on my system too.

Both are in rev 682.

On a sidenote, do you know anything about MprisPlaylist support? Kurt started it but couldn't quite get it 100% so it is currently commented out. If we could get MPRIS.vala to have full playlist support, we could take all media player stuff out of UnityIntegration.vala and avoid this whole mess.

Revision history for this message
Mantas Mikulėnas (grawity) wrote :

If I understand the documentation for GLib.DBusConnection.emit_signal() [1] correctly, the first argument is the busname to send signals *to* – if it is null, the signal is sent to all subscribers, but with the old code, the signals were sent only to BeatBox itself. (They still appear in dbus-monitor, but are not received by normal subscribers such as the GNOME Shell extension.)

Without this fix, GNOME would never notice any changes when I paused BeatBox or switched to a different song. (I'm not sure how Unity dealt with the previous behavior -- it might be polling the player for changes?)

[1]: http://valadoc.org/#!api=gio-2.0/GLib.DBusConnection.emit_signal

I haven't yet worked at all with the TrackList interface of MPRIS (and I don't know if any MPRIS clients make use of it). I will take a look at the commented-out implementation of Playlists, though it might be beyond my knowledge of BeatBox internals.

Unmerged revisions

676. By Mantas Mikulėnas

MPRIS: Update PlaybackStatus on playback_stopped signal

675. By Mantas Mikulėnas

MPRIS: Add mpris:trackid metadata, reduce code duplication

674. By Mantas Mikulėnas

MPRIS: Emit signals to all listeners

Signals sent to our own bus name never reach other programs.

673. By Mantas Mikulėnas

MPRIS: Fix range for xesam:userRating (must be 0.0~1.0)

672. By Mantas Mikulėnas

MPRIS: Export required MinimumRate, MaximumRate properties

671. By Mantas Mikulėnas

MPRIS: Fix xesam:genre metadata name

670. By Mantas Mikulėnas

MPRIS: Enable regardless of libindicate presence

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/LibraryWindow.vala'
2--- src/Core/LibraryWindow.vala 2012-07-06 22:00:14 +0000
3+++ src/Core/LibraryWindow.vala 2012-07-07 17:12:18 +0000
4@@ -114,9 +114,6 @@
5 #endif
6 #endif
7
8-
9-#if HAVE_INDICATE
10-#if HAVE_DBUSMENU
11 message("Initializing MPRIS and sound menu\n");
12 var mpris = new BeatBox.MPRIS(lm, this);
13 mpris.initialize();
14@@ -126,8 +123,6 @@
15 // that there isn't, the player will reshow when user tries to open
16 // it (app-uniqueness).
17 this.delete_event.connect(on_delete);
18-#endif
19-#endif
20
21 dragging_from_music = false;
22
23
24=== modified file 'src/DBus/MPRIS/MPRIS.vala'
25--- src/DBus/MPRIS/MPRIS.vala 2012-07-04 00:35:02 +0000
26+++ src/DBus/MPRIS/MPRIS.vala 2012-07-07 17:12:18 +0000
27@@ -18,8 +18,6 @@
28 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
30 */
31-#if HAVE_INDICATE
32-#if HAVE_DBUSMENU
33 using Gee;
34
35 public class BeatBox.MPRIS : GLib.Object {
36@@ -48,12 +46,14 @@
37 if(owner_id == 0) {
38 warning("Could not initialize MPRIS session.\n");
39 }
40+#if HAVE_INDICATE
41+#if HAVE_DBUSMENU
42 else {
43 bool have_unity = false;
44 #if HAVE_UNITY
45 have_unity = true;
46 #endif
47-
48+
49 // If Unity is running, let the implementation in UnityIntegration
50 // handle the sound menu since it is cleaner and has playlists.
51 // Otherwise, use this as a backup.
52@@ -65,6 +65,8 @@
53 debug("It's up to unity to take care for sound menu integration");
54 }
55 }
56+#endif
57+#endif
58 }
59
60 private void on_bus_acquired(DBusConnection connection, string name) {
61@@ -219,8 +221,31 @@
62
63 BeatBox.Beatbox.library_manager.media_played.connect(lm_media_played);
64 BeatBox.Beatbox.library_manager.medias_updated.connect(medias_updated);
65+ BeatBox.Beatbox.library_manager.playback_stopped.connect(playback_stopped);
66 BeatBox.Beatbox.library_window.playPauseChanged.connect(playing_changed);
67 }
68+
69+ // MPRIS requires a mpris:trackid metadata item.
70+ private GLib.ObjectPath get_trackid(BeatBox.Media s) {
71+ string id = "/net/launchpad/beatbox/Track" + s.rowid.to_string();
72+ return new GLib.ObjectPath(id);
73+ }
74+
75+ private void fill_metadata(BeatBox.Media s) {
76+ string[] artistArray = {};
77+ artistArray += s.artist;
78+ string[] genreArray = {};
79+ genreArray += s.genre;
80+
81+ _metadata.insert("mpris:trackid", get_trackid(s));
82+ _metadata.insert("xesam:artist", artistArray);
83+ _metadata.insert("xesam:album", s.album);
84+ _metadata.insert("xesam:title", s.title);
85+ _metadata.insert("xesam:genre", genreArray);
86+ _metadata.insert("mpris:artUrl", File.new_for_path(s.getAlbumArtPath()).get_uri());
87+ _metadata.insert("mpris:length", BeatBox.Beatbox.library_manager.player.getDuration()/1000);
88+ _metadata.insert("xesam:userRating", s.rating / 5.0);
89+ }
90
91 void medias_updated(Gee.LinkedList<int> ids) {
92 if(BeatBox.Beatbox.library_manager.media_info.media == null)
93@@ -237,6 +262,10 @@
94 private void playing_changed() {
95 trigger_metadata_update();
96 }
97+
98+ private void playback_stopped(int wasPlaying) {
99+ trigger_metadata_update();
100+ }
101
102 private void trigger_metadata_update() {
103 if(update_metadata_source != 0)
104@@ -254,19 +283,7 @@
105 }
106
107 void lm_media_played(BeatBox.Media s, BeatBox.Media? old) {
108- string[] artistArray = {};
109- artistArray += s.artist;
110- string[] genreArray = {};
111- genreArray += s.genre;
112-
113- _metadata.insert("xesam:artist", artistArray);
114- _metadata.insert("xesam:album", s.album);
115- _metadata.insert("xesam:title", s.title);
116- _metadata.insert("sesam:genre", genreArray);
117- _metadata.insert("mpris:artUrl", File.new_for_path(s.getAlbumArtPath()).get_uri());
118- _metadata.insert("mpris:length", BeatBox.Beatbox.library_manager.player.getDuration()/1000);
119- _metadata.insert("xesam:userRating", s.rating);
120-
121+ fill_metadata(s);
122 trigger_metadata_update();
123 }
124
125@@ -286,7 +303,7 @@
126 changed_properties = null;
127
128 try {
129- conn.emit_signal("org.mpris.MediaPlayer2.beatbox",
130+ conn.emit_signal(null,
131 "/org/mpris/MediaPlayer2",
132 "org.freedesktop.DBus.Properties",
133 "PropertiesChanged",
134@@ -398,19 +415,7 @@
135 if(s == null)
136 return _metadata;
137
138- string[] artistArray = {};
139- artistArray += s.artist;
140- string[] genreArray = {};
141- genreArray += s.genre;
142-
143- _metadata.insert("xesam:artist", artistArray);
144- _metadata.insert("xesam:album", s.album);
145- _metadata.insert("xesam:title", s.title);
146- _metadata.insert("sesam:genre", genreArray);
147- _metadata.insert("mpris:artUrl", File.new_for_path(s.getAlbumArtPath()).get_uri());
148- _metadata.insert("mpris:length", BeatBox.Beatbox.library_manager.player.getDuration()/1000);
149- _metadata.insert("xesam:userRating", s.rating);
150-
151+ fill_metadata(s);
152 return _metadata;
153 }
154 }
155@@ -430,7 +435,7 @@
156 }
157 }
158
159- /*public double MinimumRate {
160+ public double MinimumRate {
161 get {
162 return (double)1.0;
163 }
164@@ -440,7 +445,7 @@
165 get {
166 return (double)1.0;
167 }
168- }*/
169+ }
170
171 public bool CanGoNext {
172 get {
173@@ -625,5 +630,3 @@
174 }
175
176 }*/
177-#endif
178-#endif

Subscribers

People subscribed via source and target branches