1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#でMIDI通信を扱うNext MIDI Projectで受信する

Posted at

C#でMIDI通信を扱う

Next MIDI Project (MITライセンス)
http://starway.s234.xrea.com/wordpress/

にて、MIDIを受信するサンプル

このコードはCC0ライセンスとして公開

using System;
using NextMidi.MidiPort.Input.Core;
using NextMidi.MidiPort.Output.Core;
using NextMidi.MidiPort.Input;
using Avenue;
using NextMidi.DataElement;
using System.Threading;

//http://starway.s234.xrea.com/wordpress/
namespace MIDIControllerTestConsole
{
    class Program
    {
        //受信イベント
        static void MidiReceived(object sender, DataEventArgs<MidiEvent> e)
        {
            byte[] data = e.Value.ToNativeEvent(); //MIDI生値に変換
            foreach (var d in data) {
                Console.Write("{0:X2},",d);
            }
            Console.Write("\n");
        }

        static void Main(string[] args)
        {
            //ポートを開く
            var port = new MidiInPort("loopMIDI Port");
            try
            {
                port.Open();
            }
            catch
            {
                Console.WriteLine("ポートが見つかりません");
                return;
            }

            //受信イベント登録
            port.Received += MidiReceived;

            //なにかキーを押すと終了
            while (!Console.KeyAvailable) {
                Console.WriteLine("Keep-Alive");
                Thread.Sleep(1000);
            }
        }
    }
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?