Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Sep 29, 2024
1 parent bd4f5e4 commit 262b98f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion priv/scripts/playlist-add.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'undermidi.player.queue
'add
(list (binary_to_list n) (binary_to_list f)))
(lfe_io:format "Playlist state: ~p~n"
(lfe_io:format "Updated playlist state:~n~p~n"
(list (rpc:call 'undermidi@localhost
'undermidi.player.queue
'dump
Expand Down
11 changes: 7 additions & 4 deletions src/undermidi/player/queue.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
(handle_info 2)
(init 1)
(terminate 2))
;; management API
;; playlist API
(export
(add 1) (add 2)
(opt 2))
(opt 2)
(now-playing 0) (now-playing 1)
(play-next 0)
(pop-queue 0))
;; debug API
(export
(dump 0)
Expand Down Expand Up @@ -154,7 +157,7 @@
(gen_server:cast (SERVER) `#(add-entry ,(make-entry name file))))

(defun now-playing ()
(now-playing:call (SERVER) '#(now-playing)))
(now-playing (gen_server:call (SERVER) '#(now-playing))))

(defun now-playing
((`#m(name ,name))
Expand All @@ -169,7 +172,7 @@
(case (now-playing)
("" (let ((`#(ok ,pid) (supervisor:start_child
'undermidi.player.supervisor
(pop-queue))))
`(,(pop-queue)))))
(undermidi.player.worker:play pid (self))))
(_ (undermidi.errors:action-cancelled "something is already being played"))))

Expand Down
13 changes: 10 additions & 3 deletions src/undermidi/player/worker.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(terminate 2))
;; device API
(export
(play 2)
(state 1))
;; debug API
(export
Expand All @@ -31,6 +32,7 @@
(defun DELIMITER () #"\n")
(defun NAME () "player queue song/sequence handler")
(defun genserver-opts () '())
(defun play-timeout () 600000) ; 10 minutes, for super-long longs ...

;;;;;::=-----------------------------=::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;::=- gen_server implementation -=::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -54,14 +56,19 @@
`#(ok ,song))

(defun handle_call
;; Management
((`#(state) _from song)
;; API
((`#(play) _from song)
;; TODO: change this to really play the sequence
(log-info "Getting ready to sleep ...")
(timer:sleep 10000)
`#(reply ,song ,song))
;; Stop
(('stop _from song)
(log-notice "Stopping ~s ..." (list (NAME)))
`#(stop normal ok ,song))
;; Testing / debugging
((`#(state) _from song)
`#(reply ,song ,song))
((`#(echo ,msg) _from song)
`#(reply ,msg ,song))
;; Fall-through
Expand Down Expand Up @@ -106,7 +113,7 @@
;;;;;::=------------------------=::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun play (pid caller)
(gen_server:call pid `#(play))
(gen_server:call pid `#(play) (play-timeout))
(gen_server:cast caller `#(finished ,(state pid))))

(defun state (pid)
Expand Down

0 comments on commit 262b98f

Please sign in to comment.