BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __SFI_NOTE_H__ 00003 #define __SFI_NOTE_H__ 00004 00005 #include <sfi/sfitypes.hh> 00006 00007 G_BEGIN_DECLS 00008 00009 00010 /* --- (MIDI) notes --- */ 00011 /* notes are generally kept in signed integers. though they are zero 00012 * bounded, they are often used within expression that shouldn't be 00013 * promoted into unsigned integer expressions. 00014 */ 00015 #define SFI_MIN_NOTE (0) /* assumed to be 0 in various places */ 00016 #define SFI_MAX_NOTE (131 /* 123 */) 00017 00018 /* special note value to represent "no value specified" 00019 * or unparsable notes. 00020 */ 00021 #define SFI_NOTE_VOID (SFI_MAX_NOTE + 1) 00022 00023 /* kammer note, representing the kammer frequency's midi note value */ 00024 #define SFI_KAMMER_NOTE ((SfiInt) (69) /* A' */) 00025 #define SFI_KAMMER_OCTAVE ((SfiInt) (+1)) 00026 00027 /* resulting minimum and maximum octaves */ 00028 #define SFI_MIN_OCTAVE (SFI_NOTE_OCTAVE (SFI_MIN_NOTE)) 00029 #define SFI_MAX_OCTAVE (SFI_NOTE_OCTAVE (SFI_MAX_NOTE)) 00030 00031 /* macro to retrieve a valid note. simply defaults 00032 * to kammer note for invalid note values. 00033 */ 00034 #define SFI_NOTE_MAKE_VALID(n) ((n) > SFI_MAX_NOTE || (n) < SFI_MIN_NOTE ? SFI_KAMMER_NOTE : ((SfiInt) (n))) 00035 #define SFI_NOTE_IS_VALID(n) ((n) >= SFI_MIN_NOTE && (n) <= SFI_MAX_NOTE) 00036 00037 /* clamp note against boundaries in cases of underflow or overflow */ 00038 #define SFI_NOTE_CLAMP(n) (CLAMP (((SfiInt) (n)), SFI_MIN_NOTE, SFI_MAX_NOTE)) 00039 00040 00041 /* macros to compose and decompose note values into semitones and octaves */ 00042 #define SFI_NOTE_OCTAVE(n) ((((SfiInt) (n)) - SFI_NOTE_SEMITONE (n) - (SFI_KAMMER_NOTE - 9)) / 12 + SFI_KAMMER_OCTAVE) 00043 #define SFI_NOTE_SEMITONE(n) (((SfiInt) (n)) % 12 + (9 - (SFI_KAMMER_NOTE % 12))) 00044 #define SFI_NOTE_GENERIC(o,ht_i) (SFI_KAMMER_NOTE - 9 + ((SfiInt) (ht_i)) + (((gint) (o)) - SFI_KAMMER_OCTAVE) * 12) 00045 #define SFI_NOTE_C(o) (SFI_NOTE_GENERIC ((o), 0)) 00046 #define SFI_NOTE_Cis(o) (SFI_NOTE_GENERIC ((o), 1)) 00047 #define SFI_NOTE_Des(o) (SFI_NOTE_Cis (o)) 00048 #define SFI_NOTE_D(o) (SFI_NOTE_GENERIC ((o), 2)) 00049 #define SFI_NOTE_Dis(o) (SFI_NOTE_GENERIC ((o), 3)) 00050 #define SFI_NOTE_Es(o) (SFI_NOTE_Dis (o)) 00051 #define SFI_NOTE_E(o) (SFI_NOTE_GENERIC ((o), 4)) 00052 #define SFI_NOTE_F(o) (SFI_NOTE_GENERIC ((o), 5)) 00053 #define SFI_NOTE_Fis(o) (SFI_NOTE_GENERIC ((o), 6)) 00054 #define SFI_NOTE_Ges(o) (SFI_NOTE_Fis (o)) 00055 #define SFI_NOTE_G(o) (SFI_NOTE_GENERIC ((o), 7)) 00056 #define SFI_NOTE_Gis(o) (SFI_NOTE_GENERIC ((o), 8)) 00057 #define SFI_NOTE_As(o) (SFI_NOTE_Gis (o)) 00058 #define SFI_NOTE_A(o) (SFI_NOTE_GENERIC ((o), 9)) 00059 #define SFI_NOTE_Ais(o) (SFI_NOTE_GENERIC ((o), 10)) 00060 #define SFI_NOTE_Bes(o) (SFI_NOTE_Ais (o)) 00061 #define SFI_NOTE_B(o) (SFI_NOTE_GENERIC ((o), 11)) 00062 #define _SFI_NOTE_SHIFT_AUX(n,ht,dfl) (n + ht >= SFI_MIN_NOTE && n + ht <= SFI_MAX_NOTE ? n + ht : dfl) 00063 #define SFI_NOTE_SHIFT(n,ht_i) (_SFI_NOTE_SHIFT_AUX ((SfiInt) (n), (gint) (ht), (SfiInt) (n))) 00064 #define SFI_NOTE_OCTAVE_UP(n) (SFI_NOTE_SHIFT ((n), +12)) 00065 #define SFI_NOTE_OCTAVE_DOWN(n) (SFI_NOTE_SHIFT ((n), -12)) 00066 00067 00068 /* --- functions --- */ 00069 void sfi_note_examine (SfiInt note, 00070 gint *octave_p, 00071 gint *semitone_p, 00072 gboolean *black_semitone_p, 00073 gchar *letter_p); 00074 /* return a newly allocated string which describes `note' literally */ 00075 gchar* sfi_note_to_string (SfiInt note); 00076 /* return the numeric value of the note in `note_string' */ 00077 SfiInt sfi_note_from_string (const gchar *note_string); 00078 SfiInt sfi_note_from_string_err (const gchar *note_string, 00079 gchar **error_p); 00080 00081 00082 G_END_DECLS 00083 00084 #endif /* __SFI_NOTE_H__ */ 00085 00086 /* vim:set ts=8 sts=2 sw=2: */