]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/audio-item.hh
ae5c96ae95e549264a36f8808cedab6e06eb9aaa
[lilypond.git] / lily / include / audio-item.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 Jan Nieuwenhuizen <janneke@gnu.org>
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 AUDIO_ITEM_HH
21 #define AUDIO_ITEM_HH
22
23 #include "audio-element.hh"
24 #include "moment.hh"
25 #include "pitch.hh"
26
27 class Audio_item : public Audio_element
28 {
29 public:
30   Audio_column *audio_column_;
31   int channel_;
32
33   Audio_item ();
34   Audio_column *get_column () const;
35
36   virtual void render ();
37
38 private:
39   Audio_item (Audio_item const &);
40   Audio_item &operator = (Audio_item const &);
41 };
42
43 // Audio_span_dynamic is open at the end of the interval, so the volume
44 // grows/diminshes toward a target, but whether it reaches it depends on the
45 // next Audio_span_dynamic in the performance.  For example, a crescendo
46 // notated as mf < p is represented as [mf < x) [p ...) i.e. growth to some
47 // volume louder than mf followed by an abrupt change to p.
48 class Audio_span_dynamic : public Audio_element
49 {
50 public:
51   static const Real MINIMUM_VOLUME = 0.0;
52   static const Real MAXIMUM_VOLUME = 1.0;
53   static const Real DEFAULT_VOLUME = 90.0 / 127.0;
54
55 private:
56   Moment start_moment_;
57   Real start_volume_;
58   Real duration_; // = target moment - start moment
59   Real gain_; // = target volume - start volume
60
61 public:
62   Real get_start_volume () const { return start_volume_; }
63   void set_end_moment (Moment);
64   void set_volume (Real start, Real target);
65   Real get_volume (Moment) const;
66   Audio_span_dynamic (Moment mom, Real volume);
67 };
68
69 class Audio_key : public Audio_item
70 {
71 public:
72   Audio_key (int acc, bool major);
73
74   int accidentals_;
75   bool major_;
76 };
77
78 class Audio_instrument : public Audio_item
79 {
80 public:
81   Audio_instrument (string instrument_string);
82
83   string str_;
84 };
85
86 class Audio_note : public Audio_item
87 {
88 public:
89   Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposition, int velocity);
90
91   // with tieWaitForNote, there might be a skip between the tied notes!
92   void tie_to (Audio_note *, Moment skip = 0);
93   Audio_note *tie_head ();
94   virtual string to_string () const;
95
96   Pitch pitch_;
97   Moment length_mom_;
98   Pitch transposing_;
99   Audio_span_dynamic *dynamic_;
100   int extra_velocity_;
101
102   Audio_note *tied_;
103   bool tie_event_;
104 };
105
106 class Audio_piano_pedal : public Audio_item
107 {
108 public:
109   string type_string_;
110   Direction dir_;
111 };
112
113 class Audio_text : public Audio_item
114 {
115 public:
116   enum Type
117   {
118     TEXT = 1, COPYRIGHT, TRACK_NAME, INSTRUMENT_NAME, LYRIC,
119     MARKER, CUE_POINT
120   };
121
122   Audio_text (Audio_text::Type type, const string &text_string);
123
124   Type type_;
125   string text_string_;
126 };
127
128 class Audio_tempo : public Audio_item
129 {
130 public:
131   Audio_tempo (int per_minute_4);
132
133   int per_minute_4_;
134 };
135
136 class Audio_time_signature : public Audio_item
137 {
138 public:
139   Audio_time_signature (int beats, int one_beat);
140
141   int beats_;
142   int one_beat_;
143 };
144
145 class Audio_control_function_value_change : public Audio_item
146 {
147 public:
148   // Supported control functions.
149   enum Control
150   {
151     BALANCE = 0, PAN_POSITION, EXPRESSION, REVERB_LEVEL, CHORUS_LEVEL,
152     // pseudo value for representing the size of the enum; must be kept last
153     NUM_CONTROLS
154   };
155
156   Audio_control_function_value_change (Control control, Real value);
157
158   // Information about a context property corresponding to a control function
159   // (name, the corresponding enumeration value, and the allowed range for the
160   // value of the context property).
161   struct Context_property
162   {
163     const char *name_;
164     Control control_;
165     Real range_min_;
166     Real range_max_;
167   };
168
169   // Mapping from supported control functions to the corresponding context
170   // properties.
171   static const Context_property context_properties_[];
172
173   Control control_;
174   Real value_;
175 };
176
177 int moment_to_ticks (Moment);
178 Real moment_to_real (Moment);
179 Moment remap_grace_duration (Moment);
180
181 #endif // AUDIO_ITEM_HH
182