Changeset 20421
- Timestamp:
- 10/02/08 01:32:37 (3 months ago)
- Location:
- lang/actionscript/flmml/trunk/src
- Files:
-
- 8 modified
-
com/txt_nifty/sketch/flmml/MChannel.as (modified) (7 diffs)
-
com/txt_nifty/sketch/flmml/MEvent.as (modified) (2 diffs)
-
com/txt_nifty/sketch/flmml/MML.as (modified) (7 diffs)
-
com/txt_nifty/sketch/flmml/MSequencer.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MStatus.as (modified) (1 diff)
-
com/txt_nifty/sketch/flmml/MTrack.as (modified) (2 diffs)
-
com/txt_nifty/sketch/flmml/MWarning.as (modified) (1 diff)
-
flmml.swf (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MChannel.as
r15293 r20421 26 26 private var m_lpfRes:Number; 27 27 private var m_volMode:int; 28 private var m_inSens:int; 29 private var m_inPipe:int; 30 private var m_outMode:int; 31 private var m_outPipe:int; 28 32 public static var PITCH_RESOLUTION:int = 100; 29 33 protected static var s_init:int = 0; … … 33 37 protected static var s_volumeLen:int; 34 38 protected static var s_samples:Array; 39 protected static var s_pipeArr:Array; 35 40 36 41 public function MChannel() { … … 58 63 m_lpfRes = 0; 59 64 m_volMode = 0; 65 setInput(0, 0); 66 setOutput(0, 0); 60 67 } 61 68 public static function boot(numSamples:int):void { … … 75 82 } 76 83 s_samples = new Array(numSamples); 84 } 85 public static function createPipes(num:int):void { 86 s_pipeArr = new Array(num); 87 for (var i:int = 0; i < num; i++) { 88 s_pipeArr[i] = new Array(s_samples.length); 89 for (var j:int = 0; j < s_samples.length; j++) { 90 var arr:Array = s_pipeArr[i]; 91 arr[j] = 0; 92 } 93 } 77 94 } 78 95 public static function getFrequency(freqNo:int):Number { … … 169 186 public function setVolMode(m:int):void { 170 187 m_volMode = m; 188 } 189 public function setInput(i:int, p:int):void { 190 m_inSens = i * 100; 191 m_inPipe = p; 192 } 193 public function setOutput(o:int, p:int):void { 194 m_outMode = o; 195 m_outPipe = p; 171 196 } 172 197 protected function getNextSampleLinear():Number { … … 189 214 var freqNo:int; 190 215 var i:int; 216 var arr:Array; 191 217 if (end >= max) end = max; 192 218 var key:Number = m_oscillator1.getFrequency(); 193 if (m_osc2Connect == 0) { 194 // no LFO 195 m_oscillator1.getSamples(s_samples, start, end); 196 if (m_volMode == 0) m_envelope1.ampSamplesLinear(s_samples, start, end, m_velocity); 197 else m_envelope1.ampSamplesNonLinear(s_samples, start, end, m_velocity); 198 } 219 if (m_inSens == 0) { 220 if (m_osc2Connect == 0) { 221 // no input, no LFO 222 m_oscillator1.getSamples(s_samples, start, end); 223 if (m_volMode == 0) m_envelope1.ampSamplesLinear(s_samples, start, end, m_velocity); 224 else m_envelope1.ampSamplesNonLinear(s_samples, start, end, m_velocity); 225 } 226 else { 227 // no input, with LFO, linear 228 if (m_volMode == 0) { 229 for(i = start; i < end; i++) { 230 freqNo = m_freqNo; 231 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 232 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 233 } 234 m_oscillator1.setFrequency(getFrequency(freqNo)); 235 s_samples[i] = getNextSampleLinear(); 236 m_onCounter++; 237 } 238 } 239 // no input, with LFO, non linear 240 else { 241 for(i = start; i < end; i++) { 242 freqNo = m_freqNo; 243 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 244 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 245 } 246 m_oscillator1.setFrequency(getFrequency(freqNo)); 247 s_samples[i] = getNextSampleNonLinear(); 248 m_onCounter++; 249 } 250 } 251 } 252 } 253 // with input 199 254 else { 200 // with LFO, linear 201 if (m_volMode == 0) { 202 for(i = start; i < end; i++) { 203 freqNo = m_freqNo; 204 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 205 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 206 } 207 m_oscillator1.setFrequency(getFrequency(freqNo)); 208 s_samples[i] = getNextSampleLinear(); 209 m_onCounter++; 210 } 211 } 212 // with LFO, non linear 255 //trace("input "+m_inPipe); 256 if (m_osc2Connect == 0) { 257 // with input, no LFO 258 arr = s_pipeArr[m_inPipe]; 259 freqNo = getFrequency(m_freqNo); 260 if (m_volMode == 0) { 261 for(i = start; i < end; i++) { 262 m_oscillator1.setFrequency(freqNo + arr[i] * m_inSens); 263 s_samples[i] = getNextSampleLinear(); 264 } 265 } 266 else { 267 for(i = start; i < end; i++) { 268 m_oscillator1.setFrequency(freqNo + arr[i] * m_inSens); 269 s_samples[i] = getNextSampleNonLinear(); 270 } 271 } 272 } 213 273 else { 214 for(i = start; i < end; i++) { 215 freqNo = m_freqNo; 216 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 217 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 218 } 219 m_oscillator1.setFrequency(getFrequency(freqNo)); 220 s_samples[i] = getNextSampleNonLinear(); 221 m_onCounter++; 274 // with input, with LFO, linear 275 if (m_volMode == 0) { 276 arr = s_pipeArr[m_inPipe]; 277 for(i = start; i < end; i++) { 278 freqNo = m_freqNo; 279 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 280 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 281 } 282 m_oscillator1.setFrequency(getFrequency(freqNo) + arr[i] * m_inSens); 283 s_samples[i] = getNextSampleLinear(); 284 m_onCounter++; 285 } 286 } 287 // with input, with LFO, non linear 288 else { 289 arr = s_pipeArr[m_inPipe]; 290 for(i = start; i < end; i++) { 291 freqNo = m_freqNo; 292 if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 293 freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 294 } 295 m_oscillator1.setFrequency(getFrequency(freqNo) + arr[i] * m_inSens); 296 s_samples[i] = getNextSampleNonLinear(); 297 m_onCounter++; 298 } 222 299 } 223 300 } … … 225 302 m_formant.run(s_samples, start, end); 226 303 m_filter.run(s_samples, start, end, m_envelope2, m_lpfFrq, m_lpfAmt, m_lpfRes, key); 227 for(i = start; i < end; i++) { 228 amplitude = s_samples[i]; 229 sample = samples[i]; 230 sample.left += amplitude * m_panL; 231 sample.right += amplitude * m_panR; 304 switch(m_outMode) { 305 case 0: 306 //trace("output audio"); 307 for(i = start; i < end; i++) { 308 amplitude = s_samples[i]; 309 sample = samples[i]; 310 sample.left += amplitude * m_panL; 311 sample.right += amplitude * m_panR; 312 } 313 break; 314 case 1: // overwrite 315 //trace("output "+m_outPipe); 316 arr = s_pipeArr[m_outPipe]; 317 for(i = start; i < end; i++) { 318 arr[i] = s_samples[i]; 319 } 320 break; 321 case 2: // add 322 arr = s_pipeArr[m_outPipe]; 323 for(i = start; i < end; i++) { 324 arr[i] += s_samples[i]; 325 } 326 break; 327 default: 328 break; 232 329 } 233 330 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MEvent.as
r15293 r20421 40 40 public function setClose():void { set(MStatus.CLOSE, 0, 0); } 41 41 public function setVolMode(m:int):void { set(MStatus.VOL_MODE, m, 0); } 42 public function setInput(sens:int, pipe:int):void { set(MStatus.INPUT, sens, pipe); } 43 public function setOutput(mode:int, pipe:int):void { set(MStatus.OUTPUT, mode, pipe); } 42 44 public function setDelta(delta:int):void { m_delta = delta; } 43 45 public function getStatus():int { return m_status; } … … 68 70 public function getLPFRes():int { return m_data1; } 69 71 public function getVolMode():int { return m_data0; } 72 public function getInputSens():int { return m_data0; } 73 public function getInputPipe():int { return m_data1; } 74 public function getOutputMode():int { return m_data0; } 75 public function getOutputPipe():int { return m_data1; } 70 76 } 71 77 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MML.as
r19331 r20421 21 21 protected var m_noteShift:int; 22 22 protected var m_warning:String; 23 protected var m_maxPipe:int; 24 protected static var MAX_PIPE:int = 3; 23 25 24 26 public function MML() { … … 191 193 m_tracks[m_trackNo].recGate2(getUInt(2) * 2); // '*2' according to TSSCP 192 194 break; 195 /*case 'i': // Input 196 { 197 var sens:int = 0; 198 next(); 199 sens = getUInt(sens); 200 if (getChar() == ',') { 201 next(); 202 a = getUInt(a); 203 if (a > m_maxPipe) a = m_maxPipe; 204 } 205 m_tracks[m_trackNo].recInput(sens, a); 206 } 207 // @i[n],[m] m:pipe no 208 // if (n == 0) off 209 // else sensitivity = n (max:8) 210 break; 211 case 'o': // Output 212 { 213 var mode:int = 0; 214 next(); 215 mode = getUInt(mode); 216 if (getChar() == ',') { 217 next(); 218 a = getUInt(a); 219 if (a > m_maxPipe) { 220 m_maxPipe = a; 221 if (m_maxPipe >= MAX_PIPE) m_maxPipe = a = MAX_PIPE; 222 } 223 } 224 m_tracks[m_trackNo].recOutput(mode, a); 225 } 226 // @o[n],[m] m:pipe no 227 // if (n == 0) off 228 // if (n == 1) overwrite 229 // if (n == 2) add 230 break;*/ 193 231 default: 194 232 m_form = getUInt(m_form); … … 436 474 } 437 475 438 protected function macroInMacro(str:String, idArr:Array, valArr:Array):String { 476 protected function macroInMacro(str:String, idArr:Array, valArr:Array, id0:String):String { 477 var idx:int; 439 478 for(var i:int = 0; i < idArr.length; i++) { 440 479 var id:String = "$"+idArr[i]; 441 480 //trace("id:"+id); 442 var idx:int= str.indexOf(id);481 idx = str.indexOf(id); 443 482 while(idx >= 0) { 444 483 str = str.substring(0, idx) + valArr[i] + str.substring(idx + id.length); 445 484 idx = str.indexOf(id, idx); 446 485 } 486 } 487 // recursive call is prevented. 488 id0 = "$" + id0; 489 idx = str.indexOf(id0); 490 while(idx >= 0) { 491 str = str.substring(0, idx) + valArr[i] + str.substring(idx + id0.length); 492 idx = str.indexOf(id0, idx); 493 warning(MWarning.RECURSIVE_MACRO, id0); 447 494 } 448 495 return str; … … 454 501 var idArr:Array = new Array(); 455 502 var valArr:Array = new Array(); 456 var i:int;457 503 var last:int; 458 504 // [a-zA-Z][a-zA-Z0-9#\+\(\)_]* … … 483 529 // first definition 484 530 if (idx < 0) { 485 token[1] = macroInMacro(token[1], idArr, valArr );531 token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 486 532 //trace("define $"+id[i]+"="+token[1]); 487 insertLenOrder(idArr, valArr, id[ i], token[1]);533 insertLenOrder(idArr, valArr, id[0], token[1]); 488 534 } 489 535 // macro redefinition 490 536 else { 491 token[1] = macroInMacro(token[1], idArr, valArr );537 token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 492 538 //trace("redefine $"+id[i]+"="+token[1]); 493 539 valArr[idx] = token[1]; … … 592 638 m_form = MOscillator.PULSE; 593 639 m_noteShift = 0; 640 m_maxPipe = 0; 594 641 595 642 processComment(str); … … 616 663 m_sequencer.connect(m_tracks[i]); 617 664 } 665 m_sequencer.createPipes(m_maxPipe+1); 618 666 619 667 // dispatch event -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MSequencer.as
r15293 r20421 157 157 //trace((endtime.getTime() - starttime.getTime()) + "msec."); 158 158 } 159 160 public function createPipes(num:int):void { 161 MChannel.createPipes(num); 162 } 159 163 } 160 164 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MStatus.as
r18579 r20421 25 25 public static const ENVELOPE2_AD:int = 22; 26 26 public static const ENVELOPE2_SR:int = 23; 27 public static const INPUT:int = 24; 28 public static const OUTPUT:int = 25; 27 29 } 28 30 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MTrack.as
r19332 r20421 128 128 m_ch.setVolMode(e.getVolMode()); 129 129 break; 130 case MStatus.INPUT: 131 m_ch.setInput(e.getInputSens(), e.getInputPipe()); 132 break; 133 case MStatus.OUTPUT: 134 m_ch.setOutput(e.getOutputMode(), e.getOutputPipe()); 135 break; 130 136 case MStatus.CLOSE: 131 137 m_ch.close(); … … 345 351 recDelta(e); 346 352 e.setVolMode(m); 353 m_events.push(e); 354 } 355 356 public function recInput(sens:int, pipe:int):void { 357 var e:MEvent = new MEvent(); 358 recDelta(e); 359 e.setInput(sens, pipe); 360 m_events.push(e); 361 } 362 363 public function recOutput(mode:int, pipe:int):void { 364 var e:MEvent = new MEvent(); 365 recDelta(e); 366 e.setOutput(mode, pipe); 347 367 m_events.push(e); 348 368 } -
lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MWarning.as
r2293 r20421 5 5 public static const UNOPENED_COMMENT:int = 2; 6 6 public static const UNCLOSED_COMMENT:int = 3; 7 public static const RECURSIVE_MACRO:int = 4; 7 8 public static const s_string:Array = [ 8 9 "対応していないコマンド '%s' があります。", 9 10 "終わりが見つからない繰り返しがあります。", 10 11 "始まりが見つからないコメントがあります。", 11 "終わりが見つからないコメントがあります。" 12 "終わりが見つからないコメントがあります。", 13 "マクロが再帰的に呼び出されています。", 12 14 ]; 13 15 public static function getString(warnId:int, str:String):String {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)