]> git.cworth.org Git - scherzo/blob - pitch.h
13c29057bf5d25272d438e427d5c0f2c3ca4223d
[scherzo] / pitch.h
1 /* scherzo - Music notation training
2  *
3  *      pitch.h - Common structures and functions for pitches, etc.
4  *
5  * Copyright © 2010,2013 Carl Worth
6  *
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.
11  *
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.
16  *
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/ .
19  */
20
21 #define PITCH_ACCIDENTAL_MASK 0x07
22 #define PITCH_ACCIDENTAL_SHIFT 0
23
24 typedef enum pitch_accidental
25 {
26     PITCH_ACCIDENTAL_DOUBLE_FLAT,
27     PITCH_ACCIDENTAL_FLAT,
28     PITCH_ACCIDENTAL_NATURAL,
29     PITCH_ACCIDENTAL_SHARP,
30     PITCH_ACCIDENTAL_DOUBLE_SHARP
31 } pitch_accidental_t;
32
33 #define PITCH_ACCIDENTAL(pitch) (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT)
34
35 #define PITCH_NAME_MASK 0x38
36 #define PITCH_NAME_SHIFT 3
37
38 typedef enum pitch_name
39 {
40     PITCH_NAME_C,
41     PITCH_NAME_D,
42     PITCH_NAME_E,
43     PITCH_NAME_F,
44     PITCH_NAME_G,
45     PITCH_NAME_A,
46     PITCH_NAME_B,
47 } pitch_name_t;
48
49 #define PITCH_NAME(pitch) (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT)
50
51 #define PITCH(name, accidental) (((name) << PITCH_NAME_SHIFT) | (accidental))
52
53 #define PITCH_LITERAL(literal_name, literal_accidental) PITCH(PITCH_NAME_##literal_name, PITCH_ACCIDENTAL_##literal_accidental)
54
55 typedef enum pitch
56 {
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),
62
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),
68
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),
74
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),
80
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),
86
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),
92
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)
98 } pitch_t;