public ControlledObserverRGB(IControlToken controlToken, ControlSubject<Color, IControlToken> control)
        {
            this.controlToken = controlToken;

            this.observerR = Observer.Create<double>(x =>
                {
                    Color newColor = Color.FromArgb(x.GetByteScale(), control.Value.G, control.Value.B);

                    control.OnNext(newColor, this.controlToken);
                });

            this.observerG = Observer.Create<double>(x =>
                {
                    Color newColor = Color.FromArgb(control.Value.R, x.GetByteScale(), control.Value.B);

                    control.OnNext(newColor, this.controlToken);
                });

            this.observerB = Observer.Create<double>(x =>
                {
                    Color newColor = Color.FromArgb(control.Value.R, control.Value.G, x.GetByteScale());

                    control.OnNext(newColor, this.controlToken);
                });
        }
Example #2
0
 public void SetPanTilt(double pan, double tilt, IControlToken token)
 {
     SetData(token,
         Tuple.Create(DataElements.Pan, (object)pan),
         Tuple.Create(DataElements.Tilt, (object)tilt)
         );
 }
Example #3
0
 public void SetColor(Color color, double? brightness = 1.0, IControlToken token = null)
 {
     if (brightness.HasValue)
     {
         SetData(token,
             Tuple.Create(DataElements.Brightness, (object)brightness),
             Tuple.Create(DataElements.Color, (object)color)
             );
     }
     else
         SetData(token, Tuple.Create(DataElements.Color, (object)color));
 }
Example #4
0
 public void SetStrobeSpeed(double strobeSpeed, IControlToken token)
 {
     SetData(token, Tuple.Create(DataElements.StrobeSpeed, (object)strobeSpeed));
 }
Example #5
0
        public LockDemo(IEnumerable <string> args)
        {
            blackOut.ConnectTo(Exec.Blackout);
            whiteOut.ConnectTo(Exec.Whiteout);

            lightGroup.Add(lightA, lightB);

            acnOutput.Connect(new Physical.SmallRGBStrobe(lightA, 1), 20);
            acnOutput.Connect(new Physical.SmallRGBStrobe(lightB, 10), 20);
            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 0, 50), 26, 1);
            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 50, 100), 25, 1);

            testLightA.ConnectTo(x => lightA.SetBrightness(x));
            testLightA.ConnectTo(x => pixelsRoofEdge.SetBrightness(x));
            testLightB.ConnectTo(x => lightB.SetBrightness(x));

            lightA.SetColor(Color.Red, null);
            lightB.SetColor(Color.Blue, null);

            pixelsRoofEdge.SetColor(Color.Green, 0.6);

            popOut.ConnectTo(lightA);
            popOut.ConnectTo(pixelsRoofEdge);

            sub
            .LockWhenRunning(lightA, lightB)
            .RunAction(i =>
            {
                lightA.SetBrightness(1.0, i.Token);
                i.WaitFor(S(2.5));

                lightB.SetBrightness(0.5, i.Token);
                i.WaitFor(S(2.5));

                Exec.MasterEffect.Fade(lightGroup, 1.0, 0.0, 3000, token: i.Token);

                i.WaitFor(S(1));

                using (var takeOver = lightGroup.TakeControl(5))
                {
                    lightGroup.SetBrightness(1, takeOver);
                    i.WaitFor(S(1));
                }

                lightGroup.SetBrightness(1, i.Token);

                i.WaitFor(S(2));
            });

            button1.Output.Subscribe(value =>
            {
                if (value)
                {
                    this.log.Information("Button 1 pressed!");

                    sub.Run();
                }
            });

            button2.Output.Subscribe(value =>
            {
                if (value)
                {
                    this.log.Information("Button 2 pressed!");

                    if (testLock != null)
                    {
                        testLock.Dispose();
                        testLock = null;
                    }
                    else
                    {
                        testLock = lightA.TakeControl();
                    }
                }
            });

            button3.Output.Subscribe(value =>
            {
                if (value)
                {
                    this.log.Information("Button 3 pressed!");

                    popOut.Pop(color: Color.Purple, sweepDuration: S(2));

                    Thread.Sleep(500);

                    testLightA.Value = random.NextDouble();
                }
            });
        }
Example #6
0
 public void SetBrightness(double brightness, IControlToken token = null)
 {
     this.SetData(token, Utils.Data(DataElements.Brightness, brightness));
 }
Example #7
0
 public void Add(IOwnedDevice device, IControlToken token)
 {
     MemberTokens.Add(device, token);
 }
Example #8
0
        public void SetData(IControlToken token, params Tuple<DataElements, object>[] values)
        {
            var data = GetFrameBuffer(token, this);

            foreach (var kvp in values)
                data[kvp.Item1] = kvp.Item2;

            PushOutput(token);
        }
Example #9
0
        public IPushDataController GetDataObserver(IControlToken token)
        {
            if (token == null)
                throw new ArgumentNullException("token");

            return new ControlledObserverData(token, this.outputData, token.GetDataForDevice(this));
        }
 public void SetColor(Color color, double?brightness, IControlToken token)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public void SetColor(Color color, double? brightness, IControlToken token)
 {
     throw new NotImplementedException();
 }
Example #12
0
 public void SetStrobeSpeed(double strobeSpeed, IControlToken token)
 {
     this.SetData(token, Tuple.Create(DataElements.StrobeSpeed, (object)strobeSpeed));
 }
 public ControlledObserverData(IControlToken controlToken, ControlSubject <IData, IControlToken> control, IData data)
 {
     this.controlToken = controlToken;
     this.control      = control;
     this.data         = data;
 }
Example #14
0
 public void SetValue(bool value, IControlToken token = null)
 {
     this.SetData(token, Utils.Data(DataElements.Power, value));
 }
 public ControlledGroupData(IControlToken token, IObserver <IData> observer)
 {
     this.sharedData = new Data();
     this.token      = token;
     this.observer   = observer;
 }
Example #16
0
 public void SetControlToken(IControlToken token)
 {
     this.externalControlToken = token;
 }
Example #17
0
            public override void Execute(IReceivesColor device, ChannelEffectInstance.DeviceType deviceType, IControlToken token)
            {
                var currentColor = device.GetCurrentColor();

                switch (deviceType)
                {
                case ChannelEffectInstance.DeviceType.ColorR:
                    device.SetColor(Color.FromArgb((int)(Brightness * 255), currentColor.G, currentColor.B), 1, token);

                    break;

                case ChannelEffectInstance.DeviceType.ColorG:
                    device.SetColor(Color.FromArgb(currentColor.R, (int)(Brightness * 255), currentColor.B), 1, token);
                    break;

                case ChannelEffectInstance.DeviceType.ColorB:
                    device.SetColor(Color.FromArgb(currentColor.R, currentColor.G, (int)(Brightness * 255)), 1, token);
                    break;
                }
            }
Example #18
0
 public override void Execute(IReceivesBrightness device, IControlToken token)
 {
     device.SetBrightness(Brightness, token);
 }
Example #19
0
        //public void PushData(DataElements dataElement, object value)
        //{
        //    foreach (var memberToken in MemberTokens.Values)
        //        memberToken.PushData(dataElement, value);
        //}

        public bool IsOwner(IControlToken checkToken)
        {
            return(MemberTokens.ContainsValue(checkToken));
        }
 public void SetBrightness(double brightness, IControlToken token)
 {
     action(brightness);
 }
Example #21
0
 public abstract void Execute(IReceivesColor device, ChannelEffectInstance.DeviceType deviceType, IControlToken token);
Example #22
0
 public void Add(IOwnedDevice device, IControlToken token)
 {
     MemberTokens.Add(device, token);
 }
Example #23
0
 public override void Execute(IReceivesBrightness device, IControlToken token)
 {
     Executor.Current.MasterEffect.Shimmer(device, StartBrightness, EndBrightness, DurationMs, token: token);
 }
Example #24
0
 public void SetPan(double pan, IControlToken token)
 {
     this.SetData(token, Tuple.Create(DataElements.Pan, (object)pan));
 }
Example #25
0
 public bool HasControl(IControlToken checkOwner)
 {
     return this.currentOwner == null || (checkOwner != null && checkOwner.IsOwner(this.currentOwner));
 }
Example #26
0
 public void SetTilt(double tilt, IControlToken token)
 {
     this.SetData(token, Tuple.Create(DataElements.Tilt, (object)tilt));
 }
 public bool HasControl(IControlToken checkOwner)
 {
     return(this.currentOwner == null || (checkOwner != null && checkOwner.IsOwner(this.currentOwner)));
 }
Example #28
0
        public void SetColorRange(
            Color color,
            double? brightness = 1.0,
            int startX = 0,
            int startY = 0,
            int? width = null,
            int? height = null,
            IControlToken token = null)
        {
            IData data = GetFrameBuffer(token, this);

            Color injectColor;
            if (brightness.GetValueOrDefault(1.0) < 1.0)
                injectColor = GetColorFromColorAndBrightness(color, brightness.Value);
            else
                injectColor = color;

            if (!width.HasValue)
                width = this.pixelWidth;
            if (!height.HasValue)
                height = this.pixelHeight;

            var bitmap = (Bitmap)data[DataElements.PixelBitmap];

            lock (this.lockObject)
            {
                using (var g = Graphics.FromImage(bitmap))
                using (var b = new SolidBrush(injectColor))
                {
                    g.FillRectangle(b, startX, startY, width.Value, height.Value);
                }
            }

            PushOutput(token);
        }
Example #29
0
        public Task Shimmer(IReceivesBrightness device, double minBrightness, double maxBrightness, int durationMs, int priority = 1, IControlToken token = null)
        {
            if (token != null)
            {
                return(Shimmer(device.GetDataObserver(token), minBrightness, maxBrightness, durationMs));
            }

            var controlToken = device.TakeControl(priority);

            return(Shimmer(device.GetDataObserver(controlToken), minBrightness, maxBrightness, durationMs)
                   .ContinueWith(x =>
            {
                controlToken.Dispose();
            }));
        }
 public ControlledGroupData(IControlToken token, IObserver<IData> observer)
 {
     this.sharedData = new Data();
     this.token = token;
     this.observer = observer;
 }
Example #31
0
 public void SetColor(Color color, double?brightness = 1.0, IControlToken token = null)
 {
     SetColorRange(color, brightness, token: token);
 }
Example #32
0
 public bool IsOwner(IControlToken checkToken)
 {
     return(this == checkToken);
 }
Example #33
0
        public Halloween2016(IEnumerable<string> args)
        {
            hoursSmall.AddRange("6:00 pm", "8:30 pm",
                DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday);
            hoursSmall.AddRange("5:00 pm", "9:00 pm",
                DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday);

            hoursFull.AddRange("6:00 pm", "8:30 pm");
            //hoursFull.Disabled = true;
            hoursSmall.Disabled = true;

            // Logging
            hoursSmall.Output.Log("Hours small");
            hoursFull.Output.Log("Hours full");

            string expanderFilesFolder = string.Empty;
            string expFilesParam = args.FirstOrDefault(x => x.StartsWith("EXPFILES"));
            if (!string.IsNullOrEmpty(expFilesParam))
            {
                string[] parts = expFilesParam.Split('=');
                if (parts.Length == 2)
                {
                    expanderFilesFolder =
                    expanderServer.ExpanderSharedFiles = parts[1];
                }
            }

            expanderServer.AddInstance("ed86c3dc166f41ee86626897ba039ed2", expanderLedmx);      // rpi-eb0092ca
            expanderServer.AddInstance("1583f686014345888c15d7fc9c55ca3c", expanderCat);        // rpi-eb81c94e
            expanderServer.AddInstance("4ea781ef257442edb524493da8f52220", expanderAudio2);     // rpi-eba6cbc7
            expanderServer.AddInstance("76d09e6032d54e77aafec90e1fc4b35b", expanderHifi);       // rpi-eb428ef1
            expanderServer.AddInstance("60023fcde5b549b89fa828d31741dd0c", expanderPicture);    // rpi-eb91bc26
            expanderServer.AddInstance("e41d2977931d4887a9417e8adcd87306", expanderGhost);      // rpi-eb6a047c
            expanderServer.AddInstance("999861affa294fd7bbf0601505e9ae09", expanderPop);        // rpi-ebd43a38

            masterVolume.ConnectTo(Exec.MasterVolume);

            hoursSmall
                .ControlsMasterPower(catAir)
                .ControlsMasterPower(mrPumpkinAir);
            hoursFull
                .ControlsMasterPower(catAir)
                .ControlsMasterPower(mrPumpkinAir);

            buttonOverrideHours.Output.Subscribe(x =>
            {
                if (x)
                    hoursFull.SetForced(true);
                else
                    hoursFull.SetForced(null);
            });

            flashBaby.Output.Subscribe(x =>
            {
                // Flash
                if (x)
                {
                    allLights.TakeAndHoldControl(100, "FlashBaby");
                    allLights.SetBrightness(1.0, new Data(DataElements.Color, Color.White));
                }
                else
                    allLights.ReleaseControl();
            });

            floodLights.Output.Subscribe(x =>
            {
                // Flash
                if (x)
                {
                    allLights.TakeAndHoldControl(200, "FlashBaby");
                    allLights.SetBrightness(1.0, new Data(DataElements.Color, Color.White));
                }
                else
                    allLights.ReleaseControl();
            });

            emergencyStop.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.EmergencyStop);
                }
                else
                {
                    if (hoursFull.IsOpen || hoursSmall.IsOpen)
                        stateMachine.GoToDefaultState();
                    else
                        stateMachine.GoToIdle();
                }
            });

            hoursFull.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.SetDefaultState(States.BackgroundFull);

                    if (emergencyStop.Value)
                        stateMachine.GoToState(States.EmergencyStop);
                    else
                        stateMachine.GoToDefaultState();
                }
                else
                {
                    stateMachine.GoToIdle();
                    stateMachine.SetDefaultState(null);
                }
                SetManualColor();
            });

            hoursSmall.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.SetDefaultState(States.BackgroundSmall);
                    stateMachine.GoToDefaultState();
                }
                else
                {
                    stateMachine.GoToIdle();
                    stateMachine.SetDefaultState(null);
                }
                SetManualColor();
            });

            popOut1.ConnectTo(wall1Light);
            popOut1.ConnectTo(wall4Light);
            popOut1.ConnectTo(wall6Light);
            popOut1.ConnectTo(flash1);
            popOut2.ConnectTo(wall2Light);
            popOut2.ConnectTo(wall7Light);
            popOut2.ConnectTo(flash2);
            popOutAll.ConnectTo(wall1Light);
            popOutAll.ConnectTo(wall2Light);
            popOutAll.ConnectTo(wall3Light);
            popOutAll.ConnectTo(wall4Light);
            popOutAll.ConnectTo(wall5Light);
            popOutAll.ConnectTo(wall6Light);
            popOutAll.ConnectTo(wall7Light);
            popOutAll.ConnectTo(wall8Light);
            popOutAll.ConnectTo(wall9Light);
            popOutAll.ConnectTo(flash1);
            popOutAll.ConnectTo(flash2);
            popOutAll.ConnectTo(pixelsRoofEdge);
            //            popOutAll.ConnectTo(pinSpot);

            allLights.Add(
                wall1Light,
                wall2Light,
                wall3Light,
                wall4Light,
                wall5Light,
                wall6Light,
                wall7Light,
                wall8Light,
                wall9Light,
                flash1,
                flash2,
                pixelsRoofEdge,
                //                pinSpot,
                spiderLight,
                spiderWebLights,
                pumpkinLights);

            purpleLights.Add(
                wall1Light,
                wall2Light,
                wall3Light,
                wall4Light,
                wall5Light,
                wall6Light,
                wall7Light,
                wall8Light,
                wall9Light,
                pixelsRoofEdge);

            flickerEffect.ConnectTo(stairs1Light);
            flickerEffect.ConnectTo(stairs2Light);
            flickerEffect.ConnectTo(gargoyleLightsEyes);
            flickerEffect.ConnectTo(flyingSkeletonEyes);
            flickerEffect.ConnectTo(streetNumberEyes);
            flickerEffect.ConnectTo(bigSpiderEyes);
            pulsatingGargoyle.ConnectTo(gargoyleLightsCrystal);
            pulsatingGargoyle.ConnectTo(treeSkulls);
            pulsatingGargoyle.ConnectTo(spiderEyes);
            //pulsatingEffect1.ConnectTo(pinSpot, Tuple.Create<DataElements, object>(DataElements.Color, Color.FromArgb(0, 255, 0)));
            //pulsatingEffect2.ConnectTo(pinSpot, Tuple.Create<DataElements, object>(DataElements.Color, Color.FromArgb(255, 0, 0)));

            pulsatingCatLow.ConnectTo(catLights);
            pulsatingCatHigh.ConnectTo(catLights);
            pulsatingPumpkinLow.ConnectTo(pumpkinLights);
            pulsatingPumpkinHigh.ConnectTo(pumpkinLights);
            pulsatingGargoyle.ConnectTo(spiderWebLights);

            stateMachine.For(States.BackgroundSmall)
                .Controls(1, flickerEffect, pulsatingGargoyle, pulsatingCatLow, pulsatingPumpkinLow)
                .Execute(i =>
                    {
                        treeGhosts.SetBrightness(1.0);
                        treeSkulls.SetBrightness(1.0);
                        audio2.SetBackgroundVolume(0.5);

                        var purpleColor = new ColorBrightness(HSV.ColorFromRGB(0.73333333333333328, 0, 1),
                            0.16470588235294117);

                        purpleLights.SetBrightness(purpleColor.Brightness, new Data(
                            Utils.AdditionalData(DataElements.Color, purpleColor.Color),
                            Utils.AdditionalData(DataElements.ColorUltraViolet, 1.0)));

                        i.WaitUntilCancel();
                    })
                .TearDown(instance =>
                    {
                        purpleLights.SetBrightness(0.0);
                        treeGhosts.SetBrightness(0.0);
                        treeSkulls.SetBrightness(0.0);
                    });

            stateMachine.For(States.BackgroundFull)
                .Controls(1, flickerEffect, pulsatingGargoyle, pulsatingCatLow, pulsatingPumpkinLow)
                .Execute(i =>
                {
                    treeGhosts.SetBrightness(1.0);
                    treeSkulls.SetBrightness(1.0);
                    audioHifi.PlayBackground();
                    audio2.SetBackgroundVolume(0.5);
                    audio2.PlayBackground();

                    var purpleColor = new ColorBrightness(HSV.ColorFromRGB(0.73333333333333328, 0, 1),
                        0.16470588235294117);

                    purpleLights.SetBrightness(purpleColor.Brightness, new Data(DataElements.Color, purpleColor.Color));

                    while (!i.IsCancellationRequested && stateMachine.CurrentState == States.BackgroundFull)
                    {
                        i.WaitFor(S(0.5));
                        if (!this.lastFogRun.HasValue || (DateTime.Now - this.lastFogRun.Value).TotalMinutes > 5)
                        {
                            // Run the fog for a little while
                            fog.SetValue(true);
                            i.WaitFor(S(4));
                            fog.SetValue(false);
                            this.lastFogRun = DateTime.Now;
                        }
                    }
                })
                .TearDown(instance =>
                {
                    purpleLights.SetBrightness(0.0);
                    treeGhosts.SetBrightness(0.0);
                    treeSkulls.SetBrightness(0.0);

                    audioHifi.PauseBackground();
                    audio2.PauseBackground();

                    timelineThunder1.Stop();
                    timelineThunder2.Stop();
                    timelineThunder3.Stop();
                    timelineThunder4.Stop();
                    timelineThunder5.Stop();
                    timelineThunder6.Stop();
                    timelineThunder7.Stop();
                    timelineThunder8.Stop();

                    flickerEffect.Stop();
                    treeGhosts.SetBrightness(0.0);
                    treeSkulls.SetBrightness(0.0);
                });

            stateMachine.For(States.EmergencyStop)
                .Execute(i =>
                {
                    // Do nothing
                    i.WaitUntilCancel();
                });

            stateMachine.For(States.Special1)
                .Execute(i =>
                {
                    audio2.PlayNewEffect("640 The Demon Exorcised.wav");

                    i.WaitUntilCancel();
                });

            inputBrightness.Output.Subscribe(x =>
            {
                //                testLight1.SetBrightness(x);
            });

            inputH.WhenOutputChanges(x =>
            {
                //                testLight1.SetColor(HSV.ColorFromHSV(x.GetByteScale(), inputS.Value, 1.0));
            });

            inputS.Output.Subscribe(x =>
            {
                //                testLight1.SetColor(HSV.ColorFromHSV(inputH.Value.GetByteScale(), x, 1.0));
            });

            expanderHifi.AudioTrackStart.Subscribe(x =>
            {
                // Next track
                switch (x.Item2)
                {
                    case "Thunder1.wav":
                        timelineThunder1.Start();
                        audio2.PlayEffect("scream.wav");
                        break;

                    case "Thunder2.wav":
                        timelineThunder2.Start();
                        break;

                    case "Thunder3.wav":
                        timelineThunder3.Start();
                        break;

                    case "Thunder4.wav":
                        timelineThunder4.Start();
                        audio2.PlayEffect("424 Coyote Howling.wav");
                        break;

                    case "Thunder5.wav":
                        timelineThunder5.Start();
                        //                        audioEeebox.PlayEffect("sixthsense-deadpeople.wav");
                        break;

                    case "Thunder6.wav":
                        timelineThunder6.Start();
                        break;

                    case "Thunder7.wav":
                        timelineThunder7.Start();
                        break;

                    case "Thunder8.wav":
                        timelineThunder8.Start();
                        break;

                    default:
                        log.Debug("Unknown track {0}", x);
                        break;
                }
            });

            timelineThunder1.AddMs(500, "A");
            timelineThunder1.AddMs(3500, "B");
            timelineThunder1.AddMs(4500, "C");
            timelineThunder1.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder2.AddMs(500, "A");
            timelineThunder2.AddMs(1500, "B");
            timelineThunder2.AddMs(1600, "C");
            timelineThunder2.AddMs(3700, "C");
            timelineThunder2.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder3.AddMs(100, "A");
            timelineThunder3.AddMs(200, "B");
            timelineThunder3.AddMs(300, "C");
            timelineThunder3.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder4.AddMs(0, "A");
            timelineThunder4.AddMs(3500, "B");
            timelineThunder4.AddMs(4500, "C");
            timelineThunder4.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder5.AddMs(1100, "A");
            timelineThunder5.AddMs(3500, "B");
            timelineThunder5.AddMs(4700, "C");
            timelineThunder5.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder6.AddMs(1000, "A");
            timelineThunder6.AddMs(1800, "B");
            timelineThunder6.AddMs(6200, "C");
            timelineThunder6.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder7.AddMs(0, "A");
            timelineThunder7.AddMs(200, "B");
            timelineThunder7.AddMs(300, "C");
            timelineThunder7.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder8.AddMs(500, "A");
            timelineThunder8.AddMs(4000, "B");
            timelineThunder8.AddMs(4200, "C");
            timelineThunder8.TimelineTrigger += TriggerThunderTimeline;

            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 0, 50, true), SacnUniversePixel50, 1);
            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 50, 100), SacnUniversePixel100, 1);

            //acnOutput.Connect(new Physical.SmallRGBStrobe(spiderLight, 1), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall6Light, 60), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall9Light, 70), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall8Light, 40), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.RGBStrobe(wall7Light, 80), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall1Light, 310, 8), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall2Light, 300, 8), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.MFL7x10WPar(wall3Light, 320), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall4Light, 330, 8), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall5Light, 340, 8), SacnUniverseDMXLedmx);
            //            acnOutput.Connect(new Physical.MarcGamutParH7(wall6Light, 350, 8), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(stairs1Light, 97), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(stairs2Light, 98), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(treeGhosts, 52), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(treeSkulls, 263), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(spiderEyes, 262), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(popperEyes, 259), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.AmericanDJStrobe(flash1, 100), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.EliminatorFlash192(flash2, 110), SacnUniverseDMXLedmx);
            //            acnOutput.Connect(new Physical.MonopriceRGBWPinSpot(pinSpot, 20), 1);

            acnOutput.Connect(new Physical.GenericDimmer(catAir, 10), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(mrPumpkinAir, 50), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(catLights, 96), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(spiderWebLights, 99), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(pumpkinLights, 51), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsCrystal, 128), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsEyes, 129), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(flyingSkeletonEyes, 130), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(streetNumberEyes, 131), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(bigSpiderEyes, 132), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(hazerFanSpeed, 500), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(hazerHazeOutput, 501), SacnUniverseDMXCat);
            //            acnOutput.Connect(new Physical.RGBIS(testLight1, 260), 1);

            expanderLedmx.DigitalInputs[4].Connect(pumpkinMotion, false);
            expanderCat.DigitalInputs[4].Connect(catMotion, false);
            expanderCat.DigitalInputs[5].Connect(secondBeam);
            expanderCat.DigitalInputs[6].Connect(firstBeam);
            expanderLedmx.DigitalInputs[5].Connect(ghostBeam);
            expanderLedmx.DigitalInputs[6].Connect(lastBeam);
            expanderPop.DigitalOutputs[7].Connect(popper);
            expanderPop.DigitalOutputs[6].Connect(fog);
            expanderCat.DigitalOutputs[7].Connect(spiderJump1);
            expanderCat.DigitalOutputs[6].Connect(spiderJump2);
            expanderLedmx.Connect(audioPumpkin);
            expanderCat.Connect(audioCat);
            expanderHifi.Connect(audioHifi);
            expanderPop.Connect(audioPop);
            expanderAudio2.Connect(audio2);
            expanderPicture.Connect(audioFlying);

            blockMaster.WhenOutputChanges(x => UpdateOSC());
            blockCat.WhenOutputChanges(x => UpdateOSC());
            blockFirst.WhenOutputChanges(x => UpdateOSC());
            blockPicture.WhenOutputChanges(x => UpdateOSC());
            blockGhost.WhenOutputChanges(x => UpdateOSC());
            blockLast.WhenOutputChanges(x => UpdateOSC());
            blockPumpkin.WhenOutputChanges(x => UpdateOSC());

            catMotion.Output.Subscribe(x =>
            {
                if (x && (hoursFull.IsOpen || hoursSmall.IsOpen) && !blockMaster.Value && !blockCat.Value)
                    Executor.Current.Execute(catSeq);

                oscServer.SendAllClients("/1/led1", x ? 1 : 0);
            });

            pumpkinMotion.Output.Subscribe(x =>
            {
                if (x && (hoursFull.IsOpen || hoursSmall.IsOpen) && !blockMaster.Value && !blockPumpkin.Value)
                    Executor.Current.Execute(pumpkinSeq);

                //                oscServer.SendAllClients("/1/led1", x ? 1 : 0);
            });

            firstBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockFirst.Value)
                    subFirst.Run();
            });

            secondBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockPicture.Value)
                    subPicture.Run();
            });

            ghostBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockGhost.Value)
                    subGhost.Run();
            });

            lastBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockLast.Value)
                    subLast.Run();
            });

            subFog
                .RunAction(i =>
                {
                    fog.SetValue(true);
                    lastFogRun = DateTime.Now;
                    i.WaitFor(S(6));
                    fog.SetValue(false);
                });

            subFirst
                .AutoAddDevices(lockPriority: 100)
                .RunAction(i =>
                {
                    flyingSkeletonEyes.SetBrightness(1.0);
                    wall3Light.SetColor(Color.FromArgb(255, 0, 100), 0.5);
                    wall3Light.SetStrobeSpeed(1.0, i.Token);

                    //                    audioPicture.PlayEffect("162 Blood Curdling Scream of Terror.wav");
                    //audioFlying.PlayEffect("05 I'm a Little Teapot.wav", 0.05);
                    audioFlying.PlayEffect("Who is that knocking.wav");
                    i.WaitFor(S(3.0));
                    audioFlying.PlayEffect("Evil-Laugh.wav");

                    i.WaitFor(S(2.0));
                })
                .TearDown(i =>
                {
                    Exec.MasterEffect.Fade(wall3Light, 0.5, 0.0, 2000, token: i.Token).Wait();
                });

            subPicture
                .RunAction(i =>
                {
                    if (bigSpiderEyesToken != null)
                        bigSpiderEyesToken.Dispose();

                    wall8Light.SetColor(Color.White, 1, bigSpiderEyesToken);
                    wall8Light.SetStrobeSpeed(1, bigSpiderEyesToken);
                    bigSpiderEyesToken = bigSpiderEyes.TakeControl(100);
                    bigSpiderEyes.SetBrightness(0, bigSpiderEyesToken);
                    audioHifi.PlayNewEffect("Happy Halloween.wav");
                    expanderPicture.SendSerial(0, new byte[] { 0x02 });
                    i.WaitFor(S(4.0));
                    sub3dfxRandom.Run();
                    i.WaitFor(S(10.0));
                    wall8Light.SetBrightness(0);
                    subSpiderJump.Run();
                    i.WaitFor(S(4.0));
                })
                .TearDown(i =>
                {
                });

            subSpiderJump
                .RunAction(i =>
                {
                    if (bigSpiderEyesToken == null)
                        bigSpiderEyesToken = bigSpiderEyes.TakeControl(100);

                    audio2.PlayNewEffect("348 Spider Hiss.wav", 0, 1);
                    bigSpiderEyes.SetBrightness(1, bigSpiderEyesToken);
                    spiderJump1.SetValue(true);
                    i.WaitFor(S(0.5));
                    spiderJump2.SetValue(true);
                    i.WaitFor(S(2.0));
                    spiderJump1.SetValue(false);
                    spiderJump2.SetValue(false);
                })
                .TearDown(i =>
                {
                    bigSpiderEyesToken?.Dispose();
                    bigSpiderEyesToken = null;
                });

            sub3dfxRandom
                .RunAction(i =>
                {
                    byte video;
                    do
                    {
                        video = (byte)(random.Next(3) + 1);
                    } while (video == last3dfxVideo);
                    last3dfxVideo = video;

                    expanderLedmx.SendSerial(0, new byte[] { video });
                    i.WaitFor(S(12.0));
                })
                .TearDown(i =>
                {
                });

            sub3dfxLady
                .RunAction(i =>
                {
                    expanderLedmx.SendSerial(0, new byte[] { 0x02 });
                    i.WaitFor(S(12.0));
                })
                .TearDown(i =>
                {
                });

            sub3dfxMan
                .RunAction(i =>
                {
                    expanderLedmx.SendSerial(0, new byte[] { 0x03 });
                    i.WaitFor(S(12.0));
                })
                .TearDown(i =>
                {
                });

            sub3dfxKids
                .RunAction(i =>
                {
                    expanderLedmx.SendSerial(0, new byte[] { 0x01 });
                    i.WaitFor(S(12.0));
                })
                .TearDown(i =>
                {
                });

            subGhost
                .RunAction(i =>
                {
                    expanderGhost.SendSerial(0, new byte[] { 0x01 });
                    i.WaitFor(S(12.0));
                })
                .TearDown(i =>
                {
                });

            subLast
                .RunAction(i =>
                {
                    popperEyes.SetBrightness(1.0);
                    fog.SetValue(true);
                    lastFogRun = DateTime.Now;
                    audioPop.PlayEffect("Short Laugh.wav");
                    i.WaitFor(S(1.0));
                    popper.SetValue(true);
                    i.WaitFor(S(2.0));
                    audioPop.PlayEffect("Leave Now.wav");
                    i.WaitFor(S(3.0));
                    var tsk = Exec.MasterEffect.Fade(popperEyes, 1.0, 0.0, 2000, token: i.Token);
                    popper.SetValue(false);
                    tsk.Wait();
                })
                .TearDown(i =>
                {
                    fog.SetValue(false);
                    i.WaitFor(S(1.0));
                });

            catSeq.WhenExecuted
                .Execute(instance =>
                {
                    var maxRuntime = System.Diagnostics.Stopwatch.StartNew();

                    pulsatingCatLow.Stop();
                    pulsatingCatHigh.Start();
                    //                catLights.SetBrightness(1.0, instance.Token);

                    while (true)
                    {
                        switch (random.Next(4))
                        {
                            case 0:
                                audioCat.PlayEffect("266 Monster Growl 7.wav", 1.0, 1.0);
                                instance.WaitFor(TimeSpan.FromSeconds(2.0));
                                break;
                            case 1:
                                audioCat.PlayEffect("285 Monster Snarl 2.wav", 1.0, 1.0);
                                instance.WaitFor(TimeSpan.FromSeconds(3.0));
                                break;
                            case 2:
                                audioCat.PlayEffect("286 Monster Snarl 3.wav", 1.0, 1.0);
                                instance.WaitFor(TimeSpan.FromSeconds(2.5));
                                break;
                            case 3:
                                audioCat.PlayEffect("287 Monster Snarl 4.wav", 1.0, 1.0);
                                instance.WaitFor(TimeSpan.FromSeconds(1.5));
                                break;
                            default:
                                instance.WaitFor(TimeSpan.FromSeconds(3.0));
                                break;
                        }

                        instance.CancelToken.ThrowIfCancellationRequested();

                        if (maxRuntime.Elapsed.TotalSeconds > 10)
                            break;
                    }
                })
                .TearDown(instance =>
                {
                    //                Exec.MasterEffect.Fade(catLights, 1.0, 0.0, 1000, token: instance.Token);
                    //TODO: Fade out
                    pulsatingCatHigh.Stop();
                    pulsatingCatLow.Start();
                });

            pumpkinSeq.WhenExecuted
                .Execute(instance =>
                {
                    pulsatingPumpkinLow.Stop();
                    pulsatingPumpkinHigh.Start();
                    if (hoursFull.IsOpen)
                        audioPumpkin.PlayEffect("Thriller2.wav");
                    else
                        audioPumpkin.PlayEffect("Happy Halloween.wav");
                    instance.CancelToken.WaitHandle.WaitOne(40000);
                })
                .TearDown(instance =>
                {
                    pulsatingPumpkinHigh.Stop();
                    pulsatingPumpkinLow.Start();
                });

            motionSeq.WhenExecuted
                .Execute(instance =>
                {
                    //video2.PlayVideo("DancingDead_Wall_HD.mp4");

                    //                    instance.WaitFor(S(10));
                })
                .TearDown(instance =>
                {
                });

            faderR.WhenOutputChanges(v => { SetManualColor(); });
            faderG.WhenOutputChanges(v => { SetManualColor(); });
            faderB.WhenOutputChanges(v => { SetManualColor(); });
            faderBright.WhenOutputChanges(v => { SetManualColor(); });

            manualFader.WhenOutputChanges(v =>
            {
                if (v)
                    this.manualFaderToken = pixelsRoofEdge.TakeControl(200);
                else
                {
                    this.manualFaderToken?.Dispose();
                    this.manualFaderToken = null;
                }

                oscServer.SendAllClients("/ManualFader/x", v ? 1 : 0);

                SetManualColor();
            });

            ConfigureOSC();
            ConfigureMIDI();
        }
Example #34
0
        public IControlToken TakeControl(int priority = 1, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
        {
            lock (this.members)
            {
                var memberTokens = new Dictionary <IOwnedDevice, IControlToken>();
                foreach (var device in this.members)
                {
                    memberTokens.Add(device, device.TakeControl(priority, name));
                }

                var ownerCandidate = new GroupControlToken(
                    memberTokens,
                    true,
                    cToken =>
                {
                    IControlToken nextOwner;

                    lock (this.members)
                    {
                        this.owners.Remove(cToken);

                        nextOwner = this.owners.LastOrDefault();

                        this.currentOwner = nextOwner;

                        Executor.Current.SetControlToken(this, nextOwner);
                    }
                },
                    priority);

                // Insert new owner
                lock (this)
                {
                    int pos = -1;
                    for (int i = 0; i < this.owners.Count; i++)
                    {
                        if (this.owners[i].Priority < priority)
                        {
                            continue;
                        }

                        pos = i;
                        break;
                    }
                    if (pos == -1)
                    {
                        this.owners.Add(ownerCandidate);
                    }
                    else
                    {
                        this.owners.Insert(pos, ownerCandidate);
                    }
                }

                // Grab the owner with the highest priority (doesn't have to be the candidate)
                var newOwner = this.owners.Last();

                this.currentOwner = newOwner;

                Executor.Current.SetControlToken(this, newOwner);

                return(ownerCandidate);
            }
        }
Example #35
0
 public override void Execute(IReceivesBrightness device, IControlToken token)
 {
     device.SetBrightness(Brightness, token);
 }
Example #36
0
 public bool HasControl(IControlToken checkOwner)
 {
     // Checked on an individual level instead
     return(true);
 }
Example #37
0
 public void SetPan(double pan, IControlToken token)
 {
     SetData(token, Tuple.Create(DataElements.Pan, (object)pan));
 }
Example #38
0
 public IData GetFrameBuffer(IControlToken token, IReceivesData device)
 {
     return(device.GetFrameBuffer(token, device));
 }
Example #39
0
 public void SetBrightness(double brightness, IControlToken token)
 {
     action(brightness);
 }
Example #40
0
        public Task Chaser(IData[] data, int speed, IControlToken token = null)
        {
            return Executor.Current.MasterEffect.CustomJob(
                jobAction: pos =>
                {
                    var current = data[pos % data.Length];

                    double brightness = current.GetValue<double>(DataElements.Brightness) ?? 1.0;
                    Color color = current.GetValue<Color>(DataElements.Color) ?? Color.White;

                    Inject(color, brightness, token);
                },
                jobStopped: () =>
                {
                    SetBrightness(0, token);
                },
                speed: speed);
        }
Example #41
0
 public abstract void Execute(IReceivesBrightness device, IControlToken token);
Example #42
0
        public void InjectRev(Color color, double brightness, IControlToken token = null)
        {
            IData data = GetFrameBuffer(token, this);
            var bitmap = (Bitmap)data[DataElements.PixelBitmap];

            Color injectColor = GetColorFromColorAndBrightness(color, brightness);

            lock (this.lockObject)
            {
                using (var g = Graphics.FromImage(bitmap))
                {
                    g.DrawImageUnscaled(bitmap, -1, 0);

                    bitmap.SetPixel(bitmap.Width - 1, 0, injectColor);
                }
            }

            PushOutput(token);
        }
Example #43
0
        public void SetBrightness(double brightness, IControlToken token = null)
        {
            if (brightness == 0)
                // Reset owner
                owner = null;

            for (int i = 0; i < this.brightness.Length; i++)
            {
                this.brightness[i] = brightness;
            }

            RaiseMultiPixelChanged(0, this.brightness.Length);
        }
Example #44
0
 public void SetBrightness(double brightness, IControlToken token = null)
 {
     SetData(token, Utils.AdditionalData(DataElements.Brightness, brightness));
 }
Example #45
0
            public override void Execute(IReceivesColor device, ChannelEffectInstance.DeviceType deviceType, IControlToken token)
            {
                var currentColor = device.Color;
                switch (deviceType)
                {
                    case ChannelEffectInstance.DeviceType.ColorR:
                        device.SetColor(Color.FromArgb((int)(Brightness * 255), currentColor.G, currentColor.B), 1, token);
                        break;

                    case ChannelEffectInstance.DeviceType.ColorG:
                        device.SetColor(Color.FromArgb(currentColor.R, (int)(Brightness * 255), currentColor.B), 1, token);
                        break;

                    case ChannelEffectInstance.DeviceType.ColorB:
                        device.SetColor(Color.FromArgb(currentColor.R, currentColor.G, (int)(Brightness * 255)), 1, token);
                        break;
                }
            }
Example #46
0
 public void SetColor(Color color, double? brightness = 1.0, IControlToken token = null)
 {
     SetColorRange(color, brightness, 0, null, token);
 }
Example #47
0
            public override void Execute(IReceivesColor device, ChannelEffectInstance.DeviceType deviceType, IControlToken token)
            {
                Executor.Current.MasterEffect.Shimmer(new LogicalDevice.VirtualDevice(b =>
                {
                    var currentColor = device.Color;
                    switch (deviceType)
                    {
                        case ChannelEffectInstance.DeviceType.ColorR:
                            device.SetColor(Color.FromArgb((int)(b * 255), currentColor.G, currentColor.B), 1, token);
                            break;

                        case ChannelEffectInstance.DeviceType.ColorG:
                            device.SetColor(Color.FromArgb(currentColor.R, (int)(b * 255), currentColor.B), 1, token);
                            break;

                        case ChannelEffectInstance.DeviceType.ColorB:
                            device.SetColor(Color.FromArgb(currentColor.R, currentColor.G, (int)(b * 255)), 1, token);
                            break;
                    }
                }), StartBrightness, EndBrightness, DurationMs, token: token);
            }
Example #48
0
        public void SetColorRange(
            Color color,
            double? brightness = 1.0,
            int startPosition = 0,
            int? length = null,
            IControlToken token = null)
        {
            IData data = GetFrameBuffer(token, this);

            Color injectColor;
            if (brightness.GetValueOrDefault(1.0) < 1.0)
                injectColor = GetColorFromColorAndBrightness(color, brightness.Value);
            else
                injectColor = color;

            if (!length.HasValue)
                length = this.pixelCount;
            else
            {
                if (startPosition + length.Value > this.pixelCount)
                    length = this.pixelCount - startPosition;
            }

            var bitmap = (Bitmap)data[DataElements.PixelBitmap];

            lock (this.lockObject)
            {
                using (var g = Graphics.FromImage(bitmap))
                using (var b = new SolidBrush(injectColor))
                {
                    g.FillRectangle(b, startPosition, 0, length.Value, 1);
                }
            }

            PushOutput(token);
        }
Example #49
0
        public IData GetFrameBuffer(IControlToken token, IReceivesData device)
        {
            if (token == null)
            {
                // Attempt to get from call context
                token = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("TOKEN") as IControlToken;

                var groupToken = token as GroupControlToken;
                if (groupToken != null)
                {
                    if (!groupToken.LockAndGetDataFromDevice(this))
                        token = null;
                }
            }

            if (token == null)
                return GetOwnerlessData();

            return token.GetDataForDevice(device);
        }
Example #50
0
        public Halloween2016(IEnumerable <string> args)
        {
            hoursSmall.AddRange("6:00 pm", "8:30 pm",
                                DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday);
            hoursSmall.AddRange("5:00 pm", "9:00 pm",
                                DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday);

            hoursFull.AddRange("6:00 pm", "8:30 pm");
            //hoursFull.Disabled = true;
            hoursSmall.Disabled = true;

            // Logging
            hoursSmall.Output.Log("Hours small");
            hoursFull.Output.Log("Hours full");

            string expFilesParam = args.FirstOrDefault(x => x.StartsWith("EXPFILES"));

            if (!string.IsNullOrEmpty(expFilesParam))
            {
                string[] parts = expFilesParam.Split('=');
                if (parts.Length == 2)
                {
                    Exec.ExpanderSharedFiles = parts[1];
                }
            }

            expanderServer.AddInstance("ed86c3dc166f41ee86626897ba039ed2", expanderLedmx);      // rpi-eb0092ca
            expanderServer.AddInstance("1583f686014345888c15d7fc9c55ca3c", expanderCat);        // rpi-eb81c94e
            expanderServer.AddInstance("4ea781ef257442edb524493da8f52220", expanderAudio2);     // rpi-eba6cbc7
            expanderServer.AddInstance("76d09e6032d54e77aafec90e1fc4b35b", expanderHifi);       // rpi-eb428ef1
            expanderServer.AddInstance("60023fcde5b549b89fa828d31741dd0c", expanderPicture);    // rpi-eb91bc26
            expanderServer.AddInstance("e41d2977931d4887a9417e8adcd87306", expanderGhost);      // rpi-eb6a047c
            expanderServer.AddInstance("999861affa294fd7bbf0601505e9ae09", expanderPop);        // rpi-ebd43a38

            masterVolume.ConnectTo(Exec.MasterVolume);

            hoursSmall
            .ControlsMasterPower(catAir)
            .ControlsMasterPower(mrPumpkinAir);
            hoursFull
            .ControlsMasterPower(catAir)
            .ControlsMasterPower(mrPumpkinAir);

            buttonOverrideHours.Output.Subscribe(x =>
            {
                if (x)
                {
                    hoursFull.SetForced(true);
                }
                else
                {
                    hoursFull.SetForced(null);
                }
            });


            flashBaby.Output.Subscribe(x =>
            {
                // Flash
                if (x)
                {
                    allLights.TakeAndHoldControl(100, "FlashBaby");
                    allLights.SetData(null, Utils.Data(Color.White, 1.0));
                }
                else
                {
                    allLights.ReleaseControl();
                }
            });

            floodLights.Output.Subscribe(x =>
            {
                // Flash
                if (x)
                {
                    allLights.TakeAndHoldControl(200, "FlashBaby");
                    allLights.SetData(null, Utils.Data(Color.White, 1.0));
                }
                else
                {
                    allLights.ReleaseControl();
                }
            });

            emergencyStop.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.EmergencyStop);
                }
                else
                {
                    if (hoursFull.IsOpen || hoursSmall.IsOpen)
                    {
                        stateMachine.GoToDefaultState();
                    }
                    else
                    {
                        stateMachine.GoToIdle();
                    }
                }
            });

            hoursFull.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.SetDefaultState(States.BackgroundFull);

                    if (emergencyStop.Value)
                    {
                        stateMachine.GoToState(States.EmergencyStop);
                    }
                    else
                    {
                        stateMachine.GoToDefaultState();
                    }
                }
                else
                {
                    stateMachine.GoToIdle();
                    stateMachine.SetDefaultState(null);
                }
                SetManualColor();
            });

            hoursSmall.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.SetDefaultState(States.BackgroundSmall);
                    stateMachine.GoToDefaultState();
                }
                else
                {
                    stateMachine.GoToIdle();
                    stateMachine.SetDefaultState(null);
                }
                SetManualColor();
            });

            popOut1.ConnectTo(wall1Light);
            popOut1.ConnectTo(wall4Light);
            popOut1.ConnectTo(wall6Light);
            popOut1.ConnectTo(flash1);
            popOut2.ConnectTo(wall2Light);
            popOut2.ConnectTo(wall7Light);
            popOut2.ConnectTo(flash2);
            popOutAll.ConnectTo(wall1Light);
            popOutAll.ConnectTo(wall2Light);
            popOutAll.ConnectTo(wall3Light);
            popOutAll.ConnectTo(wall4Light);
            popOutAll.ConnectTo(wall5Light);
            popOutAll.ConnectTo(wall6Light);
            popOutAll.ConnectTo(wall7Light);
            popOutAll.ConnectTo(wall8Light);
            popOutAll.ConnectTo(wall9Light);
            popOutAll.ConnectTo(flash1);
            popOutAll.ConnectTo(flash2);
            popOutAll.ConnectTo(pixelsRoofEdge);
            //            popOutAll.ConnectTo(pinSpot);

            allLights.Add(
                wall1Light,
                wall2Light,
                wall3Light,
                wall4Light,
                wall5Light,
                wall6Light,
                wall7Light,
                wall8Light,
                wall9Light,
                flash1,
                flash2,
                pixelsRoofEdge,
                //                pinSpot,
                spiderLight,
                spiderWebLights,
                pumpkinLights);

            purpleLights.Add(
                wall1Light,
                wall2Light,
                wall3Light,
                wall4Light,
                wall5Light,
                wall6Light,
                wall7Light,
                wall8Light,
                wall9Light,
                pixelsRoofEdge);

            flickerEffect.ConnectTo(stairs1Light);
            flickerEffect.ConnectTo(stairs2Light);
            flickerEffect.ConnectTo(gargoyleLightsEyes);
            flickerEffect.ConnectTo(flyingSkeletonEyes);
            flickerEffect.ConnectTo(streetNumberEyes);
            flickerEffect.ConnectTo(bigSpiderEyes);
            pulsatingGargoyle.ConnectTo(gargoyleLightsCrystal);
            pulsatingGargoyle.ConnectTo(treeSkulls);
            pulsatingGargoyle.ConnectTo(spiderEyes);
            //pulsatingEffect1.ConnectTo(pinSpot, Tuple.Create<DataElements, object>(DataElements.Color, Color.FromArgb(0, 255, 0)));
            //pulsatingEffect2.ConnectTo(pinSpot, Tuple.Create<DataElements, object>(DataElements.Color, Color.FromArgb(255, 0, 0)));

            pulsatingCatLow.ConnectTo(catLights);
            pulsatingCatHigh.ConnectTo(catLights);
            pulsatingPumpkinLow.ConnectTo(pumpkinLights);
            pulsatingPumpkinHigh.ConnectTo(pumpkinLights);
            pulsatingGargoyle.ConnectTo(spiderWebLights);

            stateMachine.For(States.BackgroundSmall)
            .Controls(1, flickerEffect, pulsatingGargoyle, pulsatingCatLow, pulsatingPumpkinLow)
            .Execute(i =>
            {
                treeGhosts.SetBrightness(1.0);
                treeSkulls.SetBrightness(1.0);
                audio2.SetBackgroundVolume(0.5);

                var purpleColor = new ColorBrightness(HSV.ColorFromRGB(0.73333333333333328, 0, 1),
                                                      0.16470588235294117);

                purpleLights.SetData(null,
                                     Utils.Data(purpleColor.Brightness),
                                     Utils.Data(purpleColor.Color),
                                     Utils.Data(DataElements.ColorUltraViolet, 1.0));

                i.WaitUntilCancel();
            })
            .TearDown(instance =>
            {
                purpleLights.SetBrightness(0.0);
                treeGhosts.SetBrightness(0.0);
                treeSkulls.SetBrightness(0.0);
            });

            stateMachine.For(States.BackgroundFull)
            .Controls(1, flickerEffect, pulsatingGargoyle, pulsatingCatLow, pulsatingPumpkinLow)
            .Execute(i =>
            {
                treeGhosts.SetBrightness(1.0);
                treeSkulls.SetBrightness(1.0);
                audioHifi.PlayBackground();
                audio2.SetBackgroundVolume(0.5);
                audio2.PlayBackground();

                var purpleColor = new ColorBrightness(HSV.ColorFromRGB(0.73333333333333328, 0, 1),
                                                      0.16470588235294117);

                purpleLights.SetData(null, Utils.Data(purpleColor.Color, purpleColor.Brightness));

                while (!i.IsCancellationRequested && stateMachine.CurrentState == States.BackgroundFull)
                {
                    i.WaitFor(S(0.5));
                    if (!this.lastFogRun.HasValue || (DateTime.Now - this.lastFogRun.Value).TotalMinutes > 5)
                    {
                        // Run the fog for a little while
                        fog.SetValue(true);
                        i.WaitFor(S(4));
                        fog.SetValue(false);
                        this.lastFogRun = DateTime.Now;
                    }
                }
            })
            .TearDown(instance =>
            {
                purpleLights.SetBrightness(0.0);
                treeGhosts.SetBrightness(0.0);
                treeSkulls.SetBrightness(0.0);

                audioHifi.PauseBackground();
                audio2.PauseBackground();

                timelineThunder1.Stop();
                timelineThunder2.Stop();
                timelineThunder3.Stop();
                timelineThunder4.Stop();
                timelineThunder5.Stop();
                timelineThunder6.Stop();
                timelineThunder7.Stop();
                timelineThunder8.Stop();

                flickerEffect.Stop();
                treeGhosts.SetBrightness(0.0);
                treeSkulls.SetBrightness(0.0);
            });

            stateMachine.For(States.EmergencyStop)
            .Execute(i =>
            {
                // Do nothing
                i.WaitUntilCancel();
            });

            stateMachine.For(States.Special1)
            .Execute(i =>
            {
                audio2.PlayNewEffect("640 The Demon Exorcised.wav");

                i.WaitUntilCancel();
            });

            inputBrightness.Output.Subscribe(x =>
            {
                //                testLight1.SetBrightness(x);
            });

            inputH.WhenOutputChanges(x =>
            {
                //                testLight1.SetColor(HSV.ColorFromHSV(x.GetByteScale(), inputS.Value, 1.0));
            });

            inputS.Output.Subscribe(x =>
            {
                //                testLight1.SetColor(HSV.ColorFromHSV(inputH.Value.GetByteScale(), x, 1.0));
            });


            expanderHifi.AudioTrackStart.Subscribe(x =>
            {
                // Next track
                switch (x.Item2)
                {
                case "Thunder1.wav":
                    timelineThunder1.Start();
                    audio2.PlayEffect("scream.wav");
                    break;

                case "Thunder2.wav":
                    timelineThunder2.Start();
                    break;

                case "Thunder3.wav":
                    timelineThunder3.Start();
                    break;

                case "Thunder4.wav":
                    timelineThunder4.Start();
                    audio2.PlayEffect("424 Coyote Howling.wav");
                    break;

                case "Thunder5.wav":
                    timelineThunder5.Start();
                    //                        audioEeebox.PlayEffect("sixthsense-deadpeople.wav");
                    break;

                case "Thunder6.wav":
                    timelineThunder6.Start();
                    break;

                case "Thunder7.wav":
                    timelineThunder7.Start();
                    break;

                case "Thunder8.wav":
                    timelineThunder8.Start();
                    break;

                default:
                    log.Debug("Unknown track {0}", x);
                    break;
                }
            });

            timelineThunder1.AddMs(500, "A");
            timelineThunder1.AddMs(3500, "B");
            timelineThunder1.AddMs(4500, "C");
            timelineThunder1.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder2.AddMs(500, "A");
            timelineThunder2.AddMs(1500, "B");
            timelineThunder2.AddMs(1600, "C");
            timelineThunder2.AddMs(3700, "C");
            timelineThunder2.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder3.AddMs(100, "A");
            timelineThunder3.AddMs(200, "B");
            timelineThunder3.AddMs(300, "C");
            timelineThunder3.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder4.AddMs(0, "A");
            timelineThunder4.AddMs(3500, "B");
            timelineThunder4.AddMs(4500, "C");
            timelineThunder4.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder5.AddMs(1100, "A");
            timelineThunder5.AddMs(3500, "B");
            timelineThunder5.AddMs(4700, "C");
            timelineThunder5.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder6.AddMs(1000, "A");
            timelineThunder6.AddMs(1800, "B");
            timelineThunder6.AddMs(6200, "C");
            timelineThunder6.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder7.AddMs(0, "A");
            timelineThunder7.AddMs(200, "B");
            timelineThunder7.AddMs(300, "C");
            timelineThunder7.TimelineTrigger += TriggerThunderTimeline;

            timelineThunder8.AddMs(500, "A");
            timelineThunder8.AddMs(4000, "B");
            timelineThunder8.AddMs(4200, "C");
            timelineThunder8.TimelineTrigger += TriggerThunderTimeline;

            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 0, 50, true), SacnUniversePixel50, 1);
            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 50, 100), SacnUniversePixel100, 1);

            //acnOutput.Connect(new Physical.SmallRGBStrobe(spiderLight, 1), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall6Light, 60), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall9Light, 70), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall8Light, 40), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.RGBStrobe(wall7Light, 80), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall1Light, 310, 8), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall2Light, 300, 8), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.MFL7x10WPar(wall3Light, 320), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall4Light, 330, 8), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall5Light, 340, 8), SacnUniverseDMXLedmx);
            //            acnOutput.Connect(new Physical.MarcGamutParH7(wall6Light, 350, 8), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(stairs1Light, 97), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(stairs2Light, 98), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(treeGhosts, 52), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(treeSkulls, 263), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(spiderEyes, 262), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(popperEyes, 259), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.AmericanDJStrobe(flash1, 100), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.EliminatorFlash192(flash2, 110), SacnUniverseDMXLedmx);
            //            acnOutput.Connect(new Physical.MonopriceRGBWPinSpot(pinSpot, 20), 1);

            acnOutput.Connect(new Physical.GenericDimmer(catAir, 10), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(mrPumpkinAir, 50), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(catLights, 96), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(spiderWebLights, 99), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(pumpkinLights, 51), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsCrystal, 128), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsEyes, 129), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(flyingSkeletonEyes, 130), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(streetNumberEyes, 131), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(bigSpiderEyes, 132), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(hazerFanSpeed, 500), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(hazerHazeOutput, 501), SacnUniverseDMXCat);
            //            acnOutput.Connect(new Physical.RGBIS(testLight1, 260), 1);


            expanderLedmx.DigitalInputs[4].Connect(pumpkinMotion, false);
            expanderCat.DigitalInputs[4].Connect(catMotion, false);
            expanderCat.DigitalInputs[5].Connect(secondBeam);
            expanderCat.DigitalInputs[6].Connect(firstBeam);
            expanderLedmx.DigitalInputs[5].Connect(ghostBeam);
            expanderLedmx.DigitalInputs[6].Connect(lastBeam);
            expanderPop.DigitalOutputs[7].Connect(popper);
            expanderPop.DigitalOutputs[6].Connect(fog);
            expanderCat.DigitalOutputs[7].Connect(spiderJump1);
            expanderCat.DigitalOutputs[6].Connect(spiderJump2);
            expanderLedmx.Connect(audioPumpkin);
            expanderCat.Connect(audioCat);
            expanderHifi.Connect(audioHifi);
            expanderPop.Connect(audioPop);
            expanderAudio2.Connect(audio2);
            expanderPicture.Connect(audioFlying);


            blockMaster.WhenOutputChanges(x => UpdateOSC());
            blockCat.WhenOutputChanges(x => UpdateOSC());
            blockFirst.WhenOutputChanges(x => UpdateOSC());
            blockPicture.WhenOutputChanges(x => UpdateOSC());
            blockGhost.WhenOutputChanges(x => UpdateOSC());
            blockLast.WhenOutputChanges(x => UpdateOSC());
            blockPumpkin.WhenOutputChanges(x => UpdateOSC());


            catMotion.Output.Subscribe(x =>
            {
                if (x && (hoursFull.IsOpen || hoursSmall.IsOpen) && !blockMaster.Value && !blockCat.Value)
                {
                    Executor.Current.Execute(catSeq);
                }

                oscServer.SendAllClients("/1/led1", x ? 1 : 0);
            });

            pumpkinMotion.Output.Subscribe(x =>
            {
                if (x && (hoursFull.IsOpen || hoursSmall.IsOpen) && !blockMaster.Value && !blockPumpkin.Value)
                {
                    Executor.Current.Execute(pumpkinSeq);
                }

                //                oscServer.SendAllClients("/1/led1", x ? 1 : 0);
            });

            firstBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockFirst.Value)
                {
                    subFirst.Run();
                }
            });

            secondBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockPicture.Value)
                {
                    subPicture.Run();
                }
            });

            ghostBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockGhost.Value)
                {
                    subGhost.Run();
                }
            });

            lastBeam.Output.Subscribe(x =>
            {
                UpdateOSC();

                if (x && hoursFull.IsOpen && !emergencyStop.Value && !blockMaster.Value && !blockLast.Value)
                {
                    subLast.Run();
                }
            });

            subFog
            .RunAction(i =>
            {
                fog.SetValue(true);
                lastFogRun = DateTime.Now;
                i.WaitFor(S(6));
                fog.SetValue(false);
            });

            subFirst
            .AutoAddDevices(lockPriority: 100)
            .RunAction(i =>
            {
                flyingSkeletonEyes.SetBrightness(1.0);
                wall3Light.SetColor(Color.FromArgb(255, 0, 100), 0.5);
                wall3Light.SetStrobeSpeed(1.0, i.Token);

                //                    audioPicture.PlayEffect("162 Blood Curdling Scream of Terror.wav");
                //audioFlying.PlayEffect("05 I'm a Little Teapot.wav", 0.05);
                audioFlying.PlayEffect("Who is that knocking.wav");
                i.WaitFor(S(3.0));
                audioFlying.PlayEffect("Evil-Laugh.wav");

                i.WaitFor(S(2.0));
            })
            .TearDown(i =>
            {
                Exec.MasterEffect.Fade(wall3Light, 0.5, 0.0, 2000, token: i.Token).Wait();
            });

            subPicture
            .RunAction(i =>
            {
                if (bigSpiderEyesToken != null)
                {
                    bigSpiderEyesToken.Dispose();
                }

                wall8Light.SetColor(Color.White, 1, bigSpiderEyesToken);
                wall8Light.SetStrobeSpeed(1, bigSpiderEyesToken);
                bigSpiderEyesToken = bigSpiderEyes.TakeControl(100);
                bigSpiderEyes.SetBrightness(0, bigSpiderEyesToken);
                audioHifi.PlayNewEffect("Happy Halloween.wav");
                expanderPicture.SendSerial(0, new byte[] { 0x02 });
                i.WaitFor(S(4.0));
                sub3dfxRandom.Run();
                i.WaitFor(S(10.0));
                wall8Light.SetBrightness(0);
                subSpiderJump.Run();
                i.WaitFor(S(4.0));
            })
            .TearDown(i =>
            {
            });

            subSpiderJump
            .RunAction(i =>
            {
                if (bigSpiderEyesToken == null)
                {
                    bigSpiderEyesToken = bigSpiderEyes.TakeControl(100);
                }

                audio2.PlayNewEffect("348 Spider Hiss.wav", 0, 1);
                bigSpiderEyes.SetBrightness(1, bigSpiderEyesToken);
                spiderJump1.SetValue(true);
                i.WaitFor(S(0.5));
                spiderJump2.SetValue(true);
                i.WaitFor(S(2.0));
                spiderJump1.SetValue(false);
                spiderJump2.SetValue(false);
            })
            .TearDown(i =>
            {
                bigSpiderEyesToken?.Dispose();
                bigSpiderEyesToken = null;
            });

            sub3dfxRandom
            .RunAction(i =>
            {
                byte video;
                do
                {
                    video = (byte)(random.Next(3) + 1);
                } while (video == last3dfxVideo);
                last3dfxVideo = video;

                expanderLedmx.SendSerial(0, new byte[] { video });
                i.WaitFor(S(12.0));
            })
            .TearDown(i =>
            {
            });

            sub3dfxLady
            .RunAction(i =>
            {
                expanderLedmx.SendSerial(0, new byte[] { 0x02 });
                i.WaitFor(S(12.0));
            })
            .TearDown(i =>
            {
            });

            sub3dfxMan
            .RunAction(i =>
            {
                expanderLedmx.SendSerial(0, new byte[] { 0x03 });
                i.WaitFor(S(12.0));
            })
            .TearDown(i =>
            {
            });

            sub3dfxKids
            .RunAction(i =>
            {
                expanderLedmx.SendSerial(0, new byte[] { 0x01 });
                i.WaitFor(S(12.0));
            })
            .TearDown(i =>
            {
            });

            subGhost
            .RunAction(i =>
            {
                expanderGhost.SendSerial(0, new byte[] { 0x01 });
                i.WaitFor(S(12.0));
            })
            .TearDown(i =>
            {
            });

            subLast
            .RunAction(i =>
            {
                popperEyes.SetBrightness(1.0);
                fog.SetValue(true);
                lastFogRun = DateTime.Now;
                audioPop.PlayEffect("Short Laugh.wav");
                i.WaitFor(S(1.0));
                popper.SetValue(true);
                i.WaitFor(S(2.0));
                audioPop.PlayEffect("Leave Now.wav");
                i.WaitFor(S(3.0));
                var tsk = Exec.MasterEffect.Fade(popperEyes, 1.0, 0.0, 2000, token: i.Token);
                popper.SetValue(false);
                tsk.Wait();
            })
            .TearDown(i =>
            {
                fog.SetValue(false);
                i.WaitFor(S(1.0));
            });

            catSeq.WhenExecuted
            .Execute(instance =>
            {
                var maxRuntime = System.Diagnostics.Stopwatch.StartNew();

                pulsatingCatLow.Stop();
                pulsatingCatHigh.Start();
                //                catLights.SetBrightness(1.0, instance.Token);

                while (true)
                {
                    switch (random.Next(4))
                    {
                    case 0:
                        audioCat.PlayEffect("266 Monster Growl 7.wav", 1.0, 1.0);
                        instance.WaitFor(TimeSpan.FromSeconds(2.0));
                        break;

                    case 1:
                        audioCat.PlayEffect("285 Monster Snarl 2.wav", 1.0, 1.0);
                        instance.WaitFor(TimeSpan.FromSeconds(3.0));
                        break;

                    case 2:
                        audioCat.PlayEffect("286 Monster Snarl 3.wav", 1.0, 1.0);
                        instance.WaitFor(TimeSpan.FromSeconds(2.5));
                        break;

                    case 3:
                        audioCat.PlayEffect("287 Monster Snarl 4.wav", 1.0, 1.0);
                        instance.WaitFor(TimeSpan.FromSeconds(1.5));
                        break;

                    default:
                        instance.WaitFor(TimeSpan.FromSeconds(3.0));
                        break;
                    }

                    instance.CancelToken.ThrowIfCancellationRequested();

                    if (maxRuntime.Elapsed.TotalSeconds > 10)
                    {
                        break;
                    }
                }
            })
            .TearDown(instance =>
            {
                //                Exec.MasterEffect.Fade(catLights, 1.0, 0.0, 1000, token: instance.Token);
                //TODO: Fade out
                pulsatingCatHigh.Stop();
                pulsatingCatLow.Start();
            });

            pumpkinSeq.WhenExecuted
            .Execute(instance =>
            {
                pulsatingPumpkinLow.Stop();
                pulsatingPumpkinHigh.Start();
                if (hoursFull.IsOpen)
                {
                    audioPumpkin.PlayEffect("Thriller2.wav");
                }
                else
                {
                    audioPumpkin.PlayEffect("Happy Halloween.wav");
                }
                instance.CancelToken.WaitHandle.WaitOne(40000);
            })
            .TearDown(instance =>
            {
                pulsatingPumpkinHigh.Stop();
                pulsatingPumpkinLow.Start();
            });

            motionSeq.WhenExecuted
            .Execute(instance =>
            {
                //video2.PlayVideo("DancingDead_Wall_HD.mp4");

                //                    instance.WaitFor(S(10));
            })
            .TearDown(instance =>
            {
            });

            faderR.WhenOutputChanges(v => { SetManualColor(); });
            faderG.WhenOutputChanges(v => { SetManualColor(); });
            faderB.WhenOutputChanges(v => { SetManualColor(); });
            faderBright.WhenOutputChanges(v => { SetManualColor(); });

            manualFader.WhenOutputChanges(v =>
            {
                if (v)
                {
                    this.manualFaderToken = pixelsRoofEdge.TakeControl(200);
                }
                else
                {
                    this.manualFaderToken?.Dispose();
                    this.manualFaderToken = null;
                }

                oscServer.SendAllClients("/ManualFader/x", v ? 1 : 0);

                SetManualColor();
            });

            ConfigureOSC();
            ConfigureMIDI();
        }
Example #51
0
        public void PushOutput(IControlToken token)
        {
            if (token == null)
            {
                // Attempt to get from call context
                token = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("TOKEN") as IControlToken;

                var groupToken = token as GroupControlToken;
                if (groupToken != null)
                {
                    if (!groupToken.LockAndGetDataFromDevice(this))
                        token = null;
                }
            }

            IData data;

            if (token == null)
                data = GetOwnerlessData();
            else
                data = token.GetDataForDevice(this);

            if (data != null)
                this.outputData.OnNext(data, token);
        }
Example #52
0
 //public void PushData(DataElements dataElement, object value)
 //{
 //    foreach (var memberToken in MemberTokens.Values)
 //        memberToken.PushData(dataElement, value);
 //}
 public bool IsOwner(IControlToken checkToken)
 {
     return MemberTokens.ContainsValue(checkToken);
 }
Example #53
0
        public virtual IControlToken TakeControl(int priority = 1, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
        {
            lock (this)
            {
                var ownerCandidate = new ControlledDevice(
                    name,
                    priority,
                    populate => BuildDefaultData(populate),
                    cToken =>
                    {
                        IData restoreData;
                        IControlToken nextOwner;

                        lock (this)
                        {
                            this.owners.Remove(cToken);

                            nextOwner = this.owners.LastOrDefault();

                            if (nextOwner != null)
                                restoreData = nextOwner.GetDataForDevice(this);
                            else
                                restoreData = GetOwnerlessData();

                            restoreData = restoreData.Copy();

                            this.currentOwner = nextOwner;

                            Executor.Current.SetControlToken(this, nextOwner);
                        }

                        SetData(nextOwner, restoreData.Select(x => Tuple.Create(x.Key, x.Value)).ToArray());
                    });

                // Insert new owner
                lock (this)
                {
                    int pos = -1;
                    for (int i = 0; i < this.owners.Count; i++)
                    {
                        if (this.owners[i].Priority < priority)
                            continue;

                        pos = i;
                        break;
                    }
                    if (pos == -1)
                        this.owners.Add(ownerCandidate);
                    else
                        this.owners.Insert(pos, ownerCandidate);
                }

                // Grab the owner with the highest priority (doesn't have to be the candidate)
                var newOwner = this.owners.Last();

                this.currentOwner = newOwner;

                Executor.Current.SetControlToken(this, newOwner);

                return ownerCandidate;
            }
        }
        public virtual IControlToken TakeControl(int priority = 1, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
        {
            lock (this.lockObject)
            {
                var ownerCandidate = new ControlledDevice(
                    name,
                    priority,
                    populate => BuildDefaultData(populate),
                    cToken =>
                {
                    IData restoreData;
                    IControlToken nextOwner;

                    lock (this.lockObject)
                    {
                        this.owners.Remove(cToken);

                        nextOwner = this.owners.LastOrDefault();

                        if (nextOwner != null)
                        {
                            restoreData = nextOwner.GetDataForDevice(this);
                        }
                        else
                        {
                            restoreData = GetOwnerlessData();
                        }

                        restoreData = restoreData.Copy();

                        this.currentOwner = nextOwner;

                        Executor.Current.SetControlToken(this, nextOwner);
                    }

                    SetData(nextOwner, restoreData);
                });

                // Insert new owner
                lock (this.lockObject)
                {
                    int pos = -1;
                    for (int i = 0; i < this.owners.Count; i++)
                    {
                        if (this.owners[i].Priority < priority)
                        {
                            continue;
                        }

                        pos = i;
                        break;
                    }
                    if (pos == -1)
                    {
                        this.owners.Add(ownerCandidate);
                    }
                    else
                    {
                        this.owners.Insert(pos, ownerCandidate);
                    }
                }

                // Grab the owner with the highest priority (doesn't have to be the candidate)
                var newOwner = this.owners.Last();

                this.currentOwner = newOwner;

                Executor.Current.SetControlToken(this, newOwner);

                return(ownerCandidate);
            }
        }