Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / audio-item.cc
blob5104067fb6b78692d34e446e2ce0e62576877d53
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, Moment skip)
47 tied_ = t;
48 Audio_note *first = t;
49 while (first->tied_)
50 first = first->tied_;
51 // Add the skip to the tied note and the length of the appended note
52 // to the full duration of the tie...
53 first->length_mom_ += skip + length_mom_;
54 length_mom_ = 0;
57 Audio_key::Audio_key (int acc, bool major)
59 accidentals_ = acc;
60 major_ = major;
63 Audio_dynamic::Audio_dynamic ()
65 volume_ = -1;
68 Audio_span_dynamic::Audio_span_dynamic ()
70 grow_dir_ = CENTER;
73 void
74 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
76 assert (d);
77 dynamics_.push_back (d);
80 Moment
81 remap_grace_duration (Moment m)
83 return Moment (m.main_part_ + Rational (9,40) * m.grace_part_,
84 Rational (0));
87 Real
88 moment_to_real (Moment m)
90 return remap_grace_duration (m).main_part_.to_double ();
93 int
94 moment_to_ticks (Moment m)
96 return int (moment_to_real (m) * 384 * 4);
99 void
100 Audio_span_dynamic::render ()
102 if (dynamics_.size () <= 1)
103 return ;
105 assert (dynamics_[0]->volume_ >= 0);
107 while (dynamics_.back ()->volume_ > 0
108 && dynamics_.size () > 1
109 && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
111 dynamics_.erase (dynamics_.end () - 1);
114 if (dynamics_.size () <= 1)
116 programming_error ("(de)crescendo on items with specified volume.");
117 return ;
120 Real delta_v = grow_dir_ * 0.1;
122 Real start_v = dynamics_[0]->volume_;
123 if (dynamics_.back ()->volume_ < 0)
124 dynamics_.back ()->volume_ = max (min (start_v + grow_dir_ * 0.25, 1.0), 0.1);
126 delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
128 Moment start = dynamics_[0]->get_column ()->when ();
130 Real total_t = moment_to_real (dynamics_.back ()->get_column ()->when () - start);
132 for (vsize i = 1; i < dynamics_.size (); i ++)
134 Moment dt_moment = dynamics_[i]->get_column ()->when ()
135 - start;
137 Real dt = moment_to_real (dt_moment);
139 Real v = start_v + delta_v * (dt / total_t);
141 dynamics_[i]->volume_ = v;
147 Audio_tempo::Audio_tempo (int per_minute_4)
149 per_minute_4_ = per_minute_4;
152 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
154 beats_ = beats;
155 one_beat_ = one_beat;
158 Audio_text::Audio_text (Audio_text::Type type, string text_string)
160 text_string_ = text_string;
161 type_ = type;