]> git.cworth.org Git - scherzo/blob - pitch.h
Drop the enumerated pitch values.
[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 #include <stdint.h>
22
23 #ifndef PITCH_H
24 #define PITCH_H
25
26 #define PITCH_ACCIDENTAL_MASK 0x07
27 #define PITCH_ACCIDENTAL_SHIFT 0
28
29 typedef enum pitch_accidental
30 {
31     PITCH_ACCIDENTAL_DOUBLE_FLAT,
32     PITCH_ACCIDENTAL_FLAT,
33     PITCH_ACCIDENTAL_NATURAL,
34     PITCH_ACCIDENTAL_SHARP,
35     PITCH_ACCIDENTAL_DOUBLE_SHARP
36 } pitch_accidental_t;
37
38 #define PITCH_ACCIDENTAL(pitch) (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT)
39
40 #define PITCH_NAME_MASK 0x38
41 #define PITCH_NAME_SHIFT 3
42
43 typedef enum pitch_name
44 {
45     PITCH_NAME_C,
46     PITCH_NAME_D,
47     PITCH_NAME_E,
48     PITCH_NAME_F,
49     PITCH_NAME_G,
50     PITCH_NAME_A,
51     PITCH_NAME_B,
52 } pitch_name_t;
53
54 #define PITCH_NAME(pitch) (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT)
55
56 #define PITCH(name, accidental) (((name) << PITCH_NAME_SHIFT) | (accidental))
57
58 #define PITCH_LITERAL(literal_name, literal_accidental) PITCH(PITCH_NAME_##literal_name, PITCH_ACCIDENTAL_##literal_accidental)
59 #define PITCH_NATURAL(literal_name) PITCH_LITERAL(literal_name, NATURAL)
60
61 typedef uint32_t pitch_t;
62
63 #endif /* PITCH_H */