Esempio n. 1
0
        private MessageViewModel ProcessMessageViewModel(Message input)
        {
            string text;

            if (input is DebugMessage)
            {
                text = ((DebugMessage)input).Text;
            }
            else if (input is GeneralStatusMessage)
            {
                var input2 = (GeneralStatusMessage)input;
                text = $"General Status: {input2.ConfigurationOk}, {Convert.ToString(input2.PressedPedals, 2).PadLeft(32, '0')}, {Convert.ToString(input2.PlayedNotes, 2).PadLeft(32, '0')}, {input2.NumberOfToggledPedals}, {input2.NumberOfToggledNotes}, {input2.NumberOfReceivedBytes}, {input2.NumberOfDiscardedBytes}";

                for (int i = 0; i < 8 * sizeof(uint); i++)
                {
                    var pressed = (input2.PressedPedals >> i) % 2 != 0;
                    pressedPedals[i].IsOn.SetValue(pressed);

                    var played = (input2.PlayedNotes >> i) % 2 != 0;
                    playedNotes[i].IsOn.SetValue(played);
                }
            }
            else if (input is ConfigurationStatusMessage)
            {
                var input2        = (ConfigurationStatusMessage)input;
                var pedalPinsText = string.Join(", ", input2.PedalPins.Select(x => x.ToString()));
                text = $"Configuration Status: {input2.FirstNote}, {input2.Velocity}, {input2.DebouncingTime}, [{pedalPinsText}]";

                if (!IsEditingConfiguration.Value)
                {
                    FirstNote.SetValue(input2.FirstNote);
                    Velocity.SetValue(input2.Velocity);
                    DebouncingTime.SetValue(input2.DebouncingTime);

                    for (var i = 0; i < input2.PedalPins.Length; i++)
                    {
                        var obj = pedalPins[i];
                        obj.Value.SetValue(input2.PedalPins[i]);
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            var output = new MessageViewModel(text);

            return(output);
        }
Esempio n. 2
0
        public MainWindowViewModel()
        {
            availableDevices = new ObservableCollection <DeviceViewModel>();
            var dummyDevice = new DeviceViewModel("COM1", null);

            availableDevices.Add(dummyDevice);
            AvailableDevices = new ReadOnlyObservableCollection <DeviceViewModel>(availableDevices);
            SelectedDevice.SetValue(dummyDevice);

            receivedMessages = new ObservableCollection <MessageViewModel>();
            receivedMessages.Add(new MessageViewModel("A"));
            receivedMessages.Add(new MessageViewModel("B"));
            receivedMessages.Add(new MessageViewModel("C"));
            ReceivedMessages = new ReadOnlyObservableCollection <MessageViewModel>(receivedMessages);

            pressedPedals = new ObservableCollection <OnOffIndicatorViewModel>();
            PressedPedals = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pressedPedals);
            for (var i = 0; i < 8 * sizeof(uint); i++)
            {
                pressedPedals.Add(new OnOffIndicatorViewModel(i + 1, i % 2 != 0));
            }

            playedNotes = new ObservableCollection <OnOffIndicatorViewModel>();
            PlayedNotes = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(playedNotes);
            for (var i = 0; i < 8 * sizeof(uint); i++)
            {
                playedNotes.Add(new OnOffIndicatorViewModel(i + 1, i % 2 == 0));
            }

            FirstNote.SetValue(40);
            Velocity.SetValue(70);
            DebouncingTime.SetValue(125);

            pedalPins = new ObservableCollection <OnOffIndicatorViewModel>();
            PedalPins = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pedalPins);
            for (var i = 0; i < 8 * sizeof(uint); i++)
            {
                pedalPins.Add(new OnOffIndicatorViewModel(i + 1, false));
            }

            EditCommand  = new ManualCommand(HandleEditCommand, true);
            ApplyCommand = new ManualCommand(HandleApplyCommand, false);

            IsEditingConfiguration.SetValue(true);
        }