我可以更改mciSendString的输出midi设备吗

本文关键字:midi 输出 mciSendString 我可以 | 更新日期: 2023-09-27 18:29:29

所以我终于在这个类上找到了一个帮助我的帖子

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace MidiProgram
{
/// <summary>
/// MCIPlayer is based off code by Slain.
/// Found here: http://www.sadeveloper.net/Articles_View.aspx?articleID=212
/// </summary>
public class MCIPlayer
{
    private static readonly string sAlias = "TeaTimerAudio";
    [DllImport("winmm.dll")]
    private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
    [DllImport("Winmm.dll")]
    private static extern long PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
    public static void Play(string sFile)
    {
        _Open(sFile);
        _Play();
    }
    public static void Stop()
    {
        _Close();
    }
    private static void _Open(string sFileName)
    {
        if (_Status() != "")
            _Close();
        string sCommand = "open '"" + sFileName + "'" alias " + sAlias;
        mciSendString(sCommand, null, 0, IntPtr.Zero);
    }
    private static void _Close()
    {
        string sCommand = "close " + sAlias;
        mciSendString(sCommand, null, 0, IntPtr.Zero);
    }
    private static void _Play()
    {
        string sCommand = "play " + sAlias;
        mciSendString(sCommand, null, 0, IntPtr.Zero);
    }
    private static string _Status()
    {
        StringBuilder sBuffer = new StringBuilder(128);
        mciSendString("status " + sAlias + " mode", sBuffer, sBuffer.Capacity, IntPtr.Zero);
        return sBuffer.ToString();
    }
}
}

然而,我似乎发现了一点问题,整个程序声音,但显然它输出到(微软gs波形表合成器)在这个类中,有没有一种方法可以改变midi的输出方式,或者它只是像MediaPlayer那样以这种形式播放,请告诉我,这是我项目的最后一步,只是一个简单的代码,我可以这么做,我可以用整数或其名称指定midi设备吗,我指的是midi设备的顺序!

我可以更改mciSendString的输出midi设备吗

MCI定序器设备允许您使用set命令设置端口:

设置端口port_number