Constructor
new DX7Bank(dataopt, nameopt) → {DX7Bank}
Create a DX7Bank instance. Can be initialized with SYX data or created empty.
When data is provided, it's validated and parsed. When no data is provided,
the bank is initialized with 32 default "Init Voice" patches.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
data |
Array.<number> | ArrayBuffer | Uint8Array |
<optional> |
Bank SYX data (4104 bytes with SysEx wrapper or 4096 bytes raw) | |
name |
string |
<optional> |
"" | Optional bank name (e.g., filename without extension) |
- Source:
Returns:
- Type
- DX7Bank
Examples
// Load from file
const fileInput = document.getElementById("file-input");
fileInput.addEventListener("change", async (e) => {
const file = e.target.files[0];
const bank = await DX7Bank.fromFile(file);
console.log(bank.getVoiceNames());
});
// Create from SysEx data
const syxData = new Uint8Array([0xF0, 0x43, 0x00, 0x09, 0x20, 0x00, 0xF7]);
const bank = DX7Bank.fromSysEx(syxData, "My Bank");
// Manipulate voices
const bank = new DX7Bank();
const voice = DX7Voice.fromName("BASS 1");
bank.replaceVoice(0, voice); // Replace first voice
console.log(bank.getVoice(0).name); // "BASS 1"
// Export to SysEx
const bank = await DX7Bank.fromFile(file);
const syxData = bank.toSysEx();
download(syxData, "my-bank.syx");
// Convert to JSON for storage
const bank = await DX7Bank.fromFile(file);
const json = bank.toJSON();
localStorage.setItem("dx7-bank", JSON.stringify(json));
Classes
Methods
addVoice(voice) → {number}
Add a voice to the first empty slot
Parameters:
| Name | Type | Description |
|---|---|---|
voice |
DX7Voice | Voice to add |
- Source:
Returns:
Index where voice was added, or -1 if bank is full
- Type
- number
findVoiceByName(name) → {DX7Voice|null}
Find a voice by name (case-insensitive, partial match)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Voice name to search for |
- Source:
Returns:
- Type
- DX7Voice | null
getVoice(index) → {DX7Voice|null}
Get a specific voice by index
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | Voice index (0-31) |
- Source:
Returns:
- Type
- DX7Voice | null
getVoiceNames() → {Array.<string>}
Get all voice names
- Source:
Returns:
- Type
- Array.<string>
getVoices() → {Array.<DX7Voice>}
Get all voices in the bank
- Source:
Returns:
- Type
- Array.<DX7Voice>
replaceVoice(index, voice) → {void}
Replace a voice at the specified index (0-31). Validates the index and creates a copy
of the voice data to ensure the bank maintains its own independent copy.
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | Voice index (0-31) |
voice |
DX7Voice | Voice to insert |
- Source:
Throws:
-
If index is out of range (0-31)
- Type
- DX7ValidationError
Returns:
- Type
- void
Examples
// Replace first voice with a custom voice
const bank = await DX7Bank.fromFile(file);
const customVoice = DX7Voice.fromName("LEAD 1");
bank.replaceVoice(0, customVoice);
console.log(bank.getVoice(0).name); // "LEAD 1"
// Swap voices between banks
const bank1 = await DX7Bank.fromFile(file1);
const bank2 = await DX7Bank.fromFile(file2);
const voiceFromBank2 = bank2.getVoice(5);
bank1.replaceVoice(0, voiceFromBank2); // Copy voice from bank2 to bank1
toJSON() → {object}
Convert bank to JSON format
- Source:
Returns:
Bank data in JSON format
- Type
- object
toSysEx() → {Uint8Array}
Export bank to SysEx format
- Source:
Returns:
Full SysEx data (4104 bytes)
- Type
- Uint8Array
(async, static) fromFile(file) → {Promise.<DX7Bank>}
Load a DX7 bank from a file
Parameters:
| Name | Type | Description |
|---|---|---|
file |
File | Blob | SYX file to load |
- Source:
Throws:
-
-
If file is a single voice file
- Type
- DX7ParseError
-
-
-
If data is not valid DX7 SYX format
- Type
- DX7ValidationError
-
-
-
If file cannot be read (FileReader error)
- Type
- Error
-
Returns:
- Type
- Promise.<DX7Bank>
(static) fromJSON(json) → {DX7Bank}
Create a DX7Bank from a JSON object
Parameters:
| Name | Type | Description |
|---|---|---|
json |
DX7BankJSON | JSON representation of a DX7 bank |
- Source:
Throws:
-
If JSON structure is invalid
- Type
- DX7ValidationError
Returns:
- Type
- DX7Bank
(static) fromSysEx(data, name) → {DX7Bank}
Create a DX7Bank from SysEx data
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Array.<number> | ArrayBuffer | Uint8Array | SysEx data (4104 bytes with header/footer) or raw voice data (4096 bytes) |
name |
string | Optional bank name |
- Source:
Throws:
-
-
If SysEx header is invalid
- Type
- DX7ParseError
-
-
-
If data length is invalid
- Type
- DX7ValidationError
-
Returns:
- Type
- DX7Bank