| 1 |
// Sample for synchronized play 2 (start and stop) |
|---|
| 2 |
package { |
|---|
| 3 |
import flash.display.*; |
|---|
| 4 |
import flash.events.*; |
|---|
| 5 |
import org.si.sion.*; |
|---|
| 6 |
import org.si.sion.events.*; |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
public class SyncSequence2 extends Sprite { |
|---|
| 10 |
// driver |
|---|
| 11 |
public var driver:SiONDriver = new SiONDriver(); |
|---|
| 12 |
|
|---|
| 13 |
// voice (%5,0(sine wave) with attackRate=63 and releaseRate=32) |
|---|
| 14 |
public var sinVoice:SiONVoice = new SiONVoice(5,0,63,32); |
|---|
| 15 |
|
|---|
| 16 |
// MML data |
|---|
| 17 |
public var mainMelody:SiONData; |
|---|
| 18 |
public var arpegio:SiONData; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
// constructor |
|---|
| 22 |
function SyncSequence2() { |
|---|
| 23 |
// compile with event trigger command (%t) |
|---|
| 24 |
mainMelody = driver.compile("t100 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2"); |
|---|
| 25 |
// loops infinitly by "$" command |
|---|
| 26 |
arpegio = driver.compile("o6q1l16$c<c>g<g>;o4l4s28,-32q0$c"); |
|---|
| 27 |
|
|---|
| 28 |
// listen triggers |
|---|
| 29 |
stage.addEventListener("mouseDown", _onMouseDown); |
|---|
| 30 |
stage.addEventListener("mouseUp", _onMouseUp); |
|---|
| 31 |
|
|---|
| 32 |
// play main melody |
|---|
| 33 |
driver.play(mainMelody); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
private function _onMouseDown(e:MouseEvent) : void { |
|---|
| 38 |
// play sequence with track id of 1. And you can get delay time from returned value. |
|---|
| 39 |
var delay:Number = driver.sequenceOn(arpegio, sinVoice, 0, 0, 4, 1)/44.1; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
private function _onMouseUp(e:MouseEvent) : void { |
|---|
| 44 |
// stop track with the id of 1. stop without synchronization. |
|---|
| 45 |
driver.sequenceOff(1); |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|