-
Notifications
You must be signed in to change notification settings - Fork 4
/
MIDI.rtf
185 lines (181 loc) · 5.12 KB
/
MIDI.rtf
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;\red0\green0\blue191;\red96\green96\blue96;
\red191\green0\blue0;\red0\green0\blue191;\red191\green0\blue0;\red96\green96\blue96;\red0\green115\blue0;
\red0\green0\blue255;\red0\green0\blue246;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\f0\fs24 \cf2 \
\
\pard\pardeftab560\ql\qnatural
\f1\fs18 \cf2 (\
\
m = \cf3 SimpleMIDIFile\cf2 .read(
\f0\fs24 \cf4 "/Users/thor/quaziir/SC3/projects/studies/candyman/candyman2.mid"
\f1\fs18 \cf2 ); \cf5 // create \cf2 \
m = \cf3 SimpleMIDIFile\cf2 .read(
\f0\fs24 \cf4 "/Users/thor/quaziir/Teaching/Other/~rlee/midi/egoclam.mid"
\f1\fs18 \cf2 ); \cf5 // create \cf2 \
m = \cf3 SimpleMIDIFile\cf2 .read(\cf0 "/Users/thor/Downloads/WTK/s00016.mid"\cf2 ); \cf5 // create \
\cf0 m = \cf6 SimpleMIDIFile\cf0 .read("/Users/thor/Downloads/WTK/s00051.mid"); \cf7 // create \
\pard\pardeftab720\ql\qnatural
\cf2 \
\pard\pardeftab560\ql\qnatural
\cf2 m = \cf3 SimpleMIDIFile\cf2 .read(\cf4 "/Users/thor/Desktop/dou2.mid"\cf2 ); \cf5 // create \cf2 \
m = \cf3 SimpleMIDIFile\cf2 .read(\cf4 "/Users/thor/Desktop/fuguecm.mid"\cf2 ); \cf5 // create \cf2 \
\cf0 m = \cf6 SimpleMIDIFile\cf0 .read(\cf8 "/Users/thor/Desktop/\cf0 04A-1__Black_Dog\cf8 .mid"\cf0 ); \cf7 // create \cf0 \
\cf2 \
m.timeMode = \cf9 \\seconds\cf2 ; \cf5 // change from default to something useful\cf2 \
\
\
\
\
\
\cf5 // read it\cf2 \
m.p.play; \cf5 // takes a few seconds to start because this midifile starts with a rest\cf2 \
\
m.tracks\
\
m.noteEvents.dopostln;\
\
a = 0;\
\cf0 m.noteEvents.do(\{ |event| if(event[0]>a, \{a = event[0]\}) \})\cf2 \
a\
m.noteEvents\
\
m.noteEvents(1).dopostln;\
\
\cf3 TempoClock\cf2 .default.tempo = 1;\
\
d = 0;\
fork\{\
m.noteEvents(1).do(\{\cf10 arg\cf2 event, i;\
t = event[1];\
a = \cf3 Synth\cf2 (\cf9 \\pansaw\cf2 , [\cf9 \\freq\cf2 , event[4].midicps]);\
(t - d).wait;\
d = t;\
a.release;\
\});\
\};\
\
\
\
m.tracks.do(\{\cf10 arg\cf2 i;\
d = 0;\
fork\{\
m.noteEvents(i).do(\{\cf10 arg\cf2 event, i;\
\{t = event[1];\
a = \cf3 Synth\cf2 (\cf9 \\pansaw\cf2 , [\cf9 \\freq\cf2 , event[4].midicps]);\
(t - d).wait;\
d = t;\
a.release;\
\}.value\
\});\
\};\
\})\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\cf2 \
\cf3 SynthDef\cf2 (\cf9 \\pansaw\cf2 , \{\cf10 arg\cf2 out=0, freq=110, amp=0.5, dur=1, gate=1, cutoff=2, gain=2.5, pan=0;\
\cf10 var\cf2 signal;\
signal = \cf3 MoogFF\cf2 .ar(\cf3 Saw\cf2 .ar(freq, amp), freq*\cf3 MouseY\cf2 .kr(10, 1), gain);\
signal = signal* \cf3 EnvGen\cf2 .ar(\cf3 Env\cf2 .asr(0.01, 1, 0.1), gate, doneAction:2);\
\cf3 Out\cf2 .ar(out, \cf3 LinPan2\cf2 .ar(signal, \cf3 MouseX\cf2 .kr(-1, 1)));\
\}).add;\
\
\
\
m.tracks\
\
\pard\pardeftab720\ql\qnatural
\cf2 m.midiEvents.dopostln; \cf5 // all midi events\cf2 \
m.metaEvents.dopostln; \cf5 // notice the incorrect 'endOfTrack' events for track 1 & 2;\cf2 \
\
m.adjustEndOfTrack;\
m.metaEvents.dopostln; \cf5 // try again\cf2 \
\
m.tempoMap; \cf5 // get the tempo map ( [[ startTime, bpm ], [ etc.. ]] )\cf2 \
m.timeSignatures; \cf5 // get the time signatures ( ( [[ startTime, a/b ], [ etc.. ]] )\cf2 \
\
m.p.play; \cf5 // convert to Pattern and play\cf2 \
\
m.write; \cf5 // now play the file in Quicktime, or open with another app\cf2 \
\
m.plot; \cf5 // uses {\field{\*\fldinst{HYPERLINK "file:///Users/thor/Library/Application%20Support/SuperCollider/quarks/wslib/wslib-help/ScaledUserView.html"}}{\fldrslt \ul \ulc11 ScaledUserView}}\cf2 \
\pard\pardeftab720\ql\qnatural
\f0\fs24 \cf2 \
\
\
\
\pard\pardeftab560\ql\qnatural
\f1\fs18 \cf5 ////////\cf2 \
\
\
\{\
\cf10 var\cf2 synth;\
\cf10 var\cf2 delta = 0;\
fork\{\
m.noteEvents(1).do(\{\cf10 arg\cf2 event, i;\
\cf10 var\cf2 time;\
time = event[1];\
(time - delta).wait;\
\cf0 if((event[5] == 0) || (event[2] == \\noteOff), \{\
\cf2 synth.release\
\},\{\
synth = \cf3 Synth\cf2 (\cf9 \\pansaw\cf2 , [\cf9 \\freq\cf2 , event[4].midicps]);\
\});\
delta = time;\
\});\
\};\
\}.value;\
\
\
\{\
\cf10 var\cf2 synth;\
\cf10 var\cf2 delta = 0;\
fork\{\
m.noteEvents(3).do(\{\cf10 arg\cf2 event, i;\
\cf10 var\cf2 time;\
time = event[1];\
(time - delta).wait;\
\cf0 if((event[5] == 0) || (event[2] == \\noteOff), \{\
\cf2 synth.release\
\},\{\
synth = \cf3 Synth\cf2 (\cf9 \\pansaw\cf2 , [\cf9 \\freq\cf2 , event[4].midicps]);\
\});\
delta = time;\
\});\
\};\
\}.value;\
\
\
\
\cf5 ///////////////\cf2 \
\cf0 \
\cf2 \
m.tracks.do(\{\cf10 arg\cf2 i;\
\cf10 var\cf2 synth;\
\cf10 var\cf2 delta = 0;\
fork\{\
m.noteEvents(i).do(\{\cf10 arg\cf2 event;\
\cf10 var\cf2 time;\
time = event[1];\
(time - delta).wait;\
if((event[5] == 0) || (\cf0 event[2] == \\noteOff)\cf2 , \{\
synth.release\
\},\{\
synth = \cf3 Synth\cf2 (\cf9 \\pansaw\cf2 , [\cf9 \\freq\cf2 , event[4].midicps]);\
\});\
delta = time;\
\});\
\};\
\})\
\
~drones.hub.states.playMIDI(\cf0 "/Users/thor/Downloads/WTK/s00016.mid"\cf2 );\
\
\
\
\
\
\
\
}