]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/pitch.hh
Run grand replace for 2015.
[lilypond.git] / lily / include / pitch.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef PITCH_HH
21 #define PITCH_HH
22
23 #include "lily-proto.hh"
24 #include "smobs.hh"
25 #include "rational.hh"
26
27 /*
28   A "tonal" pitch.  This is a pitch used in diatonal western music
29   (24 quartertones in an octave), as opposed to a frequency in Hz or a
30   integer number of semitones.
31
32   Pitch is lexicographically ordered by (octave, notename, alteration).
33 */
34
35 class Pitch : public Simple_smob<Pitch>
36 {
37 public:
38   static SCM equal_p (SCM, SCM);
39   int print_smob (SCM, scm_print_state *);
40   SCM mark_smob ();
41   static const char type_p_name_[];
42 private:
43   int octave_;
44   int notename_;
45   Rational alteration_;
46   Scale *scale_;
47
48   void transpose (Pitch);
49   void up_to (int);
50   void down_to (int);
51   void normalize_octave ();
52   void normalize_alteration ();
53   void normalize ();
54
55 public:
56   int get_octave () const;
57   int get_notename () const;
58   Rational get_alteration () const;
59
60   Pitch (int octave, int notename, Rational accidental = 0);
61   Pitch ();
62
63   Pitch transposed (Pitch) const;
64   Pitch to_relative_octave (Pitch) const;
65
66   Pitch normalized () const;
67
68   static int compare (Pitch const &, Pitch const &);
69
70   int steps () const;
71   Rational tone_pitch () const;
72   int rounded_semitone_pitch () const;
73   int rounded_quartertone_pitch () const;
74   Pitch negated () const;
75   string to_string () const;
76
77   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
78 };
79
80 enum
81 {
82   DOUBLE_FLAT = -4,
83   THREE_Q_FLAT,
84   FLAT,
85   SEMI_FLAT,
86   NATURAL,
87   SEMI_SHARP,
88   SHARP,
89   THREE_Q_SHARP,
90   DOUBLE_SHARP,
91 };
92
93 extern Rational DOUBLE_FLAT_ALTERATION;
94 extern Rational THREE_Q_FLAT_ALTERATION;
95 extern Rational FLAT_ALTERATION;
96 extern Rational SEMI_FLAT_ALTERATION;
97 extern Rational NATURAL_ALTERATION;
98 extern Rational SEMI_SHARP_ALTERATION;
99 extern Rational SHARP_ALTERATION;
100 extern Rational THREE_Q_SHARP_ALTERATION;
101 extern Rational DOUBLE_SHARP_ALTERATION;
102
103 SCM ly_pitch_diff (SCM pitch, SCM root);
104 SCM ly_pitch_transpose (SCM p, SCM delta);
105
106 INSTANTIATE_COMPARE (Pitch, Pitch::compare);
107
108 extern SCM pitch_less_proc;
109 Pitch pitch_interval (Pitch const &from, Pitch const &to);
110 extern SCM Pitch_type_p_proc;
111
112 #endif /* PITCH_HH */