Skip to content
Snippets Groups Projects
Select Git revision
  • fd82b99842fb483fc990b22fc0f0db9ad7def441
  • master default protected
  • 6.14
  • 6.12
4 results

cl-fluidsynth.lisp

Blame
  • cl-fluidsynth.lisp 8.62 KiB
    ;;===========================================================================
    ;;FluidSynth API for Common Lisp/CFFI
    ;;
    ;;This program is free software; you can redistribute it and/or modify
    ;;it under the terms of the GNU Lesser General Public License as published by
    ;;the Free Software Foundation; either version 2.1 of the License, or
    ;;(at your option) any later version.
    ;;  
    ;;This program is distributed in the hope that it will be useful,
    ;;but WITHOUT ANY WARRANTY; without even the implied warranty of
    ;;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ;;GNU Lesser General Public License for more details.
    ;;  
    ;;Author: Anders Vinjar
    
    (in-package :cl-fluidsynth)
    
    ;; (oa::om-cmd-line "opera /usr/share/doc/fluidsynth-devel-1.1.6/html/index.html &")
    
    (defvar *fluidsynth* nil)
    (defvar *fluidsynth-settings* nil)
    (defvar *fluidplayer* nil)
    (defvar *fluid-midi-player* nil)
    (defvar *fluidadriver* nil)
    (defvar *soundfont-dir* (or (probe-file "/usr/share/soundfonts/")
    			    (probe-file "/usr/share/sounds/sf2/")))
    
    (defvar *soundfont* (namestring
    		     (make-pathname :directory (if *soundfont-dir* (pathname-directory *soundfont-dir*))
    				    :name "FluidR3_GM.sf2")))
    
    (defvar *fluid-midi-driver-settings* nil)
    
    (define-condition not-a-soundfont (error)
      ((soundfont :initarg :soundfont-name :reader soundfont-name)
       (synth :initarg :synth :reader fluidsynth-synth))
      (:report (lambda (condition stream)
    	     (format stream "could not load soundfont ~S into running synth ~A."
    		     (soundfont-name condition)
    		     (fluidsynth-synth condition)))))
    
    (defun prompt-for-soundfont ()
      (format t "Enter name of soundfont to load: ")
      #+capi (list (namestring (oa::om-choose-file-dialog :prompt "Enter name of soundfont to load: "
    						      :types '("sf2" "*.sf2" "All" "*.*"))))
      #-capi (multiple-value-list (eval (read))))
    
    (defun fluid-load-new-soundfont-aux (synth soundfont)
      (let ((status (fluid_synth_sfload synth soundfont 1)))
        (if (= status FLUID_FAILED)
    	(error 'not-a-soundfont :soundfont-name soundfont :synth synth)
    	status)))
    
    (defun fluid-load-new-soundfont (&optional (synth *fluidsynth*) (soundfont *soundfont*))
      (restart-case
          (fluid-load-new-soundfont-aux synth soundfont)
        (prompt (new-soundfont)
          :report "Provide soundfont-file to load."
          :interactive prompt-for-soundfont
          (setq soundfont new-soundfont))
        (reload ()
          :report "Retry loading soundfont"
          (fluid-load-new-soundfont synth soundfont)
          t)))
    
    (defun fluid-synth-setup ()
      (unless *fluidsynth*
        (progn
          (setf *fluidsynth-settings* (new_fluid_settings))
          (fluid_settings_setstr *fluidsynth-settings* "audio.driver"