2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Jan Nieuwenhuizen <janneke@gnu.org>
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.
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.
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/>.
20 #include "audio-item.hh"
22 #include "midi-item.hh"
23 #include "audio-column.hh"
27 Audio_instrument::Audio_instrument (string instrument_string)
29 str_ = instrument_string;
38 Audio_item::get_column () const
43 Audio_item::Audio_item ()
49 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing,
53 transposing_ (transposing),
55 extra_velocity_ (velocity),
57 tie_event_ (tie_event)
62 Audio_note::tie_to (Audio_note *t, Moment skip)
65 Audio_note *first = tie_head();
66 // Add the skip to the tied note and the length of the appended note
67 // to the full duration of the tie...
68 first->length_mom_ += skip + length_mom_;
73 Audio_note::tie_head ()
75 Audio_note *first = this;
82 Audio_note::to_string () const
84 string s = "#<Audio_note pitch ";
85 s += pitch_.to_string();
87 s += length_mom_.to_string();
90 s += " tied to " + tied_->to_string();
100 Audio_key::Audio_key (int acc, bool major)
106 Audio_dynamic::Audio_dynamic ()
112 Audio_span_dynamic::Audio_span_dynamic (Real min_volume, Real max_volume)
115 min_volume_ = min_volume;
116 max_volume_ = max_volume;
120 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
123 dynamics_.push_back (d);
127 remap_grace_duration (Moment m)
129 return Moment (m.main_part_ + Rational (9, 40) * m.grace_part_,
134 moment_to_real (Moment m)
136 return remap_grace_duration (m).main_part_.to_double ();
140 moment_to_ticks (Moment m)
142 return int (moment_to_real (m) * 384 * 4);
146 Audio_span_dynamic::render ()
148 if (dynamics_.size () <= 1)
151 assert (dynamics_[0]->volume_ >= 0);
153 while (dynamics_.back ()->volume_ > 0
154 && dynamics_.size () > 1
155 && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
157 dynamics_.erase (dynamics_.end () - 1);
160 if (dynamics_.size () <= 1)
162 programming_error ("Impossible or ambiguous (de)crescendo in MIDI.");
166 Real start_v = dynamics_[0]->volume_;
167 if (dynamics_.back ()->volume_ < 0)
169 // The dynamic spanner does not end with an explicit dynamic script
170 // event. Adjust the end volume by at most 1/4 of the available
171 // volume range in this case.
172 dynamics_.back ()->volume_ = max (min (start_v + grow_dir_ * (max_volume_ - min_volume_) * 0.25, max_volume_), min_volume_);
175 Real delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
177 Moment start = dynamics_[0]->get_column ()->when ();
179 Real total_t = moment_to_real (dynamics_.back ()->get_column ()->when () - start);
181 for (vsize i = 1; i < dynamics_.size (); i++)
183 Moment dt_moment = dynamics_[i]->get_column ()->when ()
186 Real dt = moment_to_real (dt_moment);
188 Real v = start_v + delta_v * (dt / total_t);
190 dynamics_[i]->volume_ = v;
194 Audio_tempo::Audio_tempo (int per_minute_4)
196 per_minute_4_ = per_minute_4;
199 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
202 one_beat_ = one_beat;
205 Audio_text::Audio_text (Audio_text::Type type, const string &text_string)
207 text_string_ = text_string;
211 Audio_control_function_value_change
212 ::Audio_control_function_value_change (Control control, Real value)
213 : control_ (control), value_ (value)
217 const Audio_control_function_value_change::Context_property
218 Audio_control_function_value_change::context_properties_[] = {
219 // property name, enum constant, lower bound for range, upper bound for range
220 { "midiBalance", BALANCE, -1.0, 1.0 },
221 { "midiPanPosition", PAN_POSITION, -1.0, 1.0 },
222 { "midiExpression", EXPRESSION, 0.0, 1.0 },
223 { "midiReverbLevel", REVERB_LEVEL, 0.0, 1.0 },
224 { "midiChorusLevel", CHORUS_LEVEL, 0.0, 1.0 },
225 // extra element to signify the end of the mapping, must be kept last
226 { 0, NUM_CONTROLS, 0.0, 0.0 }