Using javascript to handle midi events?

D

dieselmachine

Hey, I've been searching for info on this for days now, but to no
avail. I'm starting to think it's impossible, but anyway!

I've coded a little virtual keyboard, which has two octaves worth of
keys on it, and when the keyboard image is clicked, it uses the
coordinates to determine what key was pressed, then some stuff happens
that we needn't worry about. I want to make the keys play the
appropriate note when clicked, and I can't figure out how to do it.
Obviously I could create individual midis for each note that could be
pressed, and maybe preload the entire thing for quicker response. But
that is trash, especially if I expand the keyboard to full size (which
I will dammit).

Is there a way to just send a midi event, consisting only of the one
note, and have it play?
 
W

weston

Hey, I've been searching for info on this for days now, but to no
avail. I'm starting to think it's impossible, but anyway!

I've coded a little virtual keyboard, which has two octaves worth of
keys on it, and when the keyboard image is clicked, it uses the
coordinates to determine what key was pressed, then some stuff happens
that we needn't worry about. I want to make the keys play the
appropriate note when clicked, and I can't figure out how to do it.
Obviously I could create individual midis for each note that could be
pressed, and maybe preload the entire thing for quicker response. But
that is trash, especially if I expand the keyboard to full size (which
I will dammit).

Is there a way to just send a midi event, consisting only of the one
note, and have it play?

If you're using a web browser that supports data URIs
(http://en.wikipedia.org/wiki/Data:_URI ), then you can basically write
a one note MIDI file as a data URL to the source of an embed or other
media type that supports MIDI.

Unfortunately, guess which widely prevalent browser doesn't support
data URIs?

It may be IE has some other kind of built-in proprietary media object
that can handle this, tho'.
 
J

Jeremy

weston said:
If you're using a web browser that supports data URIs
(http://en.wikipedia.org/wiki/Data:_URI ), then you can basically write
a one note MIDI file as a data URL to the source of an embed or other
media type that supports MIDI.

Unfortunately, guess which widely prevalent browser doesn't support
data URIs?

It may be IE has some other kind of built-in proprietary media object
that can handle this, tho'.

That is fascinating. I had never heard of that scheme before.

I wonder what the overhead would be of opening a one-note midi file
every time a note is played? I would probably just pre-load some wave
sounds using a large set of embedded sound files and play the
appropriate one on the click of a certain key.

Jeremy
 
A

ASM

(e-mail address removed) a écrit :
Is there a way to just send a midi event, consisting only of the one
note, and have it play?

No ! not by JavaScript.

Long time ago NC came with AudioLive, a plug-in to play midi files
that you could send JS commands (in certain conditions not so easy).

Now, there are so much plug-in to play sounds, you can no more address
whatever it is

Best way would be to create a Flash file for your piano.
(but Flash knows only mp3)
 
W

weston

ASM said:
Best way would be to create a Flash file for your piano.
(but Flash knows only mp3)

I know little about Flash, but if Flash knows QuickTime, then it could
possibly also do MIDI.

Of course, you're back to the same problem: can you actually generate
the MIDI data and then play it? Or do you have preload a few
dozen/hundred MIDI/Quicktime files, one for each playable note?

I also understand QuickTime is scriptable via Javascript... though I
don't know to what degree. Still, if you could even tell it to play a
segment of a movie containing MIDI events, you could load a single
movie and play time-addressed portions of it according to which notes
you wanted to play....
 
T

Touffy

I also understand QuickTime is scriptable via Javascript... though I
don't know to what degree. Still, if you could even tell it to play a
segment of a movie containing MIDI events, you could load a single
movie and play time-addressed portions of it according to which notes
you wanted to play....

QuickTime is indeed scriptable to that extent, but only in Safari so
far (they're working to make a standardized interface that would work
in FF).
I'm not sure it would respond fast enough, but the theory is correct.

For the full specifications of the plugin's JavaScript interface, see
http://developer.apple.com/document...526-CH001-ControllingQuickTimeUsingJavaScript
 
K

Kevin Darling

I've coded a little virtual keyboard, which has two octaves worth of
keys on it, and when the keyboard image is clicked, it uses the [...]

Is there a way to just send a midi event, consisting only of the one
note, and have it play?

I don't know about MIDI, but if you Google for "javascript piano",
there's some stuff that might help.

Kev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top