tonybaldwin | blog

non compos mentis

Tickling Tunes

leave a comment »


As if I didn’t have enough to, this morning I wrote a tcl/tk front end to mplayer, for playing music (haven’t attacked video).
It will play a song, or a dir, or build a list.
I started to work on shuffling the list, but that’s proving complicated.
Of course, like other things I’ve tickled, I made it “skinnable”, insofar as the colors are all configurable.
Obviously, this requires mplayer to work.
all I wrote was a front-end gui (as there aren’t enough of those for mplayer already, too).
I’m just experimenting, trying to learn how to do various stuff.
I do want to work on the shuffle function.
I also want it to show the list of songs in a dir when playing them.
At this point, it shows the name of a song being played, the dir being played (but not the contents thereof), or the list being played.
No, it doesn’t open an existing .m3u or .pls list, either, not does it save a list.
I may or may not work on that later, too.
Really, this is not very useful, considering that there are already front ends for mplayer, and, I have more important things to work on, just something I was playing with…
But, in the interests of expanding my tcl skills, I may or may not proceed with this later, at my leisure.


# I’m going to try to make a music player
# using mplayer command line tools and
# tcl/tk for a frontend\
exec wish8.5 -f “$0″ ${1+”$@”}

package require Tk

global song
global playlist
global snum
global pid
set snum 0
set playlist [list ]
set pid ” “

bind . <Escape> {exit}

global wbg
global wtx
set wbg #b0d080
set wtx #000000

wm title . “TunezTickler”
tk_setPalette background #b0d080 foreground #000000

tk::label .ol -text “TunezTickler!!”
pack .ol -in . -side top

frame .playa -bd 2
tk::button .playa.pdir -text “Play Directory” -command {playdir}
tk::button .playa.psong -text “Play Song” -command {playsong}
tk::button .playa.adson -text “Add Song to Playlist” -command {adsong}
tk::button .playa.plist -text “PlayList” -command {playlist}
tk::button .playa.clear -text “Clear List” -command {clear}
tk::button .playa.shuf -text “Shuffle List” -command {shuffle $::playlist}
tk::button .playa.stop -text “Stop” -command {stop}
tk::button -text “BG Color” -command {winback}
tk::button .playa.fg -text “Text Color” -command {wintex}

tk::button .playa.quitit -text “Quit” -command {leave}

pack .playa.pdir -in .playa -side left
pack .playa.psong -in .playa -side left
pack .playa.adson -in .playa -side left
pack .playa.plist -in .playa -side left
pack .playa.clear -in .playa -side left
pack .playa.shuf -in .playa -side left
pack .playa.stop -in .playa -side left
pack -in .playa -side left
pack .playa.fg -in .playa -side left
pack .playa.quitit -in .playa -side right

pack .playa -in . -fill x

frame .list
text .list.songs -wrap none -yscrollcommand “.list.ys set” -xscrollcommand “.list.xs set” -height 5

scrollbar .list.ys -command “.list.songs yview”
scrollbar .list.xs -command “.list.songs xview” -orient horizontal

pack .list.xs -in .list -side bottom -fill x
pack .list.songs -in .list -side left -fill both -expand true
pack .list.ys -in .list -side left -fill y
pack .list -in . -fill x

global ftypes
set ftypes {
{all {*}}
{mp3 {.mp3}}
{ogg {.ogg}}
{wav {.wav}}

proc playsong {} {
global song
set song [tk_getOpenFile -filetypes $::ftypes]
wm title . “Now Tickling: $::song”
.list.songs insert end “$::snum $::song\n”
# eval exec mplayer $::song &
set ::pid [eval exec mplayer $::song &]

proc playdir {} {
global dir
set dir [tk_chooseDirectory]
wm title . “Now Tickling: $::dir”
# eval exec mplayer [glob $::dir/*] &
set ::pid [eval exec mplayer [glob $::dir/*] &]

proc adsong {} {

uplevel set snum [expr $::snum + 1]
set song [tk_getOpenFile -filetypes $::ftypes]

.list.songs insert end “$::snum $song\n”

uplevel lappend ::playlist $song

proc playlist {} {
wm title . “Tickling Playlist”
# eval exec mplayer $::playlist &
set ::pid [eval exec mplayer $::playlist &]

proc shuffle { playlist } {
     set n [llength $list]
     for { set i 1 } { $i < $n } { incr i } {
         set j [expr { int( rand() * $n ) }]
         set temp [lindex $list $i]
         lset list $i [lindex $list $j]
         lset list $j $temp
     set ::playlist $list
    .list.songs delete 1.0 end
    .list.songs insert end $::playlist

proc clear {} {
wm title . “Tickle Tunes”
set ::playlist ” “
.list.songs delete 1.0 end


proc winback {} {
    global wbg
    set wbg [tk_chooseColor -initialcolor $::wbg]
    if {$wbg != “”} {tk_setPalette background $wbg}


proc wintex {} {

    global wtx
    set wtx [tk_chooseColor -initialcolor $::wtx]
    if {$wtx != “”} {tk_setPalette background $::wbg foreground $wtx}


proc leave {} {
if {$::pid != ” “} {exec kill -9 $::pid; exit} else {

proc stop {} {
if {$::pid != ” “} {

exec kill -9 $::pid
set ::pid ” “

# other option for playdir? exec sh -c mplayer $::dir/*


Written by tonybaldwin

March 28, 2008 at 11:56 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: