-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-1.lisp
More file actions
123 lines (100 loc) · 3.68 KB
/
test-1.lisp
File metadata and controls
123 lines (100 loc) · 3.68 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;;;
;;; some tests for cl-fluidsynth lib, set up based on access to cl-jack bindings
;;;
;;; Author: Anders Vinjar
;;;
(cl-jack::jack-get-client-name cl-jack::*CLJACKCLIENT*)
(cl-jack::jack-get-ports cl-jack::*CLJACKCLIENT* "" "" 0)
(with-foreign-object (fluidports :pointer)
(setf fluidports (cl-jack::jack-get-ports cl-jack::*CLJACKCLIENT* "fluid" "midi" 0))
(loop for i from 0
and port = (mem-aref fluidports :string i)
while port
collect port))
(cl-jack::jack-get-ports cl-jack::*CLJACKCLIENT* "fluid" "midi" 0)
(cl-jack::jack-connect cl-jack::*CLJACKCLIENT* "OM_fluidsynth" )
;; play midi-file from file:
(setf percplayer (new_fluid_player *fluidsynth*))
(fluid_player_add percplayer "/home/andersvi/test.midi")
(fluid_player_play percplayer)
(fluid_player_get_status percplayer)
(fluid_player_stop percplayer)
(delete_fluid_player percplayer)
(progn
(delete_fluid_audio_driver *fluidadriver*)
(delete_fluid_player *fluidplayer*)
(delete_fluid_synth *fluidsynth*)
(delete_fluid_settings *fluidsynth-settings*))
(fluid_synth_noteon *fluidsynth* 0 63 127)
(fluid_synth_noteoff *fluidsynth* 0 63)
(loop repeat 120
for note = (+ 20 (random 70))
do
(fluid_synth_noteon *fluidsynth* 0 note 100)
(sleep 1/64)
(fluid_synth_noteoff *fluidsynth* 0 note))
;; arpeggio example
(defun schedule-noteon (chan key ticks)
(let ((ev (new_fluid_event)))
(fluid_event_set_dest ev synth_destination)
(fluid_event_noteon ev chan key 127)
(fluid_sequencer_send_at sequencer ev ticks 1)
(delete_fluid_event ev)))
(defun schedule-noteoff (chan key ticks)
(let ((ev (new_fluid_event)))
(fluid_event_set_dest ev synth_destination)
(fluid_event_noteoff ev chan key)
(fluid_sequencer_send_at sequencer ev ticks 1)
(delete_fluid_event ev)))
(defun schedule-timer-event ()
(let ((ev (new_fluid_event)))
(fluid_event_set_source ev -1)
(fluid_event_set_dest ev client_destination)
(fluid_event_timer ev nil)
(fluid_sequencer_send_at sequencer ev time_marker 1)
(delete_fluid_event ev)))
(defun schedule-pattern (notes duration)
(let* ((now time_marker)
(siz (length notes))
(note-duration (floor duration siz)))
(loop for i from 0 below siz
for note = (elt notes i)
do
(schedule-noteon 0 note now)
(schedule-noteoff 0 note (+ now note-duration)))
(incf time_marker duration)))
(defcallback sequencer-callback
:void ((time :unsigned-int) (event fluid_event_t)
(seq fluid_sequencer_t) (data (:pointer :void)))
(declare (ignore time event seq data))
(schedule-timer-event)
(schedule-pattern notes duration)
)
(reverse '(60 64 67 72 76 79 84 79 76 72 67 64))
(setf notes #(64 72 67 79 76 79 76 72 84 60 64 67))
(setf duration 1440)
(setf notes #(60 64 67 72 76 79 84 79 76 72 67 64))
(setf notes (make-array 12 :initial-contents
(loop repeat 12
collect (+ 12 (random 100)))))
(setf pattern_size (length notes))
(setf settings (new_fluid_settings))
(fluid_settings_setint settings "audio.jack.autoconnect" 1)
(setf synth (new_fluid_synth settings))
(setf audiodriver (new_fluid_audio_driver settings synth))
(setf sequencer (new_fluid_sequencer))
(setf synth_destination (fluid_sequencer_register_fluidsynth sequencer synth))
(setf client_destination (fluid_sequencer_register_client
sequencer
"arpeggio" (callback sequencer-callback) nil))
(setf n (fluid_synth_sfload synth "/usr/share/soundfonts/FluidR3_GM.sf2" 1))
(setf time_marker (fluid_sequencer_get_tick sequencer))
(schedule-pattern notes duration)
(schedule-timer-event)
(schedule-pattern)
;;cleanup
(progn
(delete_fluid_synth synth)
(delete_fluid_sequencer sequencer)
(delete_fluid_audio_driver audiodriver)
(delete_fluid_settings settings))