chiark / gitweb /
bin/play-rawk: Import Tk hack for listening to my DisOrder Rawk stream.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 29 Nov 2017 20:21:58 +0000 (20:21 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 29 Nov 2017 20:22:54 +0000 (20:22 +0000)
Makefile
bin/play-rawk [new file with mode: 0755]

index e98e9467506f24e78baf79032c40c626638384b3..196a33fd6ab33b15004e772c4653241771e62355 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -270,6 +270,7 @@ DOTLINKS            += .config/gtk-3.0/settings.ini
 SCRIPTLINKS            += xinitcmd lock-screen xshutdown
 SCRIPTLINKS            += un-backslashify-selection
 SCRIPTLINKS            += xpra-start-xdummy
+SCRIPTLINKS            += play-rawk
 
 DOTCPP                 += .Xdefaults
 Xdefaults_DEFS          = -DEMACSWD=$(call mdw-conf,emacs-width,77)
diff --git a/bin/play-rawk b/bin/play-rawk
new file mode 100755 (executable)
index 0000000..cb0d6f9
--- /dev/null
@@ -0,0 +1,67 @@
+#! /usr/bin/wish
+
+package require Tclx
+
+set STREAM "http://rawk.distorted.org.uk/rawk"
+catch { source $env(HOME)/.play-rawk }
+
+set CMD [list \
+            gst-launch-1.0 uridecodebin uri=$STREAM ! \
+            pulsesink client-name=play-rawk]
+
+set kidstat -
+set playing false
+set status "\[Not started]"
+
+proc update-status {} {
+  global kidstat playing status
+  set r [gets $kidstat line]
+  if {$r >= 0} {
+    set status $line
+  } elseif {[eof $kidstat]} {
+    close $kidstat
+    set playing false
+    .play configure -text "Play"
+    set status "\[Stopped]"
+  }
+}
+
+proc infanticide {} {
+  global playing kidstat
+
+  if {$playing} { catch { kill [pid $kidstat] } }
+}
+
+proc toggle-playing {} {
+  global CMD playing kidstat
+
+  if {$playing} {
+    infanticide
+  } else {
+    set kidstat [open "|$CMD 2>@1"]
+    fconfigure $kidstat -blocking false -buffering line
+    fileevent $kidstat readable update-status
+    .play configure -text "Stop"
+    set playing true
+  }
+}
+
+proc byebye {} {
+  infanticide
+  exit 0
+}
+
+button .play \
+    -text "Play" \
+    -command "toggle-playing"
+entry .status \
+    -state readonly \
+    -width 48 \
+    -textvariable status
+pack .play -side left -padx 2 -pady 2
+pack .status -side left -padx 2 -pady 2 -fill x -expand true
+bind . "q" { byebye }
+bind . "z" { wm iconify . }
+bind . <space> { .play invoke }
+##bind . <KeyPress> { puts "key <%K>" }
+wm protocol . "WM_DELETE_WINDOW" { byebye }