From 177829ccb621705f5b56fa20729791ed3e5b45ca Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Tue, 24 Feb 2026 23:28:18 +0100 Subject: [PATCH] - --- gui.rkt | 9 ++++++--- player.rkt | 56 +++++++++++++++++++++++++++++++++++++++++----------- playlist.rkt | 39 +++++++++++++++++++++++++++++------- utils.rkt | 9 ++++++++- 4 files changed, 90 insertions(+), 23 deletions(-) diff --git a/gui.rkt b/gui.rkt index 0551d5e..62920e2 100644 --- a/gui.rkt +++ b/gui.rkt @@ -239,18 +239,21 @@ (displayln (format "Open booklet ~a" path))) (define/public (open-folder path) - (displayln (format "open folder ~a" path))) + (displayln path) + (let ((folder (if (file-exists? path) (path-only path) path))) + (open-file-manager folder))) + ;(shell-execute #f folder #f #f 'sw_show))) (define/public (play) (displayln "Play button clicked") ) (define/public (next-track) - (displayln "Next track") + (send player next) ) (define/public (previous-track) - (displayln "Previous track") + (send player previous) ) (define/public (repeat) diff --git a/player.rkt b/player.rkt index 5a85bf9..9c8f1bc 100644 --- a/player.rkt +++ b/player.rkt @@ -35,6 +35,8 @@ (define current-length 0) (define current-seconds 0) + (define repeat 'no-repeat) ;; no-repeat, repeat-1, repeat-all + (define play-time-updater-state 'stopped) (define (check-ao-handle) @@ -57,7 +59,7 @@ (displayln "Starting play-time-updater") (thread (λ () (define (updater) - (if (eq? ao-handle #f) + (if (or (eq? ao-handle #f) closing) (begin (set! play-time-updater-state 'stopped) (displayln "Stopping play-time-updater") @@ -121,10 +123,11 @@ (displayln (format "opening flac handle for file: ~a" file)) (set! flac-handle (flac-open file flac-meta flac-play)) (displayln "Starting flac-read") - (flac-read flac-handle) - (set! state 'track-feeded) - (displayln "Flac read stopped") - 'track-feeded + (let ((result (flac-read flac-handle))) + (if (eq? result 'end-of-stream) + (set! state 'track-feeded) + (displayln "Flac read stopped"))) + 'worker-done ) ) ) @@ -190,17 +193,46 @@ ) (define/public (play-track i) - (unless (eq? flac-handle #f) - (flac-stop flac-handle) - (set! flac-handle #f) - ) + (displayln (format "play-track ~a" i)) + ;(unless (eq? flac-handle #f) + ; (flac-stop flac-handle) + ; (set! flac-handle #f) + ; ) + ;(set! track i) + ;(set! ct-data (send pl track i)) + ;(while (eq? state 'playing) + ; (sleep 0.1)) + ;(unless (eq? ao-handle #f) + ; (ao-clear-async ao-handle)) + ;(set! state 'play) + ;(track-nr-updater i) + (set! state 'stopped) + (close-player*) (set! track i) (set! ct-data (send pl track i)) - (while (eq? state 'playing) - (sleep 0.1)) (set! state 'play) - (track-nr-updater i) + (track-nr-updater track) ) + + (define/public (next) + (if (= (send pl length) 0) + #f + (let ((idx track)) + (set! idx (+ idx 1)) + (when (>= idx (send pl length)) + (set! idx 0)) + (send this play-track idx)) + )) + + (define/public (previous) + (if (= (send pl length) 0) + #f + (let ((idx track)) + (set! idx (- idx 1)) + (when (< idx 0) + (set! idx (- (send pl length) 1))) + (send this play-track idx) + ))) (define (state-machine) (let ((st (orig-current-seconds)) diff --git a/playlist.rkt b/playlist.rkt index 730bda1..b2f2ef7 100644 --- a/playlist.rkt +++ b/playlist.rkt @@ -41,16 +41,40 @@ (super-new) (begin (unless (eq? file #f) - (let ((tags (id3-tags (format "~a" file)))) - (set! title (tags-title tags)) - (set! artist (tags-artist tags)) - (set! album (tags-album tags)) - (set! number (tags-track tags)) - (set! length (tags-length tags)) + (let ((f (if (path? file) (path->string file) file))) + (let ((tags (id3-tags f)) + (tmpfile #f)) + (unless (tags-valid? tags) + (the-displayln "Invalid, try to open a copy of this file") + (let ((nfile (make-temporary-file "rktplayer-~a" #:copy-from f))) + (set! tags (id3-tags nfile)) + (set! tmpfile nfile) + ) + ) + (if (tags-valid? tags) + (begin + (set! title (tags-title tags)) + (set! artist (tags-artist tags)) + (set! album (tags-album tags)) + (set! number (tags-track tags)) + (set! length (tags-length tags)) + ) + (begin + (set! title "invalid tags") + (set! artist "invalid tags") + (set! album "invalid tags") + (set! number number) + (set! length -1) + ) + ) + (unless (eq? tmpfile #f) + (delete-file tmpfile)) + ) ) ) ) - )) + ) + ) (define list-len length) @@ -85,6 +109,7 @@ (if (directory-exists? p) (read-tracks-internal p) (when (and (file-exists? p) (can-add? p)) + ;(displayln (format "Adding ~a" p)) (add-track* p))))) content)) 'no-file-or-dir diff --git a/utils.rkt b/utils.rkt index 7660f6b..bb81f48 100644 --- a/utils.rkt +++ b/utils.rkt @@ -10,6 +10,7 @@ mktable simple-row-formatter while + open-file-manager ) @@ -70,5 +71,11 @@ ) ) - +(define (open-file-manager path) + (let ((folder (if (path? path) (path->string path) path))) + (case (system-type 'os) + [(windows) (process (string-append "explorer.exe " folder))] + [(macosx) (process (string-append "open " folder))] + [else (process (string-append "xdg-open " folder))])) + )