Mudela_voice::Mudela_voice (Mudela_staff* mudela_staff_l)
{
mudela_staff_l_ = mudela_staff_l;
+ last_item_l_ =0;
}
void
Mudela_voice::add_item (Mudela_item* mudela_item_l)
{
+ last_item_l_ = mudela_item_l;
mudela_item_l_list_.append (new Cons<Mudela_item> (mudela_item_l, 0));
}
+/**
+ analyse pitches to determine clef.
+ */
+String
+Mudela_voice::get_clef () const
+{
+ Mudela_note * n =0;
+
+ for (Cons<Mudela_item> *cp = mudela_item_l_list_.head_; !n && cp; cp = cp->next_)
+ {
+ n = dynamic_cast<Mudela_note*> (cp->car_);
+ }
+
+ if (!n)
+ return "";
+
+ int p = n->pitch_i_;
+
+ if (p < 56)
+ return "\\clef \"bass\";\n";
+ else if (p > 67)
+ return "\\clef \"treble\";\n";
+ else
+ return "";
+}
static int const FAIRLY_LONG_VOICE_i = 6;
void
Mudela_voice::output (Mudela_stream& mudela_stream_r)
{
- if (!mudela_item_l_list_.size_i ())
- return;
-
+ mudela_stream_r << "{ ";
if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
mudela_stream_r << '\n';
+
+ mudela_stream_r << get_clef () << '\n';
+
int current_bar_i = 0;
- Moment bar_mom = mudela_staff_l_->mudela_time_signature_l_->bar_mom ();
+ Rational bar_mom = mudela_staff_l_->mudela_time_signature_l_->bar_mom ();
for (Cons<Mudela_item>* i = mudela_item_l_list_.head_; i; i = i->next_)
{
- Moment at_mom = i->car_->mudela_column_l_->at_mom ();
+ Rational at_mom = i->car_->mudela_column_l_->at_mom ();
int bar_i = (int) (at_mom / bar_mom) + 1;
if (bar_i > current_bar_i)
{
if (current_bar_i)
{
- if (at_mom == Moment (bar_i - 1) * bar_mom)
+ if (at_mom == Rational (bar_i - 1) * bar_mom)
mudela_stream_r << "|";
mudela_stream_r << "\n% ";
mudela_stream_r << String_convert::i2dec_str (bar_i, 0, ' ');
if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
mudela_stream_r << '\n';
+
+ mudela_stream_r << "} ";
}
+