X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=pitch.h;fp=pitch.h;h=13c29057bf5d25272d438e427d5c0f2c3ca4223d;hb=08ba627b61792c7d6e31d71831f062f5a8162248;hp=0000000000000000000000000000000000000000;hpb=d25fa8b91eb2e9dad783584215c35124b65429a8;p=scherzo diff --git a/pitch.h b/pitch.h new file mode 100644 index 0000000..13c2905 --- /dev/null +++ b/pitch.h @@ -0,0 +1,98 @@ +/* scherzo - Music notation training + * + * pitch.h - Common structures and functions for pitches, etc. + * + * Copyright © 2010,2013 Carl Worth + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/ . + */ + +#define PITCH_ACCIDENTAL_MASK 0x07 +#define PITCH_ACCIDENTAL_SHIFT 0 + +typedef enum pitch_accidental +{ + PITCH_ACCIDENTAL_DOUBLE_FLAT, + PITCH_ACCIDENTAL_FLAT, + PITCH_ACCIDENTAL_NATURAL, + PITCH_ACCIDENTAL_SHARP, + PITCH_ACCIDENTAL_DOUBLE_SHARP +} pitch_accidental_t; + +#define PITCH_ACCIDENTAL(pitch) (((pitch) & PITCH_ACCIDENTAL_MASK) >> PITCH_ACCIDENTAL_SHIFT) + +#define PITCH_NAME_MASK 0x38 +#define PITCH_NAME_SHIFT 3 + +typedef enum pitch_name +{ + PITCH_NAME_C, + PITCH_NAME_D, + PITCH_NAME_E, + PITCH_NAME_F, + PITCH_NAME_G, + PITCH_NAME_A, + PITCH_NAME_B, +} pitch_name_t; + +#define PITCH_NAME(pitch) (((pitch) & PITCH_NAME_MASK) >> PITCH_NAME_SHIFT) + +#define PITCH(name, accidental) (((name) << PITCH_NAME_SHIFT) | (accidental)) + +#define PITCH_LITERAL(literal_name, literal_accidental) PITCH(PITCH_NAME_##literal_name, PITCH_ACCIDENTAL_##literal_accidental) + +typedef enum pitch +{ + PITCH_Cff = PITCH_LITERAL (C, DOUBLE_FLAT), + PITCH_Cf = PITCH_LITERAL (C, FLAT), + PITCH_C = PITCH_LITERAL (C, NATURAL), + PITCH_Cs = PITCH_LITERAL (C, SHARP), + PITCH_Css = PITCH_LITERAL (C, DOUBLE_SHARP), + + PITCH_Dff = PITCH_LITERAL (D, DOUBLE_FLAT), + PITCH_Df = PITCH_LITERAL (D, FLAT), + PITCH_D = PITCH_LITERAL (D, NATURAL), + PITCH_Ds = PITCH_LITERAL (D, SHARP), + PITCH_Dss = PITCH_LITERAL (D, DOUBLE_SHARP), + + PITCH_Eff = PITCH_LITERAL (E, DOUBLE_FLAT), + PITCH_Ef = PITCH_LITERAL (E, FLAT), + PITCH_E = PITCH_LITERAL (E, NATURAL), + PITCH_Es = PITCH_LITERAL (E, SHARP), + PITCH_Ess = PITCH_LITERAL (E, DOUBLE_SHARP), + + PITCH_Fff = PITCH_LITERAL (F, DOUBLE_FLAT), + PITCH_Ff = PITCH_LITERAL (F, FLAT), + PITCH_F = PITCH_LITERAL (F, NATURAL), + PITCH_Fs = PITCH_LITERAL (F, SHARP), + PITCH_Fss = PITCH_LITERAL (F, DOUBLE_SHARP), + + PITCH_Gff = PITCH_LITERAL (G, DOUBLE_FLAT), + PITCH_Gf = PITCH_LITERAL (G, FLAT), + PITCH_G = PITCH_LITERAL (G, NATURAL), + PITCH_Gs = PITCH_LITERAL (G, SHARP), + PITCH_Gss = PITCH_LITERAL (G, DOUBLE_SHARP), + + PITCH_Aff = PITCH_LITERAL (A, DOUBLE_FLAT), + PITCH_Af = PITCH_LITERAL (A, FLAT), + PITCH_A = PITCH_LITERAL (A, NATURAL), + PITCH_As = PITCH_LITERAL (A, SHARP), + PITCH_Ass = PITCH_LITERAL (A, DOUBLE_SHARP), + + PITCH_Bff = PITCH_LITERAL (B, DOUBLE_FLAT), + PITCH_Bf = PITCH_LITERAL (B, FLAT), + PITCH_B = PITCH_LITERAL (B, NATURAL), + PITCH_Bs = PITCH_LITERAL (B, SHARP), + PITCH_Bss = PITCH_LITERAL (B, DOUBLE_SHARP) +} pitch_t;