]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/mudela-voice.cc
release: 0.1.9
[lilypond.git] / mi2mu / mudela-voice.cc
1 //
2 // mudela-voice.cc -- implement Mudela_voice
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
5
6 #include "string-convert.hh"
7 #include "mi2mu-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
14 Mudela_voice::Mudela_voice (Mudela_staff* mudela_staff_l)
15 {
16   mudela_staff_l_ = mudela_staff_l;
17 }
18
19 void
20 Mudela_voice::add_item (Mudela_item* mudela_item_l)
21 {
22   mudela_item_l_list_.bottom().add (mudela_item_l);
23 }
24
25 Moment 
26 Mudela_voice::begin_mom()
27 {
28   return mudela_item_l_list_.size() ? 
29         mudela_item_l_list_.top()->at_mom() : Moment (0);
30 }
31
32 Moment 
33 Mudela_voice::end_mom()
34 {
35   return mudela_item_l_list_.size() ? 
36         mudela_item_l_list_.bottom()->at_mom() : Moment (0);
37 }
38
39 static int const FAIRLY_LONG_VOICE_i = 6;
40
41 void
42 Mudela_voice::output (Mudela_stream& mudela_stream_r)
43 {
44   if  (!mudela_item_l_list_.size())
45         return;
46   
47   if  (mudela_item_l_list_.size() > FAIRLY_LONG_VOICE_i)
48         mudela_stream_r << "\n";
49
50   int current_bar_i = 0;
51   Moment bar_mom = mudela_staff_l_->mudela_meter_p_->bar_mom();
52
53   for  (PCursor<Mudela_item*> i (mudela_item_l_list_); i.ok(); i++) 
54     {
55         Moment at_mom = i->mudela_column_l_->at_mom();
56         int bar_i = (int) (at_mom / bar_mom) + 1;
57         if  (bar_i > current_bar_i) 
58           {
59             if  (current_bar_i) 
60               {
61                 if  (at_mom == Moment (bar_i - 1) * bar_mom)
62                     mudela_stream_r << "|";
63                 mudela_stream_r << "\n% ";
64                 mudela_stream_r << String_convert::i2dec_str (bar_i, 0, ' ');
65                 mudela_stream_r << "\n";
66               }
67             LOGOUT(NORMAL_ver) << '[' << bar_i << ']' << flush; 
68             current_bar_i = bar_i;
69           }
70
71         mudela_stream_r << **i;
72     }
73
74   if  (mudela_item_l_list_.size() > FAIRLY_LONG_VOICE_i)
75         mudela_stream_r << "\n";
76 }
77