4

我正在开发一个 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 行为......

提前致谢

菲尔

4

1 回答 1

2

我原以为可以播放音符,但没有音符值,只有一个似乎没有意义的音高值。

不幸的是,这是不可能的。音符的音高值决定了要演奏的鼓样本。MIDI 协议没有指定“snare on”或“timpani on”。它只是说C2或E5。

That being said, if your controller and synth are using General MIDI, there is a map that is usually followed. From Wikipedia:

enter image description here

What I am getting at is that you don't have a code problem. Your problem is with interpreting those pitch values.

于 2013-04-08T17:01:22.937 回答