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/ .
26 #define PITCH_ACCIDENTAL_MASK 0x07
27 #define PITCH_ACCIDENTAL_SHIFT 0
29 typedef enum pitch_accidental
31 PITCH_ACCIDENTAL_DOUBLE_FLAT,
32 PITCH_ACCIDENTAL_FLAT,
33 PITCH_ACCIDENTAL_NATURAL,
34 PITCH_ACCIDENTAL_SHARP,
35 PITCH_ACCIDENTAL_DOUBLE_SHARP
38 #define PITCH_ACCIDENTAL(pitch) (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT)
40 #define PITCH_NAME_MASK 0x38
41 #define PITCH_NAME_SHIFT 3
43 typedef enum pitch_name
54 #define PITCH_NAME(pitch) (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT)
56 #define PITCH(name, accidental) (((name) << PITCH_NAME_SHIFT) | (accidental))
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)
61 typedef uint32_t pitch_t;