Re: randomising tracks: scripting question
You know St. Peter won't call my name, freebsd-questions! 2011/01/03 20:23:38 -0800 Joseph Olatt j...@eskimo.com = To Frank Shute : JO On Sun, Dec 26, 2010 at 05:09:30PM +, Frank Shute wrote: JO JO I generally play my tracks of an album like so: JO JO for track in $(cat trombone_shorty-backatown.m3u); do JO mplayer $track JO done JO JO They then play in the correct order. JO JO How would I go about randomising the order of play using JO sh (preferably) or perl? I have several tens of thousands of MIDI files from 90s. They are too many for 'random play' feature of the Timidity++ which is used with 'eawpats', the GUS patches. Here is my bash script to play them in random order: === #!/usr/local/bin/bash IFS=' ' fns=(`find ~/mid/ -iname '*.mid'`) while :; do timidity -a -OdS -in -j -t 1251 -E t -p a -R 500 -EFreverb=127 -EFns=4 ${fns[$((${#f...@]}*$random/32767))]} done === Of course I miss the 'Previous track' functionality. 73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB 12F8 0CE1 4AAC A0E2 6627) -- http://vereshagin.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 05:09:30PM +, Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html A little while back I wrote a perl script to randomly pick mp3, ogg, flac files from any directory specified as arg 1 and play them using mplayer. I categorize my genres by directory and with this perl script I can randomly play songs from any directory. If the script is invoked without any arguments, then it will play songs from the default hard-coded directory defined by $SONG_DIR. Don't know if this would be useful to you (or someone else). #!/usr/bin/perl -w use strict; my $SONG_DIR = /home/joji/songs/good; if ($#ARGV == 0) { $SONG_DIR = $ARGV[0]; } my %played = (); my $rand; my $dh; my @song_list; opendir($dh, $SONG_DIR); @song_list = readdir($dh); closedir($dh); my $count = $#song_list; # Perl counts from zero. If there is one item, Perl will say 0. # So to get the real count, we have to increment by 1. $count++; chdir($SONG_DIR); while ((keys %played) $count) { while (1) { $rand = int(rand($count)); if (! $played{$rand}) { $played{$rand} = 1; last; } if ((keys %played) = $count) { last; } } if ($song_list[$rand] eq . || $song_list[$rand] eq ..) { ; } else { print Playing song # . $rand . [ . $song_list[$rand] . ]\n; `mplayer \$song_list[$rand]\`; } } exit(0); ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org change cat t...n.m3u to random t..n.m3u -- Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com| http://chipsquips.com pgpvxO07hLh2G.pgp Description: PGP signature
Re: randomising tracks: scripting question
On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
How would I go about randomising the order of play using sh (preferably) or perl? I fiddled around for a minute without luck but I think between the built-in $RANDOM, tail and head you should be able to get a randomize going. I'd recommend putting a script together that just pulls a random line from a file then work from there. Post your results if yo get one working. -- # Mark Caudill ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 06:01:45PM +, RW wrote: On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) Excellent. I didn't know about random(6), I was getting lost in the manpages: there are manpages for random in 3 different sections! Should have used apropos. Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? cat trombone_shorty-backatown.m3u | xargs mplayer ... -shuffle or mplayer ... -playlist trombone_shorty-backatown.m3u -shuffle if they are in a uncommented, one-absolute-path-per-line format without extended directives? b. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 2:04 PM, b. f. bf1...@googlemail.com wrote: Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? cat trombone_shorty-backatown.m3u | xargs mplayer ... -shuffle or mplayer ... -playlist trombone_shorty-backatown.m3u -shuffle if they are in a uncommented, one-absolute-path-per-line format without extended directives? Here is something that I wrote a long time ago in python, works quite well [code] #!/usr/bin/env python def randline(f): for i,j in enumerate(file(f, 'rb')): if random.randint(0,i) == i: line = j eturn line print randline(text) [/code] Name it as you wish then it's ./file.py INPUT, granted this will only read 1 (random) line from INPUT and print it, it shouldn't be hard to modify this for your needs tho, enjoy :) C- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Dec 26, 2010, at 11:02 AM, Frank Shute wrote: On Sun, Dec 26, 2010 at 06:01:45PM +, RW wrote: On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) Excellent. I didn't know about random(6), I was getting lost in the manpages: there are manpages for random in 3 different sections! Should have used apropos. Just keep in mind that random(6) comes from the `games' distribution-set. wget -r ftp://ftp-archive.freebsd.org/pub/FreeBSD/releases/i386/8.1-RELEASE/games cd games sudo ./install.sh Not sure if it's available anywhere else. -- Devin ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org