1 /* scherzo - Music notation training
3 * pitch.h - Common structures and functions for pitches, etc.
5 * Copyright © 2010,2013 Carl Worth
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/ .
21 #define PITCH_ACCIDENTAL_MASK 0x07
22 #define PITCH_ACCIDENTAL_SHIFT 0
24 typedef enum pitch_accidental
26 PITCH_ACCIDENTAL_DOUBLE_FLAT,
27 PITCH_ACCIDENTAL_FLAT,
28 PITCH_ACCIDENTAL_NATURAL,
29 PITCH_ACCIDENTAL_SHARP,
30 PITCH_ACCIDENTAL_DOUBLE_SHARP
33 #define PITCH_ACCIDENTAL(pitch) (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT)
35 #define PITCH_NAME_MASK 0x38
36 #define PITCH_NAME_SHIFT 3
38 typedef enum pitch_name
49 #define PITCH_NAME(pitch) (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT)
51 #define PITCH(name, accidental) (((name) << PITCH_NAME_SHIFT) | (accidental))
53 #define PITCH_LITERAL(literal_name, literal_accidental) PITCH(PITCH_NAME_##literal_name, PITCH_ACCIDENTAL_##literal_accidental)
57 PITCH_Cff = PITCH_LITERAL (C, DOUBLE_FLAT),
58 PITCH_Cf = PITCH_LITERAL (C, FLAT),
59 PITCH_C = PITCH_LITERAL (C, NATURAL),
60 PITCH_Cs = PITCH_LITERAL (C, SHARP),
61 PITCH_Css = PITCH_LITERAL (C, DOUBLE_SHARP),
63 PITCH_Dff = PITCH_LITERAL (D, DOUBLE_FLAT),
64 PITCH_Df = PITCH_LITERAL (D, FLAT),
65 PITCH_D = PITCH_LITERAL (D, NATURAL),
66 PITCH_Ds = PITCH_LITERAL (D, SHARP),
67 PITCH_Dss = PITCH_LITERAL (D, DOUBLE_SHARP),
69 PITCH_Eff = PITCH_LITERAL (E, DOUBLE_FLAT),
70 PITCH_Ef = PITCH_LITERAL (E, FLAT),
71 PITCH_E = PITCH_LITERAL (E, NATURAL),
72 PITCH_Es = PITCH_LITERAL (E, SHARP),
73 PITCH_Ess = PITCH_LITERAL (E, DOUBLE_SHARP),
75 PITCH_Fff = PITCH_LITERAL (F, DOUBLE_FLAT),
76 PITCH_Ff = PITCH_LITERAL (F, FLAT),
77 PITCH_F = PITCH_LITERAL (F, NATURAL),
78 PITCH_Fs = PITCH_LITERAL (F, SHARP),
79 PITCH_Fss = PITCH_LITERAL (F, DOUBLE_SHARP),
81 PITCH_Gff = PITCH_LITERAL (G, DOUBLE_FLAT),
82 PITCH_Gf = PITCH_LITERAL (G, FLAT),
83 PITCH_G = PITCH_LITERAL (G, NATURAL),
84 PITCH_Gs = PITCH_LITERAL (G, SHARP),
85 PITCH_Gss = PITCH_LITERAL (G, DOUBLE_SHARP),
87 PITCH_Aff = PITCH_LITERAL (A, DOUBLE_FLAT),
88 PITCH_Af = PITCH_LITERAL (A, FLAT),
89 PITCH_A = PITCH_LITERAL (A, NATURAL),
90 PITCH_As = PITCH_LITERAL (A, SHARP),
91 PITCH_Ass = PITCH_LITERAL (A, DOUBLE_SHARP),
93 PITCH_Bff = PITCH_LITERAL (B, DOUBLE_FLAT),
94 PITCH_Bf = PITCH_LITERAL (B, FLAT),
95 PITCH_B = PITCH_LITERAL (B, NATURAL),
96 PITCH_Bs = PITCH_LITERAL (B, SHARP),
97 PITCH_Bss = PITCH_LITERAL (B, DOUBLE_SHARP)