-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
html midi API bindings are broken #33248
Comments
Robert looks like the requestMidiAccess should be: Future requestMidiAccess([Map options]) { However, when I now call requestMIDIAccess() I get a DOMException of "Platform dependent initialization failed." I was running this on a Linux box which might be the problem too. I'll make the change when I'm back in the office on Monday and try on a Mac. |
Tested on a Mac and I get back a MIDIAccess object. Looks right to me. I'll make the change and check it in. |
Just tested this with I do get a MidiAccess Object but that object is not quite right. E.g this fragment void Ready(HTML.MidiAccess succ) { void main() async { dynamic a = HTML.window.navigator.requestMidiAccess(); a.then(Ready); produces note that the map values for INPUTS and OUTPUTS are empty maps MidiAccess.inputs and MidiAccess.outputs do not seem to be properly initialized |
This has regressed even more. Running the code from my previous comment now yields Uncaught (in promise) TypeError: this.requestMidiAccess is not a function where midi_input.dart:20 is the line:
|
Still happening, half a year later. Uncaught TypeError: this.requestMidiAccess is not a function Dart VM version: 2.5.2 (Tue Oct 8 16:17:11 2019 +0200) on "macos_x64" |
any update? This bug is soon celebrating its 2 year anniversary. |
Still seeing this. Is there a known workaround? Using JS maybe? |
This would be yet another example of corporate sabotage. They are holding back the PWA.. |
Any update on getting MIDI to work for Flutter web? |
Curious, and unfortunate, that this has remained unaddressed for so long. I understand that are some security concerns to do with Web MIDI; could that be the reason? |
No, it is just not a priority for them. |
At least for flutter one could work around the limitation like so:
I don't know how reliable this is though. |
These days I always consider the possibility of corporate sabotage. I tend to get banned for suggesting this, but I've seen it so many times now that it has become the rule, not the exception. This is the only way the old industry can stay competitive with the emerging. |
Thanks to @DominikStarke comment, I'm using a variation of his work around successfully at the moment in a Flutter web app. Which shows that its just a case of needing to fix whatever the @terrylucas could you point me to where the source for the WebMidi classes for |
+1 I would also love to see a fix for this issue |
Ok after a lot of trial and error, probably more than any sane person would do (but this 4 year old bug really annoyed me) I seem to have discovered the cause of the problem, or at least the main problem. eg. setting up some JS to pass thru the inputs as an actual array works fine:
And with "receiving" Dart I get:
I get output as follows:
BUT switch the JS to return Unfortunately I have no idea how to go about addressing this issue as I think it could be down to how the Dart->JS compiler (I'm testing with DDC) is generating code to map across "maplike" objects from JS to Dart? The only references I could find to "maplike" here in the sdk repo that looked like it may have something to do with this was here but I've honestly no idea if thats really relevant to this. Perhaps someone like @srujzs or @jmesserly or some other Dart team member who works on the Dart->JS compiler would know more about this? It would be nice to close a very long standing bug like this, even if WebMidi is a bit niche, as Firefox has finally now also just actually released support for WebMidi too in their nightlies. |
@maks What I would do is use a I guess you know how to do this but nevertheless here is an example of
|
@maks how are you returning the inputs? I have no MIDI here so my inputs are empty be it JS or Dart. What happens with this code? import 'package:js_bindings/js_bindings.dart';
Future<JsMap> foo() async {
final a = await window.navigator.requestMIDIAccess();
print('got MIdiAccess: ${a.inputs}');
return a.inputs;
}
void main() async {
document.title = 'JS Bindings example';
final inps = await foo();
window.console.log(inps);
for (var i in inps.values) {
print('midi input:$i');
}
} |
@jodinathan Thanks for looking into this so quickly! And apologies for me not providing a better demo of the bug and what I thought to be the issue. I'm not sure why you were not seeing any midi inputs even with your plain JS code, for me on Chrome on Linux even with no midi devices plugged in I always see the "Midi Through Port - 0" input (pls see screenshot linked in the Readme of the above demo repo) I'm not sure why you were not seeing the through port at least, perhaps you had some setting in your Chrome browser that was overriding the Midi permission request dialog from being shown? It seems for instance that DartPad does this via a HTTP header. Hopefully my demo repo works for you to help demonstrate the issue here. |
@jodinathan also thank you so much for the instructions on how to look at the transpiled JS 👍🏻 I was actually searching for exactly that yesterday and had been able to find out how to do it. |
so I now really looked at the prev comment from @DominikStarke with the JS script workaround and finally noticed the use of import 'package:js/js.dart';
import 'package:js/js_util.dart' as jsutil;
import 'package:js_bindings/js_bindings.dart' as html;
void showInputs(dynamic a, dynamic b, dynamic c) {
print('got args from forEach: [$a] [$b] [$c]');
final inp = a as html.MIDIInput;
print('input name: ${inp.name}');
}
void main() async {
final access = await html.window.navigator
.requestMIDIAccess(html.MIDIOptions(sysex: true, software: false));
final inputs = access.inputs;
jsutil.callMethod(inputs, 'forEach', [allowInterop(showInputs)]);
} and I get the following output:
I had to do a quick head scratch about why its 3 args to the forEach callback function, but looking at the docs for So @jodinathan I'm using |
@maks regarding the empty map I have nothing about MIDI for what I know. The I will change it to use the underlying Js |
@jodinathan if you need virtual midi devices and are on windows you can use https://www.tobias-erichsen.de/software/virtualmidi.html |
@jodinathan First off thanks again for all your work on js_bindings! It makes things so much nicer/easier than using "package js" directly!
The output I get is:
On the topic of testing WebMidi, it looks like the default "Midi Through Port - 0" is a Linux thing, I just checked on a Mac and it doesn't have it so I think if you are on MacOS or Windows you'll need to create at least one virtual midi port per @DominikStarke latest comment here to test out the Webmidi api in Chrome, even with plain JS. |
@jodinathan thank you again! Just tried 0.0.6-dev and your new |
@maks I've tried to make the In fact, would be nice if you could test them. I will publish a stable version rn |
@sigmundch I guess issues like this can be directed to use js_bindings and closed? |
@sigmundch I would agree, given it's now possible to use |
Thank you both! This very exciting!
/cc @srujzs @rileyporter let's discuss how we want to approach this and other similar bugs on our next sync up when we are all back online. I'll keep this open in the meantime. |
Dart VM version: 2.0.0-dev.58.0 (Unknown timestamp) on "linux_x64"
(tried ddc but I believe dart2js does no work either)
The problem seems to go beyond promises:
succ.inputs is supposed to be a map from device-id to an object but
the object returned seems to always be the empty dict.
In JS I get a real object.
The text was updated successfully, but these errors were encountered: