Skip to content
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

example needed for midi api #13

Closed
robertmuth opened this issue May 14, 2022 · 3 comments
Closed

example needed for midi api #13

robertmuth opened this issue May 14, 2022 · 3 comments

Comments

@robertmuth
Copy link

I was just trying some variants discussed in:

dart-lang/sdk#33248

The best I could achieve was:

StdOut:
Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
org-dartlang-app:///web/main.dart@346+17:
Error: The method 'requestMidiAccess' isn't defined for the class 'Navigator'.

  • 'Navigator' is from 'package:js_bindings/bindings/html.dart' ('org-dartlang-app:///packages/js_bindings/bindings/html.dart').
    Error: Compilation failed.

my code is:

import 'package:js_bindings/js_bindings.dart';
import 'package:js/js.dart';
import 'package:js/js_util.dart' as jsutil;
...
  final opts = MIDIOptions(sysex: true, software: false);
  final a = await window.navigator.requestMidiAccess(opts);
...

Not sure if it is my problem or the library's.

An example that is known to work would help.

@jodinathan
Copy link
Owner

this seems to be working:

import 'package:js_bindings/js_bindings.dart';

Future<void> main() async {
  final access = await window.navigator
      .requestMIDIAccess(MIDIOptions(sysex: true, software: false));

  access.inputs.forEach((c, k, m) {
    print('Test $c\n $k\n $m');
  });
}

@robertmuth
Copy link
Author

Oops, yes I had type. Here is an example that covers a lot of the functionality. Maybe you can add it:

import 'package:js_bindings/js_bindings.dart';


dynamic make_handler(name) {
  return (msg) => print("$name}, ${msg.data}");
}

String RenderDevice(MIDIPort dev) {
  return "name=${dev.name} id=${dev.id} version=${dev.version} manu=${dev.manufacturer} type=${dev.type} ${dev.connection} ${dev.state}";
}

void HandleNewPort(event) {
  print("New Device: ${RenderDevice(event.port)}");
  event.port.addEventListener('midimessage', make_handler(event.port.name));
}

void main() async {
  print("MAIN");
  final opts = MIDIOptions(sysex: false, software: true);
  MIDIAccess access = await window.navigator.requestMIDIAccess(opts);

  access.addEventListener("statechange", HandleNewPort);

  access.inputs.forEach((c, k, m) {
    print("Input Device: ${RenderDevice(c)}");
    c.addEventListener('midimessage', make_handler(c.name));
  });

  access.outputs.forEach((c, k, m) {
    print("Output Device: ${RenderDevice(c)}");
    c.addEventListener('midimessage', make_handler(c.name));
  });
}

@jodinathan
Copy link
Owner

I've tested your code and it is working ok with the latest lib & SDK.
Open a new issue if you have problems please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants