change binary-parser version

This commit is contained in:
[poww10s]
2020-11-29 18:57:46 -05:00
parent de4808f1a7
commit aa429428d5
4 changed files with 67 additions and 50 deletions
+3 -3
View File
@@ -3765,9 +3765,9 @@
"optional": true
},
"binary-parser-encoder": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/binary-parser-encoder/-/binary-parser-encoder-1.5.3.tgz",
"integrity": "sha512-yu3tdLBYqPIwGRaXyswLoLrhaffkuZkNuXveq/jYoyBHQbFMjamHCWPFOmI2Qz+Go0Rh6wE9f6tt0EAvsgDD0g==",
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/binary-parser-encoder/-/binary-parser-encoder-1.5.2.tgz",
"integrity": "sha512-bZKR5Qo+pujq+Pvye/ZR94aRbYJx+7WijKAD7RcFi6qgtNJ4kHqAbDaH588VM2N4HylWp08Pm2l0buXqh2t5kw==",
"requires": {
"smart-buffer": "^4.1.0"
}
+1 -1
View File
@@ -7,7 +7,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"binary-parser-encoder": "^1.5.3",
"binary-parser-encoder": "^1.5.2",
"rc-slider": "^9.6.3",
"react": "^17.0.1",
"react-dom": "^17.0.1",
+16 -4
View File
@@ -1,5 +1,6 @@
import React, { useState, useEffect, useMemo } from 'react';
import { useDropzone } from 'react-dropzone';
import { Parse } from './ioParser';
import './IO.css';
const baseStyle = {
@@ -56,7 +57,7 @@ const Dropzone = ({ setFile }) => {
);
return (
<div className="dropzone-container">
<div className='dropzone-container'>
<div {...getRootProps({ style })}>
<input {...getInputProps()} />
<p>Drag and drop file here, or click to select</p>
@@ -67,14 +68,25 @@ const Dropzone = ({ setFile }) => {
export default function IO() {
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(() => {
console.log(file);
if (file) {
console.log(Parse(file));
}
});
return (
<div className="dropzone-container">
<Dropzone className="dropzone-modal" setFile={setFile} />
<div className='dropzone-container'>
<Dropzone className='dropzone-modal' setFile={fileToArrayBuffer} />
</div>
);
}
+47 -42
View File
@@ -1,41 +1,5 @@
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()
.int8('midiChannel') // in 7 bits
.bit2('assignMode')
@@ -238,15 +202,56 @@ const parser = new Parser()
.nest('timbre1', { type: timbre })
// dummy bytes *see documentation
.skip(56)
.nest('timbre2', { type: timbre })
// dummy bytes *see documentation
.skip(56)
.nest('vocoder', { type: vocoder })
// dummy bytes *see documentation
.skip(111);
.nest('timbre2', { type: timbre });
// dummy bytes *see documentation
//.skip(56)
//.nest('vocoder', { type: vocoder })
// dummy bytes *see documentation
// .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
function serialise(parser, object) {
// output object
console.log(parser.encode(object));
}
function Parse(object) {
return parse(parser, object);
}
export { Parse, serialise };