#!/bin/lilwish /* { DEMO - Playlist file service Reads existing playlist on startup. Assumes playlists are in current working directory lilwish (Lil+libpanel) demonstration app Mar 24 2020 (c) That Guy With The Hair } */ watch PlayList {} set Names [list {{{Empty}}}] set PlayList {} # # Main Control Frame # frame .top -side top -anchor left -fill BOTH label .top.l -side top -fill x -text "And So it Begins" group .top.sl -side left -anchor top -fill Y frame .top.fl -side left -anchor top -fill BOTH -expand 1 frame .top.fl.status -side bottom -fill x -anchor NE #frame .top.fl.xx -side left -anchor NE -fill BOTH -expand 1 frame .top.fl.ctl -side right -anchor NW -fill y listbox .top.fl.pl -side left -anchor NW -fill BOTH -expand 1 -var Names -cmd songselect scrollbar .top.fl.sb -subwidget [wm id .top.fl.pl] -side right -anchor n -fill y label .top.fl.status.l1 -text "Status:" -side W -anchor W label .top.fl.status.msg -text {} -side W -anchor W frame .top.sl.f -side left -anchor N -fill Y slider .top.sl.f.vol -side left -anchor N -width 20 -height 200 -fill Y -cmd setvol -expand 1 button .top.fl.status.q -text "Quit" -cmd evQuit -side right -anchor SE # # Playlist Frame # set PlayFiles [split [system ls -Q pl/*.m3u | sed -e 's/.m3u//'"] "\n"] frame .top2 -side top -anchor top -fill BOTH label .top2.l -side top -fill x -text "-- Select Playlist --" frame .top2.fl -side top -anchor top -fill BOTH -expand 1 frame .top2.status -side bottom -fill x -anchor NE listbox .top2.fl.pl -side left -anchor NW -fill BOTH -expand 1 -var PlayFiles -cmd fileselect scrollbar .top2.fl.sb -subwidget [wm id .top2.fl.pl] -side right -anchor n -fill y button .top2.status.q -text "Quit" -side right -anchor left -cmd evQuit button .top2.status.b -text "Back" -side left -anchor left -cmd "tktoplevel .top" button .top.fl.ctl.b0 -text "HEAD" -side S -anchor E -cmd "setOUT 33" button .top.fl.ctl.b1 -text " SPK" -side S -anchor E -cmd "setOUT 27" set _ 0 foreach { {Play playpause} {Stop {pctrl stop}} {Replay {pctrl {play 0}}} {Reread readPL } {Shuffle shufflePL} {Skip {pctrl skip}} {PlayLst {tktoplevel .top2}} } { set lbl [index $i 0] set cmd [index $i 1] button .top.fl.ctl.cb[inc _] -text $lbl -cmd $cmd -side top -fill x } # # Display toplevel # tktoplevel .top tkpack .top #set xy [wm sizeof .top] #wm resize 0 0 100 300 #wm resize 0 0 [index $xy 0] [index $xy 1] proc setvol { id but val} { store /dev/volume "master $val" } set _pstate pause proc playpause {} { if [streq $_pstate pause] { set _pstate resume pctrl resume tkcfg .top.fl.ctl.cb1 -text Pause } { set _pstate pause pctrl pause tkcfg .top.fl.ctl.cb1 -text Play } } proc getVOL {} { set data [system grep master /dev/volume] cfg [wm id .top.sl.f.vol] -value [index $data 1] event } proc setOUT {pin} { # Protect ears from bullshit pinmux that resets to 100% volume store /dev/volume "master 0" store /dev/audioctl "pin $pin" store /dev/volume "master 0" getVOL } proc fileselect { id button idx } { if not [streq $button 1] {return} tktoplevel .top set file [index $PlayFiles $idx].m3u pctrl stop readPL $file writePL pctrl "play 0" list } proc readPL {file} { local fd local new set new [list] set x [read $file] set x [split $x "\n"] foreach $x { if not [streq $i {}] {append new $i} } set global PlayList $new } # Prevent rand()*x rounding up to x after truncation func int {x} { set i [expr $x \ 1] if [expr $i > $x] {dec i} return $i } proc shufflePL {} { set new [list] set old [concat $PlayList] set cnt [count $old] while {$cnt} { set idx [int [expr [rand] * ( $cnt - 1 )]] dec cnt append new [index $old $idx] set old [eval list [slice $old 0 $idx] [slice $old [expr $idx + 1]] ] } set global PlayList $new writePL } proc writePL {} { foreach $PlayList { set out "${out}${i}\n" } store /mnt/playlist "$out" } proc pctrl {cmd} { store /mnt/playctl $cmd } proc songselect {id button val} { pctrl stop pctrl "play $val" } store /dev/label "PlayFS Ctrl" # # Updating listbox and changing variable name does not seem to work as expected # watch PlayList { set new [list] foreach $PlayList { set x [split $i /] set idx [count $x] set N [index $x [dec idx]] set N [repstr $N {'} {}] append new $N } set Names $new tkcfg .top.fl.pl -var Names -side W -anchor W list } getVOL readPL /mnt/playlist shufflePL set _stlast {} /* { STUPID PlaylistFS - blocks when reading playctl even when closing FD between reads Does not ever happen when using cat from the command line. Even when using cat from the system command it sometimes will just block on a read. Really annoying. } */ proc idle {n} { inc _idle local fd return ;# STUPID PlayListFS , do not read until problem can be resolved set text [system cat /mnt/playctl