Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Music App Ordering and Sounds #192

Merged
merged 20 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading