This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 20254 - Add code examples
Summary: Add code examples
Status: CLOSED FIXED
Alias: None
Product: AudioWG
Classification: Unclassified
Component: MIDI API (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: TBD
Assignee: Chris Wilson
QA Contact: public-audio
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-05 20:35 UTC by Chris Wilson
Modified: 2013-01-02 11:29 UTC (History)
3 users (show)

See Also:


Attachments

Description Chris Wilson 2012-12-05 20:35:05 UTC
We need more code examples in the spec.
Comment 1 Olivier Thereaux 2012-12-06 17:08:24 UTC
You might want to break this down a bit after a first pass.
Comment 2 Chris Wilson 2012-12-07 18:48:05 UTC
(In reply to comment #1)
> You might want to break this down a bit after a first pass.

Actually, since the API is so simple, I'll probably push in a bunch of examples in one go.

One question (email response to group is fine) - preferences for inline examples in each section, or separate example section?  I'm leaning slightly to the latter.
Comment 3 Jussi Kalliokoski 2012-12-07 19:50:06 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > You might want to break this down a bit after a first pass.
> 
> Actually, since the API is so simple, I'll probably push in a bunch of
> examples in one go.
> 
> One question (email response to group is fine) - preferences for inline
> examples in each section, or separate example section?  I'm leaning slightly
> to the latter.

Due to the simplicity of the API, I agree that the latter is probably better.
Comment 4 Chris Wilson 2012-12-07 20:42:23 UTC
Added a set of five basic examples that cover the entire API.  Other examples should be separately bugged.  https://dvcs.w3.org/hg/audio/rev/00b58322aa11.
Comment 5 Florian Bomers 2012-12-08 10:53:01 UTC
some remarks on the code examples:

9.1
> function success( midiAccess )

should be named

> function onMIDISuccess( midiAccess )


9.4
> output.send( [0x90, 60, 0x00], window.performance.now() + 1000.0 ); 
> // note off, middle C, zero velocity, timestamp = now + 1000ms.

This is actually a Note On message with 0 velocity, which is equivalent to a Note Off message with 64 velocity (if I recall correctly). It's probably easier to understand for MIDI newbies to use the actual Note Off message:

> output.send( [0x80, 60, 0x00], window.performance.now() + 1000.0 ); 
> // note off, middle C, zero velocity, timestamp = now + 1000ms.


9.5
same as 9.1
Comment 6 Chris Wilson 2012-12-10 18:02:40 UTC
https://dvcs.w3.org/hg/audio/rev/d61cc0adee7e and https://dvcs.w3.org/hg/audio/rev/39efc30b003f contain these changes:

(In reply to comment #5)
> should be named
> > function onMIDISuccess( midiAccess )

Done.

> This is actually a Note On message with 0 velocity, which is equivalent to a
> Note Off message with 64 velocity (if I recall correctly). It's probably
> easier to understand for MIDI newbies to use the actual Note Off message:

Done.

> 9.5
> same as 9.1

Done.

From James' email:
>9.2
>idx and i are the same variable. Change idx to i.

Done.

>9.3
>indexOfPort and index are the same variable. Change index to indexOfPort.

Done.

>I  think I'd also rename "event" to "msg" in onMIDIMessage(). Might give newbies a marginally easier time.

NOT done.  The parameter to the onmessage handler is an Event - I want that to be clear.

>9.4
>I think that a) the text should include the information that both messages are being sent on channel 0, and b) it might be helpful if you said a bit more about the omitted timestamp.

Done and done.

>As in 9.3, change index to indexOfPort.

Done.

>Can we have a sysex example in the official docs please?

Made it clearer that the echo example handles sysex.  Sysex is not a separate thing in the Web MIDI API - it's just another MIDIEvent, with more bytes.  (And, obviously, a different status code.)
Comment 7 Florian Bomers 2012-12-10 19:55:54 UTC
(In reply to comment #6)

thanks for the super fast changes!

> https://dvcs.w3.org/hg/audio/rev/d61cc0adee7e

includes the following addition:

"This example sends a middle C note on message immediately on MIDI channel 0 [...]"

I'm sure you are aware of this -- MIDI channels are encoded as the lower 4 bits of the status byte from 0 to 15. But when referring to them, by convention, they are numbered 1 to 16. Therefore, I think it's better to change the text to say "MIDI channel 1".

Now personally, I don't like this "convention", but with MIDI being around for 30 years, it would bring more confusion than help trying to "fix" it now.
Comment 8 Chris Wilson 2012-12-10 20:06:49 UTC
(In reply to comment #7)
> I'm sure you are aware of this -- MIDI channels are encoded as the lower 4
> bits of the status byte from 0 to 15. But when referring to them, by
> convention, they are numbered 1 to 16. Therefore, I think it's better to
> change the text to say "MIDI channel 1".
> 
> Now personally, I don't like this "convention", but with MIDI being around
> for 30 years, it would bring more confusion than help trying to "fix" it now.

Fair enough.  Fixed.
Comment 9 Olivier Thereaux 2013-01-02 11:29:24 UTC
(In reply to comment #8)
> > Now personally, I don't like this "convention", but with MIDI being around
> > for 30 years, it would bring more confusion than help trying to "fix" it now.
> 
> Fair enough.  Fixed.

I assume that with this fix, we can close this issue. Other requests for examples can be made into their own issues.