public virtual void HandleWorkerMessage(DOMEvent e) { var data = e.As <MessageEvent>().data; var cmd = data.Member("cmd").As <string>(); switch (cmd) { case AlphaSynthWebWorker.CmdReady: _workerIsReady = true; CheckReady(); break; case AlphaSynthWebWorker.CmdReadyForPlayback: _workerIsReadyForPlayback = true; CheckReadyForPlayback(); break; case AlphaSynthWebWorker.CmdPositionChanged: _timePosition = data.Member("currentTime").As <double>(); _tickPosition = data.Member("currentTick").As <int>(); TriggerEvent("positionChanged", new[] { data }); break; case AlphaSynthWebWorker.CmdPlayerStateChanged: _state = data.Member("state").As <PlayerState>(); TriggerEvent("playerStateChanged", new[] { data }); break; case AlphaSynthWebWorker.CmdFinished: TriggerEvent("finished"); break; case AlphaSynthWebWorker.CmdSoundFontLoaded: TriggerEvent("soundFontLoaded"); break; case AlphaSynthWebWorker.CmdSoundFontLoadFailed: TriggerEvent("soundFontLoadFailed"); break; case AlphaSynthWebWorker.CmdMidiLoaded: _isMidiLoaded = true; CheckReadyForPlayback(); TriggerEvent("midiFileLoaded"); break; case AlphaSynthWebWorker.CmdMidiLoadFailed: _isSoundFontLoaded = true; CheckReadyForPlayback(); TriggerEvent("midiFileLoadFailed"); break; case AlphaSynthWebWorker.CmdLog: Logger.Log(data.Member("level").As <LogLevel>(), data.Member("message").As <string>()); break; // output communication ( output <- worker ) case WebWorkerOutput.CmdOutputSequencerFinished: _output.SequencerFinished(); break; case WebWorkerOutput.CmdOutputAddSamples: _output.AddSamples(data.Member("samples").As <SampleArray>()); break; case WebWorkerOutput.CmdOutputPlay: _output.Play(); break; case WebWorkerOutput.CmdOutputPause: _output.Pause(); break; case WebWorkerOutput.CmdOutputResetSamples: _output.ResetSamples(); break; } }
public virtual void HandleWorkerMessage(MessageEvent e) { var data = e.Data; string cmd = data.cmd; switch (cmd) { case AlphaSynthWebWorker.CmdReady: _workerIsReady = true; CheckReady(); break; case AlphaSynthWebWorker.CmdReadyForPlayback: _workerIsReadyForPlayback = true; CheckReadyForPlayback(); break; case AlphaSynthWebWorker.CmdPositionChanged: _timePosition = data.currentTime; _tickPosition = data.currentTick; TriggerEvent("positionChanged", new[] { new PositionChangedEventArgs(data.currentTime, data.endTime, data.currentTick, data.endTick) }); break; case AlphaSynthWebWorker.CmdPlayerStateChanged: _state = data.state; TriggerEvent("playerStateChanged", new[] { new PlayerStateChangedEventArgs(data.state), }); break; case AlphaSynthWebWorker.CmdFinished: TriggerEvent("finished"); break; case AlphaSynthWebWorker.CmdSoundFontLoaded: TriggerEvent("soundFontLoaded"); break; case AlphaSynthWebWorker.CmdSoundFontLoadFailed: TriggerEvent("soundFontLoadFailed"); break; case AlphaSynthWebWorker.CmdMidiLoaded: CheckReadyForPlayback(); TriggerEvent("midiFileLoaded", new object[] { data.error }); break; case AlphaSynthWebWorker.CmdMidiLoadFailed: CheckReadyForPlayback(); TriggerEvent("midiFileLoadFailed", new object[] { data.error }); break; case AlphaSynthWebWorker.CmdLog: Logger.Log(data.level, "AlphaSynth", data.message); break; // output communication ( output <- worker ) case AlphaSynthWorkerSynthOutput.CmdOutputSequencerFinished: _output.SequencerFinished(); break; case AlphaSynthWorkerSynthOutput.CmdOutputAddSamples: _output.AddSamples(data.samples); break; case AlphaSynthWorkerSynthOutput.CmdOutputPlay: _output.Play(); break; case AlphaSynthWorkerSynthOutput.CmdOutputPause: _output.Pause(); break; case AlphaSynthWorkerSynthOutput.CmdOutputResetSamples: _output.ResetSamples(); break; } }
public virtual void HandleWorkerMessage(DOMEvent e) { var data = e.As <MessageEvent>().data; var cmd = data.Member("cmd").As <string>(); switch (cmd) { // responses case "isReadyForPlay": case "getState": case "getMasterVolume": case "isSoundFontLoaded": case "isMidiLoaded": TriggerEvent(cmd, new[] { data.Member("value") }); break; // events case "ready": _isWorkerReady = true; CheckForReadyState(); break; case "positionChanged": TriggerEvent(cmd, new[] { data.Member("currentTime"), data.Member("endTime"), data.Member("currentTick"), data.Member("endTick") }); break; case "playerStateChanged": TriggerEvent(cmd, new[] { data.Member("state") }); break; case "finished": TriggerEvent(cmd); break; case "soundFontLoad": TriggerEvent(cmd, new[] { data.Member("loaded"), data.Member("total") }); break; case "soundFontLoaded": TriggerEvent(cmd); break; case "soundFontLoadFailed": TriggerEvent(cmd); break; case "midiLoad": TriggerEvent(cmd, new[] { data.Member("loaded"), data.Member("total") }); break; case "midiFileLoaded": TriggerEvent(cmd); break; case "midiFileLoadFailed": TriggerEvent(cmd); break; case "readyForPlay": TriggerEvent(cmd, new[] { data.Member("value") }); break; case "log": Log(data.Member("level").As <LogLevel>(), data.Member("message").As <string>()); break; // js player communication case "playerSequencerFinished": _player.SequencerFinished(); break; case "playerAddSamples": _player.AddSamples(data.Member("samples").As <SampleArray>()); break; case "playerPlay": _player.Play(); break; case "playerPause": _player.Pause(); break; case "playerStop": _player.Stop(); break; case "playerSeek": _player.Seek(data.Member("pos").As <int>()); break; } }