private void StartReceivingMidi()
 {
     if (!SelectedMidiDevice.IsReceiving)
     {
         SelectedMidiDevice.Open();
         SelectedMidiDevice.NoteOn += ReceivingMidiDevice_NoteOn;
         SelectedMidiDevice.StartReceiving(null);
         ReceivingMidiDevice = SelectedMidiDevice;
     }
 }
Exemplo n.º 2
0
        public EAccordeonViewModel()
        {
            meAccordeon = new EAccordeon();

            try
            {
                var devId = Properties.Settings.Default.SelectedMidiDeviceId;
                SelectedMidiDevice = MidiDevices[devId];
            }
            catch { };

            try
            {
                var patchId = Properties.Settings.Default.SelectedPatchId;
                mSelectedPatchInfo = PatchInfoArray[patchId];
            }
            catch { };

            try
            {
                var patchId = Properties.Settings.Default.SelectedPatchBassId;
                mSelectedPatchBassInfo = PatchBassInfoArray[patchId];
            }
            catch { };

            MidiControllerBase defaultMidiController;

            mMidiControllers.Add(defaultMidiController = new MidiControllerVirtual(meAccordeon));
            mMidiControllers.Add(new MidiControllerSerial(meAccordeon));

            try
            {
                var cId = Properties.Settings.Default.SelectedMidiControllerId;
                mSelectedMidiController = mMidiControllers[cId];
            }
            catch { mSelectedMidiController = defaultMidiController; }


            ShowMIDIDeviceInfoCommand = new RelayCommand(o =>
            {
                MessageBox.Show(SelectedMidiDevice.GetDescription());
            },
                                                         o => { return(SelectedMidiDevice != null); })
            {
                HadleExceptions = true
            };


            MidiControllerStartCommand = new RelayCommand(o =>
            {
                SelectedMidiController.Start();
            },
                                                          o =>
            {
                return(!SelectedMidiController.IsStarted);
            })
            {
                HadleExceptions = true
            };

            MidiControllerStopCommand = new RelayCommand(o =>
            {
                SelectedMidiController.Stop();
            },
                                                         o =>
            {
                return(SelectedMidiController.IsStarted);
            })
            {
                HadleExceptions = true
            };


            mTimer          = new DispatcherTimer(DispatcherPriority.Background);
            mTimer.Interval = TimeSpan.FromMilliseconds(100);
            mTimer.Tick    += MTimer_Tick;
            mTimer.Start();
        }