Beispiel #1
0
 /**
  * This method is called by the sound system when a meta event occurs. In this case, when the
  * end-of-track meta event is received, the sequence is restarted if looping is on.
  *
  * @param event
  */
 public void meta(MetaMessage event) {
   if (event.getType() == END_OF_TRACK_MESSAGE) {
     if (sequencer != null && sequencer.isOpen() && loop) {
       sequencer.start();
     }
   }
 }
Beispiel #2
0
    public void meta(MetaMessage message) {

      if (message.getType() == 47 && playState != PAUSED && sequence != null) {
        midiEOM = true;
        if (playState != STOPPED) {
          sequencer.stop();
          playState = EOM;
        }
      }
    }
  private static MidiEvent readEvent(
      DataInputStream dataInputStream,
      long[] alRemainingBytes,
      int[] anRunningStatusByte,
      long lTicks)
      throws InvalidMidiDataException, IOException {
    int nStatusByte = readUnsignedByte(dataInputStream, alRemainingBytes);
    // TDebug.out("status byte: " + nStatusByte);
    MidiMessage message = null;
    boolean bRunningStatusApplies = false;
    int nSavedByte = 0;
    if (nStatusByte < 0x80) {
      if (anRunningStatusByte[0] != -1) {
        bRunningStatusApplies = true;
        nSavedByte = nStatusByte;
        nStatusByte = anRunningStatusByte[0];
      } else {
        throw new InvalidMidiDataException("corrupt MIDI file: status byte missing");
      }
    }
    switch (getType(nStatusByte)) {
      case STATUS_ONE_BYTE:
        int nByte = 0;
        if (bRunningStatusApplies) {
          nByte = nSavedByte;
        } else {
          nByte = readUnsignedByte(dataInputStream, alRemainingBytes);
          anRunningStatusByte[0] = nStatusByte;
        }
        ShortMessage shortMessage1 = new ShortMessage();
        shortMessage1.setMessage(nStatusByte, nByte, 0);
        message = shortMessage1;
        break;

      case STATUS_TWO_BYTES:
        int nByte1 = 0;
        if (bRunningStatusApplies) {
          nByte1 = nSavedByte;
        } else {
          nByte1 = readUnsignedByte(dataInputStream, alRemainingBytes);
          anRunningStatusByte[0] = nStatusByte;
        }
        int nByte2 = readUnsignedByte(dataInputStream, alRemainingBytes);
        ShortMessage shortMessage2 = new ShortMessage();
        shortMessage2.setMessage(nStatusByte, nByte1, nByte2);
        message = shortMessage2;
        break;

      case STATUS_SYSEX:
        if (CANCEL_RUNNING_STATUS_ON_META_AND_SYSEX) {
          anRunningStatusByte[0] = -1;
        }
        int nSysexDataLength = (int) readVariableLengthQuantity(dataInputStream, alRemainingBytes);
        byte[] abSysexData = new byte[nSysexDataLength];
        for (int i = 0; i < nSysexDataLength; i++) {
          int nDataByte = readUnsignedByte(dataInputStream, alRemainingBytes);
          abSysexData[i] = (byte) nDataByte;
        }
        SysexMessage sysexMessage = new SysexMessage();
        sysexMessage.setMessage(nStatusByte, abSysexData, nSysexDataLength);
        message = sysexMessage;
        break;

      case STATUS_META:
        if (CANCEL_RUNNING_STATUS_ON_META_AND_SYSEX) {
          anRunningStatusByte[0] = -1;
        }
        int nTypeByte = readUnsignedByte(dataInputStream, alRemainingBytes);
        int nMetaDataLength = (int) readVariableLengthQuantity(dataInputStream, alRemainingBytes);
        byte[] abMetaData = new byte[nMetaDataLength];
        for (int i = 0; i < nMetaDataLength; i++) {
          int nDataByte = readUnsignedByte(dataInputStream, alRemainingBytes);
          abMetaData[i] = (byte) nDataByte;
        }
        MetaMessage metaMessage = new MetaMessage();
        metaMessage.setMessage(nTypeByte, abMetaData, nMetaDataLength);
        message = metaMessage;
        break;
      default:
    }
    MidiEvent event = new MidiEvent(message, lTicks);
    return event;
  }