|
@ -2,15 +2,16 @@ |
|
|
#lang racket |
|
|
#lang racket |
|
|
|
|
|
|
|
|
(require racket/system) |
|
|
(require racket/system) |
|
|
|
|
|
(require racket/pretty) |
|
|
(require "helpers.rkt") |
|
|
(require "helpers.rkt") |
|
|
(require "config_parser.rkt") |
|
|
(require "config_parser.rkt") |
|
|
|
|
|
|
|
|
(define args (vector->list (current-command-line-arguments))) |
|
|
(define args (vector->list (current-command-line-arguments))) |
|
|
|
|
|
|
|
|
(define file-types (make-hash)) |
|
|
|
|
|
(define media-player (string->path (hash-ref settings "player" "/usr/bin/mplayer"))) |
|
|
(define media-player (string->path (hash-ref settings "player" "/usr/bin/mplayer"))) |
|
|
(define player-args (hash-ref settings "args" "")) |
|
|
(define player-args (hash-ref settings "args" "")) |
|
|
(update file-types (hash-ref settings "filetypes" '(("avi" #t)))) |
|
|
(define file-types |
|
|
|
|
|
(update (make-hash) (hash-ref settings "filetypes" '(("avi" #t))))) |
|
|
|
|
|
|
|
|
(define (file-list) ; list of files in the current working directory |
|
|
(define (file-list) ; list of files in the current working directory |
|
|
(map path->string ; get the strings from the list of paths |
|
|
(map path->string ; get the strings from the list of paths |
|
@ -58,41 +59,42 @@ |
|
|
(lambda () (subprocess nullport #f nullport media-player (car filenames) args)) |
|
|
(lambda () (subprocess nullport #f nullport media-player (car filenames) args)) |
|
|
list))) ; convert the 4 return values into a list |
|
|
list))) ; convert the 4 return values into a list |
|
|
|
|
|
|
|
|
(define (get-args message) |
|
|
(define (get-args message args) |
|
|
(cond ((false? message) player-args) |
|
|
(cond ((false? message) args) |
|
|
(else message))) |
|
|
(else message))) |
|
|
|
|
|
|
|
|
(define (play fnames played args) |
|
|
(define (play fnames played args) |
|
|
(cond ((null? fnames) '()) |
|
|
(cond ((null? fnames) '()) |
|
|
(else |
|
|
(else |
|
|
(let* ((results (play-files fnames args))) ; get the pid and the 3 i/o ports |
|
|
(let* ((results (play-files fnames args))) ; get the pid and the 3 i/o ports |
|
|
; send the other thread the new pid here |
|
|
(subprocess-wait (first results)) ; block until a new file is started |
|
|
; and the output port for piping input to the process |
|
|
|
|
|
; (thread-send controller-thread ((third results) (first results))) |
|
|
|
|
|
(subprocess-wait (first results)) |
|
|
|
|
|
(close-output-port (third results))) |
|
|
(close-output-port (third results))) |
|
|
(let* ((newfs (new-files played (play-list)))) |
|
|
(let* ((newfs (new-files played (play-list)))) ; get new list of files |
|
|
(play (append (cdr fnames) newfs) (update played newfs) (get-args (thread-try-receive))))))) |
|
|
(play |
|
|
|
|
|
(append (cdr fnames) newfs) ; append new files to the tail of the list of old files |
|
|
|
|
|
(update played newfs) ; update the set of played files |
|
|
|
|
|
(get-args (thread-try-receive) args)))))) ; check for new arguments from controller |
|
|
|
|
|
|
|
|
(define (controller player-thread) |
|
|
(define (controller player-thread) |
|
|
(cond |
|
|
(cond |
|
|
((compose not thread-running?) player-thread ; if the thread is not running then return |
|
|
((compose not thread-running?) player-thread ; if the thread is not running then return |
|
|
'())) |
|
|
'())) |
|
|
(display "> ") |
|
|
(display "> ") ; TODO; add gnu readline support |
|
|
(let* ((input (read-line (current-input-port) 'linefeed))) |
|
|
(let* ((input (read-line (current-input-port) 'linefeed))) |
|
|
input |
|
|
input |
|
|
(cond ((eof-object? input) '()) |
|
|
(cond ((eof-object? input) (kill-thread player-thread)) ; check if received EOF, and kill player-thread |
|
|
(else |
|
|
(else |
|
|
(thread-send player-thread input) |
|
|
(thread-send player-thread input) |
|
|
(controller player-thread))))) |
|
|
(controller player-thread))))) |
|
|
(play-list) |
|
|
|
|
|
(define player-thread (thread (lambda () (play (play-list) played player-args)))) |
|
|
(define player-thread (thread (lambda () (play (play-list) played player-args)))) |
|
|
(define controller-thread (thread (lambda () (controller player-thread)))) |
|
|
(define controller-thread (thread (lambda () (controller player-thread)))) |
|
|
|
|
|
|
|
|
; check to see if the player is running, and if not then kill the controller |
|
|
; check to see if the player is running, and if not then kill the controller |
|
|
(define (check) |
|
|
(define (check) |
|
|
; (sleep 20) |
|
|
; (sleep 20) |
|
|
(cond (((compose not thread-running?) player-thread) (kill-thread controller-thread)) |
|
|
(cond (((compose not thread-running?) player-thread) |
|
|
|
|
|
(kill-thread controller-thread)) |
|
|
(else (check)))) |
|
|
(else (check)))) |
|
|
|
|
|
|
|
|
(check) |
|
|
(check) |