| 1 |
// Sample for synchronized play (with preset voice). |
|---|
| 2 |
package { |
|---|
| 3 |
import flash.display.Sprite; |
|---|
| 4 |
import flash.events.*; |
|---|
| 5 |
import org.si.sion.*; |
|---|
| 6 |
import org.si.sion.utils.SiONPresetVoice; |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
public class SyncSequence extends Sprite { |
|---|
| 10 |
// driver |
|---|
| 11 |
public var driver:SiONDriver = new SiONDriver(); |
|---|
| 12 |
|
|---|
| 13 |
// preset voice |
|---|
| 14 |
public var presetVoice:SiONPresetVoice = new SiONPresetVoice(); |
|---|
| 15 |
|
|---|
| 16 |
// voice |
|---|
| 17 |
public var voiceClick:SiONVoice; |
|---|
| 18 |
public var voiceKeyOn:SiONVoice; |
|---|
| 19 |
|
|---|
| 20 |
// MML data |
|---|
| 21 |
public var mainMelody:SiONData; |
|---|
| 22 |
public var clickSequence:SiONData; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
// constructor |
|---|
| 26 |
function SyncSequence() { |
|---|
| 27 |
// compile |
|---|
| 28 |
mainMelody = driver.compile("t100 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2") |
|---|
| 29 |
clickSequence = driver.compile("l16v8o6cg<c>g1"); |
|---|
| 30 |
|
|---|
| 31 |
// select voice from preset |
|---|
| 32 |
voiceClick = presetVoice["valsound.piano8"]; |
|---|
| 33 |
voiceKeyOn = presetVoice["valsound.wind1"]; |
|---|
| 34 |
|
|---|
| 35 |
// listen click |
|---|
| 36 |
stage.addEventListener("click", _onClick); |
|---|
| 37 |
stage.addEventListener("keyDown", _onKeyOn); |
|---|
| 38 |
|
|---|
| 39 |
// play main melody |
|---|
| 40 |
driver.play(mainMelody); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
// click to play sequence. with synchronizaion. |
|---|
| 45 |
private function _onClick(e:Event) : void { |
|---|
| 46 |
// play with length=0(play all of sequence), delay=0(no delay), quantize=2(8th beat) |
|---|
| 47 |
driver.sequenceOn(clickSequence, voiceClick, 0, 0, 2); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
// key down ("1" to "9") to play single note |
|---|
| 52 |
private function _onKeyOn(e:KeyboardEvent) : void { |
|---|
| 53 |
// calculate note number (60=o5c=key"1") |
|---|
| 54 |
var noteNum:int = e.charCode - ("1".charCodeAt()) + 60; |
|---|
| 55 |
// key 1-9 to play note |
|---|
| 56 |
if (60<=noteNum && noteNum<=68) { |
|---|
| 57 |
// play with length=1(8th note), delay=0(no delay), quantize=2(8th beat) |
|---|
| 58 |
driver.noteOn(noteNum, voiceKeyOn, 2, 0, 2); |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|