[Muine] [PATCH] Another Random Mode
- From: Dave Barry <dave psax org>
- To: muine-list gnome org
- Subject: [Muine] [PATCH] Another Random Mode
- Date: Tue, 31 Aug 2004 05:55:14 -0700
Hello
I'm a bit new to muine, but I enjoy it and I fancied a simple random
mode.
The following patch adds a random to the playlist menu, and hooks
Next() so that when in random mode, it skips to a random song. It also
remembers the last 20 songs played in random mode, and won't replay them
(though it may replay the 21st). Does the right thing of course, if the
playlist is less than 20 songs. Anyway, it works for me, and I thought
someone else might like to have a go with it.
diff -urN muine-0.6.3/data/glade/PlaylistWindow.glade muine-0.6.3-hacked/data/glade/PlaylistWindow.glade
--- muine-0.6.3/data/glade/PlaylistWindow.glade 2004-08-30 16:25:34.000000000 -0700
+++ muine-0.6.3-hacked/data/glade/PlaylistWindow.glade 2004-08-30 09:03:40.000000000 -0700
@@ -442,6 +442,17 @@
<accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
</widget>
</child>
+
+ <child>
+ <widget class="GtkCheckMenuItem" id="random_menu_item">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Random</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <signal name="activate" handler="HandleRandomCommand" last_modification_time="Sun, 29 Aug 2004 15:34:44 GMT"/>
+ <accelerator key="T" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
</widget>
</child>
</widget>
diff -urN muine-0.6.3/po/en_GB.po muine-0.6.3-hacked/po/en_GB.po
--- muine-0.6.3/po/en_GB.po 2004-06-18 12:34:03.000000000 -0700
+++ muine-0.6.3-hacked/po/en_GB.po 2004-08-30 16:20:32.000000000 -0700
@@ -522,6 +522,9 @@
msgid "Playlist (Repeating)"
msgstr "Playlist (Repeating)"
+msgid "Playlist (Random Mode)"
+msgstr "Playlist (Random Mode)"
+
#: src/PlaylistWindow.cs:583
#, csharp-format
msgid "Playlist ({0} hour remaining)"
diff -urN muine-0.6.3/src/HandleView.cs muine-0.6.3-hacked/src/HandleView.cs
--- muine-0.6.3/src/HandleView.cs 2004-08-30 16:25:34.000000000 -0700
+++ muine-0.6.3-hacked/src/HandleView.cs 2004-08-30 11:11:23.000000000 -0700
@@ -24,6 +24,7 @@
using Gtk;
using GLib;
+
public class HandleView : TreeView
{
[DllImport ("libmuine")]
@@ -34,9 +35,14 @@
SignalDelegate cb, IntPtr data,
IntPtr p, int flags);
+ private static Random Rand;
+ private ArrayList recently_played;
+
public HandleView () : base (IntPtr.Zero)
{
Raw = pointer_list_view_new ();
+ Rand = new Random();
+ recently_played = new ArrayList (20);
g_signal_connect_data (Raw, "pointer_activated", new SignalDelegate (PointerActivatedCallback),
IntPtr.Zero, IntPtr.Zero, 0);
@@ -322,6 +328,37 @@
{
return pointer_list_view_next (Raw);
}
+
+
+ public void RandomSong ()
+ {
+ if (this.Length == 1) {
+ return;
+ }
+ trim_recent();
+ int ndex = Rand.Next () % this.Length;
+ int target = (int) this.Contents[ndex];
+ IntPtr foo = new System.IntPtr(target);
+
+ if (this.Playing != foo && !recently_played.Contains(foo)) {
+ recently_played.Add(foo);
+ this.Playing = foo;
+ this.Select (foo);
+ } else {
+ //Recurse until satisfied...
+ RandomSong ();
+ }
+
+ }
+
+ private void trim_recent ()
+ {
+ //trim the recently_played list
+ if (recently_played.Count >= 20 || recently_played.Count >= this.Length) {
+ recently_played.RemoveAt(0);
+ recently_played.TrimToSize();
+ }
+ }
public bool ForwardKeyPress (Widget orig_widget,
Gdk.EventKey e)
diff -urN muine-0.6.3/src/PlaylistWindow.cs muine-0.6.3-hacked/src/PlaylistWindow.cs
--- muine-0.6.3/src/PlaylistWindow.cs 2004-08-30 16:25:34.000000000 -0700
+++ muine-0.6.3-hacked/src/PlaylistWindow.cs 2004-08-30 18:19:16.000000000 -0700
@@ -48,6 +48,8 @@
[Glade.Widget]
private CheckMenuItem repeat_menu_item;
private bool setting_repeat_menu_item;
+ [Glade.Widget]
+ private CheckMenuItem random_menu_item;
/* toolbar widgets */
[Glade.Widget]
@@ -394,6 +396,11 @@
} catch {
repeat_menu_item.Active = false;
}
+ try {
+ random_menu_item.Active = (bool) Muine.GConfClient.Get("/apps/muine/random");
+ } catch {
+ random_menu_item.Active = false;
+ }
setting_repeat_menu_item = false;
/* connect tray icon signals */
@@ -575,6 +582,10 @@
} else {
playlist_label.Text = Muine.Catalog.GetString ("Playlist");
}
+ } else if (random_menu_item.Active) {
+
+ playlist_label.Text = Muine.Catalog.GetString ("Playlist (Random Mode)");
+
} else {
long r_seconds = remaining_songs_time + song.Duration - time;
@@ -619,7 +630,8 @@
previous_button.Sensitive = has_first;
play_pause_button.Sensitive = has_first;
next_button.Sensitive = playlist.HasNext ||
- (repeat_menu_item.Active && has_first);
+ ((repeat_menu_item.Active ||
+ random_menu_item.Active) && has_first);
play_pause_menu_item.Sensitive = previous_button.Sensitive;
icon.play_pause_menu_item.Sensitive = previous_button.Sensitive;
@@ -1093,6 +1105,14 @@
Muine.DB.UpdateSong (song);
}
+
+ if (random_menu_item.Active) {
+ playlist.RandomSong ();
+
+ SongChanged (true);
+ NSongsChanged ();
+ return;
+ }
if (playlist.HasNext) {
playlist.Next ();
@@ -1174,7 +1194,9 @@
private void HandleNextCommand (object o, EventArgs args)
{
- if (playlist.HasNext)
+ if (random_menu_item.Active)
+ playlist.RandomSong ();
+ else if (playlist.HasNext)
playlist.Next ();
else if (repeat_menu_item.Active && playlist.HasFirst)
playlist.First ();
@@ -1469,6 +1491,11 @@
NSongsChanged ();
}
+ private void HandleRandomCommand(object o, EventArgs args)
+ {
+ Muine.GConfClient.Set ("/apps/muine/random", random_menu_item.Active);
+ }
+
private void HandleHideWindowCommand (object o, EventArgs args)
{
WindowVisible = false;
--
The harder they hit us, the louder we become. Dave Barry
Like the skin on the drum dave psax org
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]