Skip to content

Commit

Permalink
ABC to MB Parser (#3925)
Browse files Browse the repository at this point in the history
* clean code , added comments

* added abc lib

* added debug statement

* fix : Formatting , Function method & method Func

* add function description

---------

Co-authored-by: Walter Bender <walter@sugarlabs.org>
  • Loading branch information
abhijeetsingh0401 and walterbender authored Sep 13, 2024
1 parent 9e62e67 commit 30b5c47
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6614,6 +6614,7 @@ class Activity {
const files = event.dataTransfer.files;
const reader = new FileReader();
let midiReader = new FileReader();

const abcReader = new FileReader();
// eslint-disable-next-line no-unused-vars
reader.onload = (theFile) => {
Expand Down Expand Up @@ -6706,17 +6707,37 @@ class Activity {
});


};

// Music Block Parser from abc to MB
abcReader.onload = (event) => {
//get the abc data and replace the / so that the block does not break
let abcData = event.target.result;
abcData = abcData.replace(/\\/g, '');

const tunebook = new ABCJS.parseOnly(abcData);

console.log(tunebook)
tunebook.forEach(tune => {
//call parseABC to parse abcdata to MB json
this.parseABC(tune);

});


};

// Work-around in case the handler is called by the
// widget drag & drop code.
if (files[0] !== undefined) {
let extension = files[0].name.split('.').pop().toLowerCase(); //file extension from input file

let isMidi = (extension == "mid") || (extension == "midi");
if (isMidi){
midiReader.readAsArrayBuffer(files[0]);
return;
}

let isABC = (extension == "abc");
if (isABC) {
abcReader.readAsText(files[0]);
Expand Down

0 comments on commit 30b5c47

Please sign in to comment.