Working scale fonction :)
This commit is contained in:
@ -7,6 +7,7 @@ import { Editor } from "./main";
|
||||
import { SoundEvent } from "./classes/SoundEvent";
|
||||
import { MidiEvent } from "./classes/MidiEvent";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { SCALES } from "./Scales"
|
||||
import { InputOptions, Player } from "./classes/ZPlayer";
|
||||
import {
|
||||
samples,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { type UserAPI } from "./API";
|
||||
import { SCALES } from "./Scales";
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
@ -239,6 +240,7 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
||||
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;
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const SCALES: Record<string, number[]> = {
|
||||
export const SCALES: Record<string, number[]> = {
|
||||
major: [0, 2, 4, 5, 7, 9, 11],
|
||||
naturalMinor: [0, 2, 3, 5, 7, 8, 10],
|
||||
harmonicMinor: [0, 2, 3, 5, 7, 8, 11],
|
||||
@ -53,18 +53,21 @@ const SCALES: Record<string, number[]> = {
|
||||
orientalA: [0, 1, 4, 5, 6, 9, 10],
|
||||
};
|
||||
|
||||
|
||||
// Legacy function, see Array.prototype.scale @ ArrayExtensions.ts
|
||||
/*
|
||||
export function scale(
|
||||
n: number,
|
||||
scaleName: string = "major",
|
||||
octave: number = 4
|
||||
): number {
|
||||
/**
|
||||
/*
|
||||
* Returns the MIDI note number for the given scale degree in the given scale.
|
||||
* @param {number} n - The scale degree, where 0 is the tonic.
|
||||
* @param {string} scaleName - The name of the scale.
|
||||
* @param {number} octave - The octave number.
|
||||
* @returns {number} The MIDI note number.
|
||||
*/
|
||||
* /
|
||||
const scale = SCALES[scaleName];
|
||||
|
||||
if (!scale) {
|
||||
@ -76,3 +79,5 @@ export function scale(
|
||||
let additionalOctaves = Math.floor(n / scale.length);
|
||||
return 60 + (octave + additionalOctaves) * 12 + scale[index];
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@ -66,6 +66,8 @@ const bindings = Object.keys(classMap).map((key) => ({
|
||||
replace: (match, p1) => `<${key} class="${classMap[key]}" ${p1}>`,
|
||||
}));
|
||||
|
||||
|
||||
|
||||
export class Editor {
|
||||
universes: Universes = template_universes;
|
||||
selected_universe: string;
|
||||
|
||||
Reference in New Issue
Block a user