更改 MIDI 编码中的乐器?
我正在尝试编写一个函数来在 Android 上动态创建 midi 文件。由于没有 javax.sound.midi 库,我只是将字节写入自己的文件。我找到了一些很棒的指南(见下文),因此我能够创建多个轨道 midis。然而,我无法弄清楚如何为任何轨道切换乐器,因此一切都只是使用默认乐器。 我认为从我读到的文档中我需要的代码是“程序更改”后跟程序编号。
到目前为止我所尝试的是将以下内容写入 byteoutputstream 数组:
track.write((byte) 192); // 128 + 64
track.write((byte) x); // x is the instrument number between 1-128.
我已将其放在音符开/关音轨信息开始之前,但它似乎除了使 midi 采取开始时间很长。我是否走在正确的轨道上,或者我错过了什么?任何帮助表示赞赏。
http://faydoc.tripod.com/formats/mid.htm https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html
I'm trying to write a function to dynamically create midi files on Android. Since there is no javax.sound.midi library I'm just writing the bytes out to file myself. I've found some great guides (see below) so I've been able to create multiple track midis. However I haven't been able to figure out how to switch instruments for any of the tracks so everythign is just using the default instrument.
I think from the documents I read the code I need is to "program change" followed by the program number.
What I've tried so far is writing the following out to a byteoutputstream array:
track.write((byte) 192); // 128 + 64
track.write((byte) x); // x is the instrument number between 1-128.
I've put this before the start of the note on/ note off track information, but it doesn't seem to do anything except make the midi take a long time to start. Am I on the right track here, or am I missing something? Any help is appreciated.
http://faydoc.tripod.com/formats/mid.htm
https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于想通了。这只是一件简单的事情,但我忘记了节目更改之前的赛道时间。一旦我添加了 0 字节,它就起作用了。
Finally figured it out. It was a just a simple thing, but I forgot to include track time before the program change. Once I added the 0 byte it worked.