2 // lilypond-voice.cc -- implement Lilypond_voice
4 // copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
6 #include "string-convert.hh"
7 #include "midi2ly-global.hh"
8 #include "lilypond-column.hh"
9 #include "lilypond-item.hh"
10 #include "lilypond-staff.hh"
11 #include "lilypond-stream.hh"
12 #include "lilypond-voice.hh"
13 #include "lilypond-score.hh"
15 extern Lilypond_score* lilypond_score_l_g;
17 Lilypond_voice::Lilypond_voice (Lilypond_staff* lilypond_staff_l)
19 lilypond_staff_l_ = lilypond_staff_l;
25 Lilypond_voice::add_item (Lilypond_item* lilypond_item_l)
27 last_item_l_ = lilypond_item_l;
28 if (Lilypond_note* n = dynamic_cast<Lilypond_note*> (lilypond_item_l))
32 lilypond_item_l_list_.append (new Cons<Lilypond_item> (lilypond_item_l, 0));
36 analyse pitches to determine clef.
39 Lilypond_voice::get_clef () const
43 for (Cons<Lilypond_item> *cp = lilypond_item_l_list_.head_; !n && cp; cp = cp->next_)
45 n = dynamic_cast<Lilypond_note*> (cp->car_);
54 return "\\clef \"bass\"\n";
56 return "\\clef \"treble\"\n";
61 static int const FAIRLY_LONG_VOICE_i = 6;
64 Lilypond_voice::output (Lilypond_stream& lilypond_stream_r)
66 lilypond_stream_r << "{ ";
67 if (lilypond_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
68 lilypond_stream_r << '\n';
71 lilypond_stream_r << get_clef () << '\n';
73 int current_bar_i = 0;
74 Rational bar_mom = lilypond_staff_l_->lilypond_time_signature_l_->bar_mom ();
76 for (Cons<Lilypond_item>* i = lilypond_item_l_list_.head_; i; i = i->next_)
78 Rational at_mom = i->car_->lilypond_column_l_->at_mom ();
79 int bar_i = (int) (at_mom / bar_mom) + 1;
80 if (bar_i > current_bar_i)
84 if (at_mom == Rational (bar_i - 1) * bar_mom)
85 lilypond_stream_r << "|";
86 lilypond_stream_r << "\n% ";
87 lilypond_stream_r << String_convert::i2dec_str (bar_i, 0, ' ');
88 lilypond_stream_r << '\n';
90 LOGOUT (NORMAL_ver) << "[" << bar_i << "]" << flush;
91 current_bar_i = bar_i;
94 lilypond_stream_r << *i->car_;
95 if (Lilypond_key* k = dynamic_cast<Lilypond_key*> (i->car_))
96 lilypond_staff_l_->lilypond_key_l_ = lilypond_score_l_g->lilypond_key_l_ = k;
99 if (lilypond_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
100 lilypond_stream_r << '\n';
102 lilypond_stream_r << "} ";