]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/pitch.hh
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / include / pitch.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2010 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 MUSICAL_PITCH_HH
21 #define MUSICAL_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,
33     alteration).
34
35 */
36 class Pitch
37 {
38 private:
39   int octave_;
40   int notename_;
41   Rational alteration_;
42   Scale *scale_;
43
44   void transpose (Pitch);
45   void up_to (int);
46   void down_to (int);
47   void normalize_octave ();
48   void normalize_alteration ();
49   void normalize ();
50
51 public:
52   int get_octave () const;
53   int get_notename () const;
54   Rational get_alteration () const;
55
56   Pitch (int octave, int notename, Rational accidental);
57   Pitch (int octave, int notename);
58   Pitch ();
59
60   Pitch transposed (Pitch) const;
61   Pitch to_relative_octave (Pitch) const;
62
63   static int compare (Pitch const &, Pitch const &);
64
65   int steps () const;
66   Rational tone_pitch () const;
67   int rounded_semitone_pitch () const;
68   int rounded_quartertone_pitch () const;
69   Pitch negated () const;
70   string to_string () const;
71
72   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
73   DECLARE_SIMPLE_SMOBS (Pitch);
74 };
75
76
77 enum {
78   DOUBLE_FLAT = -4,
79   THREE_Q_FLAT,
80   FLAT,
81   SEMI_FLAT,
82   NATURAL,
83   SEMI_SHARP,
84   SHARP,
85   THREE_Q_SHARP,
86   DOUBLE_SHARP,
87 };
88
89 extern Rational  DOUBLE_FLAT_ALTERATION;
90 extern Rational  THREE_Q_FLAT_ALTERATION;
91 extern Rational  FLAT_ALTERATION;
92 extern Rational  SEMI_FLAT_ALTERATION;
93 extern Rational  NATURAL_ALTERATION;
94 extern Rational  SEMI_SHARP_ALTERATION;
95 extern Rational  SHARP_ALTERATION;
96 extern Rational  THREE_Q_SHARP_ALTERATION;
97 extern Rational  DOUBLE_SHARP_ALTERATION;
98
99 SCM ly_pitch_diff (SCM pitch, SCM root);
100 SCM ly_pitch_transpose (SCM p, SCM delta);
101 DECLARE_UNSMOB (Pitch, pitch);
102
103 INSTANTIATE_COMPARE (Pitch, Pitch::compare);
104
105 extern SCM pitch_less_proc;
106 Pitch pitch_interval (Pitch const &from, Pitch const &to);
107
108 #endif /* MUSICAL_PITCH_HH */
109