From bf519ac7d03bb18f933500dae654c97e3c3d90e4 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Sun, 25 Jan 2026 11:31:54 +0000 Subject: [PATCH] =?UTF-8?q?Clavier=20=C3=A0=20lumi=C3=A8res=20notes=20and?= =?UTF-8?q?=20noteToFrequency=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/colorScale.ts | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/constants/colorScale.ts diff --git a/src/constants/colorScale.ts b/src/constants/colorScale.ts new file mode 100644 index 0000000..7f0cdb3 --- /dev/null +++ b/src/constants/colorScale.ts @@ -0,0 +1,45 @@ +export type ColorNote = { + note: string; + color: string; + label: string; +}; + +export const colorScale: ColorNote[] = [ + { note: "C", color: "#ff0000", label: "C" }, + { note: "C#", color: "#caa3ff", label: "C#" }, + { note: "D", color: "#ffff00", label: "D" }, + { note: "D#", color: "#5b5f8b", label: "D#" }, + { note: "E", color: "#dff8ff", label: "E" }, + { note: "F", color: "#8b1a0e", label: "F" }, + { note: "F#", color: "#18bffb", label: "F#" }, + { note: "G", color: "#ff7a00", label: "G" }, + { note: "G#", color: "#ff00ff", label: "G#" }, + { note: "A", color: "#39c52a", label: "A" }, + { note: "A#", color: "#8a8a8a", label: "A#" }, + { note: "B", color: "#0c2bff", label: "B" }, +]; + +const SEMITONES: Record = { + C: 0, + "C#": 1, + D: 2, + "D#": 3, + E: 4, + F: 5, + "F#": 6, + G: 7, + "G#": 8, + A: 9, + "A#": 10, + B: 11, +}; + +export function noteToFrequency(note: string, octave: number): number { + const semitone = SEMITONES[note]; + if (semitone === undefined) { + throw new Error(`Unsupported note: ${note}`); + } + + const midi = (octave + 1) * 12 + semitone; + return 440 * 2 ** ((midi - 69) / 12); +}