Communicating with my USB MIDI Keyboard..  
Author Message
Bobbias





PostPosted: Visual C# General, Communicating with my USB MIDI Keyboard.. Top

I'm trying to write a C# program to communicate with my MIDI controller keyboard which uses a USB connection and shows up as a USB Audio Device.

I'm wondering how exactly I can communicate with my keyboard, since I'm going to write a program that will play the appropriate note, and run in the background, so I don't need any other programs running just to listen to what I'm playing.

I've been unable to find any information on how to access my USB device, and though there are some C# USB communication libraries, I havent exactly figured out how to work them, considering usblib-win32 has no documentation of it's own, and usblib's own documentation os so minimalistic to the point of making little to no sence to someone who doesn't have a clear idea of how to access a USB device.



Visual C#1  
 
 
Brendan Grant





PostPosted: Visual C# General, Communicating with my USB MIDI Keyboard.. Top

Try this CodeProject article.

 
 
Bobbias





PostPosted: Visual C# General, Communicating with my USB MIDI Keyboard.. Top

That's helpful, but I'm not sure where to start working with it. I guess I'll just have to poke around more and figure things out myself.
 
 
Bobbias





PostPosted: Visual C# General, Communicating with my USB MIDI Keyboard.. Top

Using it to make my program (building on top of everything that toolkit supplies, and modifying some of the code in the midi listener project), I've encountered a big problem.

I'm trying to display a window to select the devices to use for input and output, and then open the MidiListener window after you select the devices, and if you hit cancel, just close the program.

 Note: I don't know much at all about multi-window stuff in C# yet, seeing as I've written very little code in C#.

Here's my main code:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Multimedia.Midi.UI;

namespace MidiWatcher
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DeviceDialog dd = new DeviceDialog();
            dd.ShowDialog();              // This shows a midi device selection dialogue
            if (dd.DialogResult == DialogResult.OK)  // if they selected midi devices
            {
                Form1 form = new Form1(dd.InputDeviceID, dd.OutputDeviceID);  // Form1 is the main prog window
                Application.Run(form);   // Causes ObjectDisposedException :S
            }
        }
    }
}