阅读 MIDI 文件规范,我认为您可以开始创建类似
public class MIDIFile {
enum FileFormat {
single_track,
syncronous_multiple_tracks,
assyncronous_multiple_tracks;
}
FileFormat file_format;
short numberOfTracks;
short deltaTimeTicks;
//Create Class for tracks, events, put some collection for storing the tracks,
//some collection for storing the events inside the tracks, etc
//Collection<Integer, MIDITrack> the type of Collection depends on application
}
public class MIDITrack {
int length;
//Collection<MIDIEvent> the type of Collection depends on application
}
public class MIDIEvent {
int delta_time;
int event_type; //Use of enum or final variables is interesting
int key;
int velocity;
}
如果您只想存储 MIDI 消息(而不是 MIDI 文件),您可以为消息做一个 Class
public class MIDIEvent {
int delta_time;
int channel;
int event_type; //Use of enum or final variables is interesting
//two bytes, interpret according the message type
byte byte0;
byte byte1;
//or more memory consuming
byte key;
byte pressure;
byte controller;
short bend;
}
您用于存储的 Collection 类型将是特定于应用程序的,您希望如何访问列表的元素等等。
如果您只想在 Collection 中插入 MIDIMessages,然后从头到尾读取,您可以使用 LinkedList(这是 List 的实现)。但是,如果您想通过索引修改消息和访问元素,您将需要使用 ArrayList(这也是 List 的实现)。
来自http://faydoc.tripod.com/formats/mid.htm的 MIDI 文件结构信息