Insane array mangling for scale arrays
This commit is contained in:
@ -6,9 +6,15 @@
|
|||||||
* @returns {Record<string, any>[]} Array of objects
|
* @returns {Record<string, any>[]} Array of objects
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export function objectWithArraysToArrayOfObjects(input: Record<string, any>, ignoredKeys: string[]): Record<string, any>[] {
|
export function objectWithArraysToArrayOfObjects(input: Record<string, any>, arraysToArrays: string[]): Record<string, any>[] {
|
||||||
ignoredKeys = ignoredKeys.map((k) => Array.isArray(input[k]) ? undefined : k).filter((k) => k !== undefined) as string[];
|
arraysToArrays.forEach((k) => {
|
||||||
const keys = Object.keys(input).filter((k) => !ignoredKeys.includes(k));
|
// Transform single array to array of arrays and keep array of arrays as is
|
||||||
|
if (Array.isArray(input[k]) && !Array.isArray(input[k][0])) {
|
||||||
|
input[k] = [input[k]];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const keys = Object.keys(input);
|
||||||
|
|
||||||
const maxLength = Math.max(
|
const maxLength = Math.max(
|
||||||
...keys.map((k) =>
|
...keys.map((k) =>
|
||||||
Array.isArray(input[k]) ? (input[k] as any[]).length : 1
|
Array.isArray(input[k]) ? (input[k] as any[]).length : 1
|
||||||
@ -20,14 +26,10 @@ export function objectWithArraysToArrayOfObjects(input: Record<string, any>, ign
|
|||||||
for (let i = 0; i < maxLength; i++) {
|
for (let i = 0; i < maxLength; i++) {
|
||||||
const event: Record<string, any> = {};
|
const event: Record<string, any> = {};
|
||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
if (ignoredKeys.includes(k)) {
|
if (Array.isArray(input[k])) {
|
||||||
event[k] = input[k];
|
|
||||||
} else {
|
|
||||||
if (Array.isArray(input[k])) {
|
|
||||||
event[k] = (input[k] as any[])[i % (input[k] as any[]).length];
|
event[k] = (input[k] as any[])[i % (input[k] as any[]).length];
|
||||||
} else {
|
} else {
|
||||||
event[k] = input[k];
|
event[k] = input[k];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.push(event);
|
output.push(event);
|
||||||
|
|||||||
@ -375,7 +375,6 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
const [note, _] = noteFromPc(
|
const [note, _] = noteFromPc(
|
||||||
(event.key as number) || "C4",
|
(event.key as number) || "C4",
|
||||||
|
|||||||
Reference in New Issue
Block a user