Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / audio-item.cc
blobe33437f631fdcc0ce6bd695a177e530d66018766
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 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"
25 Audio_instrument::Audio_instrument (string instrument_string)
27 str_ = instrument_string;
30 void
31 Audio_item::render ()
35 Audio_column *
36 Audio_item::get_column () const
38 return audio_column_;
41 Audio_item::Audio_item ()
42 : audio_column_ (0)
43 , channel_ (0)
47 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing)
49 pitch_ = p;
50 length_mom_ = m;
51 tied_ = 0;
52 transposing_ = transposing;
53 tie_event_ = tie_event;
54 volume_ = 0;
57 void
58 Audio_note::tie_to (Audio_note *t, Moment skip)
60 tied_ = t;
61 Audio_note *first = t;
62 while (first->tied_)
63 first = first->tied_;
64 // Add the skip to the tied note and the length of the appended note
65 // to the full duration of the tie...
66 first->length_mom_ += skip + length_mom_;
67 length_mom_ = 0;
70 Audio_key::Audio_key (int acc, bool major)
72 accidentals_ = acc;
73 major_ = major;
76 Audio_dynamic::Audio_dynamic ()
78 volume_ = -1;
81 Audio_span_dynamic::Audio_span_dynamic ()
83 grow_dir_ = CENTER;
86 void
87 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
89 assert (d);
90 dynamics_.push_back (d);
93 Moment
94 remap_grace_duration (Moment m)
96 return Moment (m.main_part_ + Rational (9,40) * m.grace_part_,
97 Rational (0));
100 Real
101 moment_to_real (Moment m)
103 return remap_grace_duration (m).main_part_.to_double ();
107 moment_to_ticks (Moment m)
109 return int (moment_to_real (m) * 384 * 4);
112 void
113 Audio_span_dynamic::render ()
115 if (dynamics_.size () <= 1)
116 return ;
118 assert (dynamics_[0]->volume_ >= 0);
120 while (dynamics_.back ()->volume_ > 0
121 && dynamics_.size () > 1
122 && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
124 dynamics_.erase (dynamics_.end () - 1);
127 if (dynamics_.size () <= 1)
129 programming_error ("Impossible or ambiguous (de)crescendo in MIDI.");
130 return ;
133 Real delta_v = grow_dir_ * 0.1;
135 Real start_v = dynamics_[0]->volume_;
136 if (dynamics_.back ()->volume_ < 0)
137 dynamics_.back ()->volume_ = max (min (start_v + grow_dir_ * 0.25, 1.0), 0.1);
139 delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
141 Moment start = dynamics_[0]->get_column ()->when ();
143 Real total_t = moment_to_real (dynamics_.back ()->get_column ()->when () - start);
145 for (vsize i = 1; i < dynamics_.size (); i ++)
147 Moment dt_moment = dynamics_[i]->get_column ()->when ()
148 - start;
150 Real dt = moment_to_real (dt_moment);
152 Real v = start_v + delta_v * (dt / total_t);
154 dynamics_[i]->volume_ = v;
160 Audio_tempo::Audio_tempo (int per_minute_4)
162 per_minute_4_ = per_minute_4;
165 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
167 beats_ = beats;
168 one_beat_ = one_beat;
171 Audio_text::Audio_text (Audio_text::Type type, string text_string)
173 text_string_ = text_string;
174 type_ = type;