我正在开发一个VB.net应用程序,需要从外部鼓垫读取MIDI音符值,该鼓垫在通道10上发送值.该值将用于控制我的应用程序的各个方面.
我打算使用这里找到的MIDI-dot-net类:https://code.google.com/p/midi-dot-net/读取打击乐音符值并查看其中一个读取外部键盘弹奏的示例并显示它们.
不幸的是,虽然我认为我非常接近,但我无法将其转换为我想做的事情.
那里有没有熟悉这个库的用户可以发现我的错误吗? C#不是我的主要语言(事实上,VB.net也不是!)但是如果我可以在C#中运行某些东西,那么我可以将它转换为VB.net以便在我的应用程序中使用.
或者,还有另一种更简单的方法来做我想要的吗?
到目前为止,这是我的代码:
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();
}
}
}
具体来说,我不确定如何定义NoteOn和NoteOff行为……
提前致谢
菲尔
最佳答案
I would have thought that it would be possible to get the note played but there’s no Note value, only a Pitch value which doeesn’t seem to make sense.
不幸的是,这是不可能的.音符的音高值决定了要播放的鼓样本. MIDI协议未指定“小军鼓”或“定音鼓开启”.它只是说C2或E5.
话虽如此,如果您的控制器和合成器使用通用MIDI,则通常会遵循一个地图. From Wikipedia:
我得到的是你没有代码问题.你的问题在于解释那些音高值.