简体   繁体   English

Java从MIDI序列获取乐器列表

[英]Java get instrument list from MIDI Sequence

I need to get the notes, timestamp, and instrument list and all, from general MIDI files. 我需要从常规MIDI文件中获取音符,时间戳记和乐器列表以及所有内容。

Almost everything is done, but I also need each instrument corresponding to each track otherwise the notes are useless if I don't know which instrument they belong to. 几乎所有事情都完成了,但是我还需要与每个音轨相对应的每把乐器,否则如果我不知道它们属于哪一乐器,这些音符就没用了。

It seems that this is done by getting the patch list, a patch has the instrument code in a soundbank used by the MIDI sequence. 看来这是通过获取音色列表来完成的,一个音色在MIDI序列使用的音库中具有乐器代码。

This seems straight forward, but when I try to use getPatchList() on a Sequence object it returns an empty array. 这似乎很简单,但是当我尝试在Sequence对象上使用getPatchList() ,它将返回一个空数组。

The problem?: it seems like this was never actually implemented in the java MIDI library (??), at least from what I found: 问题?:似乎至少在我发现的情况下,这实际上从未在Java MIDI库(??)中实现过:

/**
 * Get an array of patches used in this sequence.
 * 
 * @return an array of patches used in this sequence
 */
public Patch[] getPatchList()
{
  // FIXE: not quite sure how to do this yet. 
  throw new UnsupportedOperationException("Can't get patch list yet");
}

source: javax.sound.midi.Sequence 来源: javax.sound.midi.Sequence

Aparently the Android developers couldn't figure it out either. 显然,Android开发人员也无法弄清楚。 Note this is a normal java program, nothing to do with Android: 请注意,这是一个普通的Java程序,与Android无关:

public Patch[] getPatchList() {
    //FIXME
    /*
     * I don't understand how to works this method, and so
     * I simply return an empty array. 'patches' initializes
     * in the constructor as empty vector 
     */
    Patch[] patch = new Patch[patches.size()];
    patches.toArray(patch);
    return patch;
}

source: javax.sound.midi.Sequence 来源: javax.sound.midi.Sequence

So is there anything that can be done about this at all? 那么,有什么可以做的吗?
Is there another way to get the instruments? 还有其他获取乐器的方法吗?
Why is this not implemented? 为什么不执行呢?
Did no one actually ever need this since 2005? 自2005年以来,实际上没有人需要吗?

To get a MIDI device to select an instrument, you would send a Program Change message to it (which would also take into account the current setting of the Bank Select controllers). 要使MIDI设备选择乐器,您需要向其发送一个Program Change消息(该消息还将考虑Bank Select控制器的当前设置)。

To get a list of all patches in a sequence, one goes through the list of all messages, and collects all program numbers (and all bank numbers in effect at that time). 要获得序列中所有补丁的列表,请遍历所有消息的列表,并收集所有程序号(以及当时有效的所有库号)。

If your implementations are not doing this, you have to do this manually. 如果您的实现未执行此操作,则必须手动执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM