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"
24 #include "international.hh"
26 Audio_instrument::Audio_instrument (string instrument_string)
28 str_ = instrument_string;
37 Audio_item::get_column () const
42 Audio_item::Audio_item ()
48 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing,
52 transposing_ (transposing),
54 extra_velocity_ (velocity),
56 tie_event_ (tie_event)
61 Audio_note::tie_to (Audio_note *t, Moment skip)
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_;
72 Audio_note::tie_head ()
74 Audio_note *first = this;
81 Audio_note::to_string () const
83 string s = "#<Audio_note pitch ";
84 s += pitch_.to_string();
86 s += length_mom_.to_string();
89 s += " tied to " + tied_->to_string();
99 Audio_key::Audio_key (int acc, bool major)
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;
109 Audio_span_dynamic::Audio_span_dynamic (Moment mom, Real volume)
110 : start_moment_ (mom),
113 set_volume (volume, volume);
117 remap_grace_duration (Moment m)
119 return Moment (m.main_part_ + Rational (9, 40) * m.grace_part_,
124 moment_to_real (Moment m)
126 return remap_grace_duration (m).main_part_.to_double ();
130 moment_to_ticks (Moment m)
132 return int (moment_to_real (m) * 384 * 4);
135 void Audio_span_dynamic::set_end_moment (Moment mom)
137 if (mom < start_moment_)
139 programming_error (_f ("end moment (%s) < start moment (%s)",
140 mom.to_string ().c_str (),
141 start_moment_.to_string ().c_str ()));
145 duration_ = moment_to_real (mom - start_moment_);
149 Audio_span_dynamic::set_volume (Real start, Real target)
153 programming_error (_f ("invalid start volume: %f", start));
154 start = DEFAULT_VOLUME;
159 programming_error (_f ("invalid target volume: %f", target));
163 start_volume_ = start;
164 gain_ = target - start;
167 Real Audio_span_dynamic::get_volume (Moment mom) const
169 const Real when = moment_to_real (mom - start_moment_);
174 programming_error (_f ("asked to compute volume at %f for dynamic span of duration %f starting at %s",
176 start_moment_.to_string ().c_str ()));
177 return start_volume_;
180 if (when >= duration_)
182 programming_error (_f ("asked to compute volume at +%f for dynamic span of duration %f starting at %s",
184 start_moment_.to_string ().c_str ()));
185 return start_volume_ + gain_;
188 return start_volume_ + gain_ * (when / duration_);
191 Audio_tempo::Audio_tempo (int per_minute_4)
193 per_minute_4_ = per_minute_4;
196 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
199 one_beat_ = one_beat;
202 Audio_text::Audio_text (Audio_text::Type type, const string &text_string)
204 text_string_ = text_string;
208 Audio_control_change::Audio_control_change (int control, int value)
209 : control_ (control),