Skip to content

Commit 728ecf4

Browse files
Feat: Open sampler widget on sound sample drop (#4453)
* feat: open sampler widget on sound sample drop * refactor parameters and arguments of makeSamplerWidget * specify reader to readAsDataURL() when file type is audio/wav * fix removing of existing blocks on sound sample drop
1 parent 78789e6 commit 728ecf4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

js/activity.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,22 @@ class Activity {
29342934
// note block to the active block.
29352935
this.blocks.activeBlock = this.blocks.blockList.length - 1;
29362936
};
2937+
2938+
//To create a sampler widget
2939+
this.makeSamplerWidget = (sampleName, sampleData) => {
2940+
let samplerStack = [
2941+
[0, "sampler", 300 - this.blocksContainer.x, 300 - this.blocksContainer.y, [null, 1, 8]],
2942+
[1, "settimbre", 0, 0, [0, 2, 6, 7]],
2943+
[2, ["customsample", { value: ["", "", "do", 4] }], 0, 0, [1, 3, 4, 5]],
2944+
[3, ["audiofile", { value: [sampleName, sampleData] }], 0, 0, [2]],
2945+
[4, ["solfege", { value: "do" }], 0, 0, [2]],
2946+
[5, ["number", { value: 4 }], 0, 0, [2]],
2947+
[6, "vspace", 0, 0, [1, null]],
2948+
[7, "hidden", 0, 0, [1, null]],
2949+
[8, "hiddennoflow", 0, 0, [0, null]]
2950+
];
2951+
this.blocks.loadNewBlocks(samplerStack);
2952+
};
29372953

29382954
/*
29392955
* Handles keyboard shortcuts in MB
@@ -6474,6 +6490,8 @@ class Activity {
64746490
that.errorMsg(
64756491
_("Cannot load project from the file. Please check the file type.")
64766492
);
6493+
} else if (files[0].type === "audio/wav") {
6494+
this.makeSamplerWidget(files[0].name, reader.result);
64776495
} else {
64786496
const cleanData = rawData.replace("\n", " ");
64796497
let obj;
@@ -6590,6 +6608,12 @@ class Activity {
65906608
abcReader.readAsText(files[0]);
65916609
return;
65926610
}
6611+
6612+
if (files[0].type === "audio/wav") {
6613+
reader.readAsDataURL(files[0]);
6614+
return;
6615+
}
6616+
65936617
reader.readAsText(files[0]);
65946618
reader.readAsText(files[0]);
65956619
window.scroll(0, 0);

0 commit comments

Comments
 (0)