Ejemplo n.º 1
0
        public static void RunRemoteControl()
        {
            var remote          = new RemoteControl();
            var light           = new Light();
            var lightOn         = new LightOnCommand(light);
            var lightOff        = new LightOffCommand(light);
            var garageDoor      = new GarageDoor();
            var garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);
            var stereo          = new Stereo();
            var stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            var stereoOff       = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, garageDoorOpen, garageDoorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
        }
Ejemplo n.º 2
0
        public static void RunRemoteControlWithMacroCommand()
        {
            var light           = new Light();
            var lightOn         = new LightOnCommand(light);
            var lightOff        = new LightOffCommand(light);
            var garageDoor      = new GarageDoor();
            var garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);
            var stereo          = new Stereo();
            var stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            var stereoOff       = new StereoOffCommand(stereo);

            var macroOnCommand  = new MacroCommand(new ICommand[] { lightOn, garageDoorOpen, stereoOnWithCD });
            var macroOffCommand = new MacroCommand(new ICommand[] { lightOff, garageDoorClose, stereoOff });

            var remote = new RemoteControl();

            remote.SetCommand(0, macroOnCommand, macroOffCommand);
            System.Console.WriteLine(remote);

            System.Console.WriteLine("--- Pushing Macro on ---");
            remote.OnButtonWasPressed(0);
            System.Console.WriteLine("--- Pushing Macro off ---");
            remote.OffButtonWasPressed(0);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Only for example. Its bad idea - we need constructor with such parameter
 /// </summary>
 public Car()
 {
     Stereo = new Stereo();
     Engine = new Engine();
     Transmission = new Transmission();
     RocketBarrage = new RocketBarrage();
 }
Ejemplo n.º 4
0
        static void TryRemoteControl()
        {
            var remoteControl = new RemoteControl();

            var livingRoomLight = new Light("Living room");
            var kitchenLight    = new Light("Kitchen");
            var garageDoor      = new GarageDoor();
            var stereo          = new Stereo("Living room");

            var livingRoomLightOnCommand  = new LightsOnCommand(livingRoomLight);
            var livingRoomLightOffCommand = new LightsOffCommand(livingRoomLight);
            var kitchenLightOnCommand     = new LightsOnCommand(kitchenLight);
            var kitchenLightOffCommand    = new LightsOffCommand(kitchenLight);

            remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand);

            Console.WriteLine(remoteControl);

            remoteControl.PressOnButton(0);
            remoteControl.PressOffButton(0);

            remoteControl.PressOnButton(1);
            remoteControl.PressOffButton(1);
        }
Ejemplo n.º 5
0
        /// Uses 2D Newton's method using stereographic parametrization and fancy initial guess
        /// Pass:
        ///   abc - coefficients of the ellipse equation; aka the half-extents
        ///   p - point in ellipse coordinates
        public static Vector3 ClosestPointEllipsoid(
            Vector3 abc_, Vector3 p_, int numIters = 30, double threshold = 0)
        {
            // Doesn't like negative scales & result is the same by symmetry!
            vec3 abc = vec3.abs(new vec3(abc_));

            // WLOG move to the all-positive octant; move back to original octant when done.
            vec3 orig_p = new vec3(p_);
            vec3 p      = vec3.abs(orig_p);

            Stereo uv = Stereo.FromCartesian(InitialGuessClosestPointToEllipsoid(p, abc), abc);

            for (int i = 0; i < numIters; ++i)
            {
                Stereo prevUv = uv;
                uv = Iterate_Stereographic(uv, p, abc);
                if (Math.Abs(prevUv.x - uv.x) < threshold ||
                    Math.Abs(prevUv.y - uv.y) < threshold)
                {
                    break;
                }
            }

            // Move back to correct octant
            vec3 wrongOctant = uv.ToCartesian(abc);
            vec3 rightOctant = wrongOctant * orig_p.sign();

            return((Vector3)rightOctant);
        }
Ejemplo n.º 6
0
        private static string ProcessMacroCommand()
        {
            StringBuilder sb = new StringBuilder();

            RemoteControl remoteControl = new RemoteControl();

            Light  light  = new Light("Living Room");
            Stereo stereo = new Stereo();

            LightOnCommand        lightOn  = new LightOnCommand(light);
            StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);

            ICommand[] partyOn  = { lightOn, stereoOn };
            ICommand[] partyOff = { lightOff, stereoOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remoteControl.OnCommands[0]  = partyOnMacro;
            remoteControl.OffCommands[0] = partyOffMacro;

            sb.AppendLine(remoteControl.ToString());
            sb.AppendLine("--- Pushing Macro On ---");
            sb.AppendLine(remoteControl.OnButtonWasPushed(0));
            sb.AppendLine("--- Pushing Macro Off ---");
            sb.AppendLine(remoteControl.OffButtonWasPushed(0));

            return(sb.ToString());
        }
Ejemplo n.º 7
0
        static void TryRemoteControlWithMacroCommand()
        {
            Console.WriteLine("\n----- Remote control with party! -----\n");

            var remoteControl = new RemoteControl();

            var light  = new Light("Living room");
            var stereo = new Stereo("Living room");

            var lightOn   = new LightsOnCommand(light);
            var lightOff  = new LightsOffCommand(light);
            var stereoOn  = new StereoOnWithCDCommand(stereo);
            var stereoOff = new StereoOffWithCDCommand(stereo);

            var partyOn  = new ICommand[] { lightOn, stereoOn };
            var partyOff = new ICommand[] { lightOff, stereoOff };

            var partyOnCommand  = new MacroCommand(partyOn);
            var partyOffCommand = new MacroCommand(partyOff);

            remoteControl.SetCommand(0, partyOnCommand, partyOffCommand);
            Console.WriteLine(remoteControl);

            Console.WriteLine("\n-- Party on --\n");
            remoteControl.PressOnButton(0);
            Console.WriteLine("\n-- Party off --\n");
            remoteControl.PressOffButton(0);
        }
Ejemplo n.º 8
0
 public static Stereo[] Deseralize(Stream source)
 {
     using (BinaryReader reader = new BinaryReader(source, Encoding.Default, true))
     {
         //Read in the number of records
         var      records = reader.ReadInt64();
         Stereo[] stereos = new Stereo[records];
         for (long i = 0; i < records; i++)
         {
             //Read in the number of samples
             var samples = reader.ReadInt32();
             var stereo  = new Stereo(samples);
             //Read in the L channel
             for (int j = 0; j < samples; j++)
             {
                 stereo.L[j] = reader.ReadSingle();
             }
             //Read in the R channel
             for (int j = 0; j < samples; j++)
             {
                 stereo.R[j] = reader.ReadSingle();
             }
             //Set the sterieo object we created in to the array.
             stereos[i] = stereo;
         }
         return(stereos);
     }
 }
Ejemplo n.º 9
0
        public static void MacroCommandTests()
        {
            var light  = new Light("Living Room");
            var tv     = new TV("Living Room");
            var stereo = new Stereo("Living Room");
            var hottub = new Hottub();

            var lightOn  = new LightOnCommand(light);
            var stereoOn = new StereoOnWithCdCommand(stereo);
            var tvOn     = new TvOnCommand(tv);
            var hottubOn = new HottubOnCommand(hottub);

            var lightOff  = new LightOffCommand(light);
            var stereoOff = new StereoOffCommand(stereo);
            var tvOff     = new TvOffCommand(tv);
            var hottubOff = new HottubOffCommand(hottub);

            IUndoableCommand[] partyOn       = { lightOn, stereoOn, tvOn, hottubOn };
            IUndoableCommand[] partyOff      = { lightOff, stereoOff, tvOff, hottubOff };
            MacroCommand       partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand       partyOffMacro = new MacroCommand(partyOff);

            var remoteControl = new RemoteControl();

            remoteControl.SetCommand(1, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("---Pushing Macro On-- -");
            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine("---Pushing Macro Off-- -");
            remoteControl.OffButtonWasPushed(1);

            Console.ReadKey();
        }
Ejemplo n.º 10
0
        private static void CommandPattern()
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            Light  light  = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            LightOnCommand  lightOn  = new LightOnCommand(light);
            StereoOnCommand stereoOn = new StereoOnCommand(stereo);
            TVOnCommand     tvOn     = new TVOnCommand(tv);
            HottubOnCommand hottubOn = new HottubOnCommand(hottub);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            Command[] partyOn  = { lightOn, stereoOn, tvOn, hottubOn };
            Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remoteControl.setCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("--- Pushing Macro On ---");
            remoteControl.onButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Off ---");
            remoteControl.offButtonWasPushed(0);
        }
Ejemplo n.º 11
0
        public static void RunTest()
        {
            var remoteControl   = new RemoteControl();
            var livingRoomLight = new Light("Living Room");
            var kitchenLight    = new Light("Kitchen");
            var ceilingFan      = new CeilingFan("Living Room");
            var garageDoor      = new GarageDoor();
            var stereo          = new Stereo("Living Room");

            var commands = new List <IUndoableCommand>
            {
                new LightOnCommand(livingRoomLight),
                new LightOffCommand(livingRoomLight),
                new LightOnCommand(kitchenLight),
                new LightOffCommand(kitchenLight),
                new CeilingFanHighCommand(ceilingFan),
                new CeilingFanOffCommand(ceilingFan),
                new GarageDoorUpCommand(garageDoor),
                new GarageDoorDownCommand(garageDoor),
                new StereoOnWithCdCommand(stereo),
                new StereoOffCommand(stereo),
            };

            new CommandsQueue(commands, 2).ExecuteQueue();
            Console.ReadKey();
        }
Ejemplo n.º 12
0
        public static void Start()
        {
            var remoteControl = new RemoteControl();

            var light               = new Light();
            var lightOn             = new LightOnCommand(light);
            var lightOff            = new LightOffCommand(light);
            var stereo              = new Stereo();
            var stereoOn            = new StereoOnCommand(stereo);
            var stereoOff           = new StereoOffCommand(stereo);
            var ceililngFan         = new CeilingFan("Kitchen room");
            var ceililngFanLowOn    = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low);
            var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium);
            var ceililngFanHighOn   = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High);
            var ceililngFanOff      = new CeilingFanOffCommand(ceililngFan);
            var partyOn             = new MacroCommand(new ICommand[] { lightOn, stereoOn });
            var partyOff            = new MacroCommand(new ICommand[] { lightOff, stereoOff });

            remoteControl.SetCommand(2, lightOn, lightOff);
            remoteControl.SetCommand(3, stereoOn, stereoOff);
            remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff);
            remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff);
            remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff);
            remoteControl.SetCommand(1, partyOn, partyOff);
            remoteControl.P();
            RemoteControlPressButtons(remoteControl);
        }
Ejemplo n.º 13
0
        public void CommandExampleMacros()
        {
            RemoteControl remote = new RemoteControl(); // this is the invoker

            Light  livingRoomLight = new Light("Living Room");
            Stereo stereo          = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, stereoOnWithCd };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remote.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remote);
            Console.WriteLine("--- Pushing Macro On ---\n");
            remote.OnButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Off ---\n");
            remote.OffButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Undo ---\n"); // not working for every scenario
            remote.UndoButtonWasPushed();

            Console.ReadLine();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            var remote = new RemoteControl();
            var light = new Light();
            var lightOn = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);
            var stereo = new Stereo();
            var stereoOn = new StereoOnWithCDCommand(stereo);
            var stereoOff = new StereoOffWithCDCommand(stereo);
            var ceilingFan = new CeilingFan("Living Room");
            var ceilingFanHighOn = new CeilingFanHighCommand(ceilingFan);

            var macro = new MacroCommand(new ICommand[] {lightOn, stereoOn});

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(2, stereoOn, stereoOff);
            remote.SetCommand(3, ceilingFanHighOn, new NoComand());
            remote.SetCommand(4, macro, new NoComand());
            remote.OnButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OnButtonWasPushed(2);

            remote.OffButtonWasPushed(0);
            remote.OffButtonWasPushed(1);
            remote.OffButtonWasPushed(2);

            remote.UndoButtonWasPushed();

            remote.OnButtonWasPushed(3);
            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(4);
            remote.UndoButtonWasPushed();

            Console.ReadKey();
        }
Ejemplo n.º 15
0
        public static void CommandTest()
        {
            // 实例化遥控器
            RemoteControl remoteControl = new RemoteControl();
            // 实例化需要控制对象,并传入房子位置
            Stereo stereo = new Stereo("客厅");
            Light  light  = new Light("客厅");
            TV     tv     = new TV("卧室");
            // 调用设备开关方法
            StereoOnWithCDCommand stereoOnWichCD  = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOffWithCD = new StereoOffCommand(stereo);
            LightOnCommand        lightOn         = new LightOnCommand(light);
            LightOffCommand       lightOff        = new LightOffCommand(light);
            TVOnCommand           tvOn            = new TVOnCommand(tv);
            TVOffCommand          tvOff           = new TVOffCommand(tv);

            // 设置插槽位置(遥控器的哪个按钮对应哪个设备开关)
            remoteControl.SetCommand(0, lightOn, lightOff);
            remoteControl.SetCommand(3, stereoOnWichCD, stereoOffWithCD);
            remoteControl.SetCommand(5, tvOn, tvOff);
            // 输出插槽位置
            Console.WriteLine(remoteControl);
            // 按下开关
            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.OnButtonWasPushed(5);
            remoteControl.OffButtonWasPushed(5);
        }
Ejemplo n.º 16
0
        private static void CallCommand()
        {
            string house = " house ";

            Remote remoteControl = new Remote();

            //clients
            Alarm      houseAlarm = new Alarm(house);
            CeilingFan ceilingFan = new CeilingFan(house);
            GarageDoor garageDoor = new GarageDoor(house);
            Hottub     hottub     = new Hottub();
            Light      light      = new Light(house);
            Stereo     stereo     = new Stereo(house);

            remoteControl.SetCommand(0, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(1, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(2, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(3, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(4, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(5, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(6, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));



            Console.WriteLine(remoteControl.OnButtonWasPushed(0));
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            RemoteControl remote           = new RemoteControl();
            Light         kitchenRoomlight = new Light("Kitchen");
            Light         livingRoomLight  = new Light("Living Room");
            GarageDoor    garageDoor       = new GarageDoor("");
            Stereo        stereo           = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn   = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff  = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenRoomLightOn  = new LightOnCommand(kitchenRoomlight);
            LightOffCommand kitchenRoomLightOff = new LightOffCommand(kitchenRoomlight);

            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            StereoOnWidthCDCommand  stereoOnWidthCDCommand  = new StereoOnWidthCDCommand(stereo);
            StereoOffWidthCDCommand stereoOffWidthCDCommand = new StereoOffWidthCDCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, garageDoorUp, stereoOnWidthCDCommand, kitchenRoomLightOn };
            ICommand[] partyOff = { livingRoomLightOff, garageDoorDown, stereoOffWidthCDCommand, kitchenRoomLightOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remote.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remote);
            Console.WriteLine("--- Pushing Macro On ---");
            remote.onButtonWasPressed(0);
            Console.WriteLine("--- Pushing Macro Off ---");
            remote.offButtonWasPressed(0);

            Console.ReadKey();
        }
Ejemplo n.º 18
0
        public static void MacroCommandExample()
        {
            Light  light  = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            LightOnCommand  lightOn  = new LightOnCommand(light);
            StereoOnCommand stereoOn = new StereoOnCommand(stereo);
            TVOnCommand     tvOn     = new TVOnCommand(tv);
            HottubOnCommand hottubOn = new HottubOnCommand(hottub);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            ICommand[] partyOn  = { lightOn, stereoOn, tvOn, hottubOn };
            ICommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            RemoteControl remoteControl = new RemoteControl();

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl.ToString());
            Console.WriteLine("\n--- Pushing Macro On---");
            remoteControl.OnButtonPushed(0);
            Console.WriteLine("\n--- Pushing Macro Off---");
            remoteControl.OffButtonPushed(0);
        }
Ejemplo n.º 19
0
 public DFTransform(Stereo stereo, int nSamplesPerSecond) : this(libwavPINVOKE.new_DFTransform(Stereo.getCPtr(stereo), nSamplesPerSecond), true)
 {
     if (libwavPINVOKE.SWIGPendingException.Pending)
     {
         throw libwavPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 20
0
        public void Load()
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            Light      light           = new Light();
            TV         tv         = new TV();
            Hottub     hottub     = new Hottub();
            CeilingFan ceilingFan = new CeilingFan("Living Room");
            GarageDoor garageDoor = new GarageDoor();
            Stereo     stereo     = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff    = new LightOffCommand(kitchenLight);

            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);
            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);

            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCd = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            LightOnCommand  lightOn  = new LightOnCommand(light);
            StereoOnCommand stereoOn = new StereoOnCommand(stereo);
            TVOnCommand     tvOn     = new TVOnCommand(tv);
            HottubOnCommand hottubOn = new HottubOnCommand(hottub);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            Command[] partyOn  = { lightOn, stereoOn, tvOn, hottubOn };
            Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(4, stereoOnWithCd, stereoOff);
            remoteControl.SetCommand(5, garageDoorUp, garageDoorDown);
            remoteControl.SetCommand(6, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            for (int i = 0; i <= 6; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
                remoteControl.UndoButtonWasPushed();
            }
        }
Ejemplo n.º 21
0
        public static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("Chapter6 - Command");
            Console.WriteLine();

            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light          light       = new Light();
            LightOnCommand lightOn     = new LightOnCommand(light);

            remote.SetCommand(lightOn);
            remote.ButtonWasPressed();

            RemoteControl rc = new RemoteControl();

            Console.WriteLine(rc.ToString());

            Light                  lightInBedroom            = new Light();
            LightOnCommand         lightInBedroom_OnCommand  = new LightOnCommand(lightInBedroom);
            LightOffCommand        lightInBedroom_OffCommand = new LightOffCommand(lightInBedroom);
            Stereo                 myStereo              = new Stereo();
            StereoOnWithCDCommand  myStereo_On           = new StereoOnWithCDCommand(myStereo);
            StereoOffWithCDCommand myStereo_Off          = new StereoOffWithCDCommand(myStereo);
            CeilingFan             fan                   = new CeilingFan("Living room");
            CeilingFanHighCommand  ceilingFanHighCommand = new CeilingFanHighCommand(fan);
            CeilingFanOffCommand   ceilingFanOffCommand  = new CeilingFanOffCommand(fan);

            MacroCommand macroCommand_On  = new MacroCommand(new ICommand[] { lightInBedroom_OnCommand, myStereo_On, ceilingFanHighCommand });
            MacroCommand macroCommand_Off = new MacroCommand(new ICommand[] { lightInBedroom_OffCommand, myStereo_Off, ceilingFanOffCommand });

            rc.SetCommand(0, lightInBedroom_OnCommand, lightInBedroom_OffCommand);
            rc.SetCommand(1, myStereo_On, myStereo_Off);
            rc.SetCommand(2, ceilingFanHighCommand, ceilingFanOffCommand);
            rc.SetCommand(6, macroCommand_On, macroCommand_Off);

            Console.WriteLine(rc.ToString());

            rc.OnButtonWasPressed(0);
            rc.OnButtonWasPressed(1);
            rc.OffButtonWasPressed(0);
            rc.UndoButtonWasPressed();
            rc.OnButtonWasPressed(2);
            rc.UndoButtonWasPressed();

            Console.WriteLine();
            Console.WriteLine("-----------------------------");
            Console.WriteLine("Call macro command");
            rc.OnButtonWasPressed(6);
            rc.OffButtonWasPressed(6);
            Console.WriteLine();
            Console.WriteLine("-----------------------------");
            Console.WriteLine("Macro command finished");
            Console.WriteLine();

            Console.WriteLine(rc.ToString());

            Console.ReadKey();
        }
Ejemplo n.º 22
0
 public override Stereo <float> this[float offset] {
     get {
         var ps      = this.MakeInterpolationParameters(offset);
         var former  = ps.Item1;
         var latter  = ps.Item2;
         var offFrac = ps.Item3;
         return(Stereo.Create(this.Interpolate(former.Left, latter.Left, offFrac),
                              this.Interpolate(former.Right, latter.Right, offFrac)));
     }
 }
Ejemplo n.º 23
0
    public Stereo getStereoObject(memblock m)
    {
        global::System.IntPtr cPtr = libwavPINVOKE.Wave_getStereoObject(swigCPtr, memblock.getCPtr(m));
        Stereo ret = (cPtr == global::System.IntPtr.Zero) ? null : new Stereo(cPtr, false);

        if (libwavPINVOKE.SWIGPendingException.Pending)
        {
            throw libwavPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
Ejemplo n.º 24
0
 public static void Main()
 {
     Stereo[] stereos = FunctionThatCreatesTheArray();
     using (var writeStream = File.OpenWrite(@"C:\Example\MultiChannelSong.bin"))
     {
         Stereo.Serialize(stereos, writeStream);
     }
     Stereo[] newStereos;
     using (var readStream = File.OpenRead(@"C:\Example\MultiChannelSong.bin"))
     {
         newStereos = Stereo.Deseralize(readStream);
     }
 }
Ejemplo n.º 25
0
        public void TestCommand()
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light  light  = new Light();
            Stereo stereo = new Stereo();

            // we can change command dynamically
            remote.setCommand(new LightOnCommand(light));
            remote.buttonWasPressed();
            remote.setCommand(new StereoOnWithCDCommand(stereo));
            remote.buttonWasPressed();
            remote.setCommand(new StereoOffCommand(stereo));
            remote.buttonWasPressed();
        }
Ejemplo n.º 26
0
        public static void Run()
        {
            var remoteControl = new RemoteControl();

            var livingRoomLight = new Light("Living Room");
            var kitchenLight    = new Light("Kitchen");
            var ceilingFan      = new CeilingFan("Living Room");
            var garageDoor      = new GarageDoor("");
            var stereo          = new Stereo("Living Room");

            var livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOff = new LightOffCommand(livingRoomLight);

            var kitchenLightOn  = new LightOnCommand(kitchenLight);
            var kitchenLightOff = new LightOffCommand(kitchenLight);

            var ceilingFanOn  = new CeilingFanOnCommand(ceilingFan);
            var ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            var garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            var garageDoorDown = new GarageDoorDownCommand(garageDoor);

            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);

            Console.WriteLine(remoteControl);
            Console.WriteLine();

            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(1);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(2);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(2);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(3);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(3);
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            var remoteControl = new RemoteControl();

            var light      = new Light("Living Roon");
            var tv         = new TV("Living Room");
            var stereo     = new Stereo("Living Room");
            var hottub     = new Hottub();
            var garageDoor = new GarageDoor(string.Empty);

            var lightOnCommand   = new LightOnCommand(light);
            var lightOffCommand  = new LightOffCommand(light);
            var stereoOnCommand  = new StereoOnCommand(stereo);
            var stereoOffCommand = new StereoOffCommand(stereo);
            var tvOnCommand      = new TVOnCommand(tv);
            var tvOffCommand     = new TVOffCommand(tv);
            var hottubOnCommand  = new HottubOnCommand(hottub);
            var hottubOffCommand = new HottubOffCommand(hottub);

            var partyOn  = new ICommand[] { lightOnCommand, stereoOnCommand, tvOnCommand, hottubOnCommand };
            var partyOff = new ICommand[] { lightOffCommand, stereoOffCommand, tvOffCommand, hottubOffCommand };

            var partyOnMacro  = new MacroCommand(partyOn);
            var partyOffMacro = new MacroCommand(partyOff);

            //remoteControl.SetCommand(0, lightOnCommand, lightOffCommand);
            //remoteControl.SetCommand(1, tvOnCommand, tvOffCommand);
            //remoteControl.SetCommand(2, stereoOnCommand, stereoOffCommand);
            //remoteControl.SetCommand(3, hottubOnCommand, hottubOffCommand);
            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);
            remoteControl.SetCommand(6, new GarageDoorUpCommand(garageDoor), new GarageDoorDownCommand(garageDoor));

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonPressed(2);
            remoteControl.OnButtonPressed(0);
            remoteControl.OnButtonPressed(3);
            remoteControl.OnButtonPressed(1);

            remoteControl.OffButtonPressed(2);
            remoteControl.OffButtonPressed(0);
            remoteControl.OffButtonPressed(3);
            remoteControl.OffButtonPressed(1);

            remoteControl.OnButtonPressed(6);
            remoteControl.UndoButtonPressed();

            Console.Read();
        }
Ejemplo n.º 28
0
        private static string ProcessRemoteControl()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garage          = new GarageDoor();
            Stereo     stereo          = new Stereo();

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff    = new LightOffCommand(kitchenLight);

            CeilingFanOnCommand  ceilingFanOnCommand  = new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garage);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage);

            StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOffCommand      = new StereoOffCommand(stereo);

            remoteControl.OnCommands[0] = livingRoomLightOn;
            remoteControl.OnCommands[1] = kitchenLightOn;
            remoteControl.OnCommands[2] = ceilingFanOnCommand;
            remoteControl.OnCommands[3] = stereoOnWithCDCommand;

            remoteControl.OffCommands[0] = livingRoomLightOff;
            remoteControl.OffCommands[1] = kitchenLightOff;
            remoteControl.OffCommands[2] = ceilingFanOffCommand;
            remoteControl.OffCommands[3] = stereoOffCommand;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(remoteControl.ToString());

            sb.AppendLine(remoteControl.OnButtonWasPushed(0));
            sb.AppendLine(remoteControl.OffButtonWasPushed(0));
            sb.AppendLine(remoteControl.OnButtonWasPushed(1));
            sb.AppendLine(remoteControl.OffButtonWasPushed(1));
            sb.AppendLine(remoteControl.OnButtonWasPushed(2));
            sb.AppendLine(remoteControl.OffButtonWasPushed(2));
            sb.AppendLine(remoteControl.OnButtonWasPushed(3));
            sb.AppendLine(remoteControl.OffButtonWasPushed(3));

            return(sb.ToString());
        }
Ejemplo n.º 29
0
        public Mat ReadDepth( )
        {
            Mat leftFrame  = LeftCamera.ReadOriginal().Remap(LeftMapX, LeftMapY);
            Mat rightFrame = RightCamera.ReadOriginal().Remap(RightMapX, RightMapY);

            Mat disparity = new Mat();

            Stereo.Compute(leftFrame, rightFrame, disparity);

            Mat depth = new Mat();

            Cv2.ReprojectImageTo3D(disparity, depth, DisparityToDepthMappingMatrix);

            return(depth);
        }
Ejemplo n.º 30
0
        public void Command_pattern_test()
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light  light  = new Light();
            Stereo stereo = new Stereo();

            //we can change command dynamically
            remote.SetCommand(new LightOnCommand(light));
            string actualValueLight = remote.ButtonWasPressed();

            remote.SetCommand(new StereoOnWithDVDCommand(stereo));
            string actualValueStereo = remote.ButtonWasPressed();

            Assert.AreEqual(actualValueLight, "Light is on");
            Assert.AreEqual(actualValueStereo, "Stereo is on All set to set DVD");
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            #region SimpleRemoteControl
            //var remote = new SimpleRemoteControl();

            //var lightOn = new LightOnCommand(new Light());

            //remote.Slot = lightOn;
            //remote.ButtonWasPressed();

            //Console.WriteLine("-----------------------------------------------------------");

            //var doorOpen = new DoorOpenCommand(new Door());

            //remote.Slot = doorOpen;
            //remote.ButtonWasPressed();
            #endregion

            #region RemoteControl
            var remote         = new RemoteControl();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var door           = new Door();
            var doorOpen       = new DoorOpenCommand(door);
            var doorClose      = new DoorCloseCommand(door);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, doorOpen, doorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
            remote.UndoButtonWasPressed();
            #endregion

            Console.ReadKey();
        }
        public static void Run()
        {
            // Invoker
            RemoteControl remoteControl = new RemoteControl();

            // Receivers
            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("");
            Stereo     stereo          = new Stereo("Living Room");

            // Commands
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            LightOnCommand  kitchenLightOn  = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            CeilingFanOnLowCommand ceilingFanOnLow = new CeilingFanOnLowCommand(ceilingFan);
            CeilingFanOffCommand   ceilingFanOff   = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor);



            // Set Commands
            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, stereoOnWithCD, stereoOff);
            remoteControl.SetCommand(3, ceilingFanOnLow, ceilingFanOff);
            remoteControl.SetCommand(4, garageDoorUp, garageDoorDown);

            Console.WriteLine(remoteControl);

            // Invoke Commands
            for (int i = 0; i < remoteControl.numberOfSlots; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
            }
        }
Ejemplo n.º 33
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Stereo obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Ejemplo n.º 34
0
 public StereoOnWithCDCommand(Stereo stereo)
 {
     _stereo = stereo;
 }
 public StereoOffCommand(Stereo stereo)
 {
     _stereo = stereo;
 }
Ejemplo n.º 36
0
 public Definition(string text, string[] menu, Stereo.DanceTogetherA.DanceType danceType, IDanceable danceObject)
     : base(text, menu, danceType, danceObject)
 { }
Ejemplo n.º 37
0
 public DFTransform(Stereo stereo, int nSamplesPerSecond)
     : this(libwavPINVOKE.new_DFTransform(Stereo.getCPtr(stereo), nSamplesPerSecond), true)
 {
     if (libwavPINVOKE.SWIGPendingException.Pending) throw libwavPINVOKE.SWIGPendingException.Retrieve();
 }
 public RemoteControl(Light light, Ceiling ceiling, Stereo stereo)
 {
     this.light = light;
     this.ceiling = ceiling;
     this.stereo = stereo;
 }
Ejemplo n.º 39
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stereoType"></param>
        /// <param name="customEQ"></param>
        public void SetStereo(Stereo stereoType, int[] customEQ)
        {
            int i;
            int chip;

            if (stereoType != Stereo.StereoCustom && customEQ != null)
            {
                throw new ArgumentException("If stereo type is not custom, 'customEQ' parameter must be null.");
            }

            chip = (type == Chip.AY) ? 0 : 1;

            switch (stereoType)
            {
                case Stereo.Mono:
                case Stereo.ABC:
                case Stereo.ACB:
                case Stereo.BAC:
                case Stereo.BCA:
                case Stereo.CAB:
                case Stereo.CBA:
                    for (i = 0; i < 6; i++)
                        eq[i] = DEFAULT_LAYOUT[chip][(int)stereoType][i];
                    break;
                case Stereo.StereoCustom:
                    for (i = 0; i < 6; i++)
                        eq[i] = customEQ[i];
                    break;
                default:
                    throw new ArgumentException("Incorrect stereo type");
            }

            defaultStereo = false;
            dirty = true;
        }