Ejemplo n.º 1
0
  public MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
    MidiEvent event = null;
    try {
      ShortMessage a = new ShortMessage();
      a.setMessage(comd, chan, one, two);
      event = new MidiEvent(a, tick);

    } catch (Exception e) {
    }
    return event;
  }
Ejemplo n.º 2
0
 public static MidiEvent addNote(int cmmnd, int chnl, int d1, int d2, int tck) {
   MidiEvent ev = null;
   try {
     ShortMessage msg = new ShortMessage();
     msg.setMessage(cmmnd, chnl, d1, d2);
     ev = new MidiEvent(msg, tck);
   } catch (Exception ex) {
   }
   ;
   return ev;
 }
Ejemplo n.º 3
0
 public boolean createEvent(int type, int num, long tick) {
   ShortMessage message = new ShortMessage();
   try {
     message.setMessage(type + cc.num, num, cc.velocity);
     MidiEvent event = new MidiEvent(message, tick);
     track.add(event);
     return true;
   } catch (Exception ex) {
     ex.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 4
0
  /**
   * Create the MidiEvent for a note, given the data.
   *
   * @param command The command value for the ShortMessage
   * @param note The MIDI value for the note to be played
   * @param eventTime When this event should occur
   * @param velocity The velocity of this note
   * @return The MidiEvent for the note
   */
  private MidiEvent createNoteEvent(int command, int note, int eventTime, int velocity) {
    // Create the message and set its parameters to the ones given.
    ShortMessage message = new ShortMessage();
    try {
      message.setMessage(command, 0, note, velocity);
    } catch (InvalidMidiDataException ex) {
      // Something went wrong.
      ex.printStackTrace();
      System.exit(1);
    }

    // Create the MidiEvent and return it.
    return new MidiEvent(message, eventTime);
  }
  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;
  }