]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/pitch.hh
Run `make grand-replace'.
[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--2008 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_octave ();
37   void normalize_alteration ();
38   void normalize ();
39
40 public:
41   int get_octave () const;
42   int get_notename () const;
43   Rational get_alteration () const;
44
45   Pitch (int octave, int notename, Rational accidental);
46   Pitch (int octave, int notename);
47   Pitch ();
48
49   Pitch transposed (Pitch) const;
50   Pitch to_relative_octave (Pitch) const;
51
52   static int compare (Pitch const &, Pitch const &);
53
54   int steps () const;
55   Rational tone_pitch () const;
56   int rounded_semitone_pitch () const;
57   int rounded_quartertone_pitch () const;
58   Pitch negated () const;
59   string to_string () const;
60
61   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
62   DECLARE_SIMPLE_SMOBS (Pitch);
63 };
64
65
66 enum {
67   DOUBLE_FLAT = -4,
68   THREE_Q_FLAT,
69   FLAT,
70   SEMI_FLAT,
71   NATURAL,
72   SEMI_SHARP,
73   SHARP,
74   THREE_Q_SHARP,
75   DOUBLE_SHARP,
76 };
77
78 extern Rational  DOUBLE_FLAT_ALTERATION;
79 extern Rational  THREE_Q_FLAT_ALTERATION;
80 extern Rational  FLAT_ALTERATION;
81 extern Rational  SEMI_FLAT_ALTERATION;
82 extern Rational  NATURAL_ALTERATION;
83 extern Rational  SEMI_SHARP_ALTERATION;
84 extern Rational  SHARP_ALTERATION;
85 extern Rational  THREE_Q_SHARP_ALTERATION;
86 extern Rational  DOUBLE_SHARP_ALTERATION;
87
88 SCM ly_pitch_diff (SCM pitch, SCM root);
89 SCM ly_pitch_transpose (SCM p, SCM delta);
90 DECLARE_UNSMOB (Pitch, pitch);
91
92 INSTANTIATE_COMPARE (Pitch, Pitch::compare);
93
94 extern SCM pitch_less_proc;
95 Pitch pitch_interval (Pitch const &from, Pitch const &to);
96
97 #endif /* MUSICAL_PITCH_HH */
98