diff options
-rw-r--r-- | firmware/playlist.c | 261 | ||||
-rw-r--r-- | firmware/playlist.h | 63 |
2 files changed, 0 insertions, 324 deletions
diff --git a/firmware/playlist.c b/firmware/playlist.c deleted file mode 100644 index 8c46286fec..0000000000 --- a/firmware/playlist.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by wavey@wavey.org | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <stdio.h> | ||
21 | #include <malloc.h> | ||
22 | #include <time.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include "playlist.h" | ||
26 | #include "debug.h" | ||
27 | #include <file.h> | ||
28 | #include "sprintf.h" | ||
29 | |||
30 | /* | ||
31 | * load playlist info from disk | ||
32 | */ | ||
33 | int reload_playlist_info( playlist_info_t *playlist ) | ||
34 | { | ||
35 | DEBUGF( "reload_playlist_info()\n" ); | ||
36 | |||
37 | /* this is a TEMP stub version */ | ||
38 | |||
39 | /* return a dummy playlist entry */ | ||
40 | |||
41 | strncpy( playlist->filename, "test.m3u", sizeof(playlist->filename) ); | ||
42 | |||
43 | playlist->indices_count = 4; | ||
44 | |||
45 | playlist->indices = (void *)malloc( playlist->indices_count * sizeof( int ) ); | ||
46 | |||
47 | playlist->indices[0] = 3; | ||
48 | playlist->indices[1] = 2; | ||
49 | playlist->indices[2] = 1; | ||
50 | playlist->indices[3] = 9; | ||
51 | |||
52 | playlist->index = 3; | ||
53 | |||
54 | return 1; | ||
55 | } | ||
56 | |||
57 | /* | ||
58 | * read the contents of an m3u file from disk and store | ||
59 | * the indices of each listed track in an array | ||
60 | */ | ||
61 | void load_playlist( playlist_info_t *playlist, const char *filename ) { | ||
62 | |||
63 | DEBUGF( "load_playlist( %s )\n", filename ); | ||
64 | |||
65 | /* store playlist filename */ | ||
66 | strncpy( playlist->filename, filename, sizeof(playlist->filename) ); | ||
67 | |||
68 | /* add track indices to playlist data structure */ | ||
69 | add_indices_to_playlist( playlist ); | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * remove any filename and indices associated with the playlist | ||
74 | */ | ||
75 | void empty_playlist( playlist_info_t *playlist ) { | ||
76 | |||
77 | DEBUGF( "empty_playlist()\n" ); | ||
78 | |||
79 | playlist->filename[0] = '\0'; | ||
80 | playlist->indices_count = 0; | ||
81 | free( (void *)(playlist->indices) ); | ||
82 | playlist->indices = NULL; | ||
83 | playlist->index = 0; | ||
84 | } | ||
85 | |||
86 | /* | ||
87 | * calculate track offsets within a playlist file | ||
88 | */ | ||
89 | void add_indices_to_playlist( playlist_info_t *playlist ) | ||
90 | { | ||
91 | char *p; | ||
92 | int i = 0; | ||
93 | unsigned char byte; | ||
94 | unsigned char lastbyte='\n'; | ||
95 | int nread; | ||
96 | |||
97 | int fd; | ||
98 | |||
99 | fd = open(playlist->filename, O_RDONLY); | ||
100 | if(-1 == fd) | ||
101 | return; /* failure */ | ||
102 | |||
103 | |||
104 | /*DEBUGF( "add_indices_to_playlist()\n" ); */ | ||
105 | |||
106 | p = &byte; | ||
107 | |||
108 | /* loop thru buffer, store index whenever we get a new line */ | ||
109 | |||
110 | while((nread = read(fd, &byte, 1)) == 1) | ||
111 | { | ||
112 | /* move thru (any) newlines */ | ||
113 | |||
114 | if(( byte != '\n' ) && ( byte != '\r' ) && | ||
115 | ((lastbyte == '\n') || (lastbyte == '\r'))) | ||
116 | /* we're now at the start of a new track filename. store index */ | ||
117 | extend_indices( playlist, i ); | ||
118 | |||
119 | lastbyte = byte; | ||
120 | i++; | ||
121 | } | ||
122 | |||
123 | close(fd); | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * extend the array of ints | ||
128 | */ | ||
129 | void extend_indices( playlist_info_t *playlist, int new_index ) | ||
130 | { | ||
131 | /*DEBUGF( "extend_indices(%d)\n", new_index ); */ | ||
132 | |||
133 | /* increase array size count */ | ||
134 | |||
135 | playlist->indices_count++; | ||
136 | |||
137 | /* increase size of array to new count size */ | ||
138 | |||
139 | playlist->indices = (int *)realloc( playlist->indices, (playlist->indices_count) * sizeof( int ) ); | ||
140 | |||
141 | /* add new element to end of array */ | ||
142 | |||
143 | playlist->indices[ playlist->indices_count - 1 ] = new_index; | ||
144 | } | ||
145 | |||
146 | track_t next_playlist_track( playlist_info_t *playlist ) | ||
147 | { | ||
148 | track_t track; | ||
149 | strncpy( track.filename, "boogie", sizeof(track.filename) ); | ||
150 | return track; | ||
151 | } | ||
152 | |||
153 | /* | ||
154 | * randomly rearrange the array of indices for the playlist | ||
155 | */ | ||
156 | void randomise_playlist( playlist_info_t *playlist, unsigned int seed ) | ||
157 | { | ||
158 | int count = 0; | ||
159 | int candidate; | ||
160 | int store; | ||
161 | |||
162 | DEBUGF( "randomise_playlist()\n" ); | ||
163 | |||
164 | /* seed with the given seed */ | ||
165 | srand( seed ); | ||
166 | |||
167 | /* randomise entire indices list */ | ||
168 | |||
169 | while( count < playlist->indices_count ) | ||
170 | { | ||
171 | /* the rand is from 0 to RAND_MAX, so adjust to our value range */ | ||
172 | candidate = rand() % ( playlist->indices_count ); | ||
173 | |||
174 | /* now swap the values at the 'count' and 'candidate' positions */ | ||
175 | store = playlist->indices[candidate]; | ||
176 | playlist->indices[candidate] = playlist->indices[count]; | ||
177 | playlist->indices[count] = store; | ||
178 | |||
179 | /* move along */ | ||
180 | count++; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | * dump the details of a track to stdout | ||
186 | */ | ||
187 | void display_playlist_track( track_t *track ) | ||
188 | { | ||
189 | DEBUGF( "track: %s\n", track->filename ); | ||
190 | } | ||
191 | |||
192 | /* | ||
193 | * dump the current playlist info | ||
194 | */ | ||
195 | void display_current_playlist( playlist_info_t *playlist ) | ||
196 | { | ||
197 | char indices[2048]; | ||
198 | indices[0]='\0'; | ||
199 | |||
200 | /*DEBUGF( "\ndisplay_current_playlist()\n" ); */ | ||
201 | |||
202 | if( playlist->indices_count != 0 ) | ||
203 | { | ||
204 | get_indices_as_string( indices, playlist ); | ||
205 | } | ||
206 | |||
207 | DEBUGF( "\nfilename:\t%s\ntotal:\t\t%d\nindices:\t%s\ncurrent index:\t%d\n\n", | ||
208 | playlist->filename, | ||
209 | playlist->indices_count, | ||
210 | indices, | ||
211 | playlist->index ); | ||
212 | } | ||
213 | |||
214 | /* | ||
215 | * produce a string of the playlist indices | ||
216 | */ | ||
217 | void get_indices_as_string( char *string, playlist_info_t *playlist ) | ||
218 | { | ||
219 | char tmp[8]; | ||
220 | int count = 0; | ||
221 | int *p = playlist->indices; | ||
222 | |||
223 | /*DEBUGF( "get_indices_as_string()\n" ); */ | ||
224 | |||
225 | while( count < playlist->indices_count ) { | ||
226 | |||
227 | if( strlen( string ) == 0 ) | ||
228 | { | ||
229 | /* first iteration - no comma */ | ||
230 | |||
231 | snprintf( tmp, sizeof(tmp), "%d", p[count] ); | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | /* normal iteration - insert comma */ | ||
236 | |||
237 | snprintf( tmp, sizeof(tmp), ",%d", p[count] ); | ||
238 | } | ||
239 | |||
240 | strcat( string, tmp ); | ||
241 | |||
242 | count++; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /* | ||
247 | Session Start (devlin.openprojects.net:alan): Thu Apr 25 15:13:27 2002 | ||
248 | <alan> for shuffle mode, it's really easy to use the array as a random stack | ||
249 | <alan> just peek one randomly and exchange it with the last element in the stack | ||
250 | <alan> when stack is void, just grow the stack with its initial size : elements are still there but in a random order | ||
251 | <alan> note : | ||
252 | <alan> a stack is void when all songs were played | ||
253 | <alan> it is an O(1) algo | ||
254 | <alan> i don't see how you can do it with a list | ||
255 | */ | ||
256 | |||
257 | /* ----------------------------------------------------------------- | ||
258 | * local variables: | ||
259 | * eval: (load-file "rockbox-mode.el") | ||
260 | * end: | ||
261 | */ | ||
diff --git a/firmware/playlist.h b/firmware/playlist.h deleted file mode 100644 index fbc1a03c2b..0000000000 --- a/firmware/playlist.h +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by wavey@wavey.org | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef __PLAYLIST_H__ | ||
21 | #define __PLAYLIST_H__ | ||
22 | |||
23 | #include "common/track.h" | ||
24 | |||
25 | /* playlist data */ | ||
26 | |||
27 | typedef struct | ||
28 | { | ||
29 | char filename[256]; /* path name of m3u playlist on disk */ | ||
30 | int *indices; /* array of indices into the playlist */ | ||
31 | int indices_count; /* current size of indices array */ | ||
32 | int index; /* index of current track within playlist */ | ||
33 | } playlist_info_t; | ||
34 | |||
35 | int persist_playlist_info( void ); | ||
36 | int reload_playlist_info( playlist_info_t *playlist ); | ||
37 | void read_entire_file( char *buf, const char *filename ); | ||
38 | void load_playlist( playlist_info_t *playlist, const char *filename ); | ||
39 | void extract_playlist_indices( char *buf, playlist_info_t *playlist ); | ||
40 | void display_current_playlist( playlist_info_t *playlist ); | ||
41 | void get_indices_as_string( char *string, playlist_info_t *playlist ); | ||
42 | void empty_playlist( playlist_info_t *playlist ); | ||
43 | track_t next_playlist_track( playlist_info_t *playlist ); | ||
44 | void display_playlist_track( track_t *track ); | ||
45 | void add_indices_to_playlist( playlist_info_t *playlist ); | ||
46 | void extend_indices( playlist_info_t *playlist, int new_index ); | ||
47 | void randomise_playlist( playlist_info_t *playlist, unsigned int seed ); | ||
48 | int is_unused_random_in_list( int number, int *original_list, int count ); | ||
49 | |||
50 | /**********/ | ||
51 | |||
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | int create_playlist( void ); | ||
58 | /*int add_to_playlist( track_t *track );*/ | ||
59 | int remove_from_playlist( int index ); | ||
60 | int set_playlist_position( void ); | ||
61 | /*track_t * get_previous_entry_in_playlist( void );*/ | ||
62 | |||
63 | #endif /* __PLAYLIST_H__ */ | ||