注意在MIDI库中吗? [英] Note in MIDI library ?

查看:89
本文介绍了注意在MIDI库中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以一定的频率生成音符????
谢谢帮助.

I need to generate note with some frequency ????
thank for help

推荐答案

使用MIDI,您不产生频率,而是在某些乐器上使用12音高每八度音阶产生一个半音符,气质均等调音系统.

最重要的是,您可以使用一些效果,例如滚轮效果(某些控制器上的特殊滚轮模仿了吉他上的弯曲").具有这样的效果,频率会偏离其色度值,但是您无法生成任意频率,因此可以生成的效果确实受到限制.

MIDI的主要命令如弹奏音符开始"和停止弹奏音符",如风琴式控制器中的向下/向上键,并且传递给MIDI接口的数字只是键盘上的音符数".半音阶,类似于现代欧洲基于相等气质的表示法.您还可以在整个播放过程中控制音量和速度. MIDI编码的乐曲与传统现代音乐符号所写的乐谱非常匹配,如此处所述: http://en.wikipedia.org/wiki/Musical_notation [ ^ ].

有许多软件产品使用传统的现代音乐符号来渲染MIDI文件.他们可能支持以这种或某些其他记法来编辑音乐播放,播放,保存/打开生成的文档,并最终将文档导出为MIDI文件格式.您还可以使用各种(硬件)MIDI控制器录制播放.

请参见 http://en.wikipedia.org/wiki/Midi [用于Windows MIDI API的包装程序库 [ C#MIDI工具包 [
相反,这是处理音乐演算"(且仅在相同的性情下)的绝佳机器,对于作曲家而言,无需生活音乐家的参与就可以交换音乐作品,以任何音乐家都可以理解和复制的形式呈现它们,以及学习音乐和培训.

使用通过我在上面引用的库中找到的库,可以创建具有我上面提到的所有功能的软件.您只需要了解音乐理论的非常基础的知识并具有编程经验即可.

祝你好运,
—SA
With MIDI, you do not generate frequency, you generate a chromatic notes on some instrument, using 12-pitch-per-octave, equal temperament tuning system.

On top of this, you can use some effects like wheel effect ("bending" like on guitar is imitated by a special wheel on some controllers). With such effect, the frequency deviates from its chromatic value, but you cannot generate arbitrary frequency, so the effects you can generate are really limited.

Main MIDI commands are like "play note start" and "stop playing a note", like a key down/up in a organ-type controller, and the number passed to the MIDI interface is just a "number of a note" in a half-tone step, like in modern European equal temperament based notation. You also control volume and tempo throughout a play. A MIDI-encoded play closely matches the piece of scores written in traditional modern musical notation as it is described here: http://en.wikipedia.org/wiki/Musical_notation[^].

There are number of software products rendering MIDI files using traditional modern musical notation; they may support editing of music play in this or some alternative notations, play it, save/open resulting document and, ultimately, export the document to the MIDI file format. You can also record the play using all kinds of (hardware) MIDI-controllers.

See http://en.wikipedia.org/wiki/Midi[^].

What do you use for MIDI implementation?
You can read these articles and try:
Wrapper Library for Windows MIDI API[^],
C# MIDI Toolkit[^].

In my opinion, as you cannot produce really unique sound, all this is not really good to create real "analog" music good for performance, say, for writing and distributing audio CDs. If you listen MIDI music for a long time you may feel irritated by its "mechanical" sound, because all the sounds are essentially repeated many time without having unique sounds typical for life music.

Rather, this is the excellent machinery for working with "musical calculus" (and only in one equal temperament), for composers, exchange of musical compositions without participation of life musicians, presenting them in the form any musician can understand and reproduce and also for learning music and training.

Using the libraries found through the libraries I referenced above, you can create software with all of the features I mentioned above; you just need to understand very elementary basics of music theory and have programming experience.

Good luck,
—SA


要使用Midi播放C#(在Middle C旁边):
To play C# (next to Middle C) using Midi:
using System;
using System.Runtime.InteropServices;

namespace Midi
{
    // http://msdn.microsoft.com/en-us/library/dd798478(v=VS.85).aspx
    /*
    void CALLBACK MidiOutProc(
      HMIDIOUT hmo,
      UINT wMsg,
      DWORD_PTR dwInstance,
      DWORD_PTR dwParam1,
      DWORD_PTR dwParam2
    );
     */
    internal delegate void MidiOutProc(IntPtr hmo, int wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2);

    internal static class NativeMethods
    {
        public const int CALLBACK_FUNCTION = 0x00030000;
        public const int MMSYSERR_NOERROR = 0;

        // http://msdn.microsoft.com/en-us/library/dd798468(v=VS.85).aspx
        /*
    MMRESULT midiOutClose(
      HMIDIOUT hmo
    );
         */
        [DllImport("Winmm.dll")]
        public static extern int midiOutClose(IntPtr hmo);

        // http://msdn.microsoft.com/en-us/library/dd798472(v=VS.85).aspx
        /*
    UINT midiOutGetNumDevs(void);
         */
        [DllImport("Winmm.dll")]
        public static extern int midiOutGetNumDevs();

        // http://msdn.microsoft.com/en-us/library/dd798476(v=VS.85).aspx
        /*
        MMRESULT midiOutOpen(
          LPHMIDIOUT lphmo,
          UINT uDeviceID,
          DWORD_PTR dwCallback,
          DWORD_PTR dwCallbackInstance,
          DWORD dwFlags
        );
         */
        [DllImport("Winmm.dll")]
        public static extern int midiOutOpen(out IntPtr lphmo, int uDeviceID, MidiOutProc dwCallback, IntPtr dwCallbackInstance, int dwFlags);

        // http://msdn.microsoft.com/en-us/library/dd798481(v=VS.85).aspx
        /*
    MMRESULT midiOutShortMsg(
      HMIDIOUT hmo,
      DWORD dwMsg
    );
         */
        [DllImport("Winmm.dll")]
        public static extern int midiOutShortMsg(IntPtr hmo, int dwMsg);
    }
}


using System;
using System.Threading;

namespace Midi
{
    public class MidiTest
    {
        private MidiOutProc midiOutProc;

        public MidiTest()
        {
            midiOutProc = new MidiOutProc(Callback);
            if (NativeMethods.midiOutGetNumDevs() > 0)
            {
                IntPtr handle;
                if (NativeMethods.midiOutOpen(out handle, 0, midiOutProc, IntPtr.Zero, NativeMethods.CALLBACK_FUNCTION) == NativeMethods.MMSYSERR_NOERROR)
                {
                    int noteOnChannel1 = 0x90; // channel - 1
                    int noteNumber = 0x3D; // C# above middle C
                    int velocity = 0x64; // 100 (127 [7F] is Max)
                    int data = noteOnChannel1 | (noteNumber << 8) | (velocity << 16);
                    NativeMethods.midiOutShortMsg(handle, data);

                    Thread.Sleep(1000); // play note for one second

                    int noteOffChannel1 = 0x80; // channel - 1

                    data = noteOffChannel1 | (noteNumber << 8) | (velocity << 16);
                    NativeMethods.midiOutShortMsg(handle, data);

                    NativeMethods.midiOutClose(handle);
                }
            }
        }

        private void Callback(IntPtr hmo, int wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2)
        {
            //
        }
    }
}


现在只需创建一个新的MidiTest实例,您将获得一个C#!


Now just create a new MidiTest instance and you will get a C#!

new MidiTest();


这篇关于注意在MIDI库中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆