Docs: Add new procedure for barNumberVisibility
[lilypond/mpolesky.git] / lily / audio-item.cc
blob33e54d713a869b7bdfc1225fc2a9774b1ebdbe08
1 /*
2 audio-item.cc -- implement Audio items.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "audio-item.hh"
11 #include "midi-item.hh"
12 #include "audio-column.hh"
14 Audio_instrument::Audio_instrument (string instrument_string)
16 str_ = instrument_string;
19 void
20 Audio_item::render ()
24 Audio_column *
25 Audio_item::get_column () const
27 return audio_column_;
30 Audio_item::Audio_item ()
32 audio_column_ = 0;
35 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing)
37 pitch_ = p;
38 length_mom_ = m;
39 tied_ = 0;
40 transposing_ = transposing;
41 tie_event_ = tie_event;
44 void
45 Audio_note::tie_to (Audio_note *t)
47 tied_ = t;
48 Audio_note *first = t;
49 while (first->tied_)
50 first = first->tied_;
51 first->length_mom_ += length_mom_;
52 length_mom_ = 0;
55 Audio_key::Audio_key (int acc, bool major)
57 accidentals_ = acc;
58 major_ = major;
61 Audio_dynamic::Audio_dynamic ()
63 volume_ = -1;
66 Audio_span_dynamic::Audio_span_dynamic ()
68 grow_dir_ = CENTER;
71 void
72 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
74 assert (d);
75 dynamics_.push_back (d);
78 Moment
79 remap_grace_duration (Moment m)
81 return Moment (m.main_part_ + Rational (9,40) * m.grace_part_,
82 Rational (0));
85 Real
86 moment_to_real (Moment m)
88 return remap_grace_duration (m).main_part_.to_double ();
91 int
92 moment_to_ticks (Moment m)
94 return int (moment_to_real (m) * 384 * 4);
97 void
98 Audio_span_dynamic::render ()
100 if (dynamics_.size () <= 1)
101 return ;
103 assert (dynamics_[0]->volume_ >= 0);
105 while (dynamics_.back ()->volume_ > 0
106 && dynamics_.size () > 1
107 && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
109 dynamics_.erase (dynamics_.end () - 1);
112 if (dynamics_.size () <= 1)
114 programming_error ("(de)crescendo on items with specified volume.");
115 return ;
118 Real delta_v = grow_dir_ * 0.1;
120 Real start_v = dynamics_[0]->volume_;
121 if (dynamics_.back ()->volume_ < 0)
122 dynamics_.back ()->volume_ = max (min (start_v + grow_dir_ * 0.25, 1.0), 0.1);
124 delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
126 Moment start = dynamics_[0]->get_column ()->when ();
128 Real total_t = moment_to_real (dynamics_.back ()->get_column ()->when () - start);
130 for (vsize i = 1; i < dynamics_.size (); i ++)
132 Moment dt_moment = dynamics_[i]->get_column ()->when ()
133 - start;
135 Real dt = moment_to_real (dt_moment);
137 Real v = start_v + delta_v * (dt / total_t);
139 dynamics_[i]->volume_ = v;
145 Audio_tempo::Audio_tempo (int per_minute_4)
147 per_minute_4_ = per_minute_4;
150 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
152 beats_ = beats;
153 one_beat_ = one_beat;
156 Audio_text::Audio_text (Audio_text::Type type, string text_string)
158 text_string_ = text_string;
159 type_ = type;