DriverUtil: Utility Routines for Synth Drivers:

  1. public static IPatch[] createPatches(byte[] sysex)
  2. public static IPatch[] createPatches(byte[] sysex, Device device)
  3. private static IPatch[] createPatches(byte[] sysex, IDriver driver)
  4. public static IPatch createPatch(byte[] sysex)
  5. public static IDriver chooseDriver(byte[] sysex)
  6. public static IDriver chooseDriver(byte[] sysex, Device dev)
  7. public static String getPatchHeader(byte[] sysex)
  8. public static void calculateChecksum(byte[] sysex, int start, int end, int ofs)
  9. public static String[] generateNumbers(int min, int max, String format)

public static IPatch[] createPatches(byte[] sysex) {
return createPatches(sysex, chooseDriver(sysex));}
Factory method of Patch. Look up the driver for sysex byte array, and
create a patch by using the driver found. This is used for a byte array
read from a Sysex file, for which a Driver is not known.

public static IPatch[] createPatches(byte[] sysex, Device device) {
return createPatches(sysex, chooseDriver(sysex, device));
}
Factory method of Patch. Look up the driver of the specified Device for
sysex byte array, and create a patch by using the driver found.
@param device Device whose driver is looked up.

private static IPatch[] createPatches(byte[] sysex, IDriver driver)
{
if (driver == null)
return null;
else if (driver.isConverter())
return ((IConverter) driver).createPatches(sysex);
else
return new IPatch[] { ((IPatchDriver) driver).createPatch(sysex) };
} What is this method for ?

public static IPatch createPatch(byte[] sysex)
IPatchDriver driver = (IPatchDriver) chooseDriver(sysex);
return driver != null ? driver.createPatch(sysex) : null;

public static IDriver chooseDriver(byte[] sysex)
Choose proper driver for sysex byte array.
@param sysex: System Exclusive data byte array.
@return Driver object chosen
see IDriver#supportsPatch

public static IDriver chooseDriver(byte[] sysex, Device dev)
choose proper driver in a given device for sysex byte array.
see IDriver#supportsPatch

public static String getPatchHeader(byte[] sysex)
Return a hexadecimal string for
IDriver.suppportsPatch at most 16 byte
sysex data.

public static void calculateChecksum(byte[] sysex, int start, int end, int ofs) {
int sum = 0;
for (int i = start; i <= end; i++)
sum += sysex[i];
sysex[ofs] = (byte) (-sum & 0x7f);
/*
Equivalent with above.
p.sysex[ofs] = (byte) (sum & 0x7f);
p.sysex[ofs] = (byte) (p.sysex[ofs] ^ 0x7f);
p.sysex[ofs] = (byte) (p.sysex[ofs] + 1);
p.sysex[ofs] = (byte) (p.sysex[ofs] & 0x7f);
*/
}
Caluculate check sum of a byte array sysex.
The checksum calculation method of this method is used by Roland, YAMAHA,etc.
Compatibility Note: This method became 'static' method.
@param sysex: a byte array
@param start: start offset
@param end: end offset
@param ofs: offset of the checksum data
see Driver#calculateChecksum(Patch)

public static String[] generateNumbers(int min, int max, String format)
A utility method to generate an array of formatted numbers.
For example,
patchNumbers = generateNumbers(
1, minimum value
10, maximum value
"Patch 00"
pattern String for java.text.DecimalFormat
);
returns the following String array:
{"Patch 01", "Patch 02", "Patch 03", "Patch 04", "Patch 05"
"Patch 06", "Patch 07", "Patch 08", "Patch 09", "Patch 10"}


see IPatchDriver#getPatchNumbers
see IPatchDriver#getPatchNumbersForStore
see IPatchDriver#getBankNumbers

public static IPatch createNewPatch(
IPatchDriver driver,
String fileName,
int size)

Create new patch using a patch file patchFileName.
@param driver: IPatchDriver object
@param fileName: file name (relative path to driver directory)
@param size: Sysex data size
@return: IPatch object
see IPatchDriver#createPatch()