change binary-parser version
This commit is contained in:
Generated
+3
-3
@@ -3765,9 +3765,9 @@
|
|||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"binary-parser-encoder": {
|
"binary-parser-encoder": {
|
||||||
"version": "1.5.3",
|
"version": "1.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/binary-parser-encoder/-/binary-parser-encoder-1.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/binary-parser-encoder/-/binary-parser-encoder-1.5.2.tgz",
|
||||||
"integrity": "sha512-yu3tdLBYqPIwGRaXyswLoLrhaffkuZkNuXveq/jYoyBHQbFMjamHCWPFOmI2Qz+Go0Rh6wE9f6tt0EAvsgDD0g==",
|
"integrity": "sha512-bZKR5Qo+pujq+Pvye/ZR94aRbYJx+7WijKAD7RcFi6qgtNJ4kHqAbDaH588VM2N4HylWp08Pm2l0buXqh2t5kw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"smart-buffer": "^4.1.0"
|
"smart-buffer": "^4.1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.5.0",
|
"@testing-library/react": "^9.5.0",
|
||||||
"@testing-library/user-event": "^7.2.1",
|
"@testing-library/user-event": "^7.2.1",
|
||||||
"binary-parser-encoder": "^1.5.3",
|
"binary-parser-encoder": "^1.5.2",
|
||||||
"rc-slider": "^9.6.3",
|
"rc-slider": "^9.6.3",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
|
|||||||
+16
-4
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useEffect, useMemo } from 'react';
|
import React, { useState, useEffect, useMemo } from 'react';
|
||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
|
import { Parse } from './ioParser';
|
||||||
import './IO.css';
|
import './IO.css';
|
||||||
|
|
||||||
const baseStyle = {
|
const baseStyle = {
|
||||||
@@ -56,7 +57,7 @@ const Dropzone = ({ setFile }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dropzone-container">
|
<div className='dropzone-container'>
|
||||||
<div {...getRootProps({ style })}>
|
<div {...getRootProps({ style })}>
|
||||||
<input {...getInputProps()} />
|
<input {...getInputProps()} />
|
||||||
<p>Drag and drop file here, or click to select</p>
|
<p>Drag and drop file here, or click to select</p>
|
||||||
@@ -67,14 +68,25 @@ const Dropzone = ({ setFile }) => {
|
|||||||
|
|
||||||
export default function IO() {
|
export default function IO() {
|
||||||
const [file, setFile] = useState(null);
|
const [file, setFile] = useState(null);
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
// turn file into array buffer for parsing
|
||||||
|
const fileToArrayBuffer = (f) => {
|
||||||
|
reader.onload = (e) => {
|
||||||
|
setFile(new Uint8Array(e.target.result));
|
||||||
|
};
|
||||||
|
reader.readAsArrayBuffer(f);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(file);
|
if (file) {
|
||||||
|
console.log(Parse(file));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dropzone-container">
|
<div className='dropzone-container'>
|
||||||
<Dropzone className="dropzone-modal" setFile={setFile} />
|
<Dropzone className='dropzone-modal' setFile={fileToArrayBuffer} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-42
@@ -1,41 +1,5 @@
|
|||||||
import { Parser } from 'binary-parser-encoder';
|
import { Parser } from 'binary-parser-encoder';
|
||||||
|
|
||||||
function parse(parser, binary) {
|
|
||||||
// check if the binary is a valid KORG-produced SYSEX file
|
|
||||||
if (binary.length !== 297) {
|
|
||||||
throw new Error('incorrect file length');
|
|
||||||
}
|
|
||||||
if (binary[0] !== 0xf0) {
|
|
||||||
throw new Error('first byte is not SYSEX byte');
|
|
||||||
}
|
|
||||||
if (binary[1] !== 0x42) {
|
|
||||||
throw new Error('manufacturer code is not KORG');
|
|
||||||
}
|
|
||||||
if (binary[4] !== 0x40) {
|
|
||||||
throw new Error('not a program dump');
|
|
||||||
}
|
|
||||||
if (binary[5] !== 0x00) {
|
|
||||||
// in all files found in the wild it's always zero
|
|
||||||
throw new Error('sixth byte is not zero');
|
|
||||||
}
|
|
||||||
if (binary[binary.length - 1] !== 0xf7) {
|
|
||||||
throw new Error('last byte is does not end SYSEX message');
|
|
||||||
}
|
|
||||||
|
|
||||||
const trimmedBinary = binary.slice(5, -1);
|
|
||||||
// every eigth byte is padding, so we remove it
|
|
||||||
const unpaddedBinary = trimmedBinary.filter((_, idx) => idx % 8);
|
|
||||||
|
|
||||||
const buffer = Buffer.from(
|
|
||||||
Buffer.from(unpaddedBinary).toString('hex'),
|
|
||||||
'hex'
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(parser.parse(buffer));
|
|
||||||
|
|
||||||
// do stuff with the parsed object
|
|
||||||
}
|
|
||||||
|
|
||||||
const timbre = new Parser()
|
const timbre = new Parser()
|
||||||
.int8('midiChannel') // in 7 bits
|
.int8('midiChannel') // in 7 bits
|
||||||
.bit2('assignMode')
|
.bit2('assignMode')
|
||||||
@@ -238,15 +202,56 @@ const parser = new Parser()
|
|||||||
.nest('timbre1', { type: timbre })
|
.nest('timbre1', { type: timbre })
|
||||||
// dummy bytes *see documentation
|
// dummy bytes *see documentation
|
||||||
.skip(56)
|
.skip(56)
|
||||||
.nest('timbre2', { type: timbre })
|
.nest('timbre2', { type: timbre });
|
||||||
// dummy bytes *see documentation
|
// dummy bytes *see documentation
|
||||||
.skip(56)
|
//.skip(56)
|
||||||
.nest('vocoder', { type: vocoder })
|
//.nest('vocoder', { type: vocoder })
|
||||||
// dummy bytes *see documentation
|
// dummy bytes *see documentation
|
||||||
.skip(111);
|
// .skip(111);
|
||||||
|
|
||||||
|
function parse(parser, binary) {
|
||||||
|
// check if the binary is a valid KORG-produced SYSEX file
|
||||||
|
if (binary.length !== 297) {
|
||||||
|
throw new Error('incorrect file length');
|
||||||
|
}
|
||||||
|
if (binary[0] !== 0xf0) {
|
||||||
|
throw new Error('first byte is not SYSEX byte');
|
||||||
|
}
|
||||||
|
if (binary[1] !== 0x42) {
|
||||||
|
throw new Error('manufacturer code is not KORG');
|
||||||
|
}
|
||||||
|
if (binary[4] !== 0x40) {
|
||||||
|
throw new Error('not a program dump');
|
||||||
|
}
|
||||||
|
if (binary[5] !== 0x00) {
|
||||||
|
// in all files found in the wild it's always zero
|
||||||
|
throw new Error('sixth byte is not zero');
|
||||||
|
}
|
||||||
|
if (binary[binary.length - 1] !== 0xf7) {
|
||||||
|
throw new Error('last byte is does not end SYSEX message');
|
||||||
|
}
|
||||||
|
|
||||||
|
const trimmedBinary = binary.slice(5, -1);
|
||||||
|
// every eigth byte is padding, so we remove it
|
||||||
|
const unpaddedBinary = trimmedBinary.filter((_, idx) => idx % 8);
|
||||||
|
|
||||||
|
const buffer = Buffer.from(unpaddedBinary).toString('hex');
|
||||||
|
|
||||||
|
console.log(buffer);
|
||||||
|
|
||||||
|
console.log(parser.parse(unpaddedBinary));
|
||||||
|
|
||||||
|
// do stuff with the parsed object
|
||||||
|
}
|
||||||
|
|
||||||
// converts patch object to dump format the system uses
|
// converts patch object to dump format the system uses
|
||||||
function serialise(parser, object) {
|
function serialise(parser, object) {
|
||||||
// output object
|
// output object
|
||||||
console.log(parser.encode(object));
|
console.log(parser.encode(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Parse(object) {
|
||||||
|
return parse(parser, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Parse, serialise };
|
||||||
|
|||||||
Reference in New Issue
Block a user