Exemple #1
0
        static void Main(string[] args)
        {
            ip = new InputPort();
            op = new OutputPort();

            System.Console.WriteLine("Select from " + InputPort.InputCount.ToString() + " MIDI inputs:");
            for (int i = 0; i < InputPort.InputCount; i++)
            {
                System.Console.WriteLine(string.Format("  Output {0}: {1}", i, InputPort.GetInputName(i)));
            }
            ip.Open(int.Parse(System.Console.ReadLine()));

            System.Console.WriteLine("Select from " + OutputPort.OutputCount.ToString() + " MIDI outputs:");
            for (int i = 0; i < OutputPort.OutputCount; i++)
            {
                System.Console.WriteLine(string.Format("  Output {0}: {1}", i, OutputPort.GetOutputName(i)));
            }
            op.Open(int.Parse(System.Console.ReadLine()));

            ip.Start();
            op.Start();

            System.Console.WriteLine(String.Format(@"Now reading MIDI input on {0}. Press ENTER to compose a MIDI signal to send to {1}. Press E to toggle echo mode. Press ESCAPE to quit.", ip.Handle, op.Handle));

            ConsoleKeyInfo key = System.Console.ReadKey(true);
            while (key.Key != ConsoleKey.Escape)
            {
                switch (key.Key)
                {
                    case ConsoleKey.Enter:
                        SendMessage(op, ComposeMessage());
                        break;
                    case ConsoleKey.E:
                        if (echoOn)
                        {
                            ip.MessageReceived -= new InputPort.MessageReceivedDelegate(echoInToOut);
                            System.Console.WriteLine("Echo off.");
                            echoOn = false;
                        }
                        else
                        {
                            ip.MessageReceived += new InputPort.MessageReceivedDelegate(echoInToOut);
                            System.Console.WriteLine("Echo on.");
                            echoOn = true;
                        }
                        break;
                }
                key = System.Console.ReadKey(true);
            }

            ip.Stop();
            op.Stop();
            ip.Close();
            op.Close();
        }
Exemple #2
0
 public static void SendMessage(OutputPort op, string message)
 {
     op.ShortMessage(uint.Parse(message, System.Globalization.NumberStyles.HexNumber));
     System.Console.WriteLine("Message Sent.");
 }