Debian Codegraph @

src/Examples/McCurdy Collection/MIDI/MIDIControllerInitialisation.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 ; Add kvolume display
8
9
10 ;my flags on Ubuntu: -dm0 -odac -+rtaudio=alsa -b1024 -B2048 -+rtmidi=alsa -Ma
11 <CsoundSynthesizer>
12 <CsOptions>
13
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100 ;SAMPLE RATE
17 ksmps = 2 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
18 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
19 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
20
21
22 ;The opcode 'initc7' initialises a continuous controller to a specified location between its minimum and maximum value.
23
24 ;This initialisation value is expressed as a propotion of how far along its path from minimum to maximum it should begin and is therefore always a number in the range 0-1.
25 ;A value of 0 would imply that the slider begins at its lowest setting.
26 ;A value of 1 would imply that the slider begins at its highest setting.
27 ;A value of .5 would imply that the slider begins halfway along its track.
28
29 ;If you require a midi controlled variable to begin at a specific value the required initialisation value can be calculated using the formula shown below.
30 ;Initialisation defaults to 0 so if you require a controller to begin at minimum it is not necessary to initialise it.
31
32 ;NOTE THAT ONCE A SLIDER IS PHYSICALLY MOVED ITS CORRESPONDING CSOUND VARIABLE IMMEDIATELY JUMPS TO THAT NEW VALUE
33
34 ;NOTE ALSO THAT THIS INITIALISATION STATEMENT IS PLACED BETWEEN THE HEADER STATEMENTS AND THE FIRST INSTRUMENT DEFINITION (known as the instr 0 definition)
35 ;- THIS MEANS THAT THE CONTROLLER WILL BE INITIALISED UPON BEGINNING THE CSOUND SESSION *ONLY*
36 ;IF THE INITIALISATION STATEMENT IS PLACED WITHIN THE INSTRUMENT CODE ITSELF IT WILL REINITIALISE EACH TIME A NEW NOTE IS PLAYED
37
38 ; MIDICHANNEL | CTRLNUMBER | VALUE(0-1)
39 initc7 1, 1, 1
40
41 ;**************************************************************************************
42 ;* *
43 ;* Desired_Controller_Value - Controller_Minimum *
44 ;* Initial__Value = _____________________________________________________ *
45 ;* *
46 ;* Controller_Maximum - Controller_Minimum *
47 ;* *
48 ;**************************************************************************************
49
50
51 instr 1 ; SIMPLE BEEP INSTRUMENT - CAN BE ACTIVATED VIA A CONNECTED MIDI KEYBOARD
52 icps cpsmidi
53 iamp ampmidi 0.2
54
55 ;OUTPUT OPCODE CHANNEL | CTRLNUMBER | MINIMUM | MAXIMUM
56 kvolume ctrl7 1, 1, 0, 1 ;READ CONTROLLER INFORMATION FROM CONTINUOUS CONTROLLER NUMBER 1 ON MIDI CHANNEL 1 AND RESCALE TO BE WITHIN THE RANGE 0 - 1
57
58 kporttime linseg 0, .001, .01, 1, .01 ;CREATE A RAMPING UP FUNCTION THAT WILL BE USED FOR PORTAMENTO TIME - THIS WILL PREVENT PORTAMENTO-ED VARIABLES FROM GLIDING UP TO THEIR DESIRED VALUES AT NOTE ONSETS
59 kvolume portk kvolume, kporttime ;APPLY PORTAMENTO TO kvolume TO SMOOTH ITS MOVEMENT
60
61 outvalue "ctrl1",kvolume
62
63 ; INITIAL_LEVEL | ATTACK_TIME | ATTACK_LEVEL | DECAY_TIME | SUSTAIN_LEVEL | RELEASE_TIME | RELEASE_LEVEL
64 aenv linsegr 0, (.01), 1, (.1), .7, (.05), 0
65
66 asig oscili iamp,icps, 1
67 outs asig * aenv * kvolume, asig * aenv * kvolume
68 endin
69 </CsInstruments>
70 <CsScore>
71 f 1 0 1024 10 1 ; SINE WAVE
72 f 0 600 ; THIS LINE FUNCTIONS AS A DUMMY SCORE EVENT AND ALLOWS REALTIME MIDI PLAYING FOR 10 MINUTES
73 </CsScore>
74 </CsoundSynthesizer>
75 <bsbPanel>
76 <label>Widgets</label>
77 <objectName/>
78 <x>726</x>
79 <y>332</y>
80 <width>612</width>
81 <height>371</height>
82 <visible>true</visible>
83 <uuid/>
84 <bgcolor mode="nobackground">
85 <r>170</r>
86 <g>170</g>
87 <b>170</b>
88 </bgcolor>
89 <bsbObject version="2" type="BSBLabel">
90 <objectName/>
91 <x>2</x>
92 <y>2</y>
93 <width>760</width>
94 <height>369</height>
95 <uuid>{c37e13f6-7642-465f-9b2a-f059eef7bce8}</uuid>
96 <visible>true</visible>
97 <midichan>0</midichan>
98 <midicc>0</midicc>
99 <label>initc7 - Setting an Initial Value for a Continuous Controller</label>
100 <alignment>center</alignment>
101 <font>Liberation Sans</font>
102 <fontsize>18</fontsize>
103 <precision>3</precision>
104 <color>
105 <r>0</r>
106 <g>0</g>
107 <b>0</b>
108 </color>
109 <bgcolor mode="background">
110 <r>244</r>
111 <g>248</g>
112 <b>200</b>
113 </bgcolor>
114 <bordermode>border</bordermode>
115 <borderradius>5</borderradius>
116 <borderwidth>2</borderwidth>
117 </bsbObject>
118 <bsbObject version="2" type="BSBLabel">
119 <objectName/>
120 <x>3</x>
121 <y>24</y>
122 <width>600</width>
123 <height>290</height>
124 <uuid>{e41f02b8-6ad4-46dc-805c-0b2eeafbd476}</uuid>
125 <visible>true</visible>
126 <midichan>0</midichan>
127 <midicc>0</midicc>
128 <label>----------------------------------------------------------------------------------------------------------------------------------------------------
129 This example builds upon the previous example in that it demonstrates how to set the initial value of a continuous controller used in a csound orchestra. If no initial value is defined then then a ctrl7's output defaults to its minimum value. The opcode initc7 is used to set an initial value for ctrl7. Initc7 is normally placed in the instrument 0 part of the orchestra (after the orchestra header and before the first instrument) so that the controller is initialised only when the orchestra is started. If it is placed within an instrument then it will be initialised each time that instrument is activated - it is unlikely that this will be the desired behaviour. Giving initc7 an intialisation value is not entirely straightforward. We cannot give initc7 the actual value we desire as because initc7 appears before ctrl7 csound does not yet know the range of the controller. Instead, initc7 expects a value within the range 0 - 1, with a value of 0 representing the controller's minimum setting and a value of 1 representing the controller's maximum setting. Csound will subsequently adjust this value when it encounters the ctrl7 line of code. Normally we are more concerned with the precise value of ctrl7's output therefore it is useful to use the formula given in the csd to calculate the corresponding value to give initc7.
130 In this example the volume controller is initialised to its maximum setting and initc7 is therefore given the value '1' for an initial state.</label>
131 <alignment>left</alignment>
132 <font>Liberation Sans</font>
133 <fontsize>14</fontsize>
134 <precision>3</precision>
135 <color>
136 <r>0</r>
137 <g>0</g>
138 <b>0</b>
139 </color>
140 <bgcolor mode="nobackground">
141 <r>255</r>
142 <g>255</g>
143 <b>255</b>
144 </bgcolor>
145 <bordermode>noborder</bordermode>
146 <borderradius>1</borderradius>
147 <borderwidth>1</borderwidth>
148 </bsbObject>
149 <bsbObject version="2" type="BSBLabel">
150 <objectName/>
151 <x>8</x>
152 <y>314</y>
153 <width>188</width>
154 <height>50</height>
155 <uuid>{b143f42f-2cbc-4532-8df7-4ba643c60b37}</uuid>
156 <visible>true</visible>
157 <midichan>0</midichan>
158 <midicc>0</midicc>
159 <label/>
160 <alignment>left</alignment>
161 <font>Liberation Sans</font>
162 <fontsize>10</fontsize>
163 <precision>3</precision>
164 <color>
165 <r>0</r>
166 <g>0</g>
167 <b>0</b>
168 </color>
169 <bgcolor mode="nobackground">
170 <r>255</r>
171 <g>255</g>
172 <b>255</b>
173 </bgcolor>
174 <bordermode>border</bordermode>
175 <borderradius>5</borderradius>
176 <borderwidth>2</borderwidth>
177 </bsbObject>
178 <bsbObject version="2" type="BSBDisplay">
179 <objectName>ctrl1</objectName>
180 <x>89</x>
181 <y>326</y>
182 <width>80</width>
183 <height>25</height>
184 <uuid>{f8119d82-f052-4a86-8790-440c42c5d41d}</uuid>
185 <visible>true</visible>
186 <midichan>0</midichan>
187 <midicc>0</midicc>
188 <label>1.000</label>
189 <alignment>left</alignment>
190 <font>Liberation Sans</font>
191 <fontsize>12</fontsize>
192 <precision>3</precision>
193 <color>
194 <r>255</r>
195 <g>0</g>
196 <b>0</b>
197 </color>
198 <bgcolor mode="nobackground">
199 <r>255</r>
200 <g>255</g>
201 <b>255</b>
202 </bgcolor>
203 <bordermode>noborder</bordermode>
204 <borderradius>1</borderradius>
205 <borderwidth>1</borderwidth>
206 </bsbObject>
207 <bsbObject version="2" type="BSBLabel">
208 <objectName/>
209 <x>19</x>
210 <y>324</y>
211 <width>73</width>
212 <height>31</height>
213 <uuid>{4dc3e62f-8cd7-48cb-8f7f-25878ba3b97e}</uuid>
214 <visible>true</visible>
215 <midichan>0</midichan>
216 <midicc>0</midicc>
217 <label>kvolume:</label>
218 <alignment>right</alignment>
219 <font>Liberation Sans</font>
220 <fontsize>14</fontsize>
221 <precision>3</precision>
222 <color>
223 <r>255</r>
224 <g>0</g>
225 <b>0</b>
226 </color>
227 <bgcolor mode="nobackground">
228 <r>255</r>
229 <g>255</g>
230 <b>255</b>
231 </bgcolor>
232 <bordermode>noborder</bordermode>
233 <borderradius>1</borderradius>
234 <borderwidth>1</borderwidth>
235 </bsbObject>
236 </bsbPanel>
237 <bsbPresets>
238 </bsbPresets>