public AlphaSynthWebWorkerApiBase(ISynthOutput player, string alphaSynthScriptFile)
        {
            _player = player;
            _player.ReadyChanged += PlayerReadyChanged;
            _player.PositionChanged += PlayerPositionChanged;
            _player.SampleRequest += PlayerSampleRequest;
            _player.Finished += PlayerFinished;

            _events = new FastDictionary<string, FastList<JsFunction>>();

            _alphaSynthScriptFile = alphaSynthScriptFile;

            // create web worker
            _synth = new Worker(CreateWorkerUrl());
        }
示例#2
0
        public AlphaSynthWebWorkerApi(ISynthOutput player, string alphaSynthScriptFile, LogLevel logLevel)
        {
            _output                = player;
            _output.Ready         += OnOutputReady;
            _output.SamplesPlayed += OnOutputSamplesPlayed;
            _output.SampleRequest += OnOutputSampleRequest;
            _output.Finished      += OnOutputFinished;

            _events = new FastDictionary <string, FastList <Delegate> >();

            _output.Open();

            try
            {
                _synth = new Worker(alphaSynthScriptFile);
            }
            catch
            {
                // fallback to blob worker
                try
                {
                    HaxeString script = "importScripts('" + alphaSynthScriptFile + "')";
                    var        blob   = new Blob(Script.Write <object>("[ script ]"));
                    _synth = new Worker(URL.CreateObjectURL(blob));
                }
                catch (Exception e)
                {
                    Logger.Error("AlphaSynth", "Failed to create WebWorker: " + e);
                    // TODO: fallback to synchronous mode
                }
            }

            _synth.AddEventListener("message", (Action <MessageEvent>)HandleWorkerMessage, false);

            _synth.PostMessage(new
            {
                cmd        = AlphaSynthWebWorker.CmdInitialize,
                sampleRate = _output.SampleRate,
                logLevel   = logLevel
            });

            MasterVolume    = 1;
            PlaybackSpeed   = 1;
            MetronomeVolume = 0;
        }
        public ManagedThreadAlphaSynthWorkerApi(ISynthOutput output, LogLevel logLevel, Action <Action> uiInvoke)
            : base(output, logLevel)
        {
            _uiInvoke = uiInvoke;

            _threadStartedEvent      = new ManualResetEventSlim(false);
            _workerQueue             = new BlockingCollection <Action>();
            _workerCancellationToken = new CancellationTokenSource();

            _workerThread = new Thread(DoWork);
            _workerThread.IsBackground = true;
            _workerThread.Start();

            _threadStartedEvent.Wait();
            _workerQueue.Add(Initialize);
            _threadStartedEvent.Dispose();
            _threadStartedEvent = null;
        }
        public AlphaSynthWebWorkerApiBase(ISynthOutput player, string asRoot)
        {
            _asRoot = asRoot;
            _player = player;
            _player.ReadyChanged += PlayerReadyChanged;
            _player.PositionChanged += PlayerPositionChanged;
            _player.SampleRequest += PlayerSampleRequest;
            _player.Finished += PlayerFinished;

            _events = new FastDictionary<string, FastList<JsFunction>>();

            if (asRoot != "" && !asRoot.EndsWith("/"))
            {
                asRoot += "/";
            }
            _asRoot = asRoot;

            // create web worker
            _synth = new Worker(asRoot + "AlphaSynth.worker.js");
        }
示例#5
0
        public AlphaSynthWebWorkerApiBase(ISynthOutput player, string asRoot)
        {
            _asRoot = asRoot;
            _player = player;
            _player.ReadyChanged    += PlayerReadyChanged;
            _player.PositionChanged += PlayerPositionChanged;
            _player.SampleRequest   += PlayerSampleRequest;
            _player.Finished        += PlayerFinished;

            _events = new FastDictionary <string, FastList <JsFunction> >();

            if (asRoot != "" && !asRoot.EndsWith("/"))
            {
                asRoot += "/";
            }
            _asRoot = asRoot;

            // create web worker
            _synth = new Worker(asRoot + "AlphaSynth.worker.js");
        }
示例#6
0
        public AlphaSynthWebWorkerApi(ISynthOutput player, string alphaSynthScriptFile)
        {
            _output                = player;
            _output.Ready         += OnOutputReady;
            _output.SamplesPlayed += OnOutputSamplesPlayed;
            _output.SampleRequest += OnOutputSampleRequest;
            _output.Finished      += OnOutputFinished;

            _events = new FastDictionary <string, FastList <JsFunction> >();

            _output.Open();

            try
            {
                _synth = new Worker(alphaSynthScriptFile);
            }
            catch
            {
                // fallback to blob worker
                try
                {
                    var script = "importScripts('" + alphaSynthScriptFile + "')";
                    var blob   = new Blob(new[] { script });
                    _synth = new Worker(window.URL.createObjectURL(blob));
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to create WebWorker: " + e);
                    // TODO: fallback to synchronous mode
                }
            }
            _synth.addEventListener("message", HandleWorkerMessage, false);
            _synth.postMessage(new { cmd = AlphaSynthWebWorker.CmdInitialize, sampleRate = _output.SampleRate });

            MasterVolume    = 1;
            PlaybackSpeed   = 1;
            MetronomeVolume = 0;
        }
示例#7
0
 protected AlphaSynthWorkerApiBase(ISynthOutput output, LogLevel logLevel)
 {
     _output   = output;
     _logLevel = logLevel;
     Player    = null !;
 }