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 typedef uint32_t pitch_t;
28 #define PITCH_ACCIDENTAL_SHIFT (0)
29 #define PITCH_ACCIDENTAL_MASK (0x07 << PITCH_ACCIDENTAL_SHIFT)
31 #define PITCH_NAME_SHIFT (3)
32 #define PITCH_NAME_MASK (0x07 << PITCH_NAME_SHIFT)
34 #define PITCH_OCTAVE_SHIFT (6)
35 #define PITCH_OCTAVE_MASK (0x07 << PITCH_OCTAVE_SHIFT)
37 #define PITCH_ACCIDENTAL(pitch) \
38 (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT)
39 #define PITCH_NAME(pitch) \
40 (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT)
41 #define PITCH_OCTAVE(pitch) \
42 (((pitch) & PITCH_OCTAVE_MASK) >> PITCH_OCTAVE_SHIFT)
44 #define PITCH(name, accidental, octave) \
45 (((octave) << PITCH_OCTAVE_SHIFT) | \
46 ((name) << PITCH_NAME_SHIFT) | \
47 ((accidental) << PITCH_ACCIDENTAL_SHIFT))
49 #define PITCH_LITERAL(literal_name, literal_accidental, octave) \
50 PITCH(PITCH_NAME_##literal_name, \
51 PITCH_ACCIDENTAL_##literal_accidental, \
54 #define PITCH_NATURAL(literal_name, octave) \
55 PITCH_LITERAL(literal_name, NATURAL, octave)
57 typedef enum pitch_accidental
59 PITCH_ACCIDENTAL_DOUBLE_FLAT,
60 PITCH_ACCIDENTAL_FLAT,
61 PITCH_ACCIDENTAL_NATURAL,
62 PITCH_ACCIDENTAL_SHARP,
63 PITCH_ACCIDENTAL_DOUBLE_SHARP
66 typedef enum pitch_name
77 /* Octave numbers are ISO octave numbers [0:8], (so Octave 4 is from
78 * middle C to the B above middle C).