BEAST - Free Software Audio Synthesizer and Tracker  0.9.2
sfinote.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFI_NOTE_H__
3 #define __SFI_NOTE_H__
4 
5 #include <sfi/sfitypes.hh>
6 
7 G_BEGIN_DECLS
8 
9 
10 /* --- (MIDI) notes --- */
11 /* notes are generally kept in signed integers. though they are zero
12  * bounded, they are often used within expression that shouldn't be
13  * promoted into unsigned integer expressions.
14  */
15 #define SFI_MIN_NOTE (0) /* assumed to be 0 in various places */
16 #define SFI_MAX_NOTE (131 /* 123 */)
17 
18 /* special note value to represent "no value specified"
19  * or unparsable notes.
20  */
21 #define SFI_NOTE_VOID (SFI_MAX_NOTE + 1)
22 
23 /* kammer note, representing the kammer frequency's midi note value */
24 #define SFI_KAMMER_NOTE ((SfiInt) (69) /* A' */)
25 #define SFI_KAMMER_OCTAVE ((SfiInt) (+1))
26 
27 /* resulting minimum and maximum octaves */
28 #define SFI_MIN_OCTAVE (SFI_NOTE_OCTAVE (SFI_MIN_NOTE))
29 #define SFI_MAX_OCTAVE (SFI_NOTE_OCTAVE (SFI_MAX_NOTE))
30 
31 /* macro to retrieve a valid note. simply defaults
32  * to kammer note for invalid note values.
33  */
34 #define SFI_NOTE_MAKE_VALID(n) ((n) > SFI_MAX_NOTE || (n) < SFI_MIN_NOTE ? SFI_KAMMER_NOTE : ((SfiInt) (n)))
35 #define SFI_NOTE_IS_VALID(n) ((n) >= SFI_MIN_NOTE && (n) <= SFI_MAX_NOTE)
36 
37 /* clamp note against boundaries in cases of underflow or overflow */
38 #define SFI_NOTE_CLAMP(n) (CLAMP (((SfiInt) (n)), SFI_MIN_NOTE, SFI_MAX_NOTE))
39 
40 
41 /* macros to compose and decompose note values into semitones and octaves */
42 #define SFI_NOTE_OCTAVE(n) ((((SfiInt) (n)) - SFI_NOTE_SEMITONE (n) - (SFI_KAMMER_NOTE - 9)) / 12 + SFI_KAMMER_OCTAVE)
43 #define SFI_NOTE_SEMITONE(n) (((SfiInt) (n)) % 12 + (9 - (SFI_KAMMER_NOTE % 12)))
44 #define SFI_NOTE_GENERIC(o,ht_i) (SFI_KAMMER_NOTE - 9 + ((SfiInt) (ht_i)) + (((gint) (o)) - SFI_KAMMER_OCTAVE) * 12)
45 #define SFI_NOTE_C(o) (SFI_NOTE_GENERIC ((o), 0))
46 #define SFI_NOTE_Cis(o) (SFI_NOTE_GENERIC ((o), 1))
47 #define SFI_NOTE_Des(o) (SFI_NOTE_Cis (o))
48 #define SFI_NOTE_D(o) (SFI_NOTE_GENERIC ((o), 2))
49 #define SFI_NOTE_Dis(o) (SFI_NOTE_GENERIC ((o), 3))
50 #define SFI_NOTE_Es(o) (SFI_NOTE_Dis (o))
51 #define SFI_NOTE_E(o) (SFI_NOTE_GENERIC ((o), 4))
52 #define SFI_NOTE_F(o) (SFI_NOTE_GENERIC ((o), 5))
53 #define SFI_NOTE_Fis(o) (SFI_NOTE_GENERIC ((o), 6))
54 #define SFI_NOTE_Ges(o) (SFI_NOTE_Fis (o))
55 #define SFI_NOTE_G(o) (SFI_NOTE_GENERIC ((o), 7))
56 #define SFI_NOTE_Gis(o) (SFI_NOTE_GENERIC ((o), 8))
57 #define SFI_NOTE_As(o) (SFI_NOTE_Gis (o))
58 #define SFI_NOTE_A(o) (SFI_NOTE_GENERIC ((o), 9))
59 #define SFI_NOTE_Ais(o) (SFI_NOTE_GENERIC ((o), 10))
60 #define SFI_NOTE_Bes(o) (SFI_NOTE_Ais (o))
61 #define SFI_NOTE_B(o) (SFI_NOTE_GENERIC ((o), 11))
62 #define _SFI_NOTE_SHIFT_AUX(n,ht,dfl) (n + ht >= SFI_MIN_NOTE && n + ht <= SFI_MAX_NOTE ? n + ht : dfl)
63 #define SFI_NOTE_SHIFT(n,ht_i) (_SFI_NOTE_SHIFT_AUX ((SfiInt) (n), (gint) (ht), (SfiInt) (n)))
64 #define SFI_NOTE_OCTAVE_UP(n) (SFI_NOTE_SHIFT ((n), +12))
65 #define SFI_NOTE_OCTAVE_DOWN(n) (SFI_NOTE_SHIFT ((n), -12))
66 
67 
68 /* --- functions --- */
69 void sfi_note_examine (SfiInt note,
70  gint *octave_p,
71  gint *semitone_p,
72  gboolean *black_semitone_p,
73  gchar *letter_p);
74 /* return a newly allocated string which describes `note' literally */
75 gchar* sfi_note_to_string (SfiInt note);
76 /* return the numeric value of the note in `note_string' */
77 SfiInt sfi_note_from_string (const gchar *note_string);
78 SfiInt sfi_note_from_string_err (const gchar *note_string,
79  gchar **error_p);
80 
81 
82 G_END_DECLS
83 
84 #endif /* __SFI_NOTE_H__ */
85 
86 /* vim:set ts=8 sts=2 sw=2: */