在 JavaScript 中生成 MIDI
我想用 javascript 生成一系列 MIDI 音符,然后播放它。许多插件支持 MIDI,但我不知道有任何支持“data:”URL。生成 MIDI 内容并不是什么大事,但将此内容输入到播放器中却是大事。任何人都知道如何做到这一点 - 如果不是一般情况下,那么至少对于像 QuickTime 这样的特定插件?
I'd like to generate a sequence of MIDI notes in javascript and then play it. Many plugins support MIDI, but I'm not aware of any supporting "data:" URL. Generating MIDI content is not a big deal - but feeding this content into player is. Anyone knows how this can be done - if not in general, then at least for specific plugin like QuickTime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
非常简洁的问题。我最近经常使用 Base64 编码的图像,并且经常使用 http://www .greywyvern.com/code/php/binary2base64 用于图像编码。我只是尝试转换 MIDI 文件并将 base64 文本流放入 HTML,它在 Firefox 中运行得很好(这让我感到惊讶)。下面是代码(为简洁起见,删除了 Base64 流):
我不确定是否可以在 JS 中从二进制图像转换为 Base64,但我怀疑从 MIDI 可能是这样。这是一个开始。
Very neat problem. I've been working a lot lately with base64-encoded images and have regularly been using http://www.greywyvern.com/code/php/binary2base64 for image encoding. I just tried converting a MIDI file and putting the base64 text stream into an HTML and it played just fine in Firefox (which astonished me). Here's the code (with the Base64 stream removed for brevity):
I'm not sure it's possible to go from a binary image to base64 in JS, but I suspect that going from MIDI might be. It's a start.
听起来最简单的方法是将 MIDI 数据传递给 PHP 脚本,然后该脚本返回输入。
然后你可以使用“yourscript.php?your-midi-data”而不是“data:your-mini-data”。
Sounds like the easiest way would be passing the MIDI data to e.g. a PHP script which then returns the input.
Then you can use "yourscript.php?your-midi-data" instead of "data:your-mini-data".
您可能想看看我的以下博客文章。它是关于一个在客户端完全执行您想要做的事情的库。但请注意,浏览器中的跨浏览器 MIDI 再现性并不是真正一致。
http://sergimansilla.com/blog/dinamically-generate-midi-in- JavaScript/
You might want to take a look at the following blog post of mine. It is about a library that does exactly what you are trying to do, client-side. Be aware that cross browser MIDI reproducibility in browsers is not really consistent, though.
http://sergimansilla.com/blog/dinamically-generating-midi-in-javascript/
除了使用 Javascript(参见 Sergi 的帖子)之外,您还可以使用 Java 作为后备方法,我的 Javascript 到 Java 桥公开了 MIDI 框架的部分内容: http://mudcube7.blogspot.com/2010/08/dynamic-midi- Generation-in-browser.html
In addition to using Javascript (see Sergi's post), you can use Java as a fallback method with my Javascript to Java bridge that exposes portions of the MIDI framework: http://mudcube7.blogspot.com/2010/08/dynamic-midi-generation-in-browser.html
带有数据 url 的 QuickTime 适用于 Firefox 和 Chrome(最新版本,无测试版)您必须遵循 quicktime website :通过调用
QT_WriteOBJECT
函数初始化 QuickTime(我有提供指向贝多芬的 mp3 文件的初始有效 src,只是为了防止它抱怨 - 也许没有必要),按照上述参考中的详细信息注册侦听器,并在获得回调 qt_load 后,调用document.movie1.SetURL(myDataURL )
方法。我在数据 url 中使用了 Base64 编码:"data:audio/midi;base64,..."
。 (内容由 javascript 生成)。一切都运行得非常好:Play()、Stop() 等。最困难的部分是阅读他们的纪念性文档(请注意,它还有“HTML”部分)QuickTime with data url works with both Firefox and Chrome (recent releases, no betas) You have to follow instructions from quicktime website : initialize QuickTime by calling
QT_WriteOBJECT
function (I had to provide initial valid src pointing to Beethoven's mp3 file, just to keep it from complaining - maybe it's not necessary), register listeners as detailed in the said reference, and after getting callback qt_load, calldocument.movie1.SetURL(myDataURL)
method. I used base64 encoding in data url:"data:audio/midi;base64,..."
. (content was generated by javascript). Everything worked sensationally well: Play(), Stop(), etc. Most difficult part is reading their monumental doc (note that it has also "HTML" part)