Re: [Muine] [PATCH] incomplete albums



Here's a patch doing the total tracks thing then. I haven't commited it
yet, as we first need the fixing script.

Jorn

On Sat, 2005-01-15 at 17:14 +0100, Jorn Baayen wrote:
> Yea, OK, sounds like the best solution. We'll need to put a big fat
> notice on the website though, before new users start complaining that
> muine doesn't eat their albums.
> 
> I will do the Muine side of things, but I'm no shell script hero- could
> you or somebody else hack this up? 
> 
> Jorn
> 
> On Sat, 2005-01-15 at 16:42 +0200, Yo'av Moshe wrote:
> > Yeah, it's doable, but why not sticking with the first solution - using tags?
> > 
> > Muine already requires the user to have a quite-well-organized
> > library. Why can't we ask for a 'total tracks' tag from our users?
> > 
> > Not all of my albums have this tag, but I sure be willing to add it if
> > it will let me add all of my songs that has no album into muine
> > without ruining my beautiful albums list.
> > 
> > Also, we can write a nice shell script that will tag all albums under
> > whatever folder the user wants with the right 'total tracks' tag (i.e.
> > 'filltotaltracks ~/Music/Albums').
> > 
> > Yo'av.
> > 
> > 
> > On Sat, 15 Jan 2005 13:58:53 +0100, Jorn Baayen <jbaayen gnome org> wrote:
> > > On Sat, 2005-01-15 at 01:49 -0500, Tom McLaughlin wrote:
> > > > On Sat, 2005-01-15 at 01:35 +0100, Jorn Baayen wrote:
> > > > > After looking at this (I was about to commit it), I got a new idea:
> > > > >
> > > > > How about defining a minimum album time length? We could put it, at,
> > > > > say, 15 minutes- this should leave most single songs out. (And we could
> > > > > make a gconf key for it)
> > > >
> > > > Time or even number of tracks might cause some songs to be erroneously
> > > > marked.  I have Pink Floyd songs which are longer than some albums I
> > > > own.  When you do the album cover lookup, can you get the track listing
> > > > from there and used that in some way to determine full albums vs. single
> > > > songs?
> > > 
> > > Using only number of tracks is out of the question right away, because
> > > some albums have one 60 minute track (the necks), and others have many.
> > > 
> > > Can't base info off a lookup either, because there won't be matches for
> > > all albums, and besides, the user could have a different edition (+ or -
> > > bonus tracks) than the one on amazon.
> > > 
> > > What we could do, based on Jonathan's suggestion:
> > > 
> > > MinLength = 30;
> > > MinTracks = 3;
> > > 
> > > if (Length >= MinLength)
> > >    Complete = true;
> > > else if (Tracks >= MinTracks)
> > >    Complete = true;
> > > else
> > >    Complete = false;
> > > 
> > > This should catch 1-track albums, and < 30 min short albums.
> > > 
> > > As for the long pink floyd songs, if they are >= 30 mins, and have an
> > > album tag, it means they are over half of a pink floyd album, and not
> > > just a "single short song"- so I don't feel it in that case That big of
> > > a big mistake to list them in the album window. Not perfect, no, but
> > > doable..
> > > 
> > > Jorn
> > > 
> > > _______________________________________________
> > > muine-list mailing list
> > > muine-list gnome org
> > > http://mail.gnome.org/mailman/listinfo/muine-list
> > >
> 
> _______________________________________________
> muine-list mailing list
> muine-list gnome org
> http://mail.gnome.org/mailman/listinfo/muine-list
Index: libmuine/metadata.c
===================================================================
RCS file: /cvs/gnome/muine/libmuine/metadata.c,v
retrieving revision 1.14
diff -u -r1.14 metadata.c
--- libmuine/metadata.c	26 Dec 2004 11:00:28 -0000	1.14
+++ libmuine/metadata.c	15 Jan 2005 16:55:46 -0000
@@ -43,6 +43,7 @@
 	char *album;
 
 	int track_number;
+	int total_tracks;
 	int disc_number;
 
 	char *year;
@@ -59,6 +60,29 @@
 	GdkPixbuf *album_art;
 };
 
+static void
+parse_raw_track_number (Metadata *metadata,
+			const char *raw)
+{
+	char *part2;
+
+	if (raw == NULL) {
+		metadata->track_number = -1;
+		metadata->total_tracks = -1;
+
+		return;
+	}
+
+	part2 = strstr (raw, "/");
+
+	if (part2 != NULL)
+		metadata->total_tracks = atoi (part2 + 1);
+	else
+		metadata->total_tracks = -1;
+
+	metadata->track_number = atoi (raw);
+}
+
 static int
 get_mp3_duration (struct id3_tag *tag)
 {
@@ -347,10 +371,7 @@
 	metadata->album = get_mp3_comment_value (tag, ID3_FRAME_ALBUM, 0);
 
 	track_number_raw = get_mp3_comment_value (tag, ID3_FRAME_TRACK, 0);
-	if (track_number_raw != NULL)
-		metadata->track_number = atoi (track_number_raw);
-	else
-		metadata->track_number = -1;
+	parse_raw_track_number (metadata, track_number_raw);
 	g_free (track_number_raw);
 
         disc_number_raw = get_mp3_comment_value (tag, "TPOS", 0);
@@ -440,10 +461,7 @@
 	metadata->album = get_vorbis_comment_value (comment, "album", 0);
 
 	raw = vorbis_comment_query (comment, "tracknumber", 0);
-	if (raw != NULL)
-		metadata->track_number = atoi (raw);
-	else
-		metadata->track_number = -1;
+	parse_raw_track_number (metadata, raw);
 
 	raw = vorbis_comment_query (comment, "discnumber", 0);
 	if (raw != NULL)
@@ -791,6 +809,14 @@
 	g_return_val_if_fail (metadata != NULL, -1);
 
 	return metadata->track_number;
+}
+
+int
+metadata_get_total_tracks (Metadata *metadata)
+{
+	g_return_val_if_fail (metadata != NULL, -1);
+
+	return metadata->total_tracks;
 }
 
 int
Index: libmuine/metadata.h
===================================================================
RCS file: /cvs/gnome/muine/libmuine/metadata.h,v
retrieving revision 1.9
diff -u -r1.9 metadata.h
--- libmuine/metadata.h	26 Dec 2004 11:00:28 -0000	1.9
+++ libmuine/metadata.h	15 Jan 2005 16:55:46 -0000
@@ -46,6 +46,8 @@
 
 int         metadata_get_track_number    (Metadata *metadata);
 
+int         metadata_get_total_tracks    (Metadata *metadata);
+
 int         metadata_get_disc_number     (Metadata *metadata);
 
 int         metadata_get_duration        (Metadata *metadata);
Index: src/AddAlbumWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/AddAlbumWindow.cs,v
retrieving revision 1.69
diff -u -r1.69 AddAlbumWindow.cs
--- src/AddAlbumWindow.cs	14 Jan 2005 23:33:46 -0000	1.69
+++ src/AddAlbumWindow.cs	15 Jan 2005 16:55:46 -0000
@@ -89,13 +89,10 @@
 
 			Global.CoverDB.DoneLoading += new CoverDatabase.DoneLoadingHandler (OnCoversDoneLoading);
 
-			lock (Global.DB) {
-				foreach (Album a in Global.DB.Albums.Values) 
-					base.List.Append (a.Handle);
-			}
-
 			if (!Global.CoverDB.Loading)
 				EnableDragDest ();
+
+			base.Search ();
 		}
 
 		// Methods
Index: src/AddSongWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/AddSongWindow.cs,v
retrieving revision 1.63
diff -u -r1.63 AddSongWindow.cs
--- src/AddSongWindow.cs	14 Jan 2005 23:33:46 -0000	1.63
+++ src/AddSongWindow.cs	15 Jan 2005 16:55:46 -0000
@@ -77,17 +77,7 @@
 			Global.DB.SongChanged += new SongDatabase.SongChangedHandler (OnChanged);
 			Global.DB.SongRemoved += new SongDatabase.SongRemovedHandler (OnRemoved);
 
-			lock (Global.DB) {
-				int i = 0;
-
-				foreach (Song s in Global.DB.Songs.Values) {
-					base.List.Append (s.Handle);
-
-					i++;
-					if (i >= List.FakeLength)
-						break;
-				}
-			}
+			base.Search ();
 		}
 
 		// Handlers
Index: src/AddWindow.cs
===================================================================
RCS file: /cvs/gnome/muine/src/AddWindow.cs,v
retrieving revision 1.14
diff -u -r1.14 AddWindow.cs
--- src/AddWindow.cs	15 Jan 2005 00:00:03 -0000	1.14
+++ src/AddWindow.cs	15 Jan 2005 16:55:46 -0000
@@ -217,8 +217,8 @@
 			window.SizeAllocated += new SizeAllocatedHandler (OnSizeAllocated);		
 		}
 
-		// Methods :: Private :: Search
-		private bool Search ()
+		// Methods :: Protected :: Search
+		protected bool Search ()
 		{
 			AssertHasItems ();
 		
@@ -246,6 +246,9 @@
 					}
 				} else {
 					foreach (Item item in items) {
+						if (!item.Public)
+							continue;
+
 						l.Append (item.Handle);
 					
 						i++;
Index: src/Album.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Album.cs,v
retrieving revision 1.48
diff -u -r1.48 Album.cs
--- src/Album.cs	14 Jan 2005 22:40:16 -0000	1.48
+++ src/Album.cs	15 Jan 2005 16:55:46 -0000
@@ -73,6 +73,8 @@
 		private ArrayList performers;
 		private string year;
 		private string folder;
+		private int n_tracks;
+		private int total_n_tracks;
 
 		private static Hashtable pointers = new Hashtable ();
 		private static IntPtr cur_ptr = IntPtr.Zero;
@@ -94,6 +96,9 @@
 
 			folder = initial_song.Folder;
 
+			n_tracks = 1;
+			total_n_tracks = initial_song.NAlbumTracks;
+
 			cur_ptr = new IntPtr (((int) cur_ptr) + 1);
 			pointers [cur_ptr] = this;
 			base.handle = cur_ptr;
@@ -157,6 +162,11 @@
 			get { return cover_image; }
 		}
 
+		// Properties :: Public (get;)
+		public override bool Public {
+			get { return (n_tracks == total_n_tracks); }
+		}
+
 		// Properties :: Key (get;)
 		public string Key {
 			get { return Global.DB.MakeAlbumKey (folder, name); }
@@ -197,18 +207,32 @@
 
 				songs.Add (song);
 				songs.Sort (song_comparer);
+
+				bool old_complete = Public;
+				n_tracks ++;
+				if (Public != old_complete)
+					changed = true;
 			}
 		}
 
 		// Methods :: Public :: Remove
 		public void Remove (Song song, out bool changed, out bool empty)
 		{
+			changed = false;
+
 			lock (this) {
+				bool old_complete = Public;
+				n_tracks --;
+				if (Public != old_complete)
+					changed = true;
+
 				songs.Remove (song);
 
-				changed = RemoveArtistsAndPerformers (song);
+				bool artists_changed = RemoveArtistsAndPerformers (song);
+				if (artists_changed)
+					changed = true;
 
-				empty = (songs.Count == 0);
+				empty = (n_tracks == 0);
 				if (empty) {
 					pointers.Remove (base.handle);
 
@@ -238,7 +262,7 @@
 			string [] prefixes = string_prefixes.Split (' ');
 
 			string [] p_artists = new string [artists.Count];
-			for (int i = 0; i < artists.Count; i++) {
+			for (int i = 0; i < artists.Count; i ++) {
 				p_artists [i] = ((string) artists [i]).ToLower ();
 				
 				foreach (string prefix in prefixes) {
@@ -251,7 +275,7 @@
 			}
 
 			string [] p_performers = new string [performers.Count];
-			for (int i = 0; i < performers.Count; i++) {
+			for (int i = 0; i < performers.Count; i ++) {
 				p_performers [i] = ((string) performers [i]).ToLower ();
 				
 				foreach (string prefix in prefixes) {
Index: src/Global.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Global.cs,v
retrieving revision 1.8
diff -u -r1.8 Global.cs
--- src/Global.cs	15 Jan 2005 15:54:44 -0000	1.8
+++ src/Global.cs	15 Jan 2005 16:55:46 -0000
@@ -138,7 +138,7 @@
 
 			// Load song database
 			try {
-				db = new SongDatabase (5);
+				db = new SongDatabase (6);
 			} catch (Exception e) {
 				Error (String.Format (string_songdb_failed, e.Message));
 			}
Index: src/Item.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Item.cs,v
retrieving revision 1.5
diff -u -r1.5 Item.cs
--- src/Item.cs	11 Jan 2005 07:24:20 -0000	1.5
+++ src/Item.cs	15 Jan 2005 16:55:46 -0000
@@ -42,6 +42,11 @@
 			get { return handle; }
 		}
 
+		// Properties :: Public (get;)
+		public abstract bool Public {
+			get;
+		}
+
 		// Properties :: SortKey (get;)
 		public string SortKey {
 			get {
@@ -85,6 +90,9 @@
 		// Methods :: Public :: FitsCriteria
 		public bool FitsCriteria (string [] search_bits)
 		{
+			if (!Public)
+				return false;
+
 			int n_matches = 0;
 				
 			foreach (string search_bit in search_bits) {
Index: src/Metadata.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Metadata.cs,v
retrieving revision 1.20
diff -u -r1.20 Metadata.cs
--- src/Metadata.cs	14 Jan 2005 14:47:31 -0000	1.20
+++ src/Metadata.cs	15 Jan 2005 16:55:46 -0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004 Jorn Baayen <jbaayen gnome org>
+ * Copyright (C) 2004, 2005 Jorn Baayen <jbaayen gnome org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -36,21 +36,6 @@
 		// Objects
 		private IntPtr raw = IntPtr.Zero;
 
-		// Variables
-		private string title;
-		private string [] artists;
-		private string [] performers;
-		private string album;
-		private Pixbuf album_art;
-		private int track_number;
-		private int disc_number;
-		private string year;
-		private int duration;
-		private string mime_type;
-		private int mtime;
-		private double gain;
-		private double peak;
-
 		// Constructor
 		[DllImport ("libmuine")]
 		private static extern IntPtr metadata_load (string filename,
@@ -74,15 +59,11 @@
 
 		public string Title {
 			get {
-				if (title == null) {
-					IntPtr p = metadata_get_title (raw);
-					if (p == IntPtr.Zero)
-						title = "";
-					else
-						title = Marshal.PtrToStringAnsi (p);
-				}
-				
-				return title;
+				IntPtr p = metadata_get_title (raw);
+				if (p == IntPtr.Zero)
+					return "";
+				else
+					return Marshal.PtrToStringAnsi (p);
 			}
 		}
 
@@ -95,20 +76,16 @@
 
 		public string [] Artists {
 			get {
-				if (artists == null) {
-					ArrayList strings = new ArrayList ();
+				ArrayList strings = new ArrayList ();
 
-					int count = metadata_get_artist_count (raw);
-					for (int i = 0; i < count; i++) {
-						string tmp = Marshal.PtrToStringAnsi (metadata_get_artist (raw, i));
-						if (tmp.Length > 0)
-							strings.Add (tmp);
-					}
-
-					artists = (string []) strings.ToArray (typeof (string));
+				int count = metadata_get_artist_count (raw);
+				for (int i = 0; i < count; i++) {
+					string tmp = Marshal.PtrToStringAnsi (metadata_get_artist (raw, i));
+					if (tmp.Length > 0)
+						strings.Add (tmp);
 				}
 
-				return artists;
+				return (string []) strings.ToArray (typeof (string));
 			}
 		}
 
@@ -121,20 +98,16 @@
 
 		public string [] Performers {
 			get {
-				if (performers == null) {
-					ArrayList strings = new ArrayList ();
-
-					int count = metadata_get_performer_count (raw);
-					for (int i = 0; i < count; i++) {
-						string tmp = Marshal.PtrToStringAnsi (metadata_get_performer (raw, i));
-						if (tmp.Length > 0)
-							strings.Add (tmp);
-					}
+				ArrayList strings = new ArrayList ();
 
-					performers = (string []) strings.ToArray (typeof (string));
+				int count = metadata_get_performer_count (raw);
+				for (int i = 0; i < count; i++) {
+					string tmp = Marshal.PtrToStringAnsi (metadata_get_performer (raw, i));
+					if (tmp.Length > 0)
+						strings.Add (tmp);
 				}
-				
-				return performers;
+
+				return (string []) strings.ToArray (typeof (string));
 			}			
 		}
 
@@ -144,15 +117,11 @@
 
 		public string Album {
 			get { 
-				if (album == null) {
-					IntPtr p = metadata_get_album (raw);
-					if (p == IntPtr.Zero)
-						album = "";
-					else
-						album = Marshal.PtrToStringAnsi (p);
-				}
-				
-				return album;
+				IntPtr p = metadata_get_album (raw);
+				if (p == IntPtr.Zero)
+					return "";
+				else
+					return Marshal.PtrToStringAnsi (p);
 			}
 		}
 
@@ -162,15 +131,11 @@
 
 		public Pixbuf AlbumArt {
 			get { 
-				if (album_art == null) {
-					IntPtr p = metadata_get_album_art (raw);
-					if (p == IntPtr.Zero)
-						album_art = null;
-					else
-						album_art = new Pixbuf (p);
-				}
-				
-				return album_art;
+				IntPtr p = metadata_get_album_art (raw);
+				if (p == IntPtr.Zero)
+					return null;
+				else
+					return new Pixbuf (p);
 			}
 		}
 
@@ -180,9 +145,17 @@
 		
 		public int TrackNumber {
 			get { 
-				if (track_number == 0)
-					track_number = metadata_get_track_number (raw);
-				return track_number;
+				return metadata_get_track_number (raw);
+			}
+		}
+
+		// Properties :: TotalTracks (get;)
+		[DllImport ("libmuine")]
+		private static extern int metadata_get_total_tracks (IntPtr metadata);
+		
+		public int TotalTracks {
+			get { 
+				return metadata_get_total_tracks (raw);
 			}
 		}
 
@@ -192,9 +165,7 @@
 
 		public int DiscNumber {
 			get { 
-				if (disc_number == 0)
-					disc_number = metadata_get_disc_number (raw);
-				return disc_number;
+				return metadata_get_disc_number (raw);
 			}
 		}
 
@@ -204,15 +175,11 @@
 
 		public string Year {
 			get {
-				if (year == null) {
-					IntPtr p = metadata_get_year (raw);
-					if (p == IntPtr.Zero)
-						year = "";
-					else
-						year = Marshal.PtrToStringAnsi (p);
-				}
-				
-				return year;
+				IntPtr p = metadata_get_year (raw);
+				if (p == IntPtr.Zero)
+					return "";
+				else
+					return Marshal.PtrToStringAnsi (p);
 			}
 		}
 
@@ -222,9 +189,7 @@
 
 		public int Duration {
 			get { 
-				if (duration == 0)
-					duration = metadata_get_duration (raw);
-				return duration;
+				return metadata_get_duration (raw);
 			}
 		}
 
@@ -234,15 +199,11 @@
 
 		public string MimeType {
 			get {
-				if (mime_type == null) {
-					IntPtr p = metadata_get_mime_type (raw);
-					if (p == IntPtr.Zero)
-						mime_type = "";
-					else
-						mime_type = Marshal.PtrToStringAnsi (p);
-				}
-				
-				return mime_type;
+				IntPtr p = metadata_get_mime_type (raw);
+				if (p == IntPtr.Zero)
+					return "";
+				else
+					return Marshal.PtrToStringAnsi (p);
 			}
 		}
 
@@ -252,10 +213,7 @@
 
 		public int MTime {
 			get {
-				if (mtime == 0)
-					mtime = metadata_get_mtime (raw);
-					
-				return mtime; 
+				return metadata_get_mtime (raw);
 			}
 		}
 
@@ -265,9 +223,7 @@
 
 		public double Gain {
 			get { 
-				if (gain == 0)
-					gain = metadata_get_gain (raw);
-				return gain; 
+				return metadata_get_gain (raw);
 			}
 		}
 
@@ -277,10 +233,7 @@
 		
 		public double Peak {
 			get { 
-				if (peak == 0)
-					peak = metadata_get_peak (raw);
-
-				return peak; 
+				return metadata_get_peak (raw);
 			}
 		}
 	}
Index: src/Song.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Song.cs,v
retrieving revision 1.78
diff -u -r1.78 Song.cs
--- src/Song.cs	14 Jan 2005 22:40:16 -0000	1.78
+++ src/Song.cs	15 Jan 2005 16:55:46 -0000
@@ -51,6 +51,7 @@
 		private string [] performers;
 		private string album;
 		private int track_number;
+		private int n_album_tracks;
 		private int disc_number;
 		private string year;
 		private int duration;
@@ -92,17 +93,18 @@
 			filename = fn;
 
 			// Tags
-			p = Database.UnpackString      (p, out title       );
-			p = Database.UnpackStringArray (p, out artists     );
-			p = Database.UnpackStringArray (p, out performers  );
-			p = Database.UnpackString      (p, out album       );
-			p = Database.UnpackInt         (p, out track_number);
-			p = Database.UnpackInt         (p, out disc_number );
-			p = Database.UnpackString      (p, out year        );
-			p = Database.UnpackInt         (p, out duration    );
-			p = Database.UnpackInt         (p, out mtime       );
-			p = Database.UnpackDouble      (p, out gain        );
-			p = Database.UnpackDouble      (p, out peak        );
+			p = Database.UnpackString      (p, out title         );
+			p = Database.UnpackStringArray (p, out artists       );
+			p = Database.UnpackStringArray (p, out performers    );
+			p = Database.UnpackString      (p, out album         );
+			p = Database.UnpackInt         (p, out track_number  );
+			p = Database.UnpackInt         (p, out n_album_tracks);
+			p = Database.UnpackInt         (p, out disc_number   );
+			p = Database.UnpackString      (p, out year          );
+			p = Database.UnpackInt         (p, out duration      );
+			p = Database.UnpackInt         (p, out mtime         );
+			p = Database.UnpackDouble      (p, out gain          );
+			p = Database.UnpackDouble      (p, out peak          );
 
 			// cover image is loaded later
 
@@ -121,6 +123,11 @@
 		public string Folder {
 			get { return Path.GetDirectoryName (filename); }
 		}
+
+		// Properties :: Public (get;)
+		public override bool Public {
+			get { return true; }
+		}
 		
 		// Properties :: Title (get;)
 		public string Title {
@@ -152,6 +159,11 @@
 			get { return track_number; }
 		}
 
+		// Properties :: NAlbumTracks (get;)
+		public int NAlbumTracks {
+			get { return n_album_tracks; }
+		}
+
 		// Properties :: DiscNumber (get;)
 		public int DiscNumber {
 			get { return disc_number; }
@@ -285,16 +297,17 @@
 			else
 				title = Path.GetFileNameWithoutExtension (filename);
 			
-			artists      = metadata.Artists;
-			performers   = metadata.Performers;
-			album        = metadata.Album;
-			track_number = metadata.TrackNumber;
-			disc_number  = metadata.DiscNumber;
-			year         = metadata.Year;
-			duration     = metadata.Duration;
-			mtime        = metadata.MTime;
-			gain         = metadata.Gain;
-			peak         = metadata.Peak;
+			artists        = metadata.Artists;
+			performers     = metadata.Performers;
+			album          = metadata.Album;
+			track_number   = metadata.TrackNumber;
+			n_album_tracks = metadata.TotalTracks;
+			disc_number    = metadata.DiscNumber;
+			year           = metadata.Year;
+			duration       = metadata.Duration;
+			mtime          = metadata.MTime;
+			gain           = metadata.Gain;
+			peak           = metadata.Peak;
 
 			// We really need to do this here. It is ugly, we would
 			// like to keep all album cover stuff to the album class,
@@ -367,6 +380,7 @@
 			
 			Database.PackString (p, album);
 			Database.PackInt    (p, track_number);
+			Database.PackInt    (p, n_album_tracks);
 			Database.PackInt    (p, disc_number);
 			Database.PackString (p, year);
 			Database.PackInt    (p, duration);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]