Ejemplo n.º 1
0
 /**
  * Send a SYSEX MIDI message on this output
  *
  * @param msg Bytes of the sysex message, have to contain 0xF0 at the beginning and 0xF7 at the
  *     end
  * @return 1 on success, 0 on error
  */
 public int sendSysex(byte[] msg) {
   javax.sound.midi.SysexMessage msg2 = new javax.sound.midi.SysexMessage();
   try {
     msg2.setMessage(msg, msg.length);
     receiver.send(msg2, 0);
     return 1;
   } catch (InvalidMidiDataException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return 0;
   }
 }
Ejemplo n.º 2
0
 public String decodeMessage(SysexMessage message) {
   byte[] abData = message.getData();
   String strMessage = null;
   // System.out.println("sysex status: " + message.getStatus());
   if (message.getStatus() == SysexMessage.SYSTEM_EXCLUSIVE) {
     strMessage = "Sysex message: F0" + getHexString(abData);
   } else if (message.getStatus() == SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) {
     strMessage = "Continued Sysex message F7" + getHexString(abData);
     seByteCount--; // do not count the F7
   }
   seByteCount += abData.length + 1;
   seCount++; // for the status byte
   return strMessage;
 }
Ejemplo n.º 3
0
  /** @param message */
  public ArrayList<Object> decodeMessage(SysexMessage message) {
    byte[] data = message.getData();
    boolean parseMsg = true;

    // Set up the string to print
    @SuppressWarnings("unused")
    String strMessage = null;
    if (message.getStatus() == SysexMessage.SYSTEM_EXCLUSIVE) {
      strMessage = "Sysex message: F0" + getHexString(data);
      byte[] arr = message.getData();
      for (int i = 0; i < arr.length; ++i) {
        _fullSysex.add(arr[i]);
      }

      if ((message.getData()[message.getLength() - 2] & 0xFF) != 0xF7) {
        // System.out.println ("msg continues " +
        // Integer.toHexString(message.getData()[message.getLength() -
        // 2]));
        parseMsg = false;
      }
    } else if (message.getStatus() == SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) {
      strMessage = "Continued Sysex message: F7" + getHexString(data);
      byte[] arr = message.getData();
      for (int i = 0; i < arr.length; ++i) {
        _fullSysex.add(arr[i]);
      }

      if ((message.getData()[message.getLength() - 2] & 0xFF) != 0xF7) {
        parseMsg = false;
      }
    }

    // System.out.println(strMessage);
    // fileDump.writeBytes(data);

    if (parseMsg) {
      ArrayList<Object> retVal = parseMsg(_fullSysex, data);
      _fullSysex.clear();

      return retVal;
    }

    return null;
  }
  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;
  }