2 // mudela-voice.cc -- implement Mudela_voice
4 // copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
6 #include "string-convert.hh"
7 #include "midi2ly-global.hh"
8 #include "mudela-column.hh"
9 #include "mudela-item.hh"
10 #include "mudela-staff.hh"
11 #include "mudela-stream.hh"
12 #include "mudela-voice.hh"
13 #include "mudela-score.hh"
15 extern Mudela_score
* mudela_score_l_g
;
17 Mudela_voice::Mudela_voice (Mudela_staff
* mudela_staff_l
)
19 mudela_staff_l_
= mudela_staff_l
;
25 Mudela_voice::add_item (Mudela_item
* mudela_item_l
)
27 last_item_l_
= mudela_item_l
;
28 if (Mudela_note
* n
= dynamic_cast<Mudela_note
*> (mudela_item_l
))
32 mudela_item_l_list_
.append (new Cons
<Mudela_item
> (mudela_item_l
, 0));
36 analyse pitches to determine clef.
39 Mudela_voice::get_clef () const
43 for (Cons
<Mudela_item
> *cp
= mudela_item_l_list_
.head_
; !n
&& cp
; cp
= cp
->next_
)
45 n
= dynamic_cast<Mudela_note
*> (cp
->car_
);
54 return "\\clef \"bass\";\n";
56 return "\\clef \"treble\";\n";
61 static int const FAIRLY_LONG_VOICE_i
= 6;
64 Mudela_voice::output (Mudela_stream
& mudela_stream_r
)
66 mudela_stream_r
<< "{ ";
67 if (mudela_item_l_list_
.size_i () > FAIRLY_LONG_VOICE_i
)
68 mudela_stream_r
<< '\n';
71 mudela_stream_r
<< get_clef () << '\n';
73 int current_bar_i
= 0;
74 Rational bar_mom
= mudela_staff_l_
->mudela_time_signature_l_
->bar_mom ();
76 for (Cons
<Mudela_item
>* i
= mudela_item_l_list_
.head_
; i
; i
= i
->next_
)
78 Rational at_mom
= i
->car_
->mudela_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 mudela_stream_r
<< "|";
86 mudela_stream_r
<< "\n% ";
87 mudela_stream_r
<< String_convert::i2dec_str (bar_i
, 0, ' ');
88 mudela_stream_r
<< '\n';
90 LOGOUT (NORMAL_ver
) << "[" << bar_i
<< "]" << flush
;
91 current_bar_i
= bar_i
;
94 mudela_stream_r
<< *i
->car_
;
95 if (Mudela_key
* k
= dynamic_cast<Mudela_key
*> (i
->car_
))
96 mudela_staff_l_
->mudela_key_l_
= mudela_score_l_g
->mudela_key_l_
= k
;
99 if (mudela_item_l_list_
.size_i () > FAIRLY_LONG_VOICE_i
)
100 mudela_stream_r
<< '\n';
102 mudela_stream_r
<< "} ";