コード例 #1
0
ファイル: All.cs プロジェクト: whiteschool/cmdr
        internal static AControl GetControl(ACommand command)
        {
            switch (command.ControlType)
            {
            case MappingControlType.Button:
                return(Button.AButtonControl.FromCommand(command));

            case MappingControlType.FaderOrKnob:
                return(FaderOrKnob.FaderOrKnobControl.FromCommand(command));

            case MappingControlType.Encoder:
                return(new Encoder.EncoderControl(command));

            case MappingControlType.LED:
                var d1 = typeof(LED.LedControl <>);
                var t  = command.GetType();
                while (!t.IsGenericType && t.BaseType != typeof(object))
                {
                    t = t.BaseType;
                }
                if (t.IsGenericType)
                {
                    var makeme = d1.MakeGenericType(t.GenericTypeArguments);
                    return(Activator.CreateInstance(makeme, _flags, null, new object[] { command }, _culture) as AControl);
                }
                else
                {
                    return(new LED.LedControl <int>(command));
                }

            default:
                return(null);
            }
        }
コード例 #2
0
ファイル: AButtonControl.cs プロジェクト: whiteschool/cmdr
        public static AButtonControl FromCommand(ACommand command)
        {
            switch (command.InteractionMode)
            {
            case MappingInteractionMode.Trigger:
                return(new TriggerButtonControl(command));

            case MappingInteractionMode.Toggle:
                return(new ToggleButtonControl(command));

            case MappingInteractionMode.Hold:
                return(new HoldButtonControl(command));

            case MappingInteractionMode.Direct:
            case MappingInteractionMode.Reset:
                return(new DirectButtonControl(command));

            case MappingInteractionMode.Increment:
            case MappingInteractionMode.Decrement:
                if (command.GetType().InheritsOrImplements(typeof(FloatInCommand <>)))
                {
                    return(new FloatDecIncButtonControl(command));
                }
                else
                {
                    return(new IntDecIncButtonControl(command));
                }

            default:
                return(null);
            }
        }
コード例 #3
0
        private void updateContent()
        {
            Type t = _command.GetType();

            if (_command.HasValueUI)
            {
                if (t.InheritsOrImplements(typeof(EnumInCommand <>)))
                {
                    SettingsContent = new EnumCommandView(_command);
                }
                else if (t.InheritsOrImplements(typeof(FloatInCommand <>)))
                {
                    SettingsContent = new FloatCommandView(_command);
                }
                else if (t.InheritsOrImplements(typeof(IntInCommand <>)))
                {
                    SettingsContent = new IntCommandView(_command);
                }
            }
            else if (_command.ControlType == MappingControlType.LED)
            {
                if (t.InheritsOrImplements(typeof(EffectSelectorOutCommand)))
                {
                    SettingsContent = new EffectSelectorOutCommandView(_command);
                }
                else if (t.InheritsOrImplements(typeof(EnumOutCommand <>)))
                {
                    SettingsContent = new EnumOutCommandView(_command);
                }
                else if (t.InheritsOrImplements(typeof(FloatOutCommand <>)))
                {
                    SettingsContent = new FloatOutCommandView(_command);
                }
                else if (t.InheritsOrImplements(typeof(IntOutCommand <>)))
                {
                    SettingsContent = new IntOutCommandView(_command);
                }
            }
            else
            {
                SettingsContent = null;
            }

            if (SettingsContent != null)
            {
                SettingsContent.ValueChanged += (s, e) => onValueChanged();
            }

            var settings = getSettings();
            var controls = settings.Select(setting => SettingControlLibrary.SettingControlFactory.Create(setting));

            ControlSettingsContent = new SettingsEditor(controls);
        }
コード例 #4
0
ファイル: CommandView.cs プロジェクト: whiteschool/cmdr
        private INotifyPropertyChanged buildWrapper(ACommand command, Type wrapperType)
        {
            Type t = command.GetType();

            while (!t.IsGenericType && t.BaseType != typeof(object))
            {
                t = t.BaseType;
            }
            if (t.IsGenericType)
            {
                Type constructedType = wrapperType.MakeGenericType(t.GenericTypeArguments);
                return((INotifyPropertyChanged)Activator.CreateInstance(constructedType, new object[] { command }));
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Do handshake for client side.
        /// </summary>
        /// <param name="clientSocket"> Socket from client side to server side</param>
        /// <returns>null if handShake fail otherwise return instance of AProtocol</returns>
        public async Task <AProtocol> HandShakeClient(NetworkStream clientSocket)
        {
            HelloCommand hello = new HelloCommand(ClientConfig.SUPPORTED_PROTOCOLS);
            await hello.SendAsync(clientSocket);

            ACommand shouldBeOLLEH = GetCommand(await clientSocket.ReadLineAsync());

            if (shouldBeOLLEH is OllehCommand)
            {
                OllehCommand olleh    = (OllehCommand)shouldBeOLLEH;
                AProtocol    protocol = ClientConfig.PROTOCOL_FACTORY.GetProtocol(olleh.PROTOCOL);
                if (protocol != null)
                {
                    AckCommand ack = new AckCommand();
                    await ack.SendAsync(clientSocket);

                    return(protocol);
                }
                ErrorCommand error = new ErrorCommand($"Unsupported protocols '{olleh.PROTOCOL}'. Handshake failed.");
                await error.SendAsync(clientSocket);
            }
            else
            {
                printIfErrorElseSendMessage(shouldBeOLLEH, "Handshake error. Expected OllehCommand but receive " + shouldBeOLLEH.GetType().Name, clientSocket);
            }
            return(null);
        }
コード例 #6
0
        /// <summary>
        /// Do handshake for server side.
        /// </summary>
        /// <param name="serverSocket"> Socket from client side to server side</param>
        /// <returns>null if handShake fail otherwise retur instance of AProtocol</returns>
        public async Task <AProtocol> HandShakeServer(SuperNetworkStream serverSocket)
        {
            ACommand shoudBeHELLO = GetCommand(await serverSocket.ReadLineAsync());

            if (shoudBeHELLO is HelloCommand)
            {
                String       selectedProtocolLabel;
                HelloCommand hello    = (HelloCommand)shoudBeHELLO;
                AProtocol    protocol = ServerConfig.PROTOCOL_FACTORY.GetProtocol(out selectedProtocolLabel, hello.SUPPORTED_PROTOCOLS);
                if (protocol != null)
                {
                    OllehCommand olleh = new OllehCommand(selectedProtocolLabel);
                    await olleh.SendAsync(serverSocket);

                    ACommand shoudBeACK = GetCommand(await serverSocket.ReadLineAsync());
                    if (shoudBeACK is AckCommand)
                    {
                        return(protocol);
                    }
                    else
                    {
                        printIfErrorElseSendMessage(shoudBeACK, "Handshake error. Expected HelloCommand but receive:" + shoudBeACK.GetType().Name, serverSocket);
                    }
                }
                await serverSocket.SendCommandAsync(new ErrorCommand(String.Format("Unsupported protocols '{0}'. Handshake failed.", hello.SUPPORTED_PROTOCOLS)));
            }
            else
            {
                printIfErrorElseSendMessage(shoudBeHELLO, "Handshake error. Expected HelloCommand but receive:" + shoudBeHELLO.GetType().Name, serverSocket);
            }

            return(null);
        }
コード例 #7
0
        //////////
        //////////
        //////////
        //////////


        public void try_rotate_command_value(ACommand command, int step)
        {
            Type   type      = command.GetType();
            string type_name = type.FullName;

            if (command.MappingType == MappingType.Out)
            {
                return;
            }

            // BELOW ITS A HACK!
            // could not put this to work: t.InheritsOrImplements(typeof(EnumInCommand<HotcueType>)))
            // plus many other things

            // special types:
            //  null
            //  typeof(TriggerInCommand)
            //  typeof(HoldInCommand)
            //
            //  typeof(EffectSelectorInCommand)
            //  typeof(OnOffInCommand)

            if (false)
            {
                // This is just a placeholder
            }
            else if (type_name.Contains("OnOffInCommand"))
            {
                var command2  = (OnOffInCommand)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("EffectSelectorInCommand"))
            {
                var command2  = (EffectSelectorInCommand)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);


                ////// Start of Auto generated code
            }
            else if (type_name.Contains("Enums.AdvancedPanelTab"))
            {
                var command2  = (EnumInCommand <AdvancedPanelTab>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.CaptureSource"))
            {
                var command2  = (EnumInCommand <CaptureSource>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.CuePointOrLoopMoveSize"))
            {
                var command2  = (EnumInCommand <CuePointOrLoopMoveSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.CueType"))
            {
                var command2  = (EnumInCommand <CueType>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.Deck"))
            {
                var command2  = (EnumInCommand <Deck>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.DeckFlavor"))
            {
                var command2  = (EnumInCommand <DeckFlavor>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.DeckSize"))
            {
                var command2  = (EnumInCommand <DeckSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.ExpandCollapse"))
            {
                var command2  = (EnumInCommand <ExpandCollapse>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.FXRouting"))
            {
                var command2  = (EnumInCommand <FXRouting>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.FXUnitMode"))
            {
                var command2  = (EnumInCommand <FXUnitMode>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.Favorite"))
            {
                var command2  = (EnumInCommand <Favorite>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.FreezeSliceCount"))
            {
                var command2  = (EnumInCommand <FreezeSliceCount>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.FreezeSliceSize"))
            {
                var command2  = (EnumInCommand <FreezeSliceSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.Hotcue"))
            {
                var command2  = (EnumInCommand <Hotcue>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.IntExt"))
            {
                var command2  = (EnumInCommand <IntExt>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.JumpDirection"))
            {
                var command2  = (EnumInCommand <JumpDirection>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.Layout"))
            {
                var command2  = (EnumInCommand <Layout>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.ListNavigation"))
            {
                var command2  = (EnumInCommand <ListNavigation>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.ListOffset"))
            {
                var command2  = (EnumInCommand <ListOffset>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.LoopRecorderSize"))
            {
                var command2  = (EnumInCommand <LoopRecorderSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.LoopSize"))
            {
                var command2  = (EnumInCommand <LoopSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.MixerFx"))
            {
                var command2  = (EnumInCommand <MixerFx>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.ModifierValue"))
            {
                var command2  = (EnumInCommand <ModifierValue>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.MoveDirection"))
            {
                var command2  = (EnumInCommand <MoveDirection>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.MoveMode"))
            {
                var command2  = (EnumInCommand <MoveMode>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.MoveSize"))
            {
                var command2  = (EnumInCommand <MoveSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.PatternLength"))
            {
                var command2  = (EnumInCommand <PatternLength>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.PlatterScopeView"))
            {
                var command2  = (EnumInCommand <PlatterScopeView>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.PlayMode"))
            {
                var command2  = (EnumInCommand <PlayMode>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.PlaybackMode"))
            {
                var command2  = (EnumInCommand <PlaybackMode>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.QuantizeSize"))
            {
                var command2  = (EnumInCommand <QuantizeSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.Sample"))
            {
                var command2  = (EnumInCommand <Sample>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.SamplePage"))
            {
                var command2  = (EnumInCommand <SamplePage>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.ScratchControl"))
            {
                var command2  = (EnumInCommand <ScratchControl>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.SlotCell"))
            {
                var command2  = (EnumInCommand <SlotCell>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.SlotSize"))
            {
                var command2  = (EnumInCommand <SlotSize>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.SlotTriggerType"))
            {
                var command2  = (EnumInCommand <SlotTriggerType>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.TempoRange"))
            {
                var command2  = (EnumInCommand <TempoRange>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.TempoSource"))
            {
                var command2  = (EnumInCommand <TempoSource>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.TopBottom"))
            {
                var command2  = (EnumInCommand <TopBottom>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.TreeNavigation"))
            {
                var command2  = (EnumInCommand <TreeNavigation>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            else if (type_name.Contains("Enums.UpDown"))
            {
                var command2  = (EnumInCommand <UpDown>)command;
                var cur_value = command2.Value;
                command2.Value = cur_value.EnumRotate(step);
            }
            ////// End of Auto generated code
        }
コード例 #8
0
 public virtual string GetSendableCommand(ACommand s)
 {
     ACommand.Sendable commandSendable = commandsFactory.Transfer(s);
     if (commandSendable == null)
     {
         throw new ArgumentException("Protocol (" + this.GetType().Name + ") do not know command type: " + s.GetType().Name);
     }
     return(commandSendable.Serialize());
 }