]> git.donarmstrong.com Git - lilypond.git/blob - lily/audio-item.cc
Web-ja: update introduction
[lilypond.git] / lily / audio-item.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--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 #include "audio-item.hh"
21
22 #include "midi-item.hh"
23 #include "audio-column.hh"
24 #include "international.hh"
25
26 Audio_instrument::Audio_instrument (string instrument_string)
27 {
28   str_ = instrument_string;
29 }
30
31 void
32 Audio_item::render ()
33 {
34 }
35
36 Audio_column *
37 Audio_item::get_column () const
38 {
39   return audio_column_;
40 }
41
42 Audio_item::Audio_item ()
43   : audio_column_ (0),
44     channel_ (0)
45 {
46 }
47
48 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing,
49                         int velocity)
50   : pitch_ (p),
51     length_mom_ (m),
52     transposing_ (transposing),
53     dynamic_ (0),
54     extra_velocity_ (velocity),
55     tied_ (0),
56     tie_event_ (tie_event)
57 {
58 }
59
60 void
61 Audio_note::tie_to (Audio_note *t, Moment skip)
62 {
63   tied_ = t;
64   Audio_note *first = tie_head();
65   // Add the skip to the tied note and the length of the appended note
66   // to the full duration of the tie...
67   first->length_mom_ += skip + length_mom_;
68   length_mom_ = 0;
69 }
70
71 Audio_note *
72 Audio_note::tie_head ()
73 {
74   Audio_note *first = this;
75   while (first->tied_)
76     first = first->tied_;
77   return first;
78 }
79
80 string
81 Audio_note::to_string () const
82 {
83   string s = "#<Audio_note pitch ";
84   s += pitch_.to_string();
85   s += " len ";
86   s += length_mom_.to_string();
87   if (tied_)
88     {
89       s += " tied to " + tied_->to_string();
90     }
91   if (tie_event_)
92     {
93       s += " tie_event";
94     }
95   s += ">";
96   return s;
97 }
98
99 Audio_key::Audio_key (int acc, bool major)
100 {
101   accidentals_ = acc;
102   major_ = major;
103 }
104
105 const Real Audio_span_dynamic::MINIMUM_VOLUME = 0.0;
106 const Real Audio_span_dynamic::MAXIMUM_VOLUME = 1.0;
107 const Real Audio_span_dynamic::DEFAULT_VOLUME = 90.0 / 127.0;
108
109 Audio_span_dynamic::Audio_span_dynamic (Moment mom, Real volume)
110   : start_moment_ (mom),
111     duration_ (0)
112 {
113   set_volume (volume, volume);
114 }
115
116 Moment
117 remap_grace_duration (Moment m)
118 {
119   return Moment (m.main_part_ + Rational (9, 40) * m.grace_part_,
120                  Rational (0));
121 }
122
123 Real
124 moment_to_real (Moment m)
125 {
126   return remap_grace_duration (m).main_part_.to_double ();
127 }
128
129 int
130 moment_to_ticks (Moment m)
131 {
132   return int (moment_to_real (m) * 384 * 4);
133 }
134
135 void Audio_span_dynamic::set_end_moment (Moment mom)
136 {
137   if (mom < start_moment_)
138     {
139       programming_error (_f ("end moment (%s) < start moment (%s)",
140                              mom.to_string ().c_str (),
141                              start_moment_.to_string ().c_str ()));
142       mom = start_moment_;
143     }
144
145   duration_ = moment_to_real (mom - start_moment_);
146 }
147
148 void
149 Audio_span_dynamic::set_volume (Real start, Real target)
150 {
151   if (!(start >= 0))
152     {
153       programming_error (_f ("invalid start volume: %f", start));
154       start = DEFAULT_VOLUME;
155     }
156
157   if (!(target >= 0))
158     {
159       programming_error (_f ("invalid target volume: %f", target));
160       target = start;
161     }
162
163   start_volume_ = start;
164   gain_ = target - start;
165 }
166
167 Real Audio_span_dynamic::get_volume (Moment mom) const
168 {
169   const Real when = moment_to_real (mom - start_moment_);
170
171   if (when <= 0)
172     {
173       if (when < 0)
174         programming_error (_f ("asked to compute volume at %f for dynamic span of duration %f starting at %s",
175                                when, duration_,
176                                start_moment_.to_string ().c_str ()));
177       return start_volume_;
178     }
179
180   if (when >= duration_)
181     {
182       programming_error (_f ("asked to compute volume at +%f for dynamic span of duration %f starting at %s",
183                              when, duration_,
184                              start_moment_.to_string ().c_str ()));
185       return start_volume_ + gain_;
186     }
187
188   return start_volume_ + gain_ * (when / duration_);
189 }
190
191 Audio_tempo::Audio_tempo (int per_minute_4)
192 {
193   per_minute_4_ = per_minute_4;
194 }
195
196 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
197 {
198   beats_ = beats;
199   one_beat_ = one_beat;
200 }
201
202 Audio_text::Audio_text (Audio_text::Type type, const string &text_string)
203 {
204   text_string_ = text_string;
205   type_ = type;
206 }
207
208 Audio_control_change::Audio_control_change (int control, int value)
209   : control_ (control),
210     value_ (value)
211 {
212 }