-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfluidsynth_external.lisp
More file actions
77 lines (64 loc) · 2.77 KB
/
fluidsynth_external.lisp
File metadata and controls
77 lines (64 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; ===========================================================================
;;; CL setting up an external fluidsynth proc.
;;;
;;; 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.
;;;
;;; You should have received a copy of the GNU Lesser General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;;
;;; Author: Anders Vinjar
(in-package :cl-fluidsynth)
;;; setup external fluidsynth to connect midi from jack to
(defparameter *fluidsynth-pid* nil)
(defparameter *fluidynth-io* nil)
(defparameter *fluid-synth-cmd* nil)
(defparameter *fluid-soundfont* "/usr/share/soundfonts/default.sf2")
(defvar *fluidsynth-cmd* (format nil "fluidsynth -j -m jack -g 2.0 -o midi.jack.id='OM_fluid' ~A" *fluid-soundfont*))
(defun fluidsynth-launch ()
(unless *fluidsynth-pid*
(when (and (streamp *fluidynth-io*) (open-stream-p *fluidynth-io*))
(close *fluidynth-io*))
(setf *fluidsynth-pid* nil)
(multiple-value-bind (io err pid)
(system:run-shell-command *fluidsynth-cmd*
:wait nil
:input :stream
:output :stream
:error-output nil)
(declare (ignore err))
(setf *fluidsynth-pid* pid)
(setf *fluidynth-io* io)
(format *standard-output* "started fluidsynth: pid: ~A" pid)
(list pid io))))
#+cl-jack (defun fluidsynth-start-and-connect ()
(unless *fluidsynth-pid*
(fluidsynth-launch))
(mp:process-run-function "waiting-to-start-fluidsynth" nil
#'(lambda ()
(mp:process-wait "getting fluidsynth running first"
#'(lambda ()
(and cl-jack::*ClJackClient*
(cl-jack::jack-port-name cl-jack::*jack-midi-output-port*)
*fluidsynth-pid*)))
(sleep 1.0)
(cl-jack::jack-connect cl-jack::*ClJackClient*
(cl-jack::jack-port-name cl-jack::*jack-midi-output-port*)
"fluidsynth:midi"))))
(defun fluidsynth-quit ()
(when (and (open-stream-p *fluidynth-io*) *fluidsynth-pid*)
(format *fluidynth-io* "quit~%")
(format *standard-output* "~&stopped fluidsynth: pid: ~A~%" *fluidsynth-pid*)
(setf *fluidsynth-pid* nil)
(when (open-stream-p *fluidynth-io*)
(close *fluidynth-io*))))
;; (om::fluidsynth-start-and-connect)
;; (om::om-add-exit-cleanup-func 'fluidsynth-quit)