]> git.donarmstrong.com Git - lilypond.git/blob - lily/audio-item.cc
add 2007 to (c) year.
[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--2007 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)
46 {
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;
53 }
54
55 Audio_key::Audio_key (int acc, bool major)
56 {
57   accidentals_ = acc;
58   major_ = major;
59 }
60
61 Audio_dynamic::Audio_dynamic ()
62 {
63   volume_ = -1;
64 }
65
66 Audio_span_dynamic::Audio_span_dynamic ()
67 {
68   grow_dir_ = CENTER;
69 }
70
71 void
72 Audio_span_dynamic::add_absolute (Audio_dynamic *d)
73 {
74   assert (d);
75   dynamics_.push_back (d);
76 }
77
78 static Real
79 moment2real (Moment m)
80 {
81   return m.main_part_.to_double ()
82     + 0.1 * m.grace_part_.to_double ();
83 }
84
85 void
86 Audio_span_dynamic::render ()
87 {
88   if (dynamics_.size () <= 1)
89     return ;
90
91   assert (dynamics_[0]->volume_ >= 0);
92
93   while  (dynamics_.back ()->volume_ > 0
94           && dynamics_.size () > 1
95           && sign (dynamics_.back ()->volume_ - dynamics_[0]->volume_) != grow_dir_)
96     {
97       dynamics_.erase (dynamics_.end () - 1);
98     }
99
100   if (dynamics_.size () <= 1)
101     {
102       programming_error ("(de)crescendo on items with specified volume.");
103       return ;
104     }
105   
106   Real delta_v = grow_dir_ * 0.1;
107   
108   Real start_v = dynamics_[0]->volume_;
109   if (dynamics_.back ()->volume_ < 0)
110     dynamics_.back ()->volume_ = max (min (start_v + grow_dir_ * 0.25, 1.0), 0.0);
111
112   delta_v = dynamics_.back ()->volume_ - dynamics_[0]->volume_;
113
114   Moment start = dynamics_[0]->get_column ()->when ();
115
116   Real total_t = moment2real (dynamics_.back ()->get_column ()->when () - start);
117   
118   for (vsize i = 1; i < dynamics_.size(); i ++)
119     {
120       Moment dt_moment = dynamics_[i]->get_column ()->when ()
121         - start;
122
123       Real dt =  moment2real (dt_moment);
124       
125       Real v = start_v + delta_v *  (dt / total_t);
126
127       dynamics_[i]->volume_ = v;        
128     }
129 }
130
131
132
133 Audio_tempo::Audio_tempo (int per_minute_4)
134 {
135   per_minute_4_ = per_minute_4;
136 }
137
138 Audio_time_signature::Audio_time_signature (int beats, int one_beat)
139 {
140   beats_ = beats;
141   one_beat_ = one_beat;
142 }
143
144 Audio_text::Audio_text (Audio_text::Type type, string text_string)
145 {
146   text_string_ = text_string;
147   type_ = type;
148 }
149