This commit is contained in:
2026-02-24 18:16:55 +01:00
parent 75ed3365af
commit 8fb7cca9c2
7 changed files with 406 additions and 72 deletions

116
gui.rkt
View File

@@ -3,6 +3,7 @@
(require web-racket
racket/runtime-path
racket/gui
racket-sprintf
"utils.rkt"
"music-library.rkt"
"translate.rkt"
@@ -35,14 +36,70 @@
[html-file rktplayer-start]
)
(define closed #f)
(define el-seeker #f)
(define el-library #f)
(define el-playlist #f)
(define el-at #f)
(define el-length #f)
(define music-library (send settings get 'music-library (find-system-path 'home-dir)))
(define current-music-path #f)
(define playlist #f)
(define player (new player%))
(define current-at-seconds 0)
(define current-length-seconds 0)
(define (update-time at-seconds length-seconds)
(let ((as (inexact->exact (round at-seconds)))
(ls (inexact->exact (round length-seconds))))
(when (or (not (= current-at-seconds as))
(not (= current-length-seconds ls)))
(set! current-at-seconds as)
(set! current-length-seconds ls)
(let ((as-str (sprintf "%02d:%02d:%02d"
(quotient as 3600)
(quotient (remainder as 3600) 60)
(remainder (remainder as 3600) 60)))
(ls-str (sprintf "%02d:%02d:%02d"
(quotient ls 3600)
(quotient (remainder ls 3600) 60)
(remainder (remainder ls 3600) 60)))
)
(unless closed
(send el-at set-inner-html! as-str)
(send el-length set-inner-html! ls-str)
(let ((seeker (exact->inexact (/ (* 100 as) ls))))
(displayln (format "seeker = ~a" seeker))
(send el-seeker set! (format "~a" seeker)))
)
)
)
)
)
(define current-track-nr #f)
(define (update-track-nr nr)
(let ((id (λ () (string->symbol (format "track-~a" (+ current-track-nr 1))))))
(unless (eq? current-track-nr #f)
(displayln (format "current track: ~a" (id)))
(let ((el (send this element (id))))
(send el remove-class! "current")))
(set! current-track-nr nr)
(unless (eq? current-track-nr #f)
(displayln (format "current track: ~a" (id)))
(let ((el (send this element (id))))
(send el add-class! "current")))
)
)
(define player (new player%
[time-updater update-time]
[track-nr-updater update-track-nr]
[settings settings]
))
(define inner-html-handlers (make-hash))
@@ -61,6 +118,10 @@
(send el-seeker on-change! seek-reactor))
(set! el-library (send this element 'library))
(set! el-playlist (send this element 'tracks))
(set! el-at (send this element 'time))
(set! el-length (send this element 'totaltime))
(send this set-menu! (player-menu))
(send this connect-menu! 'm-quit (λ () (send this quit)))
@@ -71,7 +132,10 @@
(define/public (update-playlist)
(displayln "Updating playlist")
(let ((html (send playlist to-html)))
(send el-playlist set-inner-html! html)
(update-track-nr current-track-nr)
)
)
(define/public (update-library)
@@ -103,8 +167,7 @@
(λ (args)
(send this path-choosen (cadr row))))
(send el connect 'click
(λ (args)
(displayln args)))
(λ (args) #t))
(send el connect 'contextmenu
(λ (evt)
(send this context-for-path evt (cadr row))))
@@ -137,26 +200,24 @@
)
(define/public (context-for-path evt path)
(let* ((mnu (menu 'library-popup
(menu-item 'm-play-this (tr "Play this") #:callback (λ () (send this play-path path)))
(menu-item 'm-booklet (tr "Open booklet") #:callback (λ () (send this open-booklet path)))
(menu-item 'm-folder (tr "Open containing folder") #:callback (λ () (send this open-folder path))
#:submenu
(menu (menu-item 'm-idx (tr "Select Music Library Folder") #:separator #t)
(menu-item 'm-idy (tr "Quit") #:separator #t
#:submenu
(menu (menu-item 'mabd (tr "Ja"))
(menu-item 'mdedjk (tr "No"))
(menu-item 'sdakjfas (tr "akjfhalk"))
))
))
)
)
(js-evt (hash-ref evt 'js_evt (make-hash)))
(clientX (hash-ref js-evt 'clientX 60))
(clientY (hash-ref js-evt 'clientY 60))
)
(send this popup-menu mnu clientX clientY)
(let ((items (list
(menu-item 'm-play-this (tr "Play this") #:callback (λ () (send this play-path path))))))
(when (file-exists? path)
(set! items (append items
(list
(menu-item 'm-add-this (tr "Add this") #:callback (λ () (send this add-path path)))))))
(set! items (append items
(list
(menu-item 'm-booklet (tr "Open booklet") #:callback (λ () (send this open-booklet path))) ;; todo check if pdf file exists
(menu-item 'm-folder (tr "Open containing folder") #:callback (λ () (send this open-folder path)))
)))
(let* ((mnu (menu 'library-popup items))
(js-evt (hash-ref evt 'js_evt (make-hash)))
(clientX (hash-ref js-evt 'clientX 60))
(clientY (hash-ref js-evt 'clientY 60))
)
(send this popup-menu mnu clientX clientY)
)
)
)
@@ -169,6 +230,11 @@
(send player play playlist)
)
(define/public (add-path path)
(send playlist add-track path)
(send this update-playlist)
)
(define/public (open-booklet path)
(displayln (format "Open booklet ~a" path)))
@@ -201,6 +267,8 @@
(define/public (quit)
(displayln (format "Quitting"))
(send player quit)
(set! closed #t)
(send this close))
(define/public (select-library)