Example #1
0
 public void StopWalkyTalky()
 {
     if (this.walkyTalkyInstance != null)
     {
         CueInstance cueInstance = null;
         UnityUtil.ERRCHECK(this.walkyTalkyInstance.getCue("KeyOff", out cueInstance));
         UnityUtil.ERRCHECK(cueInstance.trigger());
         UnityUtil.ERRCHECK(this.walkyTalkyInstance.release());
         this.walkyTalkyInstance = null;
     }
 }
Example #2
0
        public void Abort()
        {
            if (this.currentInstance != null)
            {
                // Stop all
                this.currentInstance.StopAllExistingTasks();
            }

            this.currentCueId.OnNext(null);
            this.currentInstance = null;

            ReleaseLocks();
        }
            public RESULT getCue(string name, out CueInstance instance)
            {
                RESULT result = RESULT.OK;
                IntPtr cueinstanceraw = new IntPtr();
                instance = null;

                try
                {
                result = FMOD_Studio_EventInstance_GetCue(rawPtr, Encoding.UTF8.GetBytes(name + Char.MinValue), out cueinstanceraw);
                }
                catch
                {
                result = RESULT.ERR_INVALID_PARAM;
                }
                if (result != RESULT.OK)
                {
                return result;
                }
                instance = new CueInstance();
                instance.setRaw(cueinstanceraw);

                return result;
            }
Example #4
0
            public RESULT getCueByIndex(int index, out CueInstance instance)
            {
                instance = null;

                IntPtr newPtr = new IntPtr();
                RESULT result = FMOD_Studio_EventInstance_GetCueByIndex(rawPtr, index, out newPtr);
                if (result != RESULT.OK)
                {
                return result;
                }
                instance = new CueInstance(newPtr);

                return result;
            }
Example #5
0
            public RESULT getCue(string name, out CueInstance instance)
            {
                instance = null;

                IntPtr newPtr = new IntPtr();
                RESULT result = FMOD_Studio_EventInstance_GetCue(rawPtr, Encoding.UTF8.GetBytes(name + Char.MinValue), out newPtr);
                if (result != RESULT.OK)
                {
                return result;
                }
                instance = new CueInstance(newPtr);

                return result;
            }
Example #6
0
        private void RunCue(int cueId, Cue cue, bool snap, bool lastCue)
        {
            var watch = Stopwatch.StartNew();

            CancellationTokenSource cancelSource;
            if (this.triggerCancelSources.TryGetValue(cue, out cancelSource))
            {
                cancelSource.Cancel();
            }

            this.currentCueId.OnNext(cueId);

            var cueInstance = new CueInstance();

            if (cue.PartIntensity != null)
            {
                foreach (var device in cue.Devices)
                {
                    var brightnessDevice = device as IReceivesBrightness;
                    if (brightnessDevice == null)
                        continue;

                    var observer = GetControlledObserverBrightness(brightnessDevice);

                    StopCurrentTask(device, Cue.CueParts.Intensity);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        brightnessDevice.Brightness,
                        cue.PartIntensity.Destination,
                        snap ? 0 : cue.PartIntensity.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Intensity, fadeTask, () => MibCheck(cueId, device));
                }
            }

            if (cue.PartColor != null)
            {
                foreach (var device in cue.Devices)
                {
                    var colorDevice = device as IReceivesColor;
                    if (colorDevice == null)
                        continue;

                    var observer = GetControlledObserverColor(colorDevice);

                    StopCurrentTask(device, Cue.CueParts.Color);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        colorDevice.Color,
                        cue.PartColor.Destination,
                        snap ? 0 : cue.PartColor.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Color, fadeTask);
                }
            }

            if (cue.PartPan != null)
            {
                foreach (var device in cue.Devices)
                {
                    var panTiltDevice = device as IReceivesPanTilt;
                    if (panTiltDevice == null)
                        continue;

                    var observer = GetControlledObserverPan(panTiltDevice);

                    StopCurrentTask(device, Cue.CueParts.Pan);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        panTiltDevice.Pan,
                        cue.PartPan.Destination,
                        snap ? 0 : cue.PartPan.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Pan, fadeTask);
                }
            }

            if (cue.PartTilt != null)
            {
                foreach (var device in cue.Devices)
                {
                    var panTiltDevice = device as IReceivesPanTilt;
                    if (panTiltDevice == null)
                        continue;

                    var observer = GetControlledObserverTilt(panTiltDevice);

                    StopCurrentTask(device, Cue.CueParts.Tilt);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer, panTiltDevice.Tilt,
                        cue.PartTilt.Destination,
                        snap ? 0 : cue.PartTilt.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Tilt, fadeTask);
                }
            }

            this.currentInstance = cueInstance;

            var allTasks = cueInstance.GetAllTasks();

            if (allTasks.Length > 0)
            {
                Task.WhenAll(allTasks).ContinueWith(x =>
                {
                    watch.Stop();

                    this.cueCompleted.OnNext(Tuple.Create(cueId, watch.ElapsedMilliseconds));

                    if (!snap && lastCue)
                    {
                        this.currentCueId.OnNext(null);
                        this.currentInstance = null;

                        ReleaseLocks();
                    }
                });
            }
            else
            {
                watch.Stop();

                this.cueCompleted.OnNext(Tuple.Create(cueId, watch.ElapsedMilliseconds));
            }
        }
Example #7
0
        private void NextCue()
        {
            Cue cue;

            if (this.requestedCueId.HasValue)
            {
                cue = this.cues[this.requestedCueId.Value];
                this.requestedCueId = null;

                RunCue(this.requestedCueId.Value, cue, true, false);

                return;
            }

            if (this.cues.Count <= 0)
                // Nothing to do
                return;

            if (this.iterationsLeft.HasValue && this.iterationsLeft.Value == 0)
                // Done
                return;

            LockAllUsedDevices();

            cue = AdvanceCue();

            if (cue == null)
            {
                // Done
                this.currentCueId.OnNext(null);
                this.currentInstance = null;

                ReleaseLocks();
                return;
            }

            this.nextCuePos = GetNextCuePosition();

            if (this.currentCuePos == this.cues.Count - 1)
            {
                // Last cue
                if (this.iterationsLeft.HasValue)
                    this.iterationsLeft = this.iterationsLeft.Value - 1;
            }

            RunCue(this.currentCuePos, cue, false, !this.nextCuePos.HasValue);

            if (this.nextCuePos.HasValue)
            {
                var nextCue = this.cues[this.nextCuePos.Value];

                if (nextCue.Trigger == Cue.Triggers.Follow)
                {
                    CancellationTokenSource triggerCancelSource;
                    if (this.triggerCancelSources.TryGetValue(nextCue, out triggerCancelSource))
                    {
                        triggerCancelSource.Cancel();
                    }

                    triggerCancelSource = new CancellationTokenSource();
                    this.triggerCancelSources[nextCue] = triggerCancelSource;

                    Task.Delay(nextCue.TriggerTimeMs, triggerCancelSource.Token).ContinueWith(x =>
                        {
                            if (!x.IsCanceled)
                                this.triggerNext.Set();
                        });
                }
                else if (nextCue.Trigger == Cue.Triggers.CueListTime)
                {
                    //FIXME: How do we deal with this when we're playing the cuelist backwards?
                    int triggerDelay = nextCue.TriggerTimeMs - (int)this.cueListTime.ElapsedMilliseconds;

                    if (triggerDelay > 0)
                    {
                        CancellationTokenSource triggerCancelSource;
                        if (this.triggerCancelSources.TryGetValue(nextCue, out triggerCancelSource))
                        {
                            triggerCancelSource.Cancel();
                        }

                        triggerCancelSource = new CancellationTokenSource();
                        this.triggerCancelSources[nextCue] = triggerCancelSource;

                        Task.Delay(triggerDelay, triggerCancelSource.Token).ContinueWith(x =>
                        {
                            if (!x.IsCanceled)
                                this.triggerNext.Set();
                        });
                    }
                }
            }
        }
Example #8
0
        public void Abort()
        {
            if (this.currentInstance != null)
            {
                // Stop all
                this.currentInstance.StopAllExistingTasks();
            }

            this.currentCueId.OnNext(null);
            this.currentInstance = null;

            ReleaseLocks();
        }
Example #9
0
        private void RunCue(int cueId, Cue cue, bool snap, bool lastCue)
        {
            var watch = Stopwatch.StartNew();

            CancellationTokenSource cancelSource;

            if (this.triggerCancelSources.TryGetValue(cue, out cancelSource))
            {
                cancelSource.Cancel();
            }

            this.currentCueId.OnNext(cueId);

            var cueInstance = new CueInstance();

            if (cue.PartIntensity != null)
            {
                foreach (var device in cue.Devices)
                {
                    var brightnessDevice = device as IReceivesBrightness;
                    if (brightnessDevice == null)
                    {
                        continue;
                    }

                    var observer = GetControlledObserverBrightness(brightnessDevice);

                    StopCurrentTask(device, Cue.CueParts.Intensity);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        brightnessDevice.Brightness,
                        cue.PartIntensity.Destination,
                        snap ? 0 : cue.PartIntensity.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Intensity, fadeTask, () => MibCheck(cueId, device));
                }
            }

            if (cue.PartColor != null)
            {
                foreach (var device in cue.Devices)
                {
                    var colorDevice = device as IReceivesColor;
                    if (colorDevice == null)
                    {
                        continue;
                    }

                    var observer = GetControlledObserverColor(colorDevice);

                    StopCurrentTask(device, Cue.CueParts.Color);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        colorDevice.Color,
                        cue.PartColor.Destination,
                        snap ? 0 : cue.PartColor.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Color, fadeTask);
                }
            }

            if (cue.PartPan != null)
            {
                foreach (var device in cue.Devices)
                {
                    var panTiltDevice = device as IReceivesPanTilt;
                    if (panTiltDevice == null)
                    {
                        continue;
                    }

                    var observer = GetControlledObserverPan(panTiltDevice);

                    StopCurrentTask(device, Cue.CueParts.Pan);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer,
                        panTiltDevice.Pan,
                        cue.PartPan.Destination,
                        snap ? 0 : cue.PartPan.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Pan, fadeTask);
                }
            }

            if (cue.PartTilt != null)
            {
                foreach (var device in cue.Devices)
                {
                    var panTiltDevice = device as IReceivesPanTilt;
                    if (panTiltDevice == null)
                    {
                        continue;
                    }

                    var observer = GetControlledObserverTilt(panTiltDevice);

                    StopCurrentTask(device, Cue.CueParts.Tilt);

                    var fadeTask = Executor.Current.MasterEffect.Fade(
                        observer, panTiltDevice.Tilt,
                        cue.PartTilt.Destination,
                        snap ? 0 : cue.PartTilt.FadeMs);

                    cueInstance.AddNewTask(device, Cue.CueParts.Tilt, fadeTask);
                }
            }

            this.currentInstance = cueInstance;

            var allTasks = cueInstance.GetAllTasks();

            if (allTasks.Length > 0)
            {
                Task.WhenAll(allTasks).ContinueWith(x =>
                {
                    watch.Stop();

                    this.cueCompleted.OnNext(Tuple.Create(cueId, watch.ElapsedMilliseconds));

                    if (!snap && lastCue)
                    {
                        this.currentCueId.OnNext(null);
                        this.currentInstance = null;

                        ReleaseLocks();
                    }
                });
            }
            else
            {
                watch.Stop();

                this.cueCompleted.OnNext(Tuple.Create(cueId, watch.ElapsedMilliseconds));
            }
        }
Example #10
0
        private void NextCue()
        {
            Cue cue;

            if (this.requestedCueId.HasValue)
            {
                cue = this.cues[this.requestedCueId.Value];
                this.requestedCueId = null;

                RunCue(this.requestedCueId.Value, cue, true, false);

                return;
            }

            if (this.cues.Count <= 0)
            {
                // Nothing to do
                return;
            }

            if (this.iterationsLeft.HasValue && this.iterationsLeft.Value == 0)
            {
                // Done
                return;
            }

            LockAllUsedDevices();

            cue = AdvanceCue();

            if (cue == null)
            {
                // Done
                this.currentCueId.OnNext(null);
                this.currentInstance = null;

                ReleaseLocks();
                return;
            }

            this.nextCuePos = GetNextCuePosition();

            if (this.currentCuePos == this.cues.Count - 1)
            {
                // Last cue
                if (this.iterationsLeft.HasValue)
                {
                    this.iterationsLeft = this.iterationsLeft.Value - 1;
                }
            }

            RunCue(this.currentCuePos, cue, false, !this.nextCuePos.HasValue);

            if (this.nextCuePos.HasValue)
            {
                var nextCue = this.cues[this.nextCuePos.Value];

                if (nextCue.Trigger == Cue.Triggers.Follow)
                {
                    CancellationTokenSource triggerCancelSource;
                    if (this.triggerCancelSources.TryGetValue(nextCue, out triggerCancelSource))
                    {
                        triggerCancelSource.Cancel();
                    }

                    triggerCancelSource = new CancellationTokenSource();
                    this.triggerCancelSources[nextCue] = triggerCancelSource;

                    Task.Delay(nextCue.TriggerTimeMs, triggerCancelSource.Token).ContinueWith(x =>
                    {
                        if (!x.IsCanceled)
                        {
                            this.triggerNext.Set();
                        }
                    });
                }
                else if (nextCue.Trigger == Cue.Triggers.CueListTime)
                {
                    //FIXME: How do we deal with this when we're playing the cuelist backwards?
                    int triggerDelay = nextCue.TriggerTimeMs - (int)this.cueListTime.ElapsedMilliseconds;

                    if (triggerDelay > 0)
                    {
                        CancellationTokenSource triggerCancelSource;
                        if (this.triggerCancelSources.TryGetValue(nextCue, out triggerCancelSource))
                        {
                            triggerCancelSource.Cancel();
                        }

                        triggerCancelSource = new CancellationTokenSource();
                        this.triggerCancelSources[nextCue] = triggerCancelSource;

                        Task.Delay(triggerDelay, triggerCancelSource.Token).ContinueWith(x =>
                        {
                            if (!x.IsCanceled)
                            {
                                this.triggerNext.Set();
                            }
                        });
                    }
                }
            }
        }