]> git.donarmstrong.com Git - lilypond.git/blob - midi2ly/mudela-voice.cc
release: 1.3.140
[lilypond.git] / midi2ly / mudela-voice.cc
1 //
2 // mudela-voice.cc -- implement Mudela_voice
3 //
4 // copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
5
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"
14
15 extern Mudela_score* mudela_score_l_g;
16
17 Mudela_voice::Mudela_voice (Mudela_staff* mudela_staff_l)
18 {
19   mudela_staff_l_ = mudela_staff_l;
20   last_item_l_ =0;
21   last_note_l_ =0;
22 }
23
24 void
25 Mudela_voice::add_item (Mudela_item* mudela_item_l)
26 {
27   last_item_l_  = mudela_item_l;
28   if (Mudela_note* n = dynamic_cast<Mudela_note*> (mudela_item_l))
29     {
30       last_note_l_  = n;
31     }
32   mudela_item_l_list_.append (new Cons<Mudela_item> (mudela_item_l, 0));
33 }
34
35 /**
36    analyse pitches to determine clef.
37  */
38 String
39 Mudela_voice::get_clef () const
40 {
41   Mudela_note * n =0;
42
43   for (Cons<Mudela_item> *cp = mudela_item_l_list_.head_; !n && cp; cp = cp->next_)
44     {
45       n = dynamic_cast<Mudela_note*> (cp->car_);
46     }
47   
48   if (!n)
49     return "";
50
51   int p = n->pitch_i_;
52
53   if (p < 56)
54     return "\\clef \"bass\";\n";
55   else if (p > 67)
56     return "\\clef \"treble\";\n";
57   else
58     return "";
59 }
60
61 static int const FAIRLY_LONG_VOICE_i = 6;
62
63 void
64 Mudela_voice::output (Mudela_stream& mudela_stream_r)
65 {
66   mudela_stream_r << "{ ";
67   if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
68     mudela_stream_r << '\n';
69
70
71   mudela_stream_r << get_clef () << '\n';
72   
73   int current_bar_i = 0;
74   Rational bar_mom = mudela_staff_l_->mudela_time_signature_l_->bar_mom ();
75
76   for (Cons<Mudela_item>* i = mudela_item_l_list_.head_; i; i = i->next_)
77     {
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) 
81         {
82           if (current_bar_i) 
83             {
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';
89             }
90           LOGOUT (NORMAL_ver) << "[" << bar_i << "]" << flush; 
91           current_bar_i = bar_i;
92         }
93
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;
97     }
98
99   if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
100     mudela_stream_r << '\n';
101
102   mudela_stream_r << "} ";
103 }
104
105