c# - Working with MIDI in Windows Store App (Win 8.1) -
my goal receive midi messages in windows store apps. microsoft has delivered api called microsoft.windowspreview.midirt
(as nuget package).
i managed midi port, messagereceived
event not arised, although i'm pressing keys on midi keyboard, , other midi programs show me pc receives these messages.
here code:
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); } }
any ideas?
possibly-related: device watcher code not following normal pattern. here need do:
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}' id {1} added", a.name, a.id); midiwatcher.updated += (s, a) => debug.writeline("midi port id {1} updated", a.id); midiwatcher.removed += (s, a) => debug.writeline("midi port id {1} removed", a.id); midiwatcher.enumerationcompleted += (s, a) => debug.writeline("initial enumeration complete; watching changes..."); midiwatcher.start(); }
Comments
Post a Comment