Beispiel #1
0
 private static void Input_SysExDataReceived(object sender, MidiInput.SysExEventArgs e)
 {
     Console.WriteLine($"{DateTime.Now} - SysEx:" + string.Join(" ", e.Data));
 }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("--------------------------");
            Console.WriteLine("PortMidiDotNet Output Test");
            Console.WriteLine("--------------------------");
            Console.WriteLine();

            Console.WriteLine();
            if (Environment.Is64BitProcess)
                Console.WriteLine("Running In 64-bit Mode");
            else
                Console.WriteLine("Running In 32-bit Mode");
            Console.WriteLine();

            try
            {
                PortMidi.Initialize();

                var devices = PortMidi.GetDevices();

                Console.WriteLine("Input Devices");
                foreach (var device in devices.Where(d => d.SupportsInput))
                    Console.WriteLine(device.ToString());
                Console.WriteLine();

                Console.WriteLine("Output Devices");
                foreach (var device in devices.Where(d => d.SupportsOutput))
                    Console.WriteLine(device.ToString());
                Console.WriteLine();

                int deviceId = 0;
                string consoleInput = string.Empty;
                do
                {
                    Console.WriteLine("Enter index of device to test");
                    consoleInput = Console.ReadLine();
                }
                while (!int.TryParse(consoleInput, out deviceId));

                Console.WriteLine();

                var deviceInfo = devices.FirstOrDefault(d => d.DeviceId == deviceId);

                if (deviceInfo == null)
                {
                    Console.WriteLine($"No device with device Id {deviceId}");
                    return;
                }

                if (deviceInfo.SupportsInput)
                {
                    Console.WriteLine($"Testing input on '{deviceInfo.Name}'. Received messages will be displayed.");

                    var input = new MidiInput(deviceInfo);
                    input.ChannelMessageReceived += Input_MessageReceived;
                    input.SystemMessageReceived += Input_MessageReceived;
                    input.RealTimeMessageReceived += Input_MessageReceived;
                    input.SysExDataReceived += Input_SysExDataReceived;

                    if (!input.Open())
                    {
                        Console.WriteLine("Failed to open input device");
                        return;
                    }

                    Console.WriteLine("Hit any key to exit");
                    Console.WriteLine();

                    while (!Console.KeyAvailable) { }

                    input.Close();
                }
                else
                {
                    Console.WriteLine($"Testing output on '{deviceInfo.Name}'");
                    Console.WriteLine("Sending NoteOn, NoteOff and ControllerChange messages on Channel 1");

                    var output = new MidiOutput(deviceInfo);

                    if (!output.Open())
                    {
                        Console.WriteLine("Failed to open output device");
                        return;
                    }
                    Console.WriteLine("Press any key to stop");
                    Console.WriteLine();

                    int i = 0;

                    while (!Console.KeyAvailable)
                    {
                        output.SendControllerChange(1, 1, i);

                        output.SendNoteOn(1, i, 100);

                        Thread.Sleep(100);

                        output.SendNoteOff(1, i, 0);

                        ++i;

                        if (i > 127)
                            i = 0;
                    }

                    output.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("Unhandled Exception");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                PortMidi.Terminate();
            }
        }
Beispiel #3
0
 private static void Input_MessageReceived(object sender, MidiInput.MidiMessageEventArgs e)
 {
     Console.WriteLine($"{DateTime.Now} - {e.Message.MessageType}, {e.Message.Data1}, {e.Message.Data2}");
 }