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>
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
;
25 Audio_item::get_column () const
30 Audio_item::Audio_item ()
35 Audio_note::Audio_note (Pitch p
, Moment m
, bool tie_event
, Pitch transposing
)
40 transposing_
= transposing
;
41 tie_event_
= tie_event
;
45 Audio_note::tie_to (Audio_note
*t
, Moment skip
)
48 Audio_note
*first
= t
;
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_
;
57 Audio_key::Audio_key (int acc
, bool major
)
63 Audio_dynamic::Audio_dynamic ()
68 Audio_span_dynamic::Audio_span_dynamic ()
74 Audio_span_dynamic::add_absolute (Audio_dynamic
*d
)
77 dynamics_
.push_back (d
);
81 remap_grace_duration (Moment m
)
83 return Moment (m
.main_part_
+ Rational (9,40) * m
.grace_part_
,
88 moment_to_real (Moment m
)
90 return remap_grace_duration (m
).main_part_
.to_double ();
94 moment_to_ticks (Moment m
)
96 return int (moment_to_real (m
) * 384 * 4);
100 Audio_span_dynamic::render ()
102 if (dynamics_
.size () <= 1)
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.");
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 ()
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
)
155 one_beat_
= one_beat
;
158 Audio_text::Audio_text (Audio_text::Type type
, string text_string
)
160 text_string_
= text_string
;