From aa429428d5b57f9b3a7f1a9a691c19f7a2659fd8 Mon Sep 17 00:00:00 2001
From: "[poww10s]" <[theironminer@gmail.com]>
Date: Sun, 29 Nov 2020 18:57:46 -0500
Subject: [PATCH] change binary-parser version
---
package-lock.json | 6 +--
package.json | 2 +-
src/features/io/IO.js | 20 +++++++--
src/features/io/ioParser.js | 89 ++++++++++++++++++++-----------------
4 files changed, 67 insertions(+), 50 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index da9c641..b9fa743 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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"
}
diff --git a/package.json b/package.json
index a9fa2ea..08c756e 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/features/io/IO.js b/src/features/io/IO.js
index c7cda39..b93579a 100644
--- a/src/features/io/IO.js
+++ b/src/features/io/IO.js
@@ -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 (
-
+
Drag and drop file here, or click to select
@@ -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 (
-
-
+
+
);
}
diff --git a/src/features/io/ioParser.js b/src/features/io/ioParser.js
index e2fb14e..af605bd 100644
--- a/src/features/io/ioParser.js
+++ b/src/features/io/ioParser.js
@@ -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 };