]> git.jsancho.org Git - gacela.git/blob - gacela_sound.lisp
(no commit message)
[gacela.git] / gacela_sound.lisp
1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18 (eval-when (compile load eval)
19            (when (not (find-package 'gacela)) (make-package 'gacela :nicknames '(gg) :use '(lisp)))
20            (in-package 'gacela :nicknames '(gg) :use '(lisp)))
21
22
23 (defun load-sound (filename &key static)
24   (let ((key (make-resource-sound :filename filename)))
25     (cond ((get-resource key) key)
26           (t (true-load-sound filename static)))))
27
28 (defun true-load-sound (filename static)
29   (init-audio)
30   (let ((key (make-resource-sound :filename filename))
31         (sound (Mix_LoadWAV filename)))
32     (cond ((/= sound 0)
33            (set-resource key
34                          `(:id-sound ,sound)
35                          (lambda () (true-load-sound filename static))
36                          (lambda () (Mix_FreeChunk sound))
37                          :static static)
38            key))))
39