From 4ca85fa945c628031b876a32de7cba7884ab211f Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sat, 24 Jun 2017 22:35:01 -0300 Subject: [PATCH 1/3] Added pause/resume, paused channel queries and music time functions --- src/general.lisp | 38 ++++++++++++++++++++++++++++++++++++++ src/package.lisp | 10 +++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/general.lisp b/src/general.lisp index c8f3568..c9d494e 100644 --- a/src/general.lisp +++ b/src/general.lisp @@ -105,3 +105,41 @@ (defun volume-music (music-volume) "Adjust the volume of the music. Volume ranges from 0 to 128. The return value is an integer that usually represents the previous volume setting. Passing -1 as the music volume does not change the volume but instead returns the current volume setting" (mix-volume-music music-volume)) + +(defun pause (&optional (channel -1)) + "Pause channel, or all playing channels if -1 is passed in. You may still halt a paused channel" + (mix-pause channel)) + +(defun resume (&optional (channel -1)) + "Unpause channel, or all playing and paused channels if -1 is passed in" + (mix-resume channel)) + +(defun paused (channel) + "Tells you if channel is paused, or not. Channel -1 returns the number of paused threads" + (if (= -1 channel) + (get-num-paused-channels) + (/= 0 (mix-paused channel)))) + +(defun get-num-paused-channels () + "Tells you the number of paused channels" + (mix-paused -1)) + +(defun pause-music () + "Pause the music playback. You may halt paused music" + (mix-pause-music)) + +(defun resume-music () + "Unpause the music. This is safe to use on halted, paused, and already playing music" + (mix-resume-music)) + +(defun rewind-music () + "Rewind the music to the start. This is safe to use on halted, paused, and already playing music. It is not useful to rewind the music immediately after starting playback, because it starts at the beggining by default" + (mix-rewind-music)) + +(defun set-music-position (position) + "Set the position of currently playing music. It is highly recommended to read https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_65.html" + ;;Coercing here might be slow, but calling without coercion: + ;;(set-music-position 12.3) may get an error and + ;;(set-music-position 12.3d0) would run smoothly + ;;CL seems not to offer a clean cast function + (check-rc (mix-set-music-position (coerce position 'double-float)))) diff --git a/src/package.lisp b/src/package.lisp index 9ef78bf..2ebfef2 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -25,7 +25,15 @@ #:free-music #:play-music #:halt-music - #:volume-music)) + #:volume-music + #:pause + #:resume + #:paused + #:get-num-paused-channels + #:pause-music + #:resume-music + #:rewind-music + #:set-music-position)) (in-package :sdl2-mixer) From 6edf70941ebd4b3fff132e9a5a8db54558179de8 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sat, 13 Jan 2018 03:34:34 -0300 Subject: [PATCH 2/3] Removed coerce call in #'set-music-position Coerce is no longer needed. Multiplying "position" by 1.0d0 (a double-float number) coerces it without calling an expensive function. --- src/general.lisp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/general.lisp b/src/general.lisp index c9d494e..f055b6c 100644 --- a/src/general.lisp +++ b/src/general.lisp @@ -138,8 +138,4 @@ (defun set-music-position (position) "Set the position of currently playing music. It is highly recommended to read https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_65.html" - ;;Coercing here might be slow, but calling without coercion: - ;;(set-music-position 12.3) may get an error and - ;;(set-music-position 12.3d0) would run smoothly - ;;CL seems not to offer a clean cast function - (check-rc (mix-set-music-position (coerce position 'double-float)))) + (check-rc (mix-set-music-position (* position 1.0d0)))) From 3a06781b282caa27bbc00351422875ee1779266a Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 16 Jan 2018 17:21:01 +0000 Subject: [PATCH 3/3] Coerce to double-float with #'float instead of #'* --- src/general.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/general.lisp b/src/general.lisp index f055b6c..ed72886 100644 --- a/src/general.lisp +++ b/src/general.lisp @@ -138,4 +138,4 @@ (defun set-music-position (position) "Set the position of currently playing music. It is highly recommended to read https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_65.html" - (check-rc (mix-set-music-position (* position 1.0d0)))) + (check-rc (mix-set-music-position (float position 1d0))))