Ejemplo n.º 1
0
  private void initFromBuffer(byte[] buffer) {
    if (!MidiUtil.bytesEqual(buffer, IDENTIFIER, 0, 4)) {
      System.out.println("File identifier not MThd. Exiting");
      mType = 0;
      mTrackCount = 0;
      mResolution = DEFAULT_RESOLUTION;
      return;
    }

    mType = MidiUtil.bytesToInt(buffer, 8, 2);
    mTrackCount = MidiUtil.bytesToInt(buffer, 10, 2);
    mResolution = MidiUtil.bytesToInt(buffer, 12, 2);
  }
Ejemplo n.º 2
0
  public void writeToFile(File outFile) throws FileNotFoundException, IOException {
    FileOutputStream fout = new FileOutputStream(outFile);

    fout.write(IDENTIFIER);
    fout.write(MidiUtil.intToBytes(6, 4));
    fout.write(MidiUtil.intToBytes(mType, 2));
    fout.write(MidiUtil.intToBytes(mTrackCount, 2));
    fout.write(MidiUtil.intToBytes(mResolution, 2));

    for (MidiTrack T : mTracks) {
      T.writeToFile(fout);
    }

    fout.flush();
    fout.close();
  }