How to read the value of a note in C # using the Midi dot network class

I am developing a VB.net application that should read the value of a MIDI note from an external pad that sends values ​​on channel 10. This value will be used to control various aspects of my application.

I plan to use the MIDI-dot-net class found here: https://code.google.com/p/midi-dot-net/ to read the value of the note and looked at one example that reads a note played by an external keyboard, and displays them.

Unfortunately, I cannot convert this to do what I want, although I think I'm pretty close.

Are there any users who are familiar with this library and can identify my errors? C # is not my main language (in fact, VB.net is not either!), But if I can get something working in C #, then I can convert it to VB.net for use in my application.

Alternatively, is there another way to do what I want?

Here is my code:

using System; using Midi; using System.Threading; using System.Collections.Generic; namespace MidiExamples { public class Example05 : ExampleBase { public Example05() : base("Example05.cs", "Prints notes and chords as they are played.") { } public class Summarizer { public Summarizer(InputDevice inputDevice) { this.inputDevice = inputDevice; percussionPressed = new Dictionary<Percussion, string>(); inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff); } private void PrintStatus() { Console.Clear(); Console.WriteLine("Play notes and chords on the MIDI input device, and watch"); Console.WriteLine("their names printed here. Press any QUERTY key to quit."); Console.WriteLine(); // Print the currently pressed notes. List<Percussion> percussion = new List<Percussion>(percussionPressed.Keys); percussion.Sort(); Console.Write("Notes: "); for (int i = 0; i < percussion.Count; ++i) { //Pitch pitch = pitches[i]; Percussion percussionNote = percussion[i]; if (i > 0) { Console.Write(", "); } Console.Write("{0}", percussionNote.Name()); } Console.WriteLine(); } public void NoteOn(NoteOnMessage msg) { lock (this) { percussionPressed[msg.ToString] = true; PrintStatus(); } } public void NoteOff(NoteOffMessage msg) { lock (this) { percussionPressed.Remove(msg); PrintStatus(); } } private InputDevice inputDevice; private Dictionary<Percussion, string> percussionPressed; } public override void Run() { // Prompt user to choose an input device (or if there is only one, use that one). InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole(); if (inputDevice == null) { Console.WriteLine("No input devices, so can't run this example."); ExampleUtil.PressAnyKeyToContinue(); return; } inputDevice.Open(); inputDevice.StartReceiving(null); Summarizer summarizer = new Summarizer(inputDevice); ExampleUtil.PressAnyKeyToContinue(); inputDevice.StopReceiving(); inputDevice.Close(); inputDevice.RemoveAllEventHandlers(); } } } 

In particular, I'm not sure how to determine the behavior of NoteOn and NoteOff ...

Thank you in advance

Phil

+4
source share
1 answer

I would have thought it would be possible to play a note, but there is no Note value, only a Pitch value, which does not seem to make sense.

Unfortunately this is not possible. The note pitch value determines which drum pattern is played. The MIDI protocol does not indicate “trap enabled” or “timpani”. He just says C2 or E5.

At the same time, if your controller and synthesizer use General MIDI, there is a card that is usually executed. From Wikipedia :

enter image description here

What I get is that you have no problem with the code. Your problem is interpreting these pitch values.

+2
source

All Articles