]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/pitch.hh
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[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 #include "rational.hh"
15
16
17 /** A "tonal" pitch. This is a pitch used in diatonal western music
18     (24 quartertones in an octave), as opposed to a frequency in Hz or a
19     integer number of semitones.
20
21     Pitch is lexicographically ordered by (octave, notename,
22     alteration).
23
24 */
25 class Pitch
26 {
27 private:
28   int octave_;
29   int notename_;
30   Rational alteration_;
31   Scale *scale_;
32
33   void transpose (Pitch);
34   void up_to (int);
35   void down_to (int);
36   void normalize ();
37
38 public:
39   int get_octave () const;
40   int get_notename () const;
41   Rational get_alteration () const;
42
43   Pitch (int octave, int notename, Rational accidental);
44   Pitch (int octave, int notename);
45   Pitch ();
46
47   Pitch transposed (Pitch) const;
48   Pitch to_relative_octave (Pitch) const;
49
50   static int compare (Pitch const &, Pitch const &);
51
52   int steps () const;
53   Rational tone_pitch () const;
54   int rounded_semitone_pitch () const;
55   int rounded_quartertone_pitch () const;
56   Pitch negated () const;
57   string to_string () const;
58
59   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
60   DECLARE_SIMPLE_SMOBS (Pitch);
61 };
62
63
64 enum {
65   DOUBLE_FLAT = -4,
66   THREE_Q_FLAT,
67   FLAT,
68   SEMI_FLAT,
69   NATURAL,
70   SEMI_SHARP,
71   SHARP,
72   THREE_Q_SHARP,
73   DOUBLE_SHARP,
74 };
75
76 extern Rational  DOUBLE_FLAT_ALTERATION;
77 extern Rational  THREE_Q_FLAT_ALTERATION;
78 extern Rational  FLAT_ALTERATION;
79 extern Rational  SEMI_FLAT_ALTERATION;
80 extern Rational  NATURAL_ALTERATION;
81 extern Rational  SEMI_SHARP_ALTERATION;
82 extern Rational  SHARP_ALTERATION;
83 extern Rational  THREE_Q_SHARP_ALTERATION;
84 extern Rational  DOUBLE_SHARP_ALTERATION;
85
86 SCM ly_pitch_diff (SCM pitch, SCM root);
87 SCM ly_pitch_transpose (SCM p, SCM delta);
88 DECLARE_UNSMOB (Pitch, pitch);
89
90 INSTANTIATE_COMPARE (Pitch, Pitch::compare);
91
92 extern SCM pitch_less_proc;
93 Pitch pitch_interval (Pitch const &from, Pitch const &to);
94
95 #endif /* MUSICAL_PITCH_HH */
96