]> git.donarmstrong.com Git - lilypond.git/blob - lily/audio-item.cc
extend Audio_note::tie_to to contain an optional skip before the tied note
[lilypond.git] / lily / audio-item.cc
1 /*
2   audio-item.cc -- implement Audio items.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "audio-item.hh"
10
11 #include "midi-item.hh"
12 #include "audio-column.hh"
13
14 Audio_instrument::Audio_instrument (string instrument_string)
15 {
16   str_ = instrument_string;
17 }
18
19 void
20 Audio_item::render ()
21 {
22 }
23
24 Audio_column *
25 Audio_item::get_column () const
26 {
27   return audio_column_;
28 }
29
30 Audio_item::Audio_item ()
31 {
32   audio_column_ = 0;
33 }
34
35 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing)
36 {
37   pitch_ = p;
38   length_mom_ = m;
39   tied_ = 0;
40   transposing_ = transposing;
41   tie_event_ = tie_event;
42 }
43
44 void
45 Audio_note::tie_to (Audio_note *t, Moment skip)
46 {
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;
55 }
56
57 Audio_key::Audio_key (int acc, bool major)
58 {
59   accidentals_ = acc;
60   major_ = major;
61 }
62
63 Audio_dynamic::Audio_dynamic ()
64 {
65   volume_ = -1;
66 }
67
68 Audio_span_dynamic::Audio_span_dynamic ()
69 {
70   grow_dir_ = CENTER;
71 }
72
73 void
74 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
75 {
76   assert (d);
77   dynamics_.push_back (d);
78 }
79
80 Moment
81 remap_grace_duration (Moment m)
82 {
83   return Moment (m.main_part_ + Rational (9,40) * m.grace_part_,
84                  Rational (0));
85 }
86
87 Real
88 moment_to_real (Moment m)
89 {
90   return remap_grace_duration (m).main_part_.to_double ();
91 }
92
93 int
94 moment_to_ticks (Moment m)
95 {
96   return int (moment_to_real (m) * 384 * 4);
97 }
98
99 void
100 Audio_span_dynamic::render ()
101 {
102   if (dynamics_.size () <= 1)
103     return ;
104
105   assert (dynamics_[0]->volume_ >= 0);
106
107   while  (dynamics_.back ()->volume_ > 0
108           && dynamics_.size () > 1
109           && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
110     {
111       dynamics_.erase (dynamics_.end () - 1);
112     }
113
114   if (dynamics_.size () <= 1)
115     {
116       programming_error ("(de)crescendo on items with specified volume.");
117       return ;
118     }
119   
120   Real delta_v = grow_dir_ * 0.1;
121   
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);
125
126   delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
127
128   Moment start = dynamics_[0]->get_column ()->when ();
129
130   Real total_t = moment_to_real (dynamics_.back ()->get_column ()->when () - start);
131   
132   for (vsize i = 1; i < dynamics_.size (); i ++)
133     {
134       Moment dt_moment = dynamics_[i]->get_column ()->when ()
135         - start;
136
137       Real dt =  moment_to_real (dt_moment);
138       
139       Real v = start_v + delta_v *  (dt / total_t);
140
141       dynamics_[i]->volume_ = v;        
142     }
143 }
144
145
146
147 Audio_tempo::Audio_tempo (int per_minute_4)
148 {
149   per_minute_4_ = per_minute_4;
150 }
151
152 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
153 {
154   beats_ = beats;
155   one_beat_ = one_beat;
156 }
157
158 Audio_text::Audio_text (Audio_text::Type type, string text_string)
159 {
160   text_string_ = text_string;
161   type_ = type;
162 }
163