src/audio/scales.ts 795 B raw
1
export type ScaleName =
2
	| 'major'
3
	| 'minor'
4
	| 'pentatonicMaj'
5
	| 'pentatonicMin'
6
	| 'dorian';
7
8
export const SCALES: Record<ScaleName, number[]> = {
9
	major: [0, 2, 4, 5, 7, 9, 11],
10
	minor: [0, 2, 3, 5, 7, 8, 10],
11
	pentatonicMaj: [0, 2, 4, 7, 9, 0, 2],
12
	pentatonicMin: [0, 3, 5, 7, 10, 0, 3],
13
	dorian: [0, 2, 3, 5, 7, 9, 10],
14
};
15
16
export const NOTE_NAMES = [
17
	'C',
18
	'C#',
19
	'D',
20
	'D#',
21
	'E',
22
	'F',
23
	'F#',
24
	'G',
25
	'G#',
26
	'A',
27
	'A#',
28
	'B',
29
];
30
31
export const COLS = 7;
32
export const ROWS = 4;
33
34
export function cellToMidi(
35
	col: number,
36
	row: number,
37
	rootPc: number,
38
	octaveBase: number,
39
	scale: ScaleName,
40
): number {
41
	const intervals = SCALES[scale];
42
	const interval = intervals[col % intervals.length];
43
	const octave = octaveBase + (ROWS - 1 - row);
44
	return 12 * (octave + 1) + rootPc + interval;
45
}