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