;;; ========================================================================
;;; Copyright (C) 1998-2001 by Tobias Kunze Briseņo. All Rights Reserved.
;;;
;;; This library and its accompanying code is free software; you can
;;; redistribute it and/or modify it under the terms of the GNU Library
;;; General Public License as published by the Free Software Foundation;
;;; either version 2 of the License, or (at your option) any later version.
;;;
;;; This code is distributed WITHOUT ANY WARRANTY, in particular without
;;; the warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;; See the GNU Library General Public License for more details.
;;;
;;; Suggestions, comments, or bug reports are welcome. Please visit the
;;; project site at
;;; ========================================================================
;;;
;;;
;;; Summary: Simple MIDI Note Player (Lisp version)
;;;
;;; Description: Make sure Mi_D has been loaded up front. The exact
;;; procedure herefore depends on your Lisp
;;; implementation. In ACL, evaluate
;;;
;;; (progn
;;; (load "/libmi_d.so")
;;; (load "/include/mi_d.lisp")
;;; (load "/include/mi_dACL.lisp"))
;;;
;;; with appropriate substitutes for the italicized portions
;;; in the pathnames. In MCL, first make sure the shared
;;; library is in the extensions folder inside the system
;;; folder or in the same folder as your Lisp image, then,
;;; similarly, evaluate
;;;
;;; (progn
;;; (load "/include/mi_d.lisp")
;;; (load "/include/mi_dMCL.lisp"))
;;;
;;; Again, with the appropriate pathnames. Then, call `beet'
;;; with an interface name string, e.g.
;;;
;;; (beet "Software Synth")
;;;
;;; on an SGI machine with midisynth(1) installed.
;;;
;;; Bugs:
;;;
;;;
;;; $Source: /cvsroot/mi-d/mi_d/doc/examples/beet.lisp,v $
;;; $Revision: 1.3 $
;;; $Date: 2001/05/05 03:01:02 $
(defun beet (interface)
(let (res
(qtr 350) ; quarter note tempo (in ms)
(time 0) ; note time stamp
dur ; note duration
(notes ; the melody
'(64 64 65 67 67 65 64 62 60 60 62 64 64 62 62)))
;; Open MIDI for 16 channels, 1 route and connection, 16+1
;; mapping cells and allocate a small queue of 100 or so events
(setf res (mi_d:open-midi "Hello Mi_D" 16 1 1 17 100))
(if (/= res mi_d:+no-err+)
(error "Can't open MIDI (~d)" res)
(progn
;; use standard channel and route maps
(mi_d:standard-maps)
;; connect to the given interface
(setf res (mi_d:connect 0 interface :mi_d-output))
(if (/= res mi_d:+no-err+)
(error "Can't connect to ~s (~d)" interface res)
(progn
;; reset timer
(mi_d:set-time 0)
;; play the melody
(dotimes (i 15)
(setf dur (floor
(* qtr (case i (12 1.5) (13 .5) (14 2) (t 1)))))
(mi_d:write-note_3c 0 (elt notes i) 64 64 dur time)
(incf time dur))))))
(mi_d:close-midi)))
;;;
;;; EOF