我的目标是在Windows Store Apps中接收MIDI消息.Microsoft提供了一个称为Microsoft.WindowsPreview.MidiRT的API(作为nuget包).我设法获得了一个Midi端口,但是没有出现MessageReceived事件,尽管我在MIDI键盘上按了键...
我的目标是在Windows Store Apps中接收MIDI消息.
Microsoft提供了一个称为Microsoft.WindowsPreview.MidiRT的API(作为nuget包).
我设法获得了一个Midi端口,但是没有出现MessageReceived事件,尽管我在MIDI键盘上按了键,并且其他MIDI程序显示PC收到了这些消息.
这是我的代码:
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);
}
}
有任何想法吗?
解决方法:
可能相关:您的设备观察者代码未遵循正常模式.这是您需要做的:
DeviceWatcher midiWatcher;
void MonitorMidiChanges()
{
if (midiWatcher != null)
return;
var selector = MidiInPort.GetDeviceSelector();
midiWatcher = DeviceInformation.CreateWatcher(selector);
midiWatcher.Added += (s, a) => Debug.WriteLine("Midi Port named '{0}' with Id {1} was added", a.Name, a.Id);
midiWatcher.Updated += (s, a) => Debug.WriteLine("Midi Port with Id {1} was updated", a.Id);
midiWatcher.Removed += (s, a) => Debug.WriteLine("Midi Port with Id {1} was removed", a.Id);
midiWatcher.EnumerationCompleted += (s, a) => Debug.WriteLine("Initial enumeration complete; watching for changes...");
midiWatcher.Start();
}
沃梦达教程
本文标题为:c#-在Windows Store应用中使用MIDI(Win 8.1)
猜你喜欢
- unity 鼠标悬停事件操作 2023-04-10
- Unity使用LineRender断笔写字 2023-01-27
- C#设置或验证PDF文本域格式的方法详解 2023-05-12
- Winform中实现图片格式转换 2023-03-28
- 关于C#反射 你需要知道的 2023-02-25
- 深入分析c# 封装和访问修饰符 2023-03-04
- C#实现简单加减乘除计算器 2022-12-06
- C#实现简单成绩管理系统的完整步骤 2023-02-02
- C#实现的文件上传下载工具类完整实例【上传文件自动命名】 2022-11-23
- C#的并发机制优秀在哪你知道么 2023-05-17