Correctly serialise the global part of patch
This commit is contained in:
@@ -33,7 +33,7 @@ function build_patch(patch) {
|
|||||||
return {
|
return {
|
||||||
/* BYTES 0, 11 NOT 0, 12 */
|
/* BYTES 0, 11 NOT 0, 12 */
|
||||||
program_name: String.fromCharCode(...patch.slice(0, 12)),
|
program_name: String.fromCharCode(...patch.slice(0, 12)),
|
||||||
/* BYTES 13 / 14 SKIPPED */
|
/* BYTES 12 / 13 SKIPPED */
|
||||||
arp_trigger_length: patch[14],
|
arp_trigger_length: patch[14],
|
||||||
arp_trigger_pattern: toBitArray(patch[15]),
|
arp_trigger_pattern: toBitArray(patch[15]),
|
||||||
voice_mode: getBits(patch[16], 4, 5),
|
voice_mode: getBits(patch[16], 4, 5),
|
||||||
@@ -52,11 +52,11 @@ function build_patch(patch) {
|
|||||||
eq_hi_gain: patch[27],
|
eq_hi_gain: patch[27],
|
||||||
eq_low_freq: patch[28],
|
eq_low_freq: patch[28],
|
||||||
eq_low_gain: patch[29],
|
eq_low_gain: patch[29],
|
||||||
arp_tempo: patch.slice(30, 32).reduce((acc, curr) => acc + curr),
|
arp_tempo: (patch[30] << 8) + patch[31],
|
||||||
arp_on_off: patch[32] & 0x80,
|
arp_on_off: patch[32] & 0x80,
|
||||||
arp_latch: patch[32] & 0x40,
|
arp_latch: patch[32] & 0x40,
|
||||||
arp_target: getBits(patch[32], 4, 5),
|
arp_target: getBits(patch[32], 4, 5),
|
||||||
arp_key_sync: patch[32] & 0x01,
|
arp_key_sync: patch[32] & 0x00,
|
||||||
arp_type: getBits(patch[33], 0, 3),
|
arp_type: getBits(patch[33], 0, 3),
|
||||||
arp_range: getBits(patch[33], 4, 7),
|
arp_range: getBits(patch[33], 4, 7),
|
||||||
arp_gate_time: patch[34],
|
arp_gate_time: patch[34],
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default function saveStoreState(state) {
|
|||||||
{
|
{
|
||||||
...state_patch({
|
...state_patch({
|
||||||
unused: { ...state.unusedPatch },
|
unused: { ...state.unusedPatch },
|
||||||
patch: { ...state.Patch },
|
patch: { ...state.patch },
|
||||||
arpeggA: { ...state.arpeggA },
|
arpeggA: { ...state.arpeggA },
|
||||||
arpeggB: { ...state.arpeggB },
|
arpeggB: { ...state.arpeggB },
|
||||||
delay: { ...state.delay },
|
delay: { ...state.delay },
|
||||||
|
|||||||
@@ -1,5 +1,54 @@
|
|||||||
|
import { fromBitArray, buildByte } from '../utils/functions';
|
||||||
|
|
||||||
export default function serialise(patch) {
|
export default function serialise(patch) {
|
||||||
serialise_patch(patch);
|
serialise_patch(patch[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serialise_patch(patch) {}
|
function serialise_patch(patch) {
|
||||||
|
const patch_array = Array.from(Buffer.from(patch.program_name, 'ascii'));
|
||||||
|
patch_array.push(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
patch.arp_trigger_length,
|
||||||
|
fromBitArray(patch.arp_trigger_pattern),
|
||||||
|
buildByte({ value: patch.voice_mode, start: 4 }),
|
||||||
|
buildByte(
|
||||||
|
{ value: patch.scale_key, start: 4 },
|
||||||
|
{ value: patch.scale_type, start: 0 }
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
buildByte(
|
||||||
|
{ value: patch.delay_sync, start: 7 },
|
||||||
|
{ value: patch.delay_timebase, start: 0 }
|
||||||
|
),
|
||||||
|
patch.delay_time,
|
||||||
|
patch.delay_depth,
|
||||||
|
patch.delay_type,
|
||||||
|
patch.mod_lfo_speed,
|
||||||
|
patch.mod_depth,
|
||||||
|
patch.mod_type,
|
||||||
|
patch.eq_hi_freq,
|
||||||
|
patch.eq_hi_gain,
|
||||||
|
patch.eq_low_freq,
|
||||||
|
patch.eq_low_gain,
|
||||||
|
(patch.arp_tempo >> 8) & 0xff,
|
||||||
|
patch.arp_tempo & 0xff,
|
||||||
|
buildByte(
|
||||||
|
{ value: patch.arp_switch, start: 7 },
|
||||||
|
{ value: patch.arp_latch, start: 6 },
|
||||||
|
{ value: patch.arp_target, start: 4 },
|
||||||
|
{ value: patch.arp_key_sync, start: 0 }
|
||||||
|
),
|
||||||
|
buildByte(
|
||||||
|
{ value: patch.arp_type, start: 0 },
|
||||||
|
{ value: patch.arp_range, start: 4 }
|
||||||
|
),
|
||||||
|
patch.arp_gate_time,
|
||||||
|
patch.arp_resolution,
|
||||||
|
patch.arp_swing,
|
||||||
|
patch.keyboard_octave
|
||||||
|
);
|
||||||
|
console.log(patch_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialise_timbre(timbre) {}
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
const toBitArray = (n, b = 8) => [...Array(b)].map((x, i) => (n >> i) & 1);
|
const toBitArray = (n, b = 8) => [...Array(b)].map((x, i) => (n >> i) & 1);
|
||||||
|
|
||||||
|
const fromBitArray = (array) => {
|
||||||
|
return (
|
||||||
|
0 |
|
||||||
|
(array[0] << 7) |
|
||||||
|
(array[1] << 6) |
|
||||||
|
(array[2] << 5) |
|
||||||
|
(array[3] << 4) |
|
||||||
|
(array[4] << 3) |
|
||||||
|
(array[5] << 2) |
|
||||||
|
(array[6] << 1) |
|
||||||
|
(array[7] << 0)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const getBits = (byte, indexStart, indexEnd = 7) =>
|
const getBits = (byte, indexStart, indexEnd = 7) =>
|
||||||
parseInt(
|
parseInt(
|
||||||
toBitArray(byte)
|
toBitArray(byte)
|
||||||
@@ -9,6 +23,15 @@ const getBits = (byte, indexStart, indexEnd = 7) =>
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function buildByte(...args) {
|
||||||
|
// we take an objects, with the value, and the bits it takes up.
|
||||||
|
let byte = 0;
|
||||||
|
for (const element of arguments) {
|
||||||
|
byte = byte | (element.value << element.start);
|
||||||
|
}
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
const signedNumber = (byte) => (byte > 63 ? (byte ^ 64) - 64 : byte);
|
const signedNumber = (byte) => (byte > 63 ? (byte ^ 64) - 64 : byte);
|
||||||
|
|
||||||
console.assert(1 === signedNumber(1));
|
console.assert(1 === signedNumber(1));
|
||||||
@@ -29,4 +52,12 @@ function returnValue(setting, list) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { toBitArray, getBits, signedNumber, returnFromList, returnValue };
|
export {
|
||||||
|
toBitArray,
|
||||||
|
fromBitArray,
|
||||||
|
getBits,
|
||||||
|
buildByte,
|
||||||
|
signedNumber,
|
||||||
|
returnFromList,
|
||||||
|
returnValue,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user