From: Qball Cow <qball@gmpclient.org>
Date: Wed, 14 Sep 2011 13:06:39 +0200
Subject: Correct vapi binding for MPD.Song

---
 src/Providers/ChartLyrics.vala                |  4 +--
 src/Providers/HTBackdrops.vala                |  2 +-
 src/Providers/LyrDB.vala                      |  4 +--
 src/Providers/RenderCover.vala                |  2 +-
 src/Providers/music-tree.vala                 | 21 ++++++++-------
 src/Tools/gmpc-metadata-prefetcher.vala       |  2 +-
 src/Widgets/gmpc-metadata-backdrop.vala       |  2 +-
 src/Widgets/gmpc-metadata-similarartists.vala |  6 ++---
 src/Widgets/gmpc-metadata-similarsongs.vala   | 12 ++++-----
 src/Widgets/gmpc-metadata-text-label.vala     |  6 ++---
 src/Widgets/gmpc-song-links.vala              |  4 +--
 src/Widgets/gmpc-song-list.vala               |  6 ++---
 src/browsers/gmpc-metadata-browser2.vala      | 39 ++++++++++++++-------------
 src/browsers/gmpc-nowplaying2.vala            |  4 +--
 src/vala/gmpc-favorites.vala                  |  2 +-
 src/vala/gmpc-plugin.vala                     |  2 +-
 src/vala/gmpc-test-plugin.vala                |  8 +++---
 src/vapi/gmpc.vapi                            |  4 +--
 src/vapi/libmpd.vapi                          | 34 +++++++++++------------
 19 files changed, 84 insertions(+), 80 deletions(-)

diff --git a/src/Providers/ChartLyrics.vala b/src/Providers/ChartLyrics.vala
index 1409abc..604b929 100644
--- a/src/Providers/ChartLyrics.vala
+++ b/src/Providers/ChartLyrics.vala
@@ -83,7 +83,7 @@ public class Gmpc.Provider.ChartLyrics: Gmpc.Plugin.Base,Gmpc.Plugin.MetaDataIfa
 
     const string query = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=%s&song=%s";
 
-    public void get_metadata (MPD.Song song,
+    public void get_metadata (MPD.Song? song,
         Gmpc.MetaData.Type type,
         MetaDataCallback callback)
     {
@@ -105,7 +105,7 @@ public class Gmpc.Provider.ChartLyrics: Gmpc.Plugin.Base,Gmpc.Plugin.MetaDataIfa
         /* intergrate fetcher here */
         Prop *p = new Prop();
         p->this = this;
-        p->song = song;
+        p->song = song.copy();
         p->callback = callback;
         var path = query.printf(Gmpc.AsyncDownload.escape_uri(song.artist),
             Gmpc.AsyncDownload.escape_uri(song.title));
diff --git a/src/Providers/HTBackdrops.vala b/src/Providers/HTBackdrops.vala
index 2986006..fd81e97 100644
--- a/src/Providers/HTBackdrops.vala
+++ b/src/Providers/HTBackdrops.vala
@@ -55,7 +55,7 @@ public class Gmpc.Provider.HTBackdrops:
         return config.get_int_with_default(this.get_name(),"priority",0);
     }
 
-    public void get_metadata(MPD.Song song, Gmpc.MetaData.Type type, MetaDataCallback callback)
+    public void get_metadata(MPD.Song? song, Gmpc.MetaData.Type type, MetaDataCallback callback)
     {
 
         if(song == null || song.artist == null)
diff --git a/src/Providers/LyrDB.vala b/src/Providers/LyrDB.vala
index 1494c8f..2cc8b71 100644
--- a/src/Providers/LyrDB.vala
+++ b/src/Providers/LyrDB.vala
@@ -55,7 +55,7 @@ public class Gmpc.Provider.LyrDB: Gmpc.Plugin.Base,Gmpc.Plugin.MetaDataIface
 	}
 
 
-	public void get_metadata (MPD.Song song,
+	public void get_metadata (MPD.Song? song,
 		Gmpc.MetaData.Type type,
 		MetaDataCallback callback)
 	{
@@ -236,7 +236,7 @@ public class Gmpc.Provider.LyrDB: Gmpc.Plugin.Base,Gmpc.Plugin.MetaDataIface
 
 		Prop *p = new Prop();
 		p->this = this;
-		p->song = song;
+		p->song = song.copy();
 		p->callback = callback;
 		var path = query.printf(Gmpc.AsyncDownload.escape_uri(song.artist),
 			Gmpc.AsyncDownload.escape_uri(song.title));
diff --git a/src/Providers/RenderCover.vala b/src/Providers/RenderCover.vala
index 109ae4a..443de79 100644
--- a/src/Providers/RenderCover.vala
+++ b/src/Providers/RenderCover.vala
@@ -56,7 +56,7 @@ public class Gmpc.Provider.RenderCover:
         return config.get_int_with_default(this.get_name(),"priority",100);
     }
 
-    public void get_metadata(MPD.Song song, Gmpc.MetaData.Type type, MetaDataCallback callback)
+    public void get_metadata(MPD.Song? song, Gmpc.MetaData.Type type, MetaDataCallback callback)
     {
 
         if(song == null || song.artist == null || song.album == null)
diff --git a/src/Providers/music-tree.vala b/src/Providers/music-tree.vala
index d925dff..fe44c9a 100644
--- a/src/Providers/music-tree.vala
+++ b/src/Providers/music-tree.vala
@@ -82,7 +82,7 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 	/********************************
 	 * metadata code                *
 	 ********************************/
-	public void get_metadata(MPD.Song song,
+	public void get_metadata(MPD.Song? song,
 		Gmpc.MetaData.Type type,
 		MetaDataCallback callback)
 	{
@@ -136,16 +136,16 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 		switch(type)
 		{
 			case Gmpc.MetaData.Type.ALBUM_ART:
-				this.get_album_cover(directory, song, callback);
+				this.get_album_cover(directory, song.copy(), callback);
 				return;
 			case Gmpc.MetaData.Type.ARTIST_ART:
-				this.get_artist_art(directory, song, callback);
+				this.get_artist_art(directory, song.copy(), callback);
 				return;
 			case Gmpc.MetaData.Type.ARTIST_TXT:
-				this.get_biography(directory, song, callback);
+				this.get_biography(directory, song.copy(), callback);
 				return;
 			case  Gmpc.MetaData.Type.ALBUM_TXT:
-				this.get_album_info(directory,song,callback);
+				this.get_album_info(directory,song.copy(),callback);
 				return;
 				/*  Not yet supported  */
 			case  Gmpc.MetaData.Type.SONG_TXT:
@@ -260,7 +260,7 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 	/**
 	 * Get artist art
 	 */
-	private async void get_artist_art(string directory, MPD.Song song, MetaDataCallback callback)
+	private async void get_artist_art(string directory, owned MPD.Song song, MetaDataCallback callback)
 	{
 		List<Gmpc.MetaData.Item> list = null;
         log(log_domain_cp, GLib.LogLevelFlags.LEVEL_DEBUG,
@@ -313,9 +313,10 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 	/**
 	 * Get album cover
 	 */
-	private async void get_album_cover(string directory, MPD.Song song, MetaDataCallback callback)
+	private async void get_album_cover(string directory, owned MPD.Song tmp_song, MetaDataCallback callback)
 	{
 		List<Gmpc.MetaData.Item> list = null;
+		var song = tmp_song.copy();
 		log(log_domain_cp, GLib.LogLevelFlags.LEVEL_DEBUG,
 			"Query album cover");
 		// Create search query
@@ -366,9 +367,10 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 	/**
 	 * Get biography
 	 */
-	private async void get_biography(string directory, MPD.Song song, MetaDataCallback callback)
+	private async void get_biography(string directory, owned MPD.Song tmp_song, MetaDataCallback callback)
 	{
 		List<Gmpc.MetaData.Item> list = null;
+		var song = tmp_song.copy();
 		log(log_domain_cp, GLib.LogLevelFlags.LEVEL_DEBUG,
 			"Query biography");
 		// Create search query
@@ -398,9 +400,10 @@ public class Gmpc.Provider.MusicTree : Gmpc.Plugin.Base, Gmpc.Plugin.MetaDataIfa
 	/**
 	 * Get album information
 	 */
-	private async void get_album_info(string directory, MPD.Song song, MetaDataCallback callback)
+	private async void get_album_info(string directory, owned MPD.Song tmp_song, MetaDataCallback callback)
 	{
 		List<Gmpc.MetaData.Item> list = null;
+		var song = tmp_song.copy();
 		log(log_domain_cp, GLib.LogLevelFlags.LEVEL_DEBUG,
 			"Query biography");
 		// Create search query
diff --git a/src/Tools/gmpc-metadata-prefetcher.vala b/src/Tools/gmpc-metadata-prefetcher.vala
index f2d4e23..fc9eedc 100644
--- a/src/Tools/gmpc-metadata-prefetcher.vala
+++ b/src/Tools/gmpc-metadata-prefetcher.vala
@@ -50,7 +50,7 @@ public class  Gmpc.Tools.MetadataPrefetcher : Gmpc.Plugin.Base {
             int next_song_id = server.player_get_next_song_id();
             if(next_song_id > 0)
             {
-                MPD.Song song = server.playlist_get_song(next_song_id);
+                MPD.Song? song = server.playlist_get_song(next_song_id);
                 if(song != null){
                     Gmpc.MetaData.Item met = null;
                     Gmpc.MetaData.Result md_result;
diff --git a/src/Widgets/gmpc-metadata-backdrop.vala b/src/Widgets/gmpc-metadata-backdrop.vala
index bdf3b56..af94e39 100644
--- a/src/Widgets/gmpc-metadata-backdrop.vala
+++ b/src/Widgets/gmpc-metadata-backdrop.vala
@@ -75,7 +75,7 @@ namespace Gmpc
              */
             public void set_song(MPD.Song? song)
             {
-                cur_song = song;
+                cur_song = song.copy();
                 if(song == null) {
                     song_checksum = null;
                     set_from_item(null);
diff --git a/src/Widgets/gmpc-metadata-similarartists.vala b/src/Widgets/gmpc-metadata-similarartists.vala
index 978e2b3..f034fc0 100644
--- a/src/Widgets/gmpc-metadata-similarartists.vala
+++ b/src/Widgets/gmpc-metadata-similarartists.vala
@@ -27,7 +27,7 @@ private const string some_unique_name_mdsa = Config.VERSION;
 
 public class Gmpc.MetaData.Widgets.SimilarArtists : Gtk.Table
 {
-    private MPD.Song song = null;
+    private MPD.Song? song = null;
     private int columns = 1;
     private int button_width = 200;
     private void size_changed(Gdk.Rectangle alloc)
@@ -204,7 +204,7 @@ public class Gmpc.MetaData.Widgets.SimilarArtists : Gtk.Table
         var image = new Gmpc.MetaData.Image(Gmpc.MetaData.Type.ARTIST_ART, 48);
         image.set_no_cover_icon("no-artist");
         image.set_loading_cover_icon("fetching-artist");
-        var song = new MPD.Song();
+        MPD.Song song = new MPD.Song();
         song.artist = artist;
         image.set_squared(true);
         image.update_from_song_delayed(song);
@@ -253,7 +253,7 @@ public class Gmpc.MetaData.Widgets.SimilarArtists : Gtk.Table
     }
     public SimilarArtists(MPD.Server server, MPD.Song song)
     {
-        this.song = song;
+        this.song = song.copy();
 
         this.set_homogeneous(true);
 
diff --git a/src/Widgets/gmpc-metadata-similarsongs.vala b/src/Widgets/gmpc-metadata-similarsongs.vala
index 688a8a1..a604954 100644
--- a/src/Widgets/gmpc-metadata-similarsongs.vala
+++ b/src/Widgets/gmpc-metadata-similarsongs.vala
@@ -27,7 +27,7 @@ private const string some_unique_name_mdss = Config.VERSION;
 
 public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
 {
-    private MPD.Song song = null;
+    private MPD.Song? song = null;
     private Gtk.Widget pchild = null;
     private uint idle_add = 0;
     ~SimilarSongs ()
@@ -40,7 +40,7 @@ public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
 
     public SimilarSongs (MPD.Song song) 
     {
-        this.song = song;
+        this.song = song.copy();
         this.set(0.0f, 0.0f, 1.0f, 0.0f);
     }
     private void add_clicked(Gtk.Widget item)
@@ -55,7 +55,7 @@ public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
         {
             if(model.get_iter(out iter, path))
             {
-                unowned MPD.Song song = null;
+                unowned MPD.Song? song = null;
                 model.get(iter, 0, out song, -1);
                 if(song != null)
                 {
@@ -79,7 +79,7 @@ public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
             Gtk.TreePath path = list.data;
             if(model.get_iter(out iter, path))
             {
-                unowned MPD.Song song = null;
+                unowned MPD.Song? song = null;
                 model.get(iter, 0, out song, -1);
                 if(song != null)
                 {
@@ -100,7 +100,7 @@ public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
         {
             if(model.get_iter(out iter, path))
             {
-                unowned MPD.Song song = null;
+                unowned MPD.Song? song = null;
                 model.get(iter, 0, out song, -1);
                 if(song != null)
                 {
@@ -125,7 +125,7 @@ public class Gmpc.MetaData.Widgets.SimilarSongs : Gtk.Alignment
         Gtk.TreeIter iter;
         if(model.get_iter(out iter, path))
         {
-            unowned MPD.Song song = null;
+            unowned MPD.Song? song = null;
             model.get(iter, 0, out song, -1);
             if(song != null)
             {
diff --git a/src/Widgets/gmpc-metadata-text-label.vala b/src/Widgets/gmpc-metadata-text-label.vala
index cbf9ec0..f702d4a 100644
--- a/src/Widgets/gmpc-metadata-text-label.vala
+++ b/src/Widgets/gmpc-metadata-text-label.vala
@@ -83,7 +83,7 @@ namespace Gmpc.MetaData.Widgets
             this.set_padding(4,4);
             this.set_selectable(true);
             cur_type = type;
-            cur_song = song;
+            cur_song = song.copy();
             song_checksum = Gmpc.Misc.song_checksum(song);
 
             metawatcher.data_changed.connect((csong, type, result, met) => {
@@ -102,7 +102,7 @@ namespace Gmpc.MetaData.Widgets
 
             /** Query */
             Gmpc.MetaData.Item item = null;
-            var a = metawatcher.query(song, type, out item);
+            var a = metawatcher.query(cur_song, type, out item);
             if(a == Gmpc.MetaData.Result.AVAILABLE) {
                 this.set_from_item(item);
             }else if (a == Gmpc.MetaData.Result.FETCHING) {
@@ -116,7 +116,7 @@ namespace Gmpc.MetaData.Widgets
                 mitem.set_image(
                     new Gtk.Image.from_stock("gtk-refresh", Gtk.IconSize.MENU));
                 mitem.activate.connect((source)=>{
-                    metawatcher.query(song, type|Gmpc.MetaData.Type.QUERY_NO_CACHE, out item);
+                    metawatcher.query(cur_song, type|Gmpc.MetaData.Type.QUERY_NO_CACHE, out item);
                  });
                  menu.append(mitem);
                  mitem.show();
diff --git a/src/Widgets/gmpc-song-links.vala b/src/Widgets/gmpc-song-links.vala
index 61cef40..983697b 100644
--- a/src/Widgets/gmpc-song-links.vala
+++ b/src/Widgets/gmpc-song-links.vala
@@ -37,7 +37,7 @@ public class Gmpc.MetaData.Widgets.SongLinks: Gtk.Frame
         SONG
     }
     private Type type = Type.ARTIST;
-    private MPD.Song song = null;
+    private MPD.Song? song = null;
 
     ~SongLinks()
     {
@@ -52,7 +52,7 @@ public class Gmpc.MetaData.Widgets.SongLinks: Gtk.Frame
     {
         debug("Links created");
         this.type = type;
-        this.song = song;
+        this.song = song.copy();
         var event = new Gtk.EventBox();
         var label = new Gtk.Label("");
         event.add(label);
diff --git a/src/Widgets/gmpc-song-list.vala b/src/Widgets/gmpc-song-list.vala
index 09a50cf..ccbe7b4 100644
--- a/src/Widgets/gmpc-song-list.vala
+++ b/src/Widgets/gmpc-song-list.vala
@@ -71,7 +71,7 @@ public class Gmpc.Widgets.Songlist : Gmpc.Widgets.Qtable
         wlabel.set_do_bold(true);
         wlabel.set_can_focus(true);
 
-        MPD.Song song_file = song;
+        MPD.Song song_file = song.copy();
         wlabel.clicked.connect((source, event) => {
                 artist_song_clicked(song_file);
         });
@@ -114,7 +114,7 @@ public class Gmpc.Widgets.Songlist : Gmpc.Widgets.Qtable
         wlabel.set_do_bold(true);
         wlabel.set_can_focus(true);
 
-        MPD.Song song_file = song;
+        MPD.Song song_file = song.copy();
         wlabel.clicked.connect((source) => {
                 album_song_clicked(song_file);
         });
@@ -196,7 +196,7 @@ public class Gmpc.Widgets.Songlist : Gmpc.Widgets.Qtable
         ali.add(event);
 
 
-        MPD.Song song_file = song;
+        MPD.Song song_file = song.copy();
         event.button_release_event.connect((source, event) => {
             if(event.button == 1) {
                 play_song_clicked(song_file);
diff --git a/src/browsers/gmpc-metadata-browser2.vala b/src/browsers/gmpc-metadata-browser2.vala
index 704bc01..0231f36 100644
--- a/src/browsers/gmpc-metadata-browser2.vala
+++ b/src/browsers/gmpc-metadata-browser2.vala
@@ -432,7 +432,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
       */
      private void song_add_clicked(Gtk.Widget item )
      {
-        MPD.Song? song = browser_get_selected_song();
+        unowned MPD.Song? song = browser_get_selected_song();
         if(song != null)
         {
             MPD.PlayQueue.add_song(server,song.file);
@@ -731,14 +731,14 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
         }
         return null;
     }
-    private MPD.Song? browser_get_selected_song()
+    private unowned MPD.Song? browser_get_selected_song()
     {
         Gtk.TreeIter iter;
         var sel = this.tree_songs.get_selection();
         Gtk.TreeModel model;
         if(sel.get_selected(out model, out iter))
         {
-            unowned MPD.Song songs = null;
+            unowned MPD.Song? songs = null;
             this.model_songs .get(iter, 0,out songs, -1);
             return songs;
         }
@@ -851,7 +851,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
      {
         string artist = browser_get_selected_artist();
         string album = browser_get_selected_album();
-        MPD.Song? song = browser_get_selected_song();
+        unowned MPD.Song? song = browser_get_selected_song();
         if(song != null){
             MPD.PlayQueue.add_song(server,song.file);
             return;
@@ -893,7 +893,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
 
      private void play_selected_song(Gtk.Button button)
      {
-        MPD.Song? song = browser_get_selected_song();
+        unowned MPD.Song? song = browser_get_selected_song();
         if(song != null) {
             Gmpc.MpdInteraction.play_path(song.file);
         }
@@ -954,10 +954,11 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
          i++;
      }
 
-    public Gtk.Widget metadata_box_show_song(MPD.Song song, bool show_controls)
+    public Gtk.Widget metadata_box_show_song(MPD.Song tmp_song, bool show_controls)
     {
         var master_box = new Gtk.VBox (false, 6);
         var vbox = new Gtk.VBox (false,6);
+		var song = tmp_song.copy();
         vbox.border_width = 8;
 
         history_bc_header(HitemType.SONG, song.artist, song.album, song.title);
@@ -1935,15 +1936,15 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
             if(this.model_albums.get_iter_first(out titer))
             {
                 do{
-                    weak MPD.Song asong  = null;
+                    unowned MPD.Song? asong  = null;
                     this.model_albums.get(titer,0, &asong);
-                    if(song != null)
+                    if(asong != null)
                     {
                         /* Make a copy of the song. Otherwise only a reference is added to the
                          * button clicked handler.
                          * This reference can be invalid before click completed.
                          */
-                        MPD.Song but_song = asong;
+                        MPD.Song but_song = asong.copy();
 
                         /* Create button */
                         var but_hbox = new Gtk.VBox(false, 6);
@@ -2113,12 +2114,12 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
         }
         string artist = browser_get_selected_artist();
         string album = browser_get_selected_album();
-        MPD.Song? song = browser_get_selected_song();
+        unowned MPD.Song? song = browser_get_selected_song();
 
         if(song != null) {
             /** Add item to history */
-            var item = Hitem();
-            item.song = song;
+            var item = new Hitem();
+            item.song = song.copy();
             item.type = HitemType.SONG;
             history_add(item);
 
@@ -2128,7 +2129,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
             this.metadata_box.show_all();
         }else if(album != null && artist != null) {
             /** Add item to history */
-            var item = Hitem();
+            var item = new Hitem();
             item.song = new MPD.Song();
             item.song.artist =artist;
             item.song.album = album;
@@ -2138,7 +2139,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
             metadata_box_show_album(artist,album);
         }else if (artist != null) {
             /** Add item to history */
-            var item = Hitem();
+            var item = new Hitem();
             item.song = new MPD.Song();
             item.song.artist =artist;
             item.type = HitemType.ARTIST;
@@ -2146,7 +2147,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
 
             metadata_box_show_artist(artist);
         }else {
-            var item = Hitem();
+            var item = new Hitem();
             item.search_string = null;
             item.type = HitemType.BASE;
             history_add(item);
@@ -2226,7 +2227,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
         ALBUM,
         SONG
      }
-    private struct Hitem {
+    private class Hitem {
         public HitemType type;
         public MPD.Song? song;
         public string search_string ;
@@ -2294,7 +2295,7 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
         var menu = new Gtk.Menu();
         unowned List<Hitem?> iter = history.last();
         while(iter!= null){
-            var i = iter.data;
+            unowned Hitem i = iter.data;
             string label = "";
             if(i.type == HitemType.ARTIST)
                 label = i.song.artist;
@@ -2608,8 +2609,8 @@ public class  Gmpc.Browsers.Metadata : Gmpc.Plugin.Base, Gmpc.Plugin.BrowserIfac
         }
 
         /** Add item to history */
-        var item = Hitem();
-        item.song = song;
+        var item = new Hitem();
+        item.song = song.copy();
         item.type = HitemType.SONG;
         history_add(item);
 
diff --git a/src/browsers/gmpc-nowplaying2.vala b/src/browsers/gmpc-nowplaying2.vala
index 5be7d32..69f55d1 100644
--- a/src/browsers/gmpc-nowplaying2.vala
+++ b/src/browsers/gmpc-nowplaying2.vala
@@ -314,7 +314,7 @@ namespace Gmpc {
             private string song_checksum = null;
             private void update_playing()
             {
-                MPD.Song song = server.playlist_get_current_song();
+                unowned MPD.Song? song = server.playlist_get_current_song();
                 if(song == null) {
                     debug("GMPC Is playing, cannot get this");
        				if(use_backdrop)
@@ -932,7 +932,7 @@ namespace Gmpc {
                             var but_hbox = new Gtk.HBox(false, 6);
                             button.add(but_hbox);
                             var image = new Gmpc.MetaData.Image(Gmpc.MetaData.Type.ALBUM_ART, 48);
-                            var but_song = iter.song;
+                            unowned MPD.Song but_song = iter.song;
                             image.set_squared(true);
                             image.update_from_song_delayed(but_song);
 
diff --git a/src/vala/gmpc-favorites.vala b/src/vala/gmpc-favorites.vala
index b28f725..8055a5e 100644
--- a/src/vala/gmpc-favorites.vala
+++ b/src/vala/gmpc-favorites.vala
@@ -286,7 +286,7 @@ namespace Gmpc.Favorites{
         {
             if(this.song == null && song == null ) return;
             if(this.song != null  && song != null && this.song.file == song.file) return;
-            this.song = song;
+            this.song = song.copy();
             this.update(favorites);
         }
     }
diff --git a/src/vala/gmpc-plugin.vala b/src/vala/gmpc-plugin.vala
index 6e1ad29..f02f46b 100644
--- a/src/vala/gmpc-plugin.vala
+++ b/src/vala/gmpc-plugin.vala
@@ -103,7 +103,7 @@ namespace Gmpc {
         public delegate void MetaDataCallback(owned GLib.List<Gmpc.MetaData.Item>? list);
         /* untested */
         public interface MetaDataIface : Base {
-            public abstract void get_metadata (MPD.Song song, Gmpc.MetaData.Type type, MetaDataCallback callback);
+            public abstract void get_metadata (MPD.Song? song, Gmpc.MetaData.Type type, MetaDataCallback callback);
             /* Set get priority */
             public abstract int get_priority ();
             public abstract void set_priority (int priority);
diff --git a/src/vala/gmpc-test-plugin.vala b/src/vala/gmpc-test-plugin.vala
index 7e4fd00..bad3ddc 100644
--- a/src/vala/gmpc-test-plugin.vala
+++ b/src/vala/gmpc-test-plugin.vala
@@ -25,7 +25,7 @@ private const bool use_transition_tp = Gmpc.use_transition;
 
 public class Gmpc.MetaData.EditWindow : Gtk.Window {
     private const string some_unique_name = Config.VERSION;
-    private MPD.Song song = null;
+    private MPD.Song? song = null;
     private Gmpc.MetaData.Type query_type = Gmpc.MetaData.Type.ALBUM_ART;
 
     private GLib.List<unowned Gmpc.AsyncDownload.Handle> downloads = null;
@@ -481,7 +481,7 @@ public class Gmpc.MetaData.EditWindow : Gtk.Window {
     {
         clear_itemslist();
         GLib.log("MetadataSelector", GLib.LogLevelFlags.LEVEL_DEBUG, "Query metadata");
-        MPD.Song ss = this.song;
+        MPD.Song ss = this.song.copy();
         ss.artist = this.artist_entry.get_text();
         ss.album = this.album_entry.get_text();
         ss.title = this.title_entry.get_text();
@@ -570,7 +570,7 @@ public class Gmpc.MetaData.EditWindow : Gtk.Window {
     public
     EditWindow (MPD.Song song, Gmpc.MetaData.Type type) {
         var vbox = new Gtk.VBox(false, 6);
-        this.song = song;
+        this.song = song.copy();
         this.query_type = type;
         this.pbox = new Gtk.HBox(false, 6); 
         this.bar = new Gtk.ProgressBar();
@@ -791,7 +791,7 @@ public class  Gmpc.TestPlugin : Gmpc.Plugin.Base,Gmpc.Plugin.ToolMenuIface, Gmpc
         {
             if(model.get_iter(out iter, path))
             {
-                unowned MPD.Song song = null;
+                unowned MPD.Song? song = null;
                 model.get(iter,0, out song);
                 if(song != null)
                 {
diff --git a/src/vapi/gmpc.vapi b/src/vapi/gmpc.vapi
index 4a38e60..0b41fcc 100644
--- a/src/vapi/gmpc.vapi
+++ b/src/vapi/gmpc.vapi
@@ -440,9 +440,9 @@ namespace Gmpc {
 		public void set_enabled(int e);
 		public bool is_browser();
 	}
-	[CCode (cheader_filename="main.h", cname="plugins")]
+	[CCode (cheader_filename="main.h", array_length = false, cname="plugins")]
 	static weak parentPlugin[] plugins;
-	[CCode (cheader_filename="main.h", cname="num_plugins")]
+	[CCode (cname="num_plugins",cheader_filename="main.h")]
 	static int num_plugins;
 
 
diff --git a/src/vapi/libmpd.vapi b/src/vapi/libmpd.vapi
index 36b2569..2ecf6b4 100644
--- a/src/vapi/libmpd.vapi
+++ b/src/vapi/libmpd.vapi
@@ -26,30 +26,30 @@ namespace MPD {
 
     [CCode (cname = "mpd_Song",
     free_function = "mpd_freeSong",
-    copy_function = "mpd_songDup",
+	copy_function = "mpd_songDup",
+	has_type_id = false,
     cheader_filename = "libmpd/libmpdclient.h,libmpd/libmpd.h,misc.h")]
-    [Compact]
-    [Immutable]
+	[Compact]
     public class Song {
         [CCode (cname = "mpd_newSong")]
         public Song ();
-        public string file;
-        public string artist;
-        public string title;
-        public string album;
-        public string track;
-        public string name;
-        public string date;
-        public string genre;
-        public string performer;
-        public string disc;
-        public string comment;
-        public string albumartist;
+        public string? file;
+        public string? artist;
+        public string? title;
+        public string? album;
+        public string? track;
+        public string? name;
+        public string? date;
+        public string? genre;
+        public string? performer;
+        public string? disc;
+        public string? comment;
+        public string? albumartist;
         public int    time;
         public int    pos;
         public int    id;
         [CCode (cname="mpd_songDup0")]
-        public static Song copy (Song? s);
+        public Song copy ();
         [CCode (instance_pos = -1)]
         public void markup (char[] buffer, int length, string markup);
     }
@@ -147,7 +147,7 @@ namespace MPD {
             [Compact]
             public class Item {
                 public Data.Type type;
-                public MPD.Song  song;
+                public MPD.Song?  song;
                 public string tag;
                 public Playlist playlist;
               
