]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/pitch.hh
2ebbb71a4179ada0835ba590eb20fbd03583aae8
[lilypond.git] / lily / include / pitch.hh
1 /*
2   pitch.hh -- declare Pitch
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef MUSICAL_PITCH_HH
10 #define MUSICAL_PITCH_HH
11
12 #include "lily-proto.hh"
13 #include "smobs.hh"
14
15 #include "std-vector.hh"
16
17 struct Scale
18 {
19   vector<int> step_semitones_;
20   Scale ();
21   Scale (Scale const&);
22   DECLARE_SMOBS(Scale,);
23 };
24
25
26 /** A "tonal" pitch. This is a pitch used in diatonal western music
27     (24 quartertones in an octave), as opposed to a frequency in Hz or a
28     integer number of semitones.
29
30     Pitch is lexicographically ordered by (octave, notename,
31     alteration).
32
33
34     TODO:
35
36     - add indeterminate octaves, so it can be used as a key in keySigature
37 */
38 class Pitch
39 {
40 private:                                // fixme
41   /*
42     TODO: use SCM
43   */
44
45   int notename_;
46   int alteration_;
47   int octave_;
48   Scale *scale_;
49   
50   void transpose (Pitch);
51   void up_to (int);
52   void down_to (int);
53   void normalise ();
54
55 public:
56
57   int get_octave () const;
58   int get_notename () const;
59   int get_alteration () const;
60
61   Pitch (int octave, int notename, int accidental);
62   Pitch ();
63
64   Pitch transposed (Pitch) const;
65   Pitch to_relative_octave (Pitch) const;
66
67   static int compare (Pitch const &, Pitch const &);
68
69   int steps () const;
70   int semitone_pitch () const;
71   int quartertone_pitch () const;
72   string to_string () const;
73
74   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
75   DECLARE_SIMPLE_SMOBS (Pitch,);
76 };
77
78 enum
79   {
80     DOUBLE_FLAT = -4,
81     THREE_Q_FLAT,
82     FLAT,
83     SEMI_FLAT,
84     NATURAL,
85     SEMI_SHARP,
86     SHARP,
87     THREE_Q_SHARP,
88     DOUBLE_SHARP,
89   };
90
91 SCM ly_pitch_diff (SCM pitch, SCM root);
92 SCM ly_pitch_transpose (SCM p, SCM delta);
93 DECLARE_UNSMOB (Pitch, pitch);
94
95 INSTANTIATE_COMPARE (Pitch, Pitch::compare);
96
97 extern SCM pitch_less_proc;
98 Pitch pitch_interval (Pitch const &from, Pitch const &to);
99 extern Scale *default_global_scale;
100
101 #endif /* MUSICAL_PITCH_HH */
102