Skip to content

Commit

Permalink
Merge pull request #192 from NetsBlox/music-app
Browse files Browse the repository at this point in the history
Updated Music App Ordering and Sounds
  • Loading branch information
ebiwonjumit authored Jan 8, 2024
2 parents 977fc84 + da9c287 commit 9aa26eb
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5,750 deletions.
2 changes: 1 addition & 1 deletion src/procedures/music-app/SoundLibrary
Submodule SoundLibrary updated 485 files
70 changes: 55 additions & 15 deletions src/procedures/music-app/music-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ const { registerTypes } = require("./types");
const path = require("path");
const utils = require("../utils/index");
const MusicApp = {};
const soundLibrary = require("./soundLibrary.json");
const soundLibrary = require("./SoundLibrary/soundLibrary.json");
const drumLibrary = require("./SoundLibrary/drumSoundLibrary.json");
const masterSoundLibrary = [
...soundLibrary.netsbloxSoundLibrary,
...drumLibrary.drumSoundLibrary,
];

registerTypes();

MusicApp._filetoBuffer = async function (audio_path) {
const data = await fsp.readFile(audio_path);
utils.sendAudioBuffer(this.response, data);
};

/**
* Get Sounds based on query.
* @param {String=} soundType
Expand All @@ -39,28 +49,58 @@ MusicApp._getNamesBySoundType = async function (soundType = "") {

/**
* Get sounds based on query.
* @param {InstrumentNames=} InstrumentName
* @param {BPM=} BPM
* @param {Keys=} Key
* @param {ChordProgressions=} Chords
* @param {DrumPackName=} packName
* @param {DrumOneShotTypes=} drumType
* @returns {String}
*/
MusicApp.getDrumOneShotNames = async function (
packName = "",
drumType = "",
) {
var names = [];
let queriedJSON = "";

//Ensure at least one field is selected
if (packName !== "" || drumType !== "") {
queriedJSON = drumLibrary.drumSoundLibrary.filter(function (obj) { // Check if field value is empty before finding obj with value.
return (packName === "" || obj.packName === packName) &&
(drumType === "" || obj.Instrument === drumType);
});
} else {
throw Error("At least one field must be selected");
}

//Convert JSON to array of String names
for (let i = 0; i < queriedJSON.length; i++) {
names.push(queriedJSON[i].soundName);
}
return names;
};

/**
* Get sounds based on query.
* @param {Chords=} chords
* @param {Keys=} key
* @param {BPM=} bpm
* @param {InstrumentNames=} instrumentName
* @returns {Array}
*/
MusicApp.getSoundNames = async function (
InstrumentName = "",
BPM = "",
Key = "",
Chords = "",
chords = "",
key = "",
bpm = "",
instrumentName = "",
) {
var names = [];
let queriedJSON = "";

//Ensure at least one field is selected
if (InstrumentName !== "" || BPM !== "" || Key !== "" || Chords !== "") {
if (chords !== "" || key !== "" || bpm !== "" || instrumentName !== "") {
queriedJSON = soundLibrary.netsbloxSoundLibrary.filter(function (obj) { // Check if field value is empty before finding obj with value.
return (InstrumentName === "" || obj.InstrumentName === InstrumentName) &&
(BPM === "" || obj.BPM === BPM) &&
(Key === "" || obj.Key === Key) &&
(Chords === "" || obj.ChordProgression === Chords);
return (instrumentName === "" || obj.InstrumentName === instrumentName) &&
(bpm === "" || obj.BPM === bpm) &&
(key === "" || obj.Key === key) &&
(chords === "" || obj.ChordProgression === chords);
});
} else {
throw Error("At least one field must be selected");
Expand All @@ -79,7 +119,7 @@ MusicApp.getSoundNames = async function (
* @param {String=} nameOfSound
*/
MusicApp.nameToSound = async function (nameOfSound = "") {
const metadata = soundLibrary.netsbloxSoundLibrary
const metadata = masterSoundLibrary
.find((obj) => obj.soundName === nameOfSound);

if (metadata) {
Expand Down
Loading

0 comments on commit 9aa26eb

Please sign in to comment.