-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSiOPMJavaScriptBridge.as
More file actions
183 lines (144 loc) · 6.47 KB
/
Copy pathSiOPMJavaScriptBridge.as
File metadata and controls
183 lines (144 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.events.*;
import org.si.sion.*;
import org.si.sion.events.*;
import org.si.sion.utils.Translator;
public class SiOPMJavaScriptBridge extends Sprite
{
// variables
//--------------------------------------------------
public var driver:SiONDriver;
public var data:SiONData;
// constructor
//--------------------------------------------------
function SiOPMJavaScriptBridge()
{
Security.allowDomain('*');
driver = new SiONDriver();
data = new SiONData();
driver.autoStop = true;
//new pcmExample(driver);
// register javascript interfaces
ExternalInterface.addCallback("_compile", _compile);
ExternalInterface.addCallback("_play", _play);
ExternalInterface.addCallback("_stop", driver.stop);
ExternalInterface.addCallback("_pause", driver.pause);
ExternalInterface.addCallback("_trans", Translator.tsscp);
ExternalInterface.addCallback("_volume", _volume);
ExternalInterface.addCallback("_pan", _pan);
ExternalInterface.addCallback("_position",_position);
// register handlers
driver.addEventListener(SiONEvent.QUEUE_PROGRESS, _onCompileProgress);
driver.addEventListener(SiONEvent.QUEUE_COMPLETE, _onCompileComplete);
driver.addEventListener(ErrorEvent.ERROR, _onError);
driver.addEventListener(SiONEvent.STREAM, _onStream);
driver.addEventListener(SiONEvent.STREAM_START, _onStreamStart);
driver.addEventListener(SiONEvent.STREAM_STOP, _onStreamStop);
driver.addEventListener(SiONEvent.FADE_IN_COMPLETE, _onFadeInComplete);
driver.addEventListener(SiONEvent.FADE_OUT_COMPLETE, _onFadeOutComplete);
// callback onLoad
ExternalInterface.call('SIOPM._internal_onLoad', SiONDriver.VERSION);
}
// event handlers
//--------------------------------------------------
private function _onCompileProgress(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileProgress', driver.jobProgress); }
private function _onError(e:ErrorEvent) : void { ExternalInterface.call('SIOPM._internal_onError', e.text); }
private function _onStream(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onStream'); }
private function _onStreamStart(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onStreamStart'); }
private function _onStreamStop(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onStreamStop'); }
private function _onCompileComplete(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onCompileComplete', data.title); }
private function _onFadeInComplete(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onFadeInComplete'); }
private function _onFadeOutComplete(e:SiONEvent) : void { ExternalInterface.call('SIOPM._internal_onFadeOutComplete'); }
// callback function
//--------------------------------------------------
private function _compile(mml:*) : Boolean
{
if (mml) {
driver.compileQueue(mml, data);
driver.startQueue(200);
return true;
}
return false;
}
private function _play() : void
{
driver.play(data);
}
private function _volume(v:*) : Number
{
var vol:Number = Number(v);
if (!isNaN(vol)) {
driver.volume = (vol<0) ? 0 : (vol>1) ? 1 : vol;
}
return driver.volume;
}
private function _pan(p:*) : Number
{
var pan:Number = Number(p);
if (!isNaN(pan)) {
driver.pan = (pan<-1) ? -1 : (pan>1) ? 1 : pan;
}
return driver.pan;
}
private function _position(p:*) : Number
{
var pos:Number = Number(p);
if (!isNaN(pos)) {
driver.position = pos;
}
return driver.position;
}
private function _fadeIn(t:*) : void
{
var time:Number = Number(t);
if (!isNaN(time)) {
driver.fadeIn(time);
} else {
driver.fadeIn(3);
}
}
private function _fadeOut(t:*) : void
{
var time:Number = Number(t);
if (!isNaN(time)) {
driver.fadeOut(time);
} else {
driver.fadeOut(3);
}
}
}
}
/*
// special features for sample
import org.si.sion.SiONDriver;
class pcmExample {
[Embed(source="hit.mp3")] private var hit_mp3:Class;
[Embed(source="kick.mp3")] private var kick_mp3:Class;
[Embed(source="sdw.mp3")] private var sdw_mp3:Class;
[Embed(source="sds.mp3")] private var sds_mp3:Class;
[Embed(source="toml.mp3")] private var toml_mp3:Class;
[Embed(source="tomh.mp3")] private var tomh_mp3:Class;
[Embed(source="hatc.mp3")] private var hatc_mp3:Class;
[Embed(source="hath.mp3")] private var hath_mp3:Class;
[Embed(source="hato.mp3")] private var hato_mp3:Class;
[Embed(source="crash.mp3")] private var crash_mp3:Class;
[Embed(source="bell.mp3")] private var bell_mp3:Class;
function pcmExample(driver:SiONDriver)
{
driver.setPCMSound(0, new hit_mp3());
driver.setSamplerSound(60, new kick_mp3()); //o5c
driver.setSamplerSound(62, new sdw_mp3()); //o5d
driver.setSamplerSound(64, new sds_mp3()); //o5e
driver.setSamplerSound(65, new toml_mp3()); //o5f
driver.setSamplerSound(67, new tomh_mp3()); //o5g
driver.setSamplerSound(48, new hatc_mp3()); //o4c
driver.setSamplerSound(50, new hath_mp3()); //o4d
driver.setSamplerSound(52, new hato_mp3()); //o4e
driver.setSamplerSound(53, new crash_mp3()); //o4f
driver.setSamplerSound(55, new bell_mp3()); //o4g
}
}
*/