private void HandleMessage(DOMEvent e) { var data = e.As<MessageEvent>().data; var cmd = data.Member("cmd").As<string>(); switch (cmd) { case "load": Load(data.Member("data"), data.Member("indexes").As<int[]>()); break; case "invalidate": _renderer.Invalidate(); break; case "resize": _renderer.Resize(data.Member("width").As<int>()); break; case "tex": Tex(data.Member("data").As<string>()); break; case "renderMultiple": RenderMultiple(data.Member("data").As<int[]>()); break; case "updateSettings": UpdateSettings(data.Member("settings")); break; } }
private void HandleWorkerMessage(DOMEvent e) { var data = e.As<MessageEvent>().data; var cmd = data.Member("cmd").As<string>(); switch (cmd) { case "preRender": OnPreRender(); break; case "partialRenderFinished": OnPartialRenderFinished(data.Member("result").As<RenderFinishedEventArgs>()); break; case "renderFinished": OnRenderFinished(data.Member("result").As<RenderFinishedEventArgs>()); break; case "postRenderFinished": OnPostRenderFinished(); break; case "error": console.error(data.Member("exception")); break; case "loaded": var score = data.Member("score").As<Score>(); if (score.As<bool>()) { var jsonConverter = new JsonConverter(); score = jsonConverter.JsObjectToScore(score); } _workerApi.TriggerEvent("loaded", score); break; } }
public void HandleMessage(DOMEvent e) { var data = e.As<MessageEvent>().data; var cmd = data.Member("cmd").As<string>(); switch (cmd) { case "play": Play(); break; case "pause": Pause(); break; case "isReadyForPlay": PostMessage(new { cmd = "isReadyForPlay", value = IsReadyForPlay() }); break; case "getMasterVolume": PostMessage(new { cmd = "getMasterVolume", value = _player.MasterVolume }); break; case "setMasterVolume": _player.MasterVolume = data.Member("value").As<float>(); break; case "playPause": PlayPause(); break; case "stop": Stop(); break; case "setPositionTick": SetPositionTick(data.Member("tick").As<int>()); break; case "setPositionTime": SetPositionTime(data.Member("time").As<int>()); break; case "loadSoundFontUrl": LoadSoundFontUrl(data.Member("url").As<string>()); break; case "loadSoundFontBytes": LoadSoundFontBytes(data.Member("data").As<byte[]>()); break; case "loadMidiUrl": LoadMidiUrl(data.Member("url").As<string>()); break; case "loadMidiBytes": LoadMidiBytes(data.Member("data").As<byte[]>()); break; case "getState": PostMessage(new { cmd = "getState", value = GetState() }); break; case "isSoundFontLoaded": PostMessage(new { cmd = "isSoundFontLoaded", value = IsSoundFontLoaded() }); break; case "isMidiLoaded": PostMessage(new { cmd = "isMidiLoaded", value = IsMidiLoaded() }); break; case "setLogLevel": SetLogLevel(data.Member("level").As<LogLevel>()); break; } }
private void HandleMessage(DOMEvent e) { var data = e.As<MessageEvent>().data; var cmd = data.Member("cmd").As<string>(); switch (cmd) { case "playerSampleRequest": OnSampleRequest(); break; case "playerFinished": OnFinished(); break; case "playerPositionChanged": OnPositionChanged(data.Member("pos").As<int>()); break; } }
private void HandleMessage(DOMEvent e) { var data = e.As<MessageEvent>().data; var cmd = data.Member("cmd").As<string>(); switch (cmd) { case "load": Load(data.Member("data"), data.Member("indexes").As<int[]>()); break; case "tex": Tex(data.Member("data").As<string>()); break; case "renderMultiple": RenderMultiple(data.Member("data").As<int[]>()); 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; } }