W3C home > Mailing lists > Public > public-audio@w3.org > October to December 2012

Re: [Web MIDI API] Examples and a serializer

From: Jussi Kalliokoski <jussi.kalliokoski@gmail.com>
Date: Mon, 17 Dec 2012 18:44:41 +0200
Message-ID: <CAJhzemUaa=A_S+m6_9XM8qHrsz4C-j-SuR0P18czgGUOPC1BLg@mail.gmail.com>
To: Marcos Caceres <marcosscaceres@gmail.com>
Cc: "public-audio@w3.org" <public-audio@w3.org>
On Mon, Dec 17, 2012 at 6:25 PM, Marcos Caceres <marcosscaceres@gmail.com>wrote:

>
>
>
> On Monday, December 17, 2012 at 4:14 PM, Jussi Kalliokoski wrote:
>
> > On Sun, Dec 16, 2012 at 1:13 AM, Marcos Caceres <
> marcosscaceres@gmail.com (mailto:marcosscaceres@gmail.com)> wrote:
> > > In "Getting Access to the MIDI System" and in "A Simple Loopback", it
> would be better if you just wrapped the code in a self invoking function.
> That way, you can avoid the whole discussion about avoiding globals:
> > >
> > > (function(){
> > > …example here...
> > > }());
> > >
> > > Also, please don't use if statements without curly braces… yes, it's
> part of JS, but every style guide recommends against doing this. It means
> code won't lint and can also lead to unforeseen errors.
> >
> > Well, there are style guides for pretty much every imaginable way of
> doing things... :D But I agree, if it goes to another line, wrap it in
> braces.
> As it's non-normative stuff, I'm happy to rework the examples and send you
> a text file with the code.
> >
> >
> > > Lastly, the "Enumerating Inputs and Outputs" example makes a strong
> use case for adding either a serializer [1] to the MIDIPort interface. It
> would be nice if the object serialized into a JSON compatible structure
> (i.e., add toJSON compatibility). I think all that needs to be added to
> MIDIPort is:
> > >
> > > serializer = { id, manufacturer, name, type, version};
> >
> > I'm pretty sure that conflicts with our current idea of how to add
> worker support, i.e. making MIDI ports copyable / transferable via
> sendMessage(), since if we added a serializer, sendMessage() would accept
> MIDIPorts already, converting them to JSON objects, right?
> >
>
> Sorry, I'm not sure I understand how that conflicts. I might just be
> ignorant here, but my understanding is that toJSON is just a method on the
> prototype. Can you explain a bit more why that would cause a problem when
> being passed to sendMessage()?
>

Well actually I was hoping you'd know better than I did, but if I've
understood it correctly, adding a serializer to Something makes instances
of Something possible to send to a worker via postMessage(). So suppose our
plan for worker support was:

// midi-worker.js

this.onmessage = function (e) {
  if (e.data) {
    var port = e.data
    // do something with the port
  }
}

// midi-mainthread.js

midiWorker.postMessage(midiAccess.getInput(0))

Now, if we had a serializer and it worked like I think it does, we'd have a
possible backwards compatibility issue introducing this functionality,
because the port would have been previously a plain JS object whereas now
it would be a MIDIPort instance. Not that it's very likely that we'd have a
backwards-compatibility issue like this. :D

Cheers,
Jussi
Received on Monday, 17 December 2012 16:45:25 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:50:04 UTC