Skip to content

Instantly share code, notes, and snippets.

@colxi
Created January 18, 2020 18:06
Show Gist options
  • Save colxi/9a0ed453fd2ff4caca92d8552b186234 to your computer and use it in GitHub Desktop.
Save colxi/9a0ed453fd2ff4caca92d8552b186234 to your computer and use it in GitHub Desktop.
Type Definition for musical Nodes (MIDI notation, standard musical notation, JSON based object notation)
/**
*
* Notes :
* Classic Piano keys range : 'A0' (MIDI 21) - 'C8' (MIDI 109)
* MIDI supported keys range : 'C-1' (MIDI 0) - 'G9' (MIDI 127)
*
*/
// prettier-ignore
const MIDINoteIds = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127
] as const
type MIDINoteId = typeof MIDINoteIds[number]
// prettier-ignore
let NoteFrequencies = [
12543.85, 11839.82, 11175.30, 10548.08, 9956.06, 9397.27, 8869.84, 8372.02, 7902.13, 7458.62, 7040.00, 6644.88,
6271.93, 5919.91, 5587.65, 5274.04, 4978.03, 4698.64, 4434.92, 4186.01, 3951.07, 3729.31, 3520.00, 3322.44,
3135.96, 2959.96, 2793.83, 2637.02, 2489.02, 2349.32, 2217.46, 2093.00, 1975.53, 1864.66, 1760.00, 1661.22,
1567.98, 1479.98, 1396.91, 1318.51, 1244.51, 1174.66, 1108.73, 1046.50, 987.77, 932.33, 880.00, 830.61,
783.99, 739.99, 698.46, 659.26, 622.25, 587.33, 554.37, 523.25, 493.88, 466.16, 440.00, 415.30,
392.00, 369.99, 349.23, 329.63, 311.13, 293.66, 277.18, 261.63, 246.94, 233.08, 220.00, 207.65,
196.00, 185.00, 174.61, 164.81, 155.56, 146.83, 138.59, 130.81, 123.47, 116.54, 110.00, 103.83,
98.00, 92.50, 87.31, 82.41, 77.78, 73.42, 69.30, 65.41, 61.74, 58.27, 55.0, 51.91,
49.0, 46.25, 43.65, 41.2, 38.89, 36.71, 34.65, 32.7, 30.87, 29.14, 27.5, 25.96,
24.5, 23.12, 21.83, 20.6, 19.45, 18.35, 17.32, 16.35, 15.43, 14.57, 13.75, 12.98,
12.25, 11.56, 10.91, 10.3, 9.72, 9.18, 8.66, 8.18
] as const
type NoteFrequency = typeof NoteFrequencies[number]
// prettier-ignore
const AbsoluteNoteNames = [
'C-1', 'C#-1', 'D-1', 'D#-1', 'E-1', 'F-1', 'F#-1', 'G-1', 'G#-1', 'A-1', 'A#-1', 'B-1',
'C0', 'C#0', 'D0', 'D#0', 'E0', 'F0', 'F#0', 'G0', 'G#0', 'A0', 'A#0', 'B0',
'C1', 'C#1', 'D1', 'D#1', 'E1', 'F1', 'F#1', 'G1', 'G#1', 'A1', 'A#1', 'B1',
'C2', 'C#2', 'D2', 'D#2', 'E2', 'F2', 'F#2', 'G2', 'G#2', 'A2', 'A#2', 'B2',
'C3', 'C#3', 'D3', 'D#3', 'E3', 'F3', 'F#3', 'G3', 'G#3', 'A3', 'A#3', 'B3',
'C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4',
'C5', 'C#5', 'D5', 'D#5', 'E5', 'F5', 'F#5', 'G5', 'G#5', 'A5', 'A#5', 'B5',
'C6', 'C#6', 'D6', 'D#6', 'E6', 'F6', 'F#6', 'G6', 'G#6', 'A6', 'A#6', 'B6',
'C7', 'C#7', 'D7', 'D#7', 'E7', 'F7', 'F#7', 'G7', 'G#7', 'A7', 'A#7', 'B7',
'C8', 'C#8', 'D8', 'D#8', 'E8', 'F8', 'F#8', 'G8', 'G#8', 'A8', 'A#8', 'B8',
'C9', 'C#9', 'D9', 'D#9', 'E9', 'F9', 'F#9', 'G9'
] as const
type AbsoluteNoteName = typeof AbsoluteNoteNames[number]
const NoteNames = ['C', 'D', 'E', 'F', 'G', 'A', 'B'] as const
const Octaves = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const
const Accidents = ['#', '##', 'b', 'bb'] as const
type NoteName = typeof NoteNames[number]
type OctaveId = typeof Octaves[number]
type Accident = typeof Accidents[number]
interface Note {
name: NoteName
octave: OctaveId
accidents?: Accident
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment