Working scale fonction :)

This commit is contained in:
JulienH2000
2023-09-21 19:09:06 +02:00
parent 4e4a2ac0bf
commit a838624ac8
4 changed files with 38 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { type UserAPI } from "./API";
import { SCALES } from "./Scales";
export {};
declare global {
@ -238,7 +239,8 @@ export const makeArrayExtensions = (api: UserAPI) => {
for (let j = 0; j < amount; j++) {
result.push(this[i]);
}
}
}
this.length = 0;
this.push(...result);
return this;
@ -341,3 +343,27 @@ export const makeArrayExtensions = (api: UserAPI) => {
};
Array.prototype.rand = Array.prototype.random;
};
Array.prototype.scale = function <T>(this: T[], scaleName: string = "major") {
const scale = SCALES[scaleName];
if (!scale) {
throw new Error(`Unknown scale ${scaleName}`);
}
let result = [];
for (let i = 0; i < scale.length; i++) {
if (!this[i]) {
result.push(this[0] + scale[i]);
} else {
result.push(this[i] + scale[i]);
}
}
this.shift()
this.push(...result);
return this;
};