예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         serialPort1.PortName = comboBox3.Text;
         serialPort1.BaudRate = int.Parse(comboBox4.Text);
         serialPort1.Open();
         inputDevice = InputDevice.GetById(comboBox1.SelectedIndex);
         inputDevice.EventReceived += OnEventReceived1;
         inputDevice.StartEventsListening();
         button1.Enabled            = false;
         button2.Enabled            = true;
         comboBox1.Enabled          = false;
         comboBox3.Enabled          = false;
         comboBox4.Enabled          = false;
         toolStripStatusLabel1.Text = "Sending data from " + inputDevice.Name + " to " + serialPort1.PortName;
         textBox1.AppendText("Midi device opened: " + inputDevice.Name + Environment.NewLine);
         textBox1.AppendText("Serial device opened: " + serialPort1.PortName + " Baud Rate: " + serialPort1.BaudRate.ToString()
                             + Environment.NewLine);
     }
     catch (System.IO.IOException)
     {
         MessageBox.Show("COM 포트 열기 실패", "Error");
     }
     catch (MidiDeviceException)
     {
         MessageBox.Show("Midi 장치 열기 실패", "Error");
     }
 }
예제 #2
0
        public static int Connect(string name, KeyController _keyController)
        {
            wetMidiKeyboard = InputDevice.GetById(Convert.ToInt32(name.Split('|')[1]));
            {
                try
                {
                    wetMidiKeyboard.EventReceived += MidiKeyboard_EventReceived;
                    wetMidiKeyboard.StartEventsListening();
                    cts = new CancellationTokenSource();
                    kc  = _keyController;
                    kc.UpdateKeyMap();
                    Task.Run(() =>
                    {
                        //var keyPlayLists = mtk.ArrangeKeyPlays(mtk.Index);
                        NoteProcess(cts.Token);
                    }, cts.Token);
                }
                catch (Exception e)
                {
                    MessageBox.Show($"连接错误 \r\n {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(0);
        }
예제 #3
0
        private void DeviceComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (InputDevice.GetById(DeviceComboBox.SelectedIndex) == currentMidiDevice)
            {
                return;
            }

            SelectDevice(DeviceComboBox.SelectedIndex);
            StartListeningButton.Enabled = true;
            StopListeningButton.Enabled  = true;
        }
예제 #4
0
        public void CheckInputDeviceId(string deviceName)
        {
            var device = InputDevice.GetByName(deviceName);

            Assert.IsNotNull(device, $"Unable to get device '{deviceName}' by its name.");

            var deviceId = device.Id;

            device = InputDevice.GetById(deviceId);
            Assert.IsNotNull(device, $"Unable to get device '{deviceName}' by its ID.");
            Assert.AreEqual(deviceName, device.Name, "Device retrieved by ID is not the same as retrieved by its name.");
        }
예제 #5
0
 private void btnConnectMidi_Click(object sender, EventArgs e)
 {
     if (cbMidiDevices.Items.Count > 0)
     {
         InputDevice inputDevice = InputDevice.GetById(((ComboboxItem)cbMidiDevices.SelectedItem).Value);
         inputDevice.EventReceived += OnEventReceived;
         inputDevice.StartEventsListening();
     }
     else
     {
         MessageBox.Show("Error", "No Midi Device selected");
     }
 }
예제 #6
0
        private void getDevice()
        {
            try
            {
                TextBox.CheckForIllegalCrossThreadCalls = false;
                Globals.inputDevice = InputDevice.GetById(0);
                Globals.inputDevice.EventReceived += OnEventReceived;
                Globals.inputDevice.StartEventsListening();
                Globals.stop = false;
            }

            catch
            {
            }
        }
예제 #7
0
        private void Form2_Load(object sender, EventArgs e)
        {
            int    deviceCount       = InputDevice.GetDevicesCount();
            string deviceCountString = deviceCount.ToString();

            textBox1.Text = deviceCountString;
            //Console.WriteLine(deviceString);     //seems to crash when highlight textbox


            using (var inputDevice = InputDevice.GetById(0))
            {
                inputDevice.EventReceived += OnEventReceived;
                inputDevice.StartEventsListening();
                textBox2.Text = inputDevice.Name;
                int    midiIDINT    = inputDevice.Id;
                string midiIDString = midiIDINT.ToString();
                midiID.Text = midiIDString;
            }
        }
예제 #8
0
    public void Setup(SyncObject syncObject)
    {
        if (syncObject.OriginalNodeId != syncObject.Node.NodeId)
        {
            Logger.Log("MidiInputTag", "midiInput tag only works on the original node");
            return;
        }

        if (InputDevice.GetDevicesCount() == 0)
        {
            Logger.Error("MidiInputTag", "MIDI input device not found");
            return;
        }

        device = InputDevice.GetById(0);    // Open the first device
        device.StartEventsListening();
        device.EventReceived += OnEventReceived;

        syncObject.BeforeSync += OnBeforeSync;  // Add update function
    }
예제 #9
0
        private void SelectDevice(int id)
        {
            InputDevice newDevice = InputDevice.GetById(id);

            if (currentMidiDevice?.Id == newDevice.Id)
            {
                return;
            }
            else
            {
                if (currentMidiDevice != null)
                {
                    currentMidiDevice.EventReceived -= OnMidiEventReceived;
                    currentMidiDevice.Dispose();
                }
            }

            currentMidiDevice = newDevice;
            currentMidiDevice.EventReceived += OnMidiEventReceived;
            Log($"Selected {currentMidiDevice.Name}.");
        }
예제 #10
0
 public MidiHandler(int deviceId)
 {
     inputDevice = InputDevice.GetById(deviceId);
     OpenDevice();
 }