Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] Autoplay feature
From: Yves (yves_at_rougy.net)
Date: 2002-07-18


        Hello all,

  I've had fun playing with rockbox these days. I have added a feature
that automatically starts playing my playlist at startup. Just because
I'm too lazy to toggle the shuffle mode manually and then select my
playlist.

I haven't tried the rtc saving prefs, because I have a jukebox, not a
recorder... This pref saving can be enhanced (I use a full byte for
saving a bool...).

However, for the moment, it always start to play the same song, but I
think it's a seed pb for the random code...

Here is the patch, do not hesitate to play with.

        Yves

PS: BTW, the default playlist must be "/all.m3u", it's hardcoded, but
without saving prefs, I don't know how to do otherwise. It may be better
to call it /default.m3u, isn't it ?



Return-Path: <owner-rockbox_at_cool.haxx.se>
Received: (from majordom_at_localhost)
        by labb.contactor.se (8.11.6/8.11.6) id g6JDLNI08997
        for rockbox-list; Fri, 19 Jul 2002 15:21:23 +0200
X-Authentication-Warning: labb.contactor.se: majordom set sender to owner-rockbox_at_cool.haxx.se using -f
Received: from smtp016.mail.yahoo.com (smtp016.mail.yahoo.com [216.136.174.113])
        by labb.contactor.se (8.11.6/8.11.6) with SMTP id g6JDLM708992
        for <rockbox_at_cool.haxx.se>; Fri, 19 Jul 2002 15:21:22 +0200
Received: from unknown (HELO tallancoke) (lmarlow_at_63.172.39.2 with login)
  by smtp.mail.vip.sc5.yahoo.com with SMTP; 19 Jul 2002 01:18:14 -0000
From: "Lee Marlow" <lmarlow_at_yahoo.com>
To: <rockbox_at_cool.haxx.se>
Subject: [PATCH] Playlist reset
Date: Thu, 18 Jul 2002 19:21:56 -0600
Message-ID: <00d701c22ec2$ac57bf00$4a01000a_at_tallancoke>
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="----=_NextPart_000_00D8_01C22E90.61BD4F00"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.3416
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Importance: Normal
Sender: owner-rockbox_at_cool.haxx.se
Precedence: bulk
Reply-To: rockbox_at_cool.haxx.se

This is a multi-part message in MIME format.

------=_NextPart_000_00D8_01C22E90.61BD4F00
Content-Type: text/plain;
        charset="us-ascii"
Content-Transfer-Encoding: 7bit

The attached patch will allow switching shuffle modes to take affect
when the next song is loaded. I use this mainly when listening to all
of my music in shuffle mode. When you get to a song from an album that
you want to hear more of you can just switch shuffle mode off to hear
the rest of the album. Then just switch back to shuffle when you want
to hear something different.

Lee
lmarlow_at_yahoo.com
irc: mecraw

------=_NextPart_000_00D8_01C22E90.61BD4F00
Content-Type: application/octet-stream;
        name="playlist_reset.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="playlist_reset.diff"

Index: playlist.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvsroot/rockbox/apps/playlist.h,v=0A=
retrieving revision 1.7=0A=
diff -u -r1.7 playlist.h=0A=
--- playlist.h 17 Jul 2002 23:23:57 -0000 1.7=0A=
+++ playlist.h 19 Jul 2002 01:13:56 -0000=0A=
@@ -33,6 +33,7 @@=0A=
     int index; /* index of *NEXT* track to play */=0A=
     int seed; /* random seed */=0A=
     int amount; /* number of tracks in the index */=0A=
+ bool shuffled; /* whether this list has been shuffled */=0A=
 } playlist_info_t;=0A=
 =0A=
 extern playlist_info_t playlist;=0A=
@@ -41,6 +42,7 @@=0A=
 void play_list(char *dir, char *file);=0A=
 char* playlist_next(int steps, char *dirname);=0A=
 void randomise_playlist( playlist_info_t *playlist, unsigned int seed );=0A=
+void reset_playlist( playlist_info_t *playlist );=0A=
 void empty_playlist( playlist_info_t *playlist );=0A=
 void add_indices_to_playlist( playlist_info_t *playlist );=0A=
 =0A=
Index: playlist.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvsroot/rockbox/apps/playlist.c,v=0A=
retrieving revision 1.21=0A=
diff -u -r1.21 playlist.c=0A=
--- playlist.c 17 Jul 2002 23:07:45 -0000 1.21=0A=
+++ playlist.c 19 Jul 2002 01:13:56 -0000=0A=
@@ -43,6 +43,21 @@=0A=
     int i;=0A=
     char buf[MAX_PATH+1];=0A=
 =0A=
+ if (playlist.shuffled !=3D global_settings.playlist_shuffle)=0A=
+ {=0A=
+ /* the shuffle mode was changed */=0A=
+ seek =3D playlist.indices[playlist.index]; /* get current =
position */=0A=
+=0A=
+ if (playlist.shuffled)=0A=
+ reset_playlist(&playlist);=0A=
+ else=0A=
+ randomise_playlist(&playlist, playlist.seed);=0A=
+=0A=
+ for (i=3D0; i<playlist.amount; i++)=0A=
+ if (playlist.indices[i] =3D=3D seek)=0A=
+ playlist.index =3D i; /* set index to current position =
*/=0A=
+ }=0A=
+=0A=
     playlist.index =3D (playlist.index+steps) % playlist.amount;=0A=
     seek =3D playlist.indices[playlist.index];=0A=
 =0A=
@@ -115,7 +130,7 @@=0A=
     if(global_settings.playlist_shuffle) {=0A=
         lcd_puts(0,0,"Shuffling...");=0A=
         lcd_update();=0A=
- randomise_playlist( &playlist, current_tick );=0A=
+ randomise_playlist( &playlist, playlist.seed );=0A=
     }=0A=
 =0A=
     lcd_puts(0,0,"Playing... ");=0A=
@@ -133,6 +148,8 @@=0A=
     playlist->filename[0] =3D '\0';=0A=
     playlist->index =3D 0;=0A=
     playlist->amount =3D 0;=0A=
+ playlist->seed =3D current_tick;=0A=
+ playlist->shuffled =3D false;=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -210,6 +227,9 @@=0A=
  */=0A=
 void randomise_playlist( playlist_info_t *playlist, unsigned int seed )=0A=
 {=0A=
+ if (playlist->shuffled && playlist->seed =3D=3D seed)=0A=
+ return;=0A=
+=0A=
     int count =3D 0;=0A=
     int candidate;=0A=
     int store;=0A=
@@ -232,6 +252,27 @@=0A=
         /* move along */=0A=
         count++;=0A=
     }=0A=
+=0A=
+ playlist->seed =3D seed;=0A=
+ playlist->shuffled =3D true;=0A=
+}=0A=
+=0A=
+static int playlist_index_compare(const void* a, const void* b)=0A=
+{=0A=
+ return ( *(int*)a - *(int*)b );=0A=
+}=0A=
+=0A=
+/*=0A=
+ * reset the array of indices for the playlist to its original =
configuration=0A=
+ */=0A=
+void reset_playlist( playlist_info_t *playlist )=0A=
+{=0A=
+ if (!playlist->shuffled)=0A=
+ return;=0A=
+=0A=
+ qsort(playlist->indices, playlist->amount, sizeof(int), =
playlist_index_compare);=0A=
+=0A=
+ playlist->shuffled =3D false;=0A=
 }=0A=
 =0A=
 /* -----------------------------------------------------------------=0A=

------=_NextPart_000_00D8_01C22E90.61BD4F00--



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa