在Windows Store App(Win 8.1)中使用MIDI [英] Working with MIDI in Windows Store App (Win 8.1)

查看:154
本文介绍了在Windows Store App(Win 8.1)中使用MIDI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在Windows Store应用程序中接收MIDI消息. Microsoft已提供称为Microsoft.WindowsPreview.MidiRT的API(作为nuget程序包).

My goal is to receive MIDI messages in Windows Store Apps. Microsoft has delivered an API called Microsoft.WindowsPreview.MidiRT (as a nuget package).

我设法获得了一个Midi端口,但是没有出现MessageReceived事件,尽管我在MIDI键盘上按了键,并且其他MIDI程序显示PC收到了这些消息.

I managed to get a midi port, but MessageReceived event is not arised, although I'm pressing keys on my MIDI keyboard, and other MIDI programs show me that PC receives these messages.

这是我的代码:

public sealed partial class MainPage : Page
{
    private MidiInPort port;

    public MainPage()
    {
        this.InitializeComponent();
        DeviceWatcher watcher = DeviceInformation.CreateWatcher();
        watcher.Updated += watcher_Updated;
        watcher.Start();
    }

    protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
    {
        base.OnNavigatingFrom(e);
        port.Dispose();
    }

    async void watcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
    {
        DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector());
        foreach (var item in deviceCollection)
        {
            Debug.WriteLine(item.Name);
            if (port == null)
            {
                port = await MidiInPort.FromIdAsync(item.Id);
                port.MessageReceived += port_MessageReceived;
            }
        }
    }

    void port_MessageReceived(MidiInPort sender, MidiMessageReceivedEventArgs args)
    {
        Debug.WriteLine(args.Message.Type);
    }
}

有什么想法吗?

推荐答案

我设法使其正常运行.我已经将platfrom更改为x64,现在可以使用了(我曾经为x86构建过该平台).但是,仍然存在一个问题(甚至更大):我想将此问题与Unity3d集成,但是Unity3d不允许构建x64 Windows应用程序,另一方面,x86 MIDI构建在x64机器上不起作用.

I managed to make it work. I've changed the platfrom to x64, and now it works (I used to build it for x86). There is still a problem though (and it is even bigger): I want to integrate this with Unity3d, but Unity3d doesn't allow to build x64 windows apps, on the other hand x86 MIDI build doesn't work on x64 machines.

已添加:

尽管此API取决于您的体系结构,但据报道新的Windows 10 api却没有,因此,如果您以Win10为目标,则它应该更简单.

Although this API depends on your architecture, a new Windows 10 api reportedly does not, so it should be simpler, if you target Win10.

这篇关于在Windows Store App(Win 8.1)中使用MIDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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