Debian Codegraph @

src/Examples/McCurdy Collection/MIDI/BasicMonophonicSynth.csd

raw
1 ;Writen by Iain McCurdy, 2006
2
3 ; Modified for QuteCsound by René, February 2011
4 ; Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6 ;Notes on modifications from original csd:
7
8
9 ;my flags on Ubuntu: -dm0 -odac -+rtaudio=alsa -b1024 -B2048 -+rtmidi=alsa -Ma
10 <CsoundSynthesizer>
11 <CsOptions>
12
13 </CsOptions>
14 <CsInstruments>
15 sr = 44100 ;SAMPLE RATE
16 ksmps = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
17 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
18 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
19
20
21 ;INITIALISE GLOBAL VARIABLES
22 gkcps init 0
23 gkNumInstr1 init 0
24 gkvib init 0
25
26
27 instr 1
28 icps cpsmidi ;READ VALUES FOR FREQUENCY FROM A MIDI KEYBOARD
29 gkcps = icps ;CREATE A K-RATE GLOBAL VARIABLE FROM MIDI FREQ. VALUES
30
31 ;CREATE A VIBRATO FUNCTION - THIS ENVELOPE WILL BE TRIGGERED WITH EACH NEW NEW THAT IS PRESSED WHETHER LEGATO OR NOT
32 ivibamp = .1
33 ivibdelayTim = .3
34 ivibRiseTim = 1
35 kvibenv expseg .001, (ivibdelayTim), .001, (ivibRiseTim), ivibamp, (1), ivibamp
36 kvibfreq = 6
37 ivibwave = 1
38 kvib oscil kvibenv, kvibfreq, ivibwave
39 gkvib = kvib+1
40
41 ;INSTR 2 IS INSTRUCTED TO PLAY A VERY LONG NOTE - ONLY ONE NOTE AT A TIME IS ALLOWED
42 ; KTRIGGER, KMINTIM, KMAXNUM, KINSNUM, KWHEN, KDUR
43 schedkwhen 1, 0, 1, 2, 0, 3600
44 endin
45
46 instr 2
47
48 kporttime_gui invalue "Portamento"
49
50 kreleaseflag release
51 gkNumInstr1 active 1 ;SENSE THE NUMBER OF NOTES ARE BEING PLAYED BY INSTR 1
52 if gkNumInstr1!=0||kreleaseflag=1 kgoto KEEP_PLAYING ;IF INSTR 1 IS PLAYING AT LEAST ONE NOTE THEN INSTR 2 MUSTN'T TURN ITSELF OFF
53 ;I.E. SKIP THE NEXT LINE...
54 turnoff ;INSTR 2 TURNS ITSELF OFF
55 KEEP_PLAYING: ;SKIP TO HERE IF INSTR 1 IS STILL PLAYING
56
57 ;CREATE PORTAMENTO ON PITCH PARAMETER
58 kporttime linseg 0, .01, 1, 1, 1
59 kporttime = kporttime * kporttime_gui
60 kcps portk gkcps, kporttime
61
62 ;CREATE AN OSILLATOR USING THE vco OPCODE
63 iwave = 1
64 kpw = .5
65 ifn = 1
66 imaxd = 1
67 ileak = 0
68 inyx = .5
69 asig vco 0.3, kcps*gkvib, iwave, kpw, ifn, imaxd, ileak, inyx
70
71 ;FILTER ENVELOPE - ALL LEVELS ARE GIVEN IN OCT FORMAT
72 iFAttTim = .1 ;ATTACK TIME
73 iFAttLev = 7 ;ATTACK LEVEL
74 iFDecTim = .1 ;DECAY TIME
75 iFSusLev = 5 ;SUSTAIN LEVEL
76 iFRelTim = 0.01 ;RELEASE TIME
77 ;CREATE AN ENVELOPE WITH A MIDI RELEASE SEGMENT TO INFLUENCE THE FILTER CUTOFF
78 kFEnv linsegr 0, iFAttTim, iFAttLev, iFDecTim, iFSusLev, iFRelTim, 0
79 kCFOct = 6 ;BASE LEVEL OF THE FILTER (BEFORE THE ENVELOPE IS ADDED)
80 kCFcps = cpsoct(kCFOct+kFEnv) ;FINAL FILTER CUTOFF VALUE (IN CPS) INCORPORATING THE FILTER ENVELOPE AND THE FILTER BASE LEVEL
81 kres = .5 ;RESOSNANCE
82 iscale = 1
83 ;CREATE A FILTERED VERSION OF THE OSCILLATOR SIGNAL
84 aFilt moogvcf asig, kCFcps, kres ,iscale
85 ;SEND FILTERED SIGNAL TO OUTPUT
86 aenv linsegr 0,0.001,1,0.01,0 ;ANTI CLICK ENVELOPE
87 outs aFilt * aenv, aFilt * aenv
88 endin
89 </CsInstruments>
90 <CsScore>
91 f 1 0 131072 10 1 ;A SINE WAVE - USED BY BOTH THE VIBRATO AND THE vco
92 f 0 3600 ;DUMMY SCORE EVENT - REAL TIME PERFORMANCE FOR 1 HOUR
93 </CsScore>
94 </CsoundSynthesizer>
95 <bsbPanel>
96 <label>Widgets</label>
97 <objectName/>
98 <x>661</x>
99 <y>241</y>
100 <width>718</width>
101 <height>352</height>
102 <visible>true</visible>
103 <uuid/>
104 <bgcolor mode="background">
105 <r>170</r>
106 <g>170</g>
107 <b>170</b>
108 </bgcolor>
109 <bsbObject version="2" type="BSBLabel">
110 <objectName/>
111 <x>2</x>
112 <y>2</y>
113 <width>711</width>
114 <height>345</height>
115 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
116 <visible>true</visible>
117 <midichan>0</midichan>
118 <midicc>0</midicc>
119 <label>Basic Monophonic MIDI Synthesizer</label>
120 <alignment>center</alignment>
121 <font>Liberation Sans</font>
122 <fontsize>18</fontsize>
123 <precision>3</precision>
124 <color>
125 <r>0</r>
126 <g>0</g>
127 <b>0</b>
128 </color>
129 <bgcolor mode="background">
130 <r>244</r>
131 <g>248</g>
132 <b>200</b>
133 </bgcolor>
134 <bordermode>border</bordermode>
135 <borderradius>5</borderradius>
136 <borderwidth>2</borderwidth>
137 </bsbObject>
138 <bsbObject version="2" type="BSBLabel">
139 <objectName/>
140 <x>7</x>
141 <y>21</y>
142 <width>702</width>
143 <height>259</height>
144 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
145 <visible>true</visible>
146 <midichan>0</midichan>
147 <midicc>0</midicc>
148 <label>--------------------------------------------------------------------------------------------------------------------------
149 You will need to have a midi keyboard connected to the computer for this to work. Monosynths can be implemented using 2 separate instruments and the schedkwhen opcode. The instrument containing the schedkwhen is midi triggered the schedkwhen opcode triggers a second instrument which is the one that actually produces the sound. Crucially the imaxnum parameter (maximum number of simultaneous notes allowed) in the schedkwhen opcode line is set to 1. The active opcode is used (in instr 2) to sense how many notes instr 1 is playing. If instr 1 isn't playing any notes then instr 2 turns itself off. Pitch variables are passed from the first instrument to the second using global variables. Portamento (portk) is used to implement glisandi between overlapping notes.
150 There are two ways in which envelopes can be triggered in monophonic synths:
151 1 - triggered only once, at the beginning of a sequence of overlapping notes.
152 2 - triggered with each new new that is pressed whether overlapping or not.
153 Two different envelopes which illustrate these two situations have been implemented in this example:
154 1 - a filter envelope is put in instrument 2 so that it will only trigger with the first of a series of overlapping notes.
155 2 - a vibrato function (with an vibrato depth envelope) is placed in instr 1 so that it will trigger each time a new note is is pressed whether legato or not.</label>
156 <alignment>left</alignment>
157 <font>Liberation Sans</font>
158 <fontsize>14</fontsize>
159 <precision>3</precision>
160 <color>
161 <r>0</r>
162 <g>0</g>
163 <b>0</b>
164 </color>
165 <bgcolor mode="nobackground">
166 <r>255</r>
167 <g>255</g>
168 <b>255</b>
169 </bgcolor>
170 <bordermode>noborder</bordermode>
171 <borderradius>1</borderradius>
172 <borderwidth>1</borderwidth>
173 </bsbObject>
174 <bsbObject version="2" type="BSBLabel">
175 <objectName/>
176 <x>10</x>
177 <y>288</y>
178 <width>695</width>
179 <height>50</height>
180 <uuid>{b143f42f-2cbc-4532-8df7-4ba643c60b37}</uuid>
181 <visible>true</visible>
182 <midichan>0</midichan>
183 <midicc>0</midicc>
184 <label/>
185 <alignment>left</alignment>
186 <font>Liberation Sans</font>
187 <fontsize>10</fontsize>
188 <precision>3</precision>
189 <color>
190 <r>0</r>
191 <g>0</g>
192 <b>0</b>
193 </color>
194 <bgcolor mode="nobackground">
195 <r>255</r>
196 <g>255</g>
197 <b>255</b>
198 </bgcolor>
199 <bordermode>border</bordermode>
200 <borderradius>5</borderradius>
201 <borderwidth>2</borderwidth>
202 </bsbObject>
203 <bsbObject version="2" type="BSBLabel">
204 <objectName/>
205 <x>12</x>
206 <y>310</y>
207 <width>180</width>
208 <height>30</height>
209 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
210 <visible>true</visible>
211 <midichan>0</midichan>
212 <midicc>0</midicc>
213 <label>Portamento Time</label>
214 <alignment>left</alignment>
215 <font>Liberation Sans</font>
216 <fontsize>10</fontsize>
217 <precision>3</precision>
218 <color>
219 <r>0</r>
220 <g>0</g>
221 <b>0</b>
222 </color>
223 <bgcolor mode="nobackground">
224 <r>255</r>
225 <g>255</g>
226 <b>255</b>
227 </bgcolor>
228 <bordermode>noborder</bordermode>
229 <borderradius>1</borderradius>
230 <borderwidth>1</borderwidth>
231 </bsbObject>
232 <bsbObject version="2" type="BSBHSlider">
233 <objectName>Portamento</objectName>
234 <x>12</x>
235 <y>292</y>
236 <width>689</width>
237 <height>26</height>
238 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
239 <visible>true</visible>
240 <midichan>0</midichan>
241 <midicc>0</midicc>
242 <minimum>0.00000000</minimum>
243 <maximum>1.00000000</maximum>
244 <value>0.06095791</value>
245 <mode>lin</mode>
246 <mouseControl act="jump">continuous</mouseControl>
247 <resolution>-1.00000000</resolution>
248 <randomizable group="0">false</randomizable>
249 </bsbObject>
250 <bsbObject version="2" type="BSBDisplay">
251 <objectName>Portamento</objectName>
252 <x>641</x>
253 <y>310</y>
254 <width>60</width>
255 <height>30</height>
256 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
257 <visible>true</visible>
258 <midichan>0</midichan>
259 <midicc>0</midicc>
260 <label>0.061</label>
261 <alignment>right</alignment>
262 <font>Liberation Sans</font>
263 <fontsize>9</fontsize>
264 <precision>3</precision>
265 <color>
266 <r>0</r>
267 <g>0</g>
268 <b>0</b>
269 </color>
270 <bgcolor mode="nobackground">
271 <r>255</r>
272 <g>255</g>
273 <b>255</b>
274 </bgcolor>
275 <bordermode>noborder</bordermode>
276 <borderradius>1</borderradius>
277 <borderwidth>1</borderwidth>
278 </bsbObject>
279 </bsbPanel>
280 <bsbPresets>
281 </bsbPresets>
282 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>