public void EndUpdate() { if (_data == null) { return; } if (Host.InvokeRequired) { try { Host.Invoke(_methodInvoker); } catch (ObjectDisposedException e) { e.Message.CrashLog(); } } else { if (_refCount == 0) { } else if (--_refCount == 0) { var index = 0; while (index < _data.Length) { _data[index] = 0; index++; } try { foreach (var engineBuffer in _instances.Select(context => context.EngineBuffer)) { for (index = 0; index < engineBuffer.Length; index++) { _data[index] = Math.Max(_data[index], engineBuffer[index]); } } } catch (Exception exception) { throw new Exception(string.Format("(Router - Update)\n{0}", exception.Message), exception); } try { lock (_outputPlugins) { foreach (var outputPlugIn in _outputPlugins.Where(outputPlugIn => (outputPlugIn.From != 0) && outputPlugIn.ContextInitialized)) { Array.Copy(_data, outputPlugIn.From - 1, outputPlugIn.Buffer, 0, (outputPlugIn.To - outputPlugIn.From) + 1); var eventDrivenOutputPlugIn = outputPlugIn.PlugIn as IEventDrivenOutputPlugIn; if (eventDrivenOutputPlugIn == null) { continue; } eventDrivenOutputPlugIn.Event(outputPlugIn.Buffer); } } } catch (Exception exception2) { throw new Exception(string.Format(Resources.RouterOutputError, exception2.Message), exception2); } } } }
private void TimerTick(EngineContext context) { if (!_eventTimer.Enabled || _isStopping) { return; } context.TickCount = (context.SoundChannel != null) && context.SoundChannel.IsPlaying ? (int)context.SoundChannel.Position : context.StartOffset + ((int)context.Timekeeper.ElapsedMilliseconds); var num = context.TickCount / context.CurrentSequence.EventPeriod; if ((context.TickCount >= context.SequenceTickLength) || (num >= context.MaxEvent)) { _fmod.Stop(context.SoundChannel); context.Timekeeper.Stop(); context.Timekeeper.Reset(); if (IsLooping) { LogAudio(_engineContext.CurrentSequence); StartContextAudio(_engineContext); context.Timekeeper.Start(); OnSequenceChange(); } else { Host.Invoke(new MethodInvoker(Stop)); } } else if (num != context.LastIndex) { context.LastIndex = num; FireEvent(context, context.LastIndex); } }
private void InitEngineContext(ref EngineContext context, int sequenceIndex) { if (context == null) { return; } context.Timekeeper.Stop(); if (Host.InvokeRequired) { Host.Invoke(new InitEngineContextDelegate(InitEngineContext), context, sequenceIndex); } else if ((sequenceIndex == -1) || (CurrentObject.EventSequences.Count <= sequenceIndex)) { FinalizeEngineContext(context); } else { var executableObject = CurrentObject.EventSequences[sequenceIndex].Sequence; if (context.RouterContext == null) { context.RouterContext = _plugInRouter.CreateContext(new byte[executableObject.FullChannelCount], _useSequencePluginData ? executableObject.PlugInData : CurrentObject.SetupData, executableObject); } if (CurrentObject.Mask.Length > sequenceIndex) { context.ChannelMask = CurrentObject.Mask[sequenceIndex]; } context.TickCount = 0; context.LastIndex = -1; context.SequenceTickLength = executableObject.Time; context.StartOffset = 0; if (_fmod != null) { context.SoundChannel = executableObject.Audio != null?_fmod.LoadSound(Path.Combine(Paths.AudioPath, executableObject.Audio.FileName), context.SoundChannel) : _fmod.LoadSound(null); } context.CurrentSequence = executableObject; context.MaxEvent = context.CurrentSequence.TotalEventPeriods; context.LastPeriod = new byte[context.CurrentSequence.FullChannels.Count]; for (var i = 0; i < context.LastPeriod.Length; i++) { context.LastPeriod[i] = (byte)i; } context.Data = ReconfigureSourceData(executableObject); } }
private void StartContextAudio(EngineContext context) { if (context.CurrentSequence.Audio == null) { return; } if (Host.InvokeRequired) { MethodInvoker method = delegate { PrepareAudio(context, context.StartOffset); StartAudio(context); }; Host.Invoke(method); } else { PrepareAudio(context, context.StartOffset); StartAudio(context); } }