5

MIDI ファイルを取得して読み取り、そのデータを何らかのデータ構造に保存したいと考えています。このサイトを使用して、ファイルを読む簡単な方法を見つけました。これは魅力的です。

MIDI ファイルの読み込み

次に、その出力を取得して保存する方法を見つける必要があります。キーは一意である必要があり、Object 型の List はあまり適していないため、Hash Map は理想的ではないようです。私の最良の選択肢が何であるかについてのアイデア。私はそれをテキストまたは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

あとは、この情報を保存する最適な方法を見つける必要があります。私はおそらく、「なぜ」これをやろうとしているのかについてもはっきりしているはずです。私は、このデータを取得し、Batik (私は何も知らない) を使用して画面に表示しようとしている別の開発者と協力しています。

すべての回答に感謝します...今夜、それぞれを詳しく見ていきます...

4

1 に答える 1

4

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ファイルではなく)、メッセージのクラスを実行できます

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 に MIDIMessages を挿入し、最初から最後まで読み取るだけの場合は、LinkedList (List の実装) を使用できます。ただし、メッセージを変更し、インデックスによって要素にアクセスする場合は、ArrayList を使用する必要があります (これも List の実装です)。

http://faydoc.tripod.com/formats/mid.htmからの MIDI ファイル構造の情報

于 2013-09-04T05:01:19.830 に答える