Connect() public method

public Connect ( LogicalDevice logicalDevice ) : MonoExpanderInstance
logicalDevice LogicalDevice
return MonoExpanderInstance
        public ExpanderDemo(IEnumerable <string> args)
        {
            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("ec30b8eda95b4c5cab46bf630d74810e", expanderLocal);
            expanderServer.AddInstance("ed86c3dc166f41ee86626897ba039ed2", expander1);
            expanderServer.AddInstance("10520fdcf14d47cba31da8b6e05d01d8", expander2);

            expander1.DigitalInputs[6].Connect(in1);
            expander1.DigitalOutputs[7].Connect(out1);
            expander1.Connect(audio1);
            expander2.Connect(audio2);

            in1.Output.Subscribe(x =>
            {
                if (x)
                {
//                    audio2.PlayTrack("02. Frozen - Do You Want to Build a Snowman.wav");
                    audio1.PlayEffect("WarmHugs.wav");
                }
                //                    audio2.PlayTrack("08 Feel the Light.wav");
                //                    audioLocal.PlayEffect("WarmHugs.wav");

                out1.SetValue(x);
            });
        }
Example #2
0
        public Halloween2017(IEnumerable <string> args)
        {
            mainSchedule.AddRange("5:00 pm", "9:00 pm",
                                  DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Sunday);
            mainSchedule.AddRange("5:00 pm", "9:00 pm",
                                  DayOfWeek.Friday, DayOfWeek.Saturday);

            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("4ea781ef257442edb524493da8f52220", expanderAudio2);     // rpi-eba6cbc7
            expanderServer.AddInstance("ed86c3dc166f41ee86626897ba039ed2", expanderLedmx);      // rpi-eb0092ca
            expanderServer.AddInstance("1583f686014345888c15d7fc9c55ca3c", expanderCat);        // rpi-eb81c94e
            expanderServer.AddInstance("d6fc4e752af04022bf3c1a1166a557bb", expanderHifi);       // rpi-eb428ef1
            expanderServer.AddInstance("60023fcde5b549b89fa828d31741dd0c", expanderPicture);    // rpi-eb91bc26
            expanderServer.AddInstance("e41d2977931d4887a9417e8adcd87306", expanderGhost);      // rpi-eb6a047c
            expanderServer.AddInstance("999861affa294fd7bbf0601505e9ae09", expanderMrPumpkin);  // rpi-ebd43a38
            expanderServer.AddInstance("992f8db68e874248b5ee667d23d74ac3", expanderSpider);     // rpi-eb9b3145
            expanderServer.AddInstance("db9b41a596cb4ed28e91f11a59afb95a", expanderRocking);    // rpi-eb32e5f9
            expanderServer.AddInstance("acbfada45c674077b9154f6a0e0df359", expanderFlying);     // rpi-eb35666e
            expanderServer.AddInstance("2e105175a66549d4a0ab7f8d446c2e29", expanderPopper);     // rpi-eb997095

            masterVolume.ConnectTo(Exec.MasterVolume);


            grumpyCat = new Modules.HalloweenGrumpyCat(
                air: catAir,
                light: catLights,
                audioPlayer: audioCat,
                name: nameof(grumpyCat));
            stateMachine.WhenStates(States.BackgroundFull, States.BackgroundSmall).Controls(grumpyCat.InputPower);

            pictureFrame = new Modules.HalloweenPictureFrame(
                medeaWizPlayer: pictureFrame1,
                name: nameof(pictureFrame));
            stateMachine.WhenStates(States.BackgroundFull).Controls(pictureFrame.InputPower);

            flyingSkeleton = new Modules.HalloweenFlying(
                eyes: flyingSkeletonEyes,
                fogStairsLight1: fogStairsLight1,
                fogStairsLight2: fogStairsLight2,
                fogStairsPump1: fogStairsPump1,
                fogStairsPump2: fogStairsPump2,
                audioPlayer: audioFlying,
                name: nameof(flyingSkeleton));
            stateMachine.WhenStates(States.BackgroundFull).Controls(flyingSkeleton.InputPower);

            firstBeam.Output.Controls(flyingSkeleton.InputTrigger);

            rockingChair = new Modules.HalloweenRocker(
                rockingMotor: rockingChairMotor,
                ladyEyes: ladyMovingEyes,
                strobeLight: rockingChairLight,
                audioPlayer: audioRocking,
                name: nameof(pictureFrame));
            stateMachine.WhenStates(States.BackgroundFull).Controls(rockingChair.InputPower);

            rockingMotion.Output.Controls(rockingChair.InputTrigger);

            mrPumpkin = new Modules.HalloweenMrPumpkin(
                air: mrPumpkinAir,
                light: pumpkinLights,
                audioPlayer: audioPumpkin,
                name: nameof(mrPumpkin));
            stateMachine.WhenStates(States.BackgroundFull, States.BackgroundSmall).Controls(mrPumpkin.InputPower);

            frankGhost = new Modules.HalloweenFrankGhost(
                air: frankGhostAir,
                light: pixelsFrankGhost,
                audioPlayer: audioFrankGhost,
                name: nameof(frankGhost));
            stateMachine.WhenStates(States.BackgroundFull, States.BackgroundSmall).Controls(frankGhost.InputPower);

            spiderDrop = new Modules.HalloweenSpiderDrop(
                smallSpiderEyes: smallSpiderEyes,
                eyesLight: spiderEyes,
                drop: spiderDropRelease,
                venom: spiderVenom,
                strobeLight: flashUnderSpider,
                audioPlayer: audioSpider,
                name: nameof(spiderDrop));
            stateMachine.WhenStates(States.BackgroundFull).Controls(spiderDrop.InputPower);

            fireProjector = new Modules.FireProjector(
                fire: fire,
                name: nameof(fireProjector));
            stateMachine.WhenStates(States.BackgroundFull, States.Setup).Controls(fireProjector.InputPower);

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


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

            testButton1.Output.Subscribe(x =>
            {
            });

            testButton2.Output.Subscribe(x =>
            {
            });

            testButton3.Output.Subscribe(x =>
            {
            });

            testButton4.Output.Subscribe(x =>
            {
            });

            setupMode.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.Setup);
                }
                else
                {
                    stateMachine.GoToDefaultState();
                }
            });

            fullOn.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.BackgroundFull);
                }
                else
                {
                    stateMachine.GoToDefaultState();
                }
            });

            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 (mainSchedule.IsOpen)
                    {
                        stateMachine.GoToDefaultState();
                    }
                    else
                    {
                        stateMachine.GoToIdle();
                    }
                }
            });

            mainSchedule.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(flashTree);
            popOut2.ConnectTo(wall2Light);
            //popOut2.ConnectTo(wall7Light);
            //popOut2.ConnectTo(flashUnderSpider);
            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(flashTree);
            //popOutAll.ConnectTo(flashUnderSpider);
            popOutAll.ConnectTo(pixelsRoofEdge);
            popOutAll.ConnectTo(pixelsFrankGhost);
            //            popOutAll.ConnectTo(pinSpot);

            allLights.Add(
                wall1Light,
                wall2Light,
                wall3Light,
                wall4Light,
                wall5Light,
                wall6Light,
                rockingChairLight,
                //wall7Light,
                //wall8Light,
                //wall9Light,
                flashTree,
                flashUnderSpider,
                pixelsRoofEdge,
                pixelsFrankGhost,
                //                pinSpot,
                spiderLight,
                fogStairsLight1,
                fogStairsLight2,
                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)));

            pulsatingGargoyle.ConnectTo(spiderWebLights);

            stateMachine.For(States.Setup)
            .Controls(1, flickerEffect, pulsatingGargoyle)
            .Execute(ins =>
            {
                ins.WaitUntilCancel();
            });

            stateMachine.For(States.BackgroundSmall)
            .Controls(1, flickerEffect, pulsatingGargoyle)
            .Execute(i =>
            {
                treeGhosts.SetBrightness(1.0);
                treeSkulls.SetBrightness(1.0);
                audioHifi.SetBackgroundVolume(0.5);
                audioHifi.PlayBackground();
                ladyMovingEyes.SetValue(true);

                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 =>
            {
                ladyMovingEyes.SetValue(false);
                Exec.Cancel(sub3dfxLady);
                audioHifi.PauseBackground();
                purpleLights.SetBrightness(0.0);
                treeGhosts.SetBrightness(0.0);
                treeSkulls.SetBrightness(0.0);
            });

            stateMachine.For(States.BackgroundFull)
            .Controls(1, flickerEffect, pulsatingGargoyle)
            .Execute(i =>
            {
                treeGhosts.SetBrightness(1.0);
                treeSkulls.SetBrightness(1.0);
                audioHifi.PlayBackground();
                audioHifi.SetBackgroundVolume(0.7);
                //Exec.Execute(sub3dfxLady);

                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
                        lastFog.SetValue(true);
                        i.WaitFor(S(4));
                        lastFog.SetValue(false);
                        this.lastFogRun = DateTime.Now;
                    }
                }
            })
            .TearDown(instance =>
            {
                purpleLights.SetBrightness(0.0);
                treeGhosts.SetBrightness(0.0);
                treeSkulls.SetBrightness(0.0);

                audioHifi.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();
                    audioHifi.PlayEffect("scream.wav");
                    break;

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

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

                case "Thunder4.wav":
                    timelineThunder4.Start();
                    audioHifi.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.Pixel1D(pixelsFrankGhost, 0, 5), SacnUniverseFrankGhost, 1);

            acnOutput.Connect(new Physical.FogMachineA(fogStairsPump1, fogStairsLight1, 1), SacnUniverseDMXFogA);
            acnOutput.Connect(new Physical.FogMachineA(fogStairsPump2, fogStairsLight2, 10), SacnUniverseDMXFogA);

            //acnOutput.Connect(new Physical.SmallRGBStrobe(spiderLight, 1), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(wall6Light, 60), SacnUniverseEdmx4A);
            //acnOutput.Connect(new Physical.RGBStrobe(wall9Light, 70), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.RGBStrobe(rockingChairLight, 40), SacnUniverseEdmx4A);
            //acnOutput.Connect(new Physical.RGBStrobe(wall7Light, 80), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.DMXCommandOutput(pictureFrame1, 1, TimeSpan.FromMilliseconds(500), 0), SacnUniverseEdmx4B);
            acnOutput.Connect(new Physical.DMXCommandOutput(lady3dfx, 1, TimeSpan.FromMilliseconds(500), 0), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall1Light, 340, 8), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.RGBStrobe(wall2Light, 80), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall3Light, 330, 8), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall4Light, 310, 8), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.MarcGamutParH7(wall5Light, 300, 8), SacnUniverseEdmx4A);
            //            acnOutput.Connect(new Physical.MarcGamutParH7(wall6Light, 350, 8), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(stairs1Light, 66), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(stairs2Light, 51), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(treeGhosts, 67), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(treeSkulls, 131), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(spiderEyes, 128), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(popperEyes, 132), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(popper, 133), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.AmericanDJStrobe(flashTree, 100), SacnUniverseEdmx4A);
            acnOutput.Connect(new Physical.EliminatorFlash192(flashUnderSpider, 110), SacnUniverseDMXFogA);
            //            acnOutput.Connect(new Physical.MonopriceRGBWPinSpot(pinSpot, 20), 1);

            acnOutput.Connect(new Physical.GenericDimmer(fire, 1), SacnUniverseFire);

            acnOutput.Connect(new Physical.GenericDimmer(frankGhostAir, 10), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(mrPumpkinAir, 11), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(spiderWebLights, 99), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(catAir, 64), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(catLights, 65), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(pumpkinLights, 50), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsCrystal, 128), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(gargoyleLightsEyes, 129), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(flyingSkeletonEyes, 134), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(smallSpiderEyes, 135), SacnUniverseDMXLedmx);
            acnOutput.Connect(new Physical.GenericDimmer(streetNumberEyes, 131), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(bigSpiderEyes, 132), SacnUniverseDMXCat);
            acnOutput.Connect(new Physical.GenericDimmer(hazerFanSpeed, 500), SacnUniverseDMXFogA);
            acnOutput.Connect(new Physical.GenericDimmer(hazerHazeOutput, 501), SacnUniverseDMXFogA);
            //            acnOutput.Connect(new Physical.RGBIS(testLight1, 260), 1);


            expanderLedmx.DigitalInputs[4].Connect(frankGhostMotion, false);
            expanderLedmx.DigitalInputs[5].Connect(mrPumpkinMotion, false);
            expanderLedmx.DigitalInputs[6].Connect(rockingMotion, false);
            expanderCat.DigitalInputs[7].Connect(catMotion);
            expanderCat.DigitalInputs[6].Connect(secondBeam);
            expanderCat.DigitalInputs[5].Connect(spiderDropTrigger, inverted: true);
            expanderCat.DigitalInputs[4].Connect(firstBeam);
            expanderLedmx.DigitalInputs[7].Connect(lastBeam);
            //expanderMrPumpkin.DigitalOutputs[7].Connect(popper);
            expanderLedmx.DigitalOutputs[2].Connect(lastFog, inverted: true);
            expanderMrPumpkin.DigitalOutputs[7].Connect(rockingChairMotor);
            expanderMrPumpkin.DigitalOutputs[4].Connect(ladyMovingEyes);
            expanderLedmx.DigitalOutputs[0].Connect(spiderDropRelease);
            expanderLedmx.DigitalOutputs[1].Connect(spiderVenom);
            expanderCat.DigitalOutputs[6].Connect(spiderJump2);
            expanderLedmx.Connect(audioFrankGhost);
            expanderCat.Connect(audioCat);
            expanderHifi.Connect(audioHifi);
            expanderMrPumpkin.Connect(audioPumpkin);
            //expanderAudio2.Connect(audio2);
            expanderFlying.Connect(audioFlying);
            expanderSpider.Connect(audioSpider);
            expanderRocking.Connect(audioRocking);
            expanderPopper.Connect(audioPopper);

            expanderHifi.BackgroundAudioFiles = new string[]
            {
                "Thunder1.wav",
                "Thunder2.wav",
                "Thunder3.wav",
                "Thunder4.wav",
                "Thunder5.wav",
                "Thunder6.wav",
                "Thunder7.wav",
                "Thunder8.wav"
            };
            expanderRocking.BackgroundAudioFiles = new string[]
            {
                "68 Creaky Wooden Floorboards.wav"
            };

            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());

            Utils.ReactiveOr(blockCat, blockMaster).Controls(grumpyCat.InputTriggerBlock);
            Utils.ReactiveOr(blockPumpkin, blockMaster).Controls(mrPumpkin.InputTriggerBlock);
            Utils.ReactiveOr(blockFrankGhost, blockMaster).Controls(frankGhost.InputTriggerBlock);
            Utils.ReactiveOr(blockSpiderDrop, blockMaster).Controls(spiderDrop.InputTriggerBlock);
            Utils.ReactiveOr(blockFire, blockMaster).Controls(fireProjector.InputTriggerBlock);
            Utils.ReactiveOr(blockPicture, blockMaster).Controls(pictureFrame.InputTriggerBlock);
            Utils.ReactiveOr(blockRocking, blockMaster).Controls(rockingChair.InputTriggerBlock);
            Utils.ReactiveOr(blockFirst, blockMaster).Controls(flyingSkeleton.InputTriggerBlock);

            catMotion.Controls(grumpyCat.InputTrigger);
            secondBeam.Controls(pictureFrame.InputTrigger);
            mrPumpkinMotion.Controls(mrPumpkin.InputTrigger);
            frankGhostMotion.Controls(frankGhost.InputTrigger);
            spiderDropTrigger.Controls(spiderDrop.InputTrigger);

            spiderDropTrigger.Output.Subscribe(x =>
            {
                if (x)
                {
                    Exec.Execute(sub3dfxLady);
                }
            });

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

                if (x && (stateMachine.CurrentState == States.BackgroundFull || stateMachine.CurrentState == States.Setup) && !emergencyStop.Value && !blockMaster.Value && !blockLast.Value)
                {
                    subLast.Run();
                }
            });

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

            sub3dfxLady
            .RunAction(i =>
            {
                i.WaitFor(S(1));

                if (random.Next(2) == 0)
                {
                    lady3dfx.SendCommand(null, 99);
                    i.WaitFor(S(30));
                }
                else
                {
                    lady3dfx.SendCommand(null, (byte)(random.Next(4) + 1));
                    i.WaitFor(S(60 * 2.0));
                }
            })
            .TearDown(i =>
            {
                lady3dfx.SendCommand(null, 255);
            });

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

            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 #3
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 #4
0
        public Xmas2015(IEnumerable <string> args)
        {
            hours.AddRange("4:00 pm", "10:00 pm");

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

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

            pulsatingEffect1.ConnectTo(lightOlaf);
            pulsatingEffect2.ConnectTo(lightR2D2);
            pulsatingEffect3.ConnectTo(pixelsRoofEdge, Utils.Data(Color.Red));
            pulsatingEffect4.ConnectTo(lightBlueButton);
            pulsatingEffect4.ConnectTo(lightRedButton);

            expanderServer.AddInstance("ec30b8eda95b4c5cab46bf630d74810e", expanderLocal);
            expanderServer.AddInstance("ed86c3dc166f41ee86626897ba039ed2", expander1);      // rpi-eb0092ca
            expanderServer.AddInstance("10520fdcf14d47cba31da8b6e05d01d8", expander2);      // rpi-eb428ef1
            expanderServer.AddInstance("59ebb8e925c94182a0f6e0ef09180200", expander3);      // rpi-eba6cbc7
            expanderServer.AddInstance("1583f686014345888c15d7fc9c55ca3c", expander4);      // rpi-eb81c94e

            expander1.DigitalInputs[5].Connect(inR2D2);
            expander1.DigitalInputs[4].Connect(inOlaf);
            expander1.DigitalInputs[6].Connect(inShowMachine);
            expander1.DigitalOutputs[7].Connect(out1);
            expander4.DigitalOutputs[7].Connect(snowMachine);

            expander4.DigitalInputs[5].Connect(inBlueButton);
            expander4.DigitalInputs[4].Connect(inRedButton);

            expander1.Connect(audio1);
            expander2.Connect(audioMain);
            expander3.Connect(video3);
            expander4.Connect(audioDarthVader);

            blackOut.ConnectTo(Exec.Blackout);
            whiteOut.ConnectTo(Exec.Whiteout);

            midiAkai.Controller(midiChannel, 1).Subscribe(x => blackOut.Value = x.Value);
            midiAkai.Controller(midiChannel, 2).Subscribe(x => whiteOut.Value = x.Value);

            dmxPlayback.Load(Path.Combine(Exec.ExpanderSharedFiles, "Seq", "XmasLoop.bin"), 15);
            dmxPlayback.Loop = true;

            var pixelMapping = Framework.Utility.PixelMapping.GeneratePixelMappingFromGlediatorPatch(
                Path.Combine(Exec.ExpanderSharedFiles, "Glediator", "ArtNet 14-15 20x10.patch.glediator"));

            dmxPlayback.SetOutput(pixelsMatrix, pixelMapping);

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

            inflatablesRunning.Subscribe(x =>
            {
                airReindeer.SetValue(x);

                Exec.SetKey("InflatablesRunning", x.ToString());
            });

            // Read from storage
            inflatablesRunning.OnNext(Exec.GetSetKey("InflatablesRunning", false));

            //            hours.Output.Log("Hours inside");

            stateMachine.ForFromSubroutine(States.Background, subBackground);
            stateMachine.ForFromSubroutine(States.Music1, subMusic1);
            stateMachine.ForFromSubroutine(States.Music2, subMusic2);
            stateMachine.ForFromSubroutine(States.SantaVideo, subSantaVideo);
            stateMachine.ForFromSubroutine(States.DarthVader, subStarWars);

            airR2D2.SetValue(true);
            airSanta1.SetValue(true);
            airOlaf.SetValue(true);
            laser.SetValue(true);

            hours
            //    .ControlsMasterPower(packages)
            //    .ControlsMasterPower(airSnowman)
            .ControlsMasterPower(airOlaf)
            .ControlsMasterPower(laser)
            .ControlsMasterPower(airSanta1)
            .ControlsMasterPower(airR2D2);
            //    .ControlsMasterPower(airSanta);

            buttonStartInflatables.Output.Subscribe(x =>
            {
                if (x && hours.IsOpen)
                {
                    inflatablesRunning.OnNext(true);
                }
            });

            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 0, 50), SacnUniverse6, 1);
            acnOutput.Connect(new Physical.Pixel1D(pixelsRoofEdge, 50, 100), SacnUniverse5, 1);

            var pixelMapping2D = Framework.Utility.PixelMapping.GeneratePixelMapping(20, 10, pixelOrder: Framework.Utility.PixelOrder.HorizontalSnakeBottomLeft);

            acnOutput.Connect(new Physical.Pixel2D(pixelsMatrix, pixelMapping2D), SacnUniverse10, 1);

            acnOutput.Connect(new Physical.Pixel1D(saberPixels, 0, 32), SacnUniverse12, 1);

            acnOutput.Connect(new Physical.GenericDimmer(airOlaf, 10), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(airReindeer, 12), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(airR2D2, 11), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightHat1, 96), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightHat2, 97), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightHat3, 98), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightHat4, 99), SacnUniverseDMX);
            acnOutput.Connect(new Physical.RGBStrobe(lightVader, 60), SacnUniverseDMX);
            acnOutput.Connect(new Physical.RGBStrobe(lightWall1, 70), SacnUniverseDMX);
            acnOutput.Connect(new Physical.RGBStrobe(lightWall2, 40), SacnUniverseDMX);
            acnOutput.Connect(new Physical.RGBStrobe(lightWall3, 80), SacnUniverseDMX);

            acnOutput.Connect(new Physical.GenericDimmer(laser, 4), SacnUniverseRenardBig);

            acnOutput.Connect(new Physical.GenericDimmer(lightOlaf, 128), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightSanta, 131), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightSnowman, 132), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightSnowman, 132), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightBlueButton, 262), SacnUniverseDMX);
            acnOutput.Connect(new Physical.GenericDimmer(lightRedButton, 263), SacnUniverseDMX);

            acnOutput.Connect(new Physical.GenericDimmer(lightR2D2, 16), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightRail2, 10), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet5, 11), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet6, 19), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(airSanta1, 20), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet7, 22), SacnUniverseRenardBig);

            acnOutput.Connect(new Physical.GenericDimmer(lightStairs2, 25), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightXmasTree, 26), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightReindeer2, 29), SacnUniverseRenardBig);
            acnOutput.Connect(new Physical.GenericDimmer(lightReindeer1, 32), SacnUniverseRenardBig);

            acnOutput.Connect(new Physical.GenericDimmer(lightStairs1, 1), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet2, 2), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet1, 3), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet3, 4), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightNet4, 5), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightRail1, 6), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightTopper1, 7), SacnUniverseRenardSmall);
            acnOutput.Connect(new Physical.GenericDimmer(lightTopper2, 8), SacnUniverseRenardSmall);

            hours.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToDefaultState();
                }
                else
                {
                    //if (buttonOverrideHours.Active)
                    //    return;

                    stateMachine.GoToIdle();

                    // Needed?
                    System.Threading.Thread.Sleep(200);

                    inflatablesRunning.OnNext(false);
                }
            });

            subBackground
            .LockWhenRunning(
                lightNet1,
                lightNet2,
                lightNet3,
                lightNet4,
                lightNet5,
                lightNet6,
                lightNet7,
                lightNet8,
                lightTopper1,
                lightTopper2,
                lightXmasTree,
                lightStairs1,
                lightStairs2,
                lightRail1,
                lightRail2,
                lightSanta,
                lightSnowman,
                lightHat1,
                lightHat2,
                lightHat3,
                lightHat4,
                lightReindeer1,
                lightReindeer2,
                lightVader,
                lightWall1,
                lightWall2,
                lightWall3,
                lightR2D2,
                lightOlaf,
                saberPixels)
            .RunAction(i =>
            {
                pulsatingEffect4.Start();
                lightR2D2.SetBrightness(1, i.Token);
                lightOlaf.SetBrightness(1, i.Token);
                lightNet1.SetBrightness(1, i.Token);
                lightNet2.SetBrightness(1, i.Token);
                lightNet3.SetBrightness(1, i.Token);
                lightNet4.SetBrightness(1, i.Token);
                lightNet5.SetBrightness(1, i.Token);
                lightNet6.SetBrightness(1, i.Token);
                lightNet7.SetBrightness(1, i.Token);
                lightNet8.SetBrightness(1, i.Token);
                lightTopper1.SetBrightness(1, i.Token);
                lightTopper2.SetBrightness(1, i.Token);
                lightXmasTree.SetBrightness(1, i.Token);
                lightStairs1.SetBrightness(1, i.Token);
                lightStairs2.SetBrightness(1, i.Token);
                lightRail1.SetBrightness(1, i.Token);
                lightRail2.SetBrightness(1, i.Token);
                lightSanta.SetBrightness(1, i.Token);
                lightSnowman.SetBrightness(1, i.Token);
                lightHat1.SetBrightness(1, i.Token);
                lightHat2.SetBrightness(1, i.Token);
                lightHat3.SetBrightness(1, i.Token);
                lightHat4.SetBrightness(1, i.Token);
                lightReindeer1.SetBrightness(1, i.Token);
                lightReindeer2.SetBrightness(1, i.Token);
                lightVader.SetColor(Color.Red, 1, i.Token);
                lightWall1.SetColor(Color.Red, 1, i.Token);
                lightWall2.SetColor(Color.Red, 1, i.Token);
                lightWall3.SetColor(Color.Red, 1, i.Token);

                saberPixels.SetColor(Color.Red, 0.4, i.Token);

                subCandyCane.Run();
                dmxPlayback.Run();

                i.WaitUntilCancel();

                dmxPlayback.Stop();
                Exec.Cancel(subCandyCane);
                pulsatingEffect4.Stop();
            });

            subCandyCane
            .LockWhenRunning(pixelsRoofEdge)
            .RunAction(i =>
            {
                const int spacing = 4;

                while (true)
                {
                    for (int x = 0; x < spacing; x++)
                    {
                        pixelsRoofEdge.Inject((x % spacing) == 0 ? Color.Red : Color.White, 0.5, i.Token);

                        i.WaitFor(S(0.30), true);
                    }
                }
            });

            subSnow
            .RunAction(ins =>
            {
                snowMachine.SetValue(true);

                ins.WaitFor(S(30));
            })
            .TearDown(i =>
            {
                snowMachine.SetValue(false);
            });

            subStarWarsCane
            .LockWhenRunning(
                pixelsRoofEdge,
                pixelsMatrix)
            .RunAction(instance =>
            {
                const int spacing = 4;

                while (!instance.CancelToken.IsCancellationRequested)
                {
                    for (int i = 0; i < spacing; i++)
                    {
                        switch (i % spacing)
                        {
                        case 0:
                        case 1:
                            pixelsRoofEdge.InjectRev(Color.Yellow, 1.0, instance.Token);
                            break;

                        case 2:
                        case 3:
                            pixelsRoofEdge.InjectRev(Color.Orange, 0.2, instance.Token);
                            break;
                        }

                        instance.WaitFor(S(0.1));

                        if (instance.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                }
            });

            subMusic1
            .RunAction(ins =>
            {
                audioMain.PlayTrack("08 Feel the Light.wav");
                ins.WaitFor(S(240));
            }).TearDown(i =>
            {
                lorFeelTheLight.Stop();
                audioMain.PauseTrack();
            });

            subMusic2
            .RunAction(ins =>
            {
                snowMachine.SetValue(true);
                audioMain.PlayTrack("T.P.E. - 04 - Josh Groban - Believe.flac");
                ins.WaitFor(S(260));
            }).TearDown(i =>
            {
                snowMachine.SetValue(false);
                lorBelieve.Stop();
                audioMain.PauseTrack();
            });

            subSantaVideo
            .RunAction(i =>
            {
                pulsatingEffect3.Start();
                switch (random.Next(6))
                {
                case 0:
                    video3.PlayVideo("NBC_DeckTheHalls_Holl_H.mp4");
                    break;

                case 1:
                    video3.PlayVideo("NBC_AllThruHouse_Part1_Holl_H.mp4");
                    break;

                case 2:
                    video3.PlayVideo("NBC_AllThruHouse_Part2_Holl_H.mp4");
                    break;

                case 3:
                    video3.PlayVideo("NBC_AllThruHouse_Part3_Holl_H.mp4");
                    break;

                case 4:
                    video3.PlayVideo("NBC_JingleBells_Holl_H.mp4");
                    break;

                case 5:
                    video3.PlayVideo("NBC_WeWishYou_Holl_H.mp4");
                    break;
                }

                i.WaitFor(S(120), false);
                pulsatingEffect3.Stop();
            });

            subOlaf
            .RunAction(i =>
            {
                pulsatingEffect1.Start();
                audio1.PlayNewEffect("WarmHugs.wav", 0.0, 1.0);
                i.WaitFor(S(10));
                pulsatingEffect1.Stop();
            });

            subR2D2
            .RunAction(i =>
            {
                pulsatingEffect2.Start();
                audio1.PlayNewEffect("Im C3PO.wav", 1.0, 0.0);
                i.WaitFor(S(4));
                audio1.PlayNewEffect("Processing R2D2.wav", 0.5, 0.0);
                i.WaitFor(S(5));
                pulsatingEffect2.Stop();
            });

            subStarWars
            .LockWhenRunning(
                saberPixels,
                lightVader,
                lightR2D2)
            .RunAction(instance =>
            {
                //Exec.Cancel(subCandyCane);
                subStarWarsCane.Run();
                lightR2D2.SetBrightness(1.0, instance.Token);

                audioMain.PlayTrack("01. Star Wars - Main Title.wav");

                instance.WaitFor(S(16));

                /*
                 *  elJesus.SetPower(true);
                 *  pulsatingStar.Start();
                 *  lightJesus.SetColor(Color.White, 0.3);
                 *  light3wise.SetOnlyColor(Color.LightYellow);
                 *  light3wise.RunEffect(new Effect2.Fader(0.0, 1.0), S(1.0));*/

                Exec.MasterEffect.Fade(lightVader, 0.0, 1.0, 1000, token: instance.Token, additionalData: Utils.Data(Color.Red));
                instance.WaitFor(S(2.5));

                Exec.Cancel(subStarWarsCane);
                instance.WaitFor(S(0.5));

                audioDarthVader.PlayEffect("saberon.wav");
                for (int sab = 00; sab < 32; sab++)
                {
                    saberPixels.Inject(Color.Red, 0.5, instance.Token);
                    instance.WaitFor(S(0.01));
                }
                instance.WaitFor(S(1));
                audioMain.PauseTrack();

                lightVader.SetColor(Color.Red, 1.0, instance.Token);
                audioDarthVader.PlayEffect("father.wav");
                instance.WaitFor(S(5));

                lightVader.SetBrightness(0.0, instance.Token);
                //light3wise.TurnOff();
                //lightJesus.TurnOff();
                //pulsatingStar.Stop();
                //elJesus.TurnOff();

                audioDarthVader.PlayEffect("force1.wav");
                instance.WaitFor(S(4));

                audioDarthVader.PlayEffect("saberoff.wav");
                instance.WaitFor(S(0.7));
                for (int sab = 0; sab < 16; sab++)
                {
                    saberPixels.InjectRev(Color.Black, 0, instance.Token);
                    saberPixels.InjectRev(Color.Black, 0, instance.Token);
                    instance.WaitFor(S(0.01));
                }
                //elLightsaber.SetPower(false);
                instance.WaitFor(S(2));

                //lightJesus.TurnOff();
                //light3wise.TurnOff();
                //elLightsaber.TurnOff();
                //pulsatingStar.Stop();
                //elJesus.TurnOff();
                //instance.WaitFor(S(2));
            })
            .TearDown(i =>
            {
                audioMain.PauseTrack();
            });


            midiAkai.Note(midiChannel, 36).Subscribe(x =>
            {
                if (x)
                {
                    subOlaf.Run();
                }
            });

            midiAkai.Note(midiChannel, 37).Subscribe(x =>
            {
                if (x)
                {
                    subR2D2.Run();
                }
            });

            midiAkai.Note(midiChannel, 38).Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.Music1);
                }
                //                    audio2.PlayTrack("08 Feel the Light.wav");
            });

            midiAkai.Note(midiChannel, 39).Subscribe(x =>
            {
                if (x)
                {
                    lorFeelTheLight.Stop();
                    audioMain.PauseTrack();
                }
            });

            midiAkai.Note(midiChannel, 40).Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToState(States.SantaVideo);
                }
            });

            inOlaf.Output.Subscribe(x =>
            {
                if (x && hours.IsOpen)
                {
                    subOlaf.Run();
                }
            });

            inR2D2.Output.Subscribe(x =>
            {
                if (x && hours.IsOpen)
                {
                    subR2D2.Run();
                }
            });

            inRedButton.Output.Subscribe(x =>
            {
                if (x)
                {
                    if (hours.IsOpen)
                    {
                        if (stateMachine.CurrentState == States.Background)
                        {
                            stateMachine.GoToState(States.DarthVader);
                        }
                    }
                    else
                    {
                        audioDarthVader.PlayEffect("darthvader_lackoffaith.wav");
                    }
                }
            });

            inBlueButton.Output.Subscribe(x =>
            {
                if (x)
                {
                    if (hours.IsOpen)
                    {
                        subSnow.Run();
                        if (stateMachine.CurrentState == States.Background)
                        {
                            stateMachine.GoToState(States.Music2);
                        }
                    }
                    else
                    {
                        audioDarthVader.PlayEffect("darkside.wav");
                    }
                }
            });

            audioMain.AudioTrackStart += (o, e) =>
            {
                switch (e.FileName)
                {
                case "08 Feel the Light.wav":
                    lorFeelTheLight.Start(27830);
                    break;

                case "T.P.E. - 04 - Josh Groban - Believe.flac":
                    lorBelieve.Start();
                    break;
                }
            };

            audioMain.AudioTrackDone += (o, e) =>
            {
                //                Thread.Sleep(5000);
                //    audio2.PlayTrack("08 Feel the Light.wav");
            };

            inShowMachine.Output.Subscribe(x =>
            {
                snowMachine.SetValue(x);
                //                lightRedButton.SetBrightness(x ? 1.0 : 0.0);
                //if (x)
                //    stateMachine.GoToState(States.Music1);
            });

            in2.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToIdle();
                }
            });

            in3.Output.Subscribe(x =>
            {
                if (x)
                {
                    stateMachine.GoToDefaultState();
                }
            });

            ImportAndMapFeelTheLight();
            ImportAndMapBelieve();
        }