From bc04e12cf3c193c3b5620f3b6e0ded852f221fb8 Mon Sep 17 00:00:00 2001 From: jsancho Date: Tue, 26 Oct 2010 19:09:57 +0000 Subject: [PATCH] --- gacela.lisp | 3 +++ gacela_sound.lisp | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/gacela.lisp b/gacela.lisp index f174a48..299ab90 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -157,6 +157,9 @@ (defun make-resource-sound (&key filename) `(:type sound :filename ,filename)) +(defun make-resource-music (&key filename) + `(:type music :filename ,filename)) + (defmacro get-rtime (key) `(resource-time (gethash ,key resources-table))) diff --git a/gacela_sound.lisp b/gacela_sound.lisp index e0cdf56..e1a4c9b 100644 --- a/gacela_sound.lisp +++ b/gacela_sound.lisp @@ -37,3 +37,31 @@ :static static) key)))) +(defun play-sound (sound &optional (loops 0)) + (let ((id-sound (getf (get-resource sound) :id-sound))) + (/= (Mix_PlayChannel -1 id-sound loops) -1))) + +(defun load-music (filename &key static) + (let ((key (make-resource-music :filename filename))) + (cond ((get-resource key) key) + (t (true-load-music filename static))))) + +(defun true-load-music (filename static) + (init-audio) + (let ((key (make-resource-music :filename filename)) + (music (Mix_LoadMUS filename))) + (cond ((/= music 0) + (set-resource key + `(:id-music ,music) + (lambda () (true-load-music filename static)) + (lambda () (Mix_FreeMusic music)) + :static static) + key)))) + +(defun playing-music? () + (/= (Mix_PlayingMusic) 0)) + +(defun play-music (music &optional (loops -1)) + (cond ((not (playing-music?)) + (let ((id-music (getf (get-resource music) :id-music))) + (/= (Mix_PlayMusic id-music loops) -1))))) -- 2.39.5