Browse Source

made more better

master
wes 12 years ago
parent
commit
d3e8d859b6
  1. 4
      config_parser.rkt
  2. 2
      helpers.rkt
  3. 34
      lazyplay.rkt

4
config_parser.rkt

@ -7,7 +7,7 @@
(read ip)) (read ip))
(close-input-port ip) (close-input-port ip)
(define settings (make-hash)) (define settings
(update settings parsed) (update (make-hash) parsed))
(provide settings) (provide settings)

2
helpers.rkt

@ -12,5 +12,7 @@
(define (flip f) (define (flip f)
(lambda (y x) (f x y))) (lambda (y x) (f x y)))
(define nowhere (open-output-nowhere 'nowhere #t))
(provide (all-defined-out)) (provide (all-defined-out))

34
lazyplay.rkt

@ -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
@ -55,44 +56,45 @@
(let* ((nullport (let* ((nullport
(open-output-file (string->path "/dev/null") #:exists 'append))) ; we don't want any output from the process (open-output-file (string->path "/dev/null") #:exists 'append))) ; we don't want any output from the process
(call-with-values (call-with-values
(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 (close-output-port (third results)))
; (thread-send controller-thread ((third results) (first results))) (let* ((newfs (new-files played (play-list)))) ; get new list of files
(subprocess-wait (first results)) (play
(close-output-port (third results))) (append (cdr fnames) newfs) ; append new files to the tail of the list of old files
(let* ((newfs (new-files played (play-list)))) (update played newfs) ; update the set of played files
(play (append (cdr fnames) newfs) (update played newfs) (get-args (thread-try-receive))))))) (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)