1<CsoundSynthesizer> 2<CsOptions> 3-+max_str_len=10000 4</CsOptions> 5<CsInstruments> 6 7/****SOUNDFILE MERGER**** 8joachim heintz june 2010**/ 9 100dbfs = 1 11ksmps = 128; if you want to avoid that some samples without sound are added at the end of the soundfile, use ksmps=1. but this will be slow for large files 12nchnls = 8; THIS DETERMINES THE NUMBER OF CHANNELS IN YOUR MERGE FILE 13 14 opcode StrayGetEl, ii, Sijj 15;returns the startindex and the endindex (= the first space after the element) for ielindex in String. if startindex returns -1, the element has not been found 16Stray, ielindx, isepA, isepB xin 17;;DEFINE THE SEPARATORS 18isep1 = (isepA == -1 ? 32 : isepA) 19isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB)) 20Sep1 sprintf "%c", isep1 21Sep2 sprintf "%c", isep2 22;;INITIALIZE SOME PARAMETERS 23ilen strlen Stray 24istartsel = -1; startindex for searched element 25iendsel = -1; endindex for searched element 26iel = 0; actual number of element while searching 27iwarleer = 1 28indx = 0 29 if ilen == 0 igoto end ;don't go into the loop if Stray is empty 30loop: 31Snext strsub Stray, indx, indx+1; next sign 32isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1 33isep2p strcmp Snext, Sep2; 0 if Snext is sep2 34;;NEXT SIGN IS NOT SEP1 NOR SEP2 35if isep1p != 0 && isep2p != 0 then 36 if iwarleer == 1 then; first character after a separator 37 if iel == ielindx then; if searched element index 38istartsel = indx; set it 39iwarleer = 0 40 else ;if not searched element index 41iel = iel+1; increase it 42iwarleer = 0; log that it's not a separator 43 endif 44 endif 45;;NEXT SIGN IS SEP1 OR SEP2 46else 47 if istartsel > -1 then; if this is first selector after searched element 48iendsel = indx; set iendsel 49 igoto end ;break 50 else 51iwarleer = 1 52 endif 53endif 54 loop_lt indx, 1, ilen, loop 55end: xout istartsel, iendsel 56 endop 57 58 opcode StrayLen, i, Sjj 59;returns the number of elements in Stray. elements are defined by two separators as ASCII coded characters: isep1 defaults to 32 (= space), isep2 defaults to 9 (= tab). if just one separator is used, isep2 equals isep1 60Stray, isepA, isepB xin 61;;DEFINE THE SEPARATORS 62isep1 = (isepA == -1 ? 32 : isepA) 63isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB)) 64Sep1 sprintf "%c", isep1 65Sep2 sprintf "%c", isep2 66;;INITIALIZE SOME PARAMETERS 67ilen strlen Stray 68icount = 0; number of elements 69iwarsep = 1 70indx = 0 71 if ilen == 0 igoto end ;don't go into the loop if String is empty 72loop: 73Snext strsub Stray, indx, indx+1; next sign 74isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1 75isep2p strcmp Snext, Sep2; 0 if Snext is sep2 76 if isep1p == 0 || isep2p == 0 then; if sep1 or sep2 77iwarsep = 1; tell the log so 78 else ; if not 79 if iwarsep == 1 then ; and has been sep1 or sep2 before 80icount = icount + 1; increase counter 81iwarsep = 0; and tell you are ot sep1 nor sep2 82 endif 83 endif 84 loop_lt indx, 1, ilen, loop 85end: xout icount 86 endop 87 88 opcode Merge, 0, Sii 89Stray, inels, iel xin 90ist, ien StrayGetEl Stray, iel, 124 91Sel strsub Stray, ist, ien 92asig soundin Sel 93 outch iel+1, asig 94 if iel+1 < inels then 95 Merge Stray, inels, iel+1 96 endif 97 endop 98 99 100instr 1 101;user input 102Stray invalue "_MBrowse"; filenames, separated by '|' 103;get length from first element 104ist, ien StrayGetEl Stray, 0, 124; get first element 105Sfirst strsub Stray, ist, ien 106idur filelen Sfirst 107p3 = (ksmps == 1 ? idur : idur + ksmps/sr); avoid omitting samples at the end 108;merge 109inels StrayLen Stray, 124; number of input files 110 if inels > nchnls then 111 prints "WARNING!%nNUMBER OF INPUT FILES (%d) ARE GREATER THAN NUMBER OF OUTPUT CHANNELS (%d)!%nNOT ALL INPUT FILES WILL BE WRITTEN. ADJUST THE nchnls PARAMETER IN THE ORCHESTRA HEADER TO AVOID THIS.%n", inels, nchnls 112 elseif inels < nchnls then; probably crashing 113 prints "ERROR!%nNUMBER OF INPUT FILES (%d) ARE GREATER THAN NUMBER OF OUTPUT CHANNELS (%d)!%nPLEASE ADJUST THE nchnls PARAMETER IN THE ORCHESTRA HEADER!%n" 114 turnoff 115 endif 116 Merge Stray, inels, 0 117endin 118</CsInstruments> 119<CsScore> 120i 1 0 1 121e 122</CsScore> 123</CsoundSynthesizer> 124 125<bsbPanel> 126 <label>Widgets</label> 127 <objectName/> 128 <x>313</x> 129 <y>195</y> 130 <width>464</width> 131 <height>325</height> 132 <visible>true</visible> 133 <uuid/> 134 <bgcolor mode="background"> 135 <r>170</r> 136 <g>170</g> 137 <b>127</b> 138 </bgcolor> 139 <bsbObject version="2" type="BSBButton"> 140 <objectName>_MBrowse</objectName> 141 <x>364</x> 142 <y>69</y> 143 <width>100</width> 144 <height>30</height> 145 <uuid>{6d6f3649-5d94-4759-afc8-887cc1872c39}</uuid> 146 <visible>true</visible> 147 <midichan>0</midichan> 148 <midicc>-3</midicc> 149 <type>value</type> 150 <pressedValue>1.00000000</pressedValue> 151 <stringvalue/> 152 <text>Select Files</text> 153 <image>/</image> 154 <eventLine/> 155 <latch>false</latch> 156 <latched>false</latched> 157 </bsbObject> 158 <bsbObject version="2" type="BSBLineEdit"> 159 <objectName>_MBrowse</objectName> 160 <x>17</x> 161 <y>72</y> 162 <width>345</width> 163 <height>24</height> 164 <uuid>{dcd7f769-c32b-4cc8-bc82-9848d5b36937}</uuid> 165 <visible>true</visible> 166 <midichan>0</midichan> 167 <midicc>-3</midicc> 168 <label/> 169 <alignment>left</alignment> 170 <font>Lucida Grande</font> 171 <fontsize>12</fontsize> 172 <precision>3</precision> 173 <color> 174 <r>0</r> 175 <g>0</g> 176 <b>0</b> 177 </color> 178 <bgcolor mode="nobackground"> 179 <r>206</r> 180 <g>206</g> 181 <b>206</b> 182 </bgcolor> 183 <background>nobackground</background> 184 </bsbObject> 185 <bsbObject version="2" type="BSBButton"> 186 <objectName>_Render</objectName> 187 <x>104</x> 188 <y>104</y> 189 <width>184</width> 190 <height>30</height> 191 <uuid>{a9b11523-b4f3-419f-8637-88da098e53f3}</uuid> 192 <visible>true</visible> 193 <midichan>0</midichan> 194 <midicc>-3</midicc> 195 <type>value</type> 196 <pressedValue>1.00000000</pressedValue> 197 <stringvalue/> 198 <text>Merge!</text> 199 <image>/</image> 200 <eventLine>i1 0 10</eventLine> 201 <latch>false</latch> 202 <latched>true</latched> 203 </bsbObject> 204 <bsbObject version="2" type="BSBLabel"> 205 <objectName/> 206 <x>85</x> 207 <y>16</y> 208 <width>335</width> 209 <height>39</height> 210 <uuid>{46df577d-4fc5-4d07-a9cb-08d73733ad30}</uuid> 211 <visible>true</visible> 212 <midichan>0</midichan> 213 <midicc>-3</midicc> 214 <label>SOUNDFILE MERGER</label> 215 <alignment>center</alignment> 216 <font>Arial</font> 217 <fontsize>24</fontsize> 218 <precision>3</precision> 219 <color> 220 <r>0</r> 221 <g>0</g> 222 <b>0</b> 223 </color> 224 <bgcolor mode="nobackground"> 225 <r>255</r> 226 <g>255</g> 227 <b>255</b> 228 </bgcolor> 229 <bordermode>noborder</bordermode> 230 <borderradius>1</borderradius> 231 <borderwidth>1</borderwidth> 232 </bsbObject> 233 <bsbObject version="2" type="BSBLabel"> 234 <objectName/> 235 <x>19</x> 236 <y>147</y> 237 <width>445</width> 238 <height>178</height> 239 <uuid>{e54e17da-3808-49a3-84a6-608f476c3200}</uuid> 240 <visible>true</visible> 241 <midichan>0</midichan> 242 <midicc>0</midicc> 243 <label>Merges any number of mono files to a multichannel file. The number of channels in the output file is determined by the 'nchnls' parameter in the header of this CSD file. 244MAKE SURE YOUR nchnls EQUALS THE NUMBER OF YOU INPUT FILES! (If nchnls=8 but you just gave 7 mono files as input, it will probably crash.) 245The merge file will be written as specified in the Configure > Run tab ("Output Filename").</label> 246 <alignment>left</alignment> 247 <font>Arial</font> 248 <fontsize>14</fontsize> 249 <precision>3</precision> 250 <color> 251 <r>0</r> 252 <g>0</g> 253 <b>0</b> 254 </color> 255 <bgcolor mode="nobackground"> 256 <r>255</r> 257 <g>255</g> 258 <b>255</b> 259 </bgcolor> 260 <bordermode>noborder</bordermode> 261 <borderradius>1</borderradius> 262 <borderwidth>1</borderwidth> 263 </bsbObject> 264</bsbPanel> 265<bsbPresets> 266</bsbPresets> 267<EventPanel name="" tempo="60.00000000" loop="8.00000000" x="360" y="248" width="612" height="322" visible="false" loopStart="0" loopEnd="0"> </EventPanel> 268