我想获取一个MIDI文件,读取它,然后将数据存储在某种数据结构中.使用这个网站,我发现了一种简单的方法来阅读文件,它就像一个魅力:
现在我需要找出一种获取输出并存储它的方法.哈希映射似乎并不理想,因为键需要是唯一的,而类型为Object的List看起来并不好.关于我最好的选择可能是什么想法.我想我可能会把它输出到文本或csv ...思考?
更新:关于我已有的更多细节.
这是我得到的输出(通过System.out.println):
@0 Channel: 1 Note on, E5 key=76 velocity: 127
@192 Channel: 1 Note off, E5 key=76 velocity: 64
@192 Channel: 1 Note on, D#5 key=75 velocity: 127
@384 Channel: 1 Note off, D#5 key=75 velocity: 64
@384 Channel: 1 Note on, E5 key=76 velocity: 127
Run Code Online (Sandbox Code Playgroud)
现在我只需要找到存储这些信息的最佳方法.我应该说"为什么"我也试图这样做.我正在与另一位开发人员合作,他将使用这些数据并使用Batik(我一无所知)将其显示在屏幕上.
感谢所有回复......今晚我会密切关注他们每一个......
阅读 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;
}
Run Code Online (Sandbox Code Playgroud)
如果您只想存储 MIDI 消息(因此不是 MIDI 文件),您可以为消息创建一个类
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;
}
Run Code Online (Sandbox Code Playgroud)
您用来存储的集合类型将特定于应用程序、您希望如何访问列表元素等等。
如果您只想在集合中插入 MIDIMessages,然后从第一个到最后一个读取,您可以使用 LinkedList(这是 List 的实现)。但是,如果您想修改消息并通过索引访问元素,则需要使用 ArrayList(这也是 List 的实现)。
MIDI 文件结构信息来自http://faydoc.tripod.com/formats/mid.htm
归档时间: |
|
查看次数: |
741 次 |
最近记录: |