PlayEffect() public method

public PlayEffect ( string name ) : NetworkAudioPlayer
name string
return NetworkAudioPlayer
示例#1
0
        public override void Start()
        {
            pulsatingEffect1.AddDevice(lightHatsRight);
            pulsatingEffect2
            .AddDevice(lightCeiling1)
            .AddDevice(lightCeiling2)
            .AddDevice(lightCeiling3);

            candyCane
            .WhenExecuted
            .SetUp(() => allPixels.TurnOff())
            .Execute(instance =>
            {
                const int spacing = 4;

                while (true)
                {
                    for (int i = 0; i < spacing; i++)
                    {
                        allPixels.Inject((i % spacing) == 0 ? Color.Red : Color.White, 1.0);

                        instance.WaitFor(S(0.2), true);
                    }
                }
            })
            .TearDown(() => allPixels.TurnOff());

            starwarsCane
            .WhenExecuted
            .Execute(instance =>
            {
                const int spacing = 4;

                allPixels.TurnOff();

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

                        case 2:
                        case 3:
                            allPixels.InjectRev(Color.Orange, 0.2);
                            break;
                        }

                        instance.WaitFor(S(0.1));

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

            backgroundLoop
            .WhenExecuted
            .SetUp(() =>
            {
                pulsatingEffect1.Start();
                lightGarlandLeft.Brightness  = 1;
                lightGarlandRight.Brightness = 1;
                lightIcicles.Brightness      = 1;
                lightTreesRight.Brightness   = 1;
                lightHatsRight.Brightness    = 1;
                lightNetLeft.Brightness      = 0.5;
                lightNetRight.Brightness     = 0.5;
                lightReindeers.Brightness    = 1;
                lightTree.Brightness         = 1;
                lightCeiling1.SetColor(Color.Red, 0.5);
                lightCeiling2.SetColor(Color.Red, 0.5);
                lightCeiling3.SetColor(Color.Red, 0.5);

                Executor.Current.Execute(candyCane);
            })
            .TearDown(() =>
            {
                Executor.Current.Cancel(candyCane);

                EverythingOff();
            });


            musicSeq
            .Loop
            .WhenExecuted
            .SetUp(() =>
            {
                audioPlayer.CueTrack("21 Christmas Canon Rock");
                // Make sure it's ready
                System.Threading.Thread.Sleep(800);

                EverythingOff();
            })
            .Execute(instance =>
            {
                audioPlayer.PlayTrack();
                var task = timeline.Start();

                try
                {
                    task.Wait(instance.CancelToken);

                    instance.WaitFor(S(10));
                }
                finally
                {
                    timeline.Stop();
                    audioPlayer.PauseTrack();
                }

                if (!instance.IsCancellationRequested)
                {
                    instance.WaitFor(S(2));
                }
                EverythingOff();

                instance.WaitFor(S(2), true);


                Executor.Current.Execute(backgroundLoop);
                instance.WaitFor(S(30));
                Executor.Current.Cancel(backgroundLoop);
                EverythingOff();
                instance.WaitFor(S(1));
            })
            .TearDown(() =>
            {
                EverythingOff();
            });

            buttonSeq
            .Loop
            .WhenExecuted
            .Execute(instance =>
            {
                buttonLightBlue.SetPower(true);
                buttonLightRed.SetPower(false);
                instance.WaitFor(S(0.2));
                buttonLightBlue.SetPower(false);
                buttonLightRed.SetPower(true);
                instance.WaitFor(S(0.2));
            })
            .TearDown(() =>
            {
                buttonLightBlue.SetPower(false);
                buttonLightRed.SetPower(false);
            });

            fatherSeq
            .WhenExecuted
            .Execute(instance =>
            {
                Executor.Current.Execute(starwarsCane);

                EverythingOff();

                audioPlayer.CueTrack("01 Star Wars_ Main Title");
                // Make sure it's ready
                instance.WaitFor(S(0.5));
                audioPlayer.PlayTrack();

                lightCeiling1.SetOnlyColor(Color.Yellow);
                lightCeiling2.SetOnlyColor(Color.Yellow);
                lightCeiling3.SetOnlyColor(Color.Yellow);
                pulsatingEffect2.Start();
                instance.WaitFor(S(16));
                pulsatingEffect2.Stop();
                audioPlayer.PauseTrack();
                Executor.Current.Cancel(starwarsCane);
                allPixels.TurnOff();
                instance.WaitFor(S(0.5));

                elJesus.SetPower(true);
                lightJesus.SetColor(Color.White, 0.3);

                instance.WaitFor(S(1.5));

                elLightsaber.SetPower(true);
                audioPlayer.PlayEffect("saberon");
                instance.WaitFor(S(1));

                lightVader.SetColor(Color.Red, 1.0);
                audioPlayer.PlayEffect("father");
                instance.WaitFor(S(3));

                lightVader.TurnOff();
                audioPlayer.PlayEffect("saberoff");
                instance.WaitFor(S(0.5));
                elLightsaber.SetPower(false);
                instance.WaitFor(S(1));

                lightJesus.TurnOff();
                elLightsaber.TurnOff();
                elJesus.TurnOff();
            });

            breathSeq
            .WhenExecuted
            .Execute(instance =>
            {
                audioPlayer.PlayEffect("Darth Breathing");
                instance.WaitFor(S(4));
            });

            laserSeq
            .WhenExecuted
            .SetUp(() =>
            {
                allPixels.TurnOff();
            })
            .Execute(instance =>
            {
                audioPlayer.PlayEffect("lazer");

                var cb = new ColorBrightness[6];
                cb[0]  = new ColorBrightness(Color.Black, 1.0);
                cb[1]  = new ColorBrightness(Color.Red, 1.0);
                cb[2]  = new ColorBrightness(Color.Orange, 1.0);
                cb[3]  = new ColorBrightness(Color.Yellow, 1.0);
                cb[4]  = new ColorBrightness(Color.Blue, 1.0);
                cb[5]  = new ColorBrightness(Color.White, 1.0);

                for (int i = -6; i < allPixels.Pixels; i++)
                {
                    allPixels.SetColors(i, cb);
                    System.Threading.Thread.Sleep(25);
                }

                instance.WaitFor(S(1));
            })
            .TearDown(() =>
            {
                allPixels.TurnOff();
            });

            stateMachine.ForFromSequence(States.Background, backgroundLoop);

            stateMachine.ForFromSequence(States.Music, musicSeq);

            stateMachine.ForFromSequence(States.Vader, fatherSeq);


            // Start Reindeer
            buttonStartReindeer.ActiveChanged += (sender, e) =>
            {
                if (!e.NewState)
                {
                    return;
                }

                if (hours.IsOpen)
                {
                    bigReindeer.SetPower(true);
                }
                else
                {
                    TestAllPixels(Color.Red, 1.0, S(1));
                    TestAllPixels(Color.Red, 0.5, S(1));

                    TestAllPixels(Color.Green, 1.0, S(1));
                    TestAllPixels(Color.Green, 0.5, S(1));

                    TestAllPixels(Color.Blue, 1.0, S(1));
                    TestAllPixels(Color.Blue, 0.5, S(1));

                    TestAllPixels(Color.Purple, 1.0, S(1));
                    TestAllPixels(Color.Purple, 0.5, S(1));

                    TestAllPixels(Color.White, 1.0, S(1));
                    TestAllPixels(Color.White, 0.5, S(1));

                    allPixels.TurnOff();
                }
            };

            // Red Button
            buttonRed.ActiveChanged += (sender, e) =>
            {
                if (!e.NewState)
                {
                    return;
                }

                if (hours.IsOpen)
                {
                    stateMachine.SetMomentaryState(States.Vader);
                }
                else
                {
                    Executor.Current.Execute(laserSeq);
                }
            };

            // Blue Button
            buttonBlue.ActiveChanged += (sender, e) =>
            {
                if (!e.NewState)
                {
                    return;
                }

                if (hours.IsOpen)
                {
                    if (stateMachine.CurrentState == States.Background)
                    {
                        stateMachine.SetMomentaryState(States.Music);
                    }
                }
                else
                {
                    Executor.Current.Execute(breathSeq);
                }
            };

            // Hours
            hours.OpenHoursChanged += (sender, e) =>
            {
                if (e.IsOpenNow)
                {
                    stateMachine.SetState(States.Background);

                    Executor.Current.Execute(buttonSeq);
                }
                else
                {
                    Executor.Current.Cancel(buttonSeq);

                    stateMachine.Hold();
                    bigReindeer.SetPower(false);
                }
            };
        }
示例#2
0
        public override void Start()
        {
            var explosion = new Controller.Sequence("Explosion");

            explosion.WhenExecuted
            .Execute(instance =>
            {
                audioPlayer.PlayEffect("18384__inferno__largex");
                instance.WaitFor(MS(300));
                int d = 100;
                explosion1.SetBrightness(1);
                instance.WaitFor(MS(d));
                explosion1.SetBrightness(0.5);
                explosion2.SetBrightness(1);
                instance.WaitFor(MS(d));
                explosion1.TurnOff();
                explosion2.SetBrightness(0.5);
                explosion3.SetBrightness(1);
                instance.WaitFor(MS(d));
                explosion2.TurnOff();
                explosion3.SetBrightness(0.5);
                explosion4.SetBrightness(1);
                instance.WaitFor(MS(d));
                explosion3.TurnOff();
                explosion4.SetBrightness(0.5);
                instance.WaitFor(MS(d));
                explosion4.TurnOff();
            });

            var seq = new Controller.Sequence("Seq");

            seq.WhenExecuted
            .Execute(instance =>
            {
                //                    audioPlayer.PlayEffect("tie_fighter");
                //                    x.WaitFor(Seconds(2));

                audioPlayer.PlayEffect("Lazer");
                instance.WaitFor(MS(300));
                audioPlayer.PlayEffect("Lazer");

                var cb = new ColorBrightness[6];
                cb[0]  = new ColorBrightness(Color.Black, 1.0);
                cb[1]  = new ColorBrightness(Color.Red, 1.0);
                cb[2]  = new ColorBrightness(Color.Orange, 1.0);
                cb[3]  = new ColorBrightness(Color.Yellow, 1.0);
                cb[4]  = new ColorBrightness(Color.Blue, 1.0);
                cb[5]  = new ColorBrightness(Color.White, 1.0);

                for (int i = -6; i < 50; i++)
                {
                    testPixels.SetColors(i, cb);
                    instance.WaitFor(MS(10));
                }

                if (random.Next(10) > 5)
                {
                    Executor.Current.Execute(explosion);
                }
            });

            //            flickerEffect.AddDevice(candyLight);
            testButton.ActiveChanged += (sender, e) =>
            {
                if (e.NewState)
                {
                    this.log.Information("Button press!");
                    Executor.Current.Execute(seq);
                    //                    audioPlayer.PlayEffect("Lazer");
                }
                else
                {
                    this.log.Information("Button depress!");

                    //                    testPixels.SetColor(0, Color.Blue);
                }
            };
        }
        public HalloweenScene1(IEnumerable <string> args, System.Collections.Specialized.NameValueCollection settings)
        {
            hours             = new OperatingHours("Hours");
            georgeStrobeLight = new StrobeDimmer("George Strobe");
            spiderLight       = new StrobeColorDimmer("Spider Light");
            skullsLight       = new Dimmer("Skulls");
            cobWebLight       = new Dimmer("Cob Web");
            blinkyEyesLight   = new Switch("Blinky Eyes");
            rgbLightRight     = new StrobeColorDimmer("Light Right");
            georgeLight       = new StrobeColorDimmer("George Light");
            leftSkeletonLight = new StrobeColorDimmer("Skeleton Light");
            georgeMotor       = new MotorWithFeedback("George Motor");
            candyLight        = new StrobeColorDimmer("Candy Light");
            spiderLift        = new Switch("Slider Lift");
            smokeMachine      = new Switch("Smoke Machine");
            spiderEyes        = new Switch("Spider Eyes");
            pressureMat       = new DigitalInput("Pressure Mat");
            testButton        = new DigitalInput("Test");

            pulsatingEffect1 = new Effect.Pulsating(S(2), 0.1, 0.4);
            pulsatingEffect2 = new Effect.Pulsating(S(2), 0.3, 0.5);
            candyPulse       = new Effect.Pulsating(S(3), 0.01, 0.1);
            flickerEffect    = new Effect.Flicker(0.4, 0.6);

            audioPlayer = new Physical.NetworkAudioPlayer(
                settings["NetworkAudioPlayerIP"],
                int.Parse(settings["NetworkAudioPlayerPort"]));

            hours.AddRange("6:00 pm", "10:00 pm");

            var testSequence = new Controller.Sequence("Test Sequence");

            testSequence
            .WhenExecuted
            .Execute(instance =>
            {
                candyPulse.Start();
                audioPlayer.PlayEffect("Laugh");
                georgeMotor.SetVector(1.0, 160, S(5));
                georgeStrobeLight.SetStrobe(0.55, 1.0);
                georgeLight.SetStrobe(0.78, Color.Brown);

                georgeMotor.WaitForVectorReached();
                instance.WaitFor(S(2));
                georgeStrobeLight.TurnOff();
                georgeLight.TurnOff();

                georgeMotor.SetVector(0.9, 0, S(6));
                georgeMotor.WaitForVectorReached();
                candyPulse.Stop();
            });

            var testSequence2 = new Controller.Sequence("Test Sequence 2");

            testSequence2.WhenExecuted
            .Execute(instance =>
            {
                audioPlayer.PlayEffect("348 Spider Hiss");
                spiderLight.SetStrobe(0.78, Color.Red);

                spiderLift.SetPower(true);

                instance.WaitFor(S(3));

                // Spider up
                audioPlayer.PlayEffect("Scream");
                spiderLift.SetPower(false);

                instance.WaitFor(S(2));
                spiderLight.TurnOff();
            });

            var testSequence3 = new Controller.Sequence("Test Sequence 3");

            testSequence3.WhenExecuted
            .Execute(instance =>
            {
                spiderEyes.SetPower(true);
                instance.WaitFor(S(10));
                spiderEyes.SetPower(false);
            });

            var mainSequence = new Controller.Sequence("Main Sequence");

            mainSequence.WhenExecuted
            .Execute(instance =>
            {
                pulsatingEffect1.Stop();
                pulsatingEffect2.Stop();
                flickerEffect.Stop();
                blinkyEyesLight.SetPower(false);
                candyLight.SetColor(Color.Red);

                audioPlayer.PauseBackground();
                audioPlayer.PlayEffect("Door-creak");
                instance.WaitFor(S(2));


                instance.WaitFor(S(2));
                candyPulse.Stop();
                candyLight.SetStrobe(1, Color.White);
                instance.WaitFor(S(0.5));
                candyLight.TurnOff();
                instance.WaitFor(S(1));

                audioPlayer.PlayEffect("348 Spider Hiss");
                instance.WaitFor(S(0.5));
                spiderLight.SetStrobe(0.78, Color.Red);

                spiderLift.SetPower(true);
                spiderEyes.SetPower(true);

                instance.WaitFor(S(1));
                audioPlayer.PlayEffect("348 Spider Hiss");
                instance.WaitFor(S(2));

                // Spider up
                audioPlayer.PlayEffect("Scream");
                spiderLift.SetPower(false);
                spiderEyes.SetPower(false);
                smokeMachine.SetPower(true);

                instance.WaitFor(S(2));
                spiderLight.TurnOff();
                audioPlayer.PlayEffect("Violin screech");
                instance.WaitFor(S(2));


                // Skeleton to the right
                //                    audioPlayer.PlayEffect("Ghostly");
                rgbLightRight.SetStrobe(0.78, Color.Violet);
                instance.WaitFor(MS(1000));
                rgbLightRight.SetColor(Color.Red);
                instance.WaitFor(MS(1000));
                rgbLightRight.SetColor(Color.Blue);
                instance.WaitFor(S(2));
                rgbLightRight.TurnOff();
                instance.WaitFor(S(1));


                // Skeleton to the left
                audioPlayer.PlayEffect("death-scream");
                instance.WaitFor(S(0.5));
                leftSkeletonLight.SetStrobe(0.78, Color.Pink);
                instance.WaitFor(S(3));
                smokeMachine.SetPower(false);
                instance.WaitFor(S(1));
                leftSkeletonLight.TurnOff();


                // George
                audioPlayer.PlayEffect("Laugh");
                instance.WaitFor(MS(800));
                georgeMotor.SetVector(1.0, 160, S(5));
                georgeStrobeLight.SetStrobe(0.55, 1.0);
                georgeLight.SetStrobe(0.78, Color.Brown);

                georgeMotor.WaitForVectorReached();
                instance.WaitFor(S(2));
                georgeStrobeLight.TurnOff();
                georgeLight.TurnOff();

                candyPulse.MinBrightness = 0.05;
                candyPulse.MaxBrightness = 1.0;
                candyLight.SetColor(Color.Violet);
                candyPulse.Start();
                georgeMotor.SetVector(0.9, 0, S(6));
                georgeMotor.WaitForVectorReached();


                blinkyEyesLight.SetPower(true);

                flickerEffect.Start();
                pulsatingEffect1.Start();

                instance.WaitFor(S(5));
                smokeMachine.SetPower(true);

                audioPlayer.PlayBackground();
                // Wait for reset
                instance.WaitFor(S(15));
                pulsatingEffect2.Start();
                candyPulse.MinBrightness = 0.01;
                candyPulse.MaxBrightness = 0.1;
                candyLight.SetColor(Color.Green);
                smokeMachine.SetPower(false);
            });

            pressureMat.ActiveChanged += (sender, e) =>
            {
                if (e.NewState)
                {
                    if (hours.IsOpen)
                    {
                        Executor.Current.Execute(mainSequence);
                    }
                    else
                    {
                        audioPlayer.PlayEffect("Laugh");
                    }
                }
            };

            testButton.ActiveChanged += (sender, e) =>
            {
                if (e.NewState)
                {
                    Executor.Current.Execute(mainSequence);
                }
            };

            hours.OpenHoursChanged += (sender, e) =>
            {
                if (e.IsOpenNow)
                {
                    pulsatingEffect1.Start();
                    pulsatingEffect2.Start();
                    flickerEffect.Start();
                    candyPulse.Start();
                    blinkyEyesLight.SetPower(true);
                    audioPlayer.PlayBackground();
                }
                else
                {
                    pulsatingEffect1.Stop();
                    pulsatingEffect2.Stop();
                    flickerEffect.Stop();
                    candyPulse.Stop();
                    blinkyEyesLight.SetPower(false);
                    audioPlayer.PauseBackground();
                }
            };

            // Have it turned off, but prepare it with blue color for the effect
            rgbLightRight.SetColor(Color.Blue, 0);
            candyLight.SetColor(Color.Green, 0);
            pulsatingEffect1.AddDevice(rgbLightRight);
            pulsatingEffect2.AddDevice(cobWebLight);
            candyPulse.AddDevice(candyLight);

            flickerEffect.AddDevice(skullsLight);
        }