Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Music shuffling

by Hue-Bond (Priest)
on Jul 09, 2008 at 07:18 UTC ( [id://696398]=note: print w/replies, xml ) Need Help??


in reply to Re: Music shuffling
in thread Music shuffling

The simplest solution I found to the OP issue was to divide the track list in two halves, then play each one of them alternately:

## pseudocode my @list = shuffle get_tracks; my @list1 = @list[0..@list/2-1]; my @list2 = @list[@list/2..$#list]; while (1) { play @list1; play @list2; shuffle @list1; shuffle @list2; }

Regarding this:

Now, how you gonna make sure that NIN isn't followed by Elton John.

I have thought about a database with style tags and a mechanism for specifying which styles are allowable after a given song:

## pseudocode my @style_levels = ( [ qw/noise/ ], [ qw/metal heavy/ ], [ qw/pop rock/ ], [ qw/chill_out classical/ ], ); sub get_next_song { my $cur_song = shift; my $cur_style = get_style_from_db $cur_song; ## now we have 'pop' +, 'classical'... my $index = get_index $cur_style; ## walk @style_level +s and return the index where 'pop' or 'classical' has been found my $next_index = $index + (-1,0,1)[rand 3]; ## randomly go to ne +xt, current or previous style level (TODO: bounds checking) my $next_style = ${ $style_levels[$next_index] }[ rand @{$style_le +vels[$next_index]} ]; ## choose a style of this level return get_song { style => $next_style }; ## pick some song of + this style }

--
David Serrano

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://696398]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found