Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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;
            }
        }