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
)
48 Audio_note
*first
= t
;
51 first
->length_mom_
+= length_mom_
;
55 Audio_key::Audio_key (int acc
, bool major
)
61 Audio_dynamic::Audio_dynamic ()
66 Audio_span_dynamic::Audio_span_dynamic ()
72 Audio_span_dynamic::add_absolute (Audio_dynamic
*d
)
75 dynamics_
.push_back (d
);
79 remap_grace_duration (Moment m
)
81 return Moment (m
.main_part_
+ Rational (9,40) * m
.grace_part_
,
86 moment_to_real (Moment m
)
88 return remap_grace_duration (m
).main_part_
.to_double ();
92 moment_to_ticks (Moment m
)
94 return int (moment_to_real (m
) * 384 * 4);
98 Audio_span_dynamic::render ()
100 if (dynamics_
.size () <= 1)
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.");
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 ()
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
)
153 one_beat_
= one_beat
;
156 Audio_text::Audio_text (Audio_text::Type type
, string text_string
)
158 text_string_
= text_string
;