]> git.donarmstrong.com Git - lilypond.git/blob - midi2ly/mudela-voice.cc
release: 1.3.18
[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 }
22
23 void
24 Mudela_voice::add_item (Mudela_item* mudela_item_l)
25 {
26   last_item_l_  = mudela_item_l;
27   mudela_item_l_list_.append (new Cons<Mudela_item> (mudela_item_l, 0));
28 }
29
30 /**
31    analyse pitches to determine clef.
32  */
33 String
34 Mudela_voice::get_clef () const
35 {
36   Mudela_note * n =0;
37
38   for (Cons<Mudela_item> *cp = mudela_item_l_list_.head_; !n && cp; cp = cp->next_)
39     {
40       n = dynamic_cast<Mudela_note*> (cp->car_);
41     }
42   
43   if (!n)
44     return "";
45
46   int p = n->pitch_i_;
47
48   if (p < 56)
49     return "\\clef \"bass\";\n";
50   else if (p > 67)
51     return "\\clef \"treble\";\n";
52   else
53     return "";
54 }
55
56 static int const FAIRLY_LONG_VOICE_i = 6;
57
58 void
59 Mudela_voice::output (Mudela_stream& mudela_stream_r)
60 {
61   mudela_stream_r << "{ ";
62   if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
63     mudela_stream_r << '\n';
64
65
66   mudela_stream_r << get_clef () << '\n';
67   
68   int current_bar_i = 0;
69   Rational bar_mom = mudela_staff_l_->mudela_time_signature_l_->bar_mom ();
70
71   for (Cons<Mudela_item>* i = mudela_item_l_list_.head_; i; i = i->next_)
72     {
73       Rational at_mom = i->car_->mudela_column_l_->at_mom ();
74       int bar_i = (int) (at_mom / bar_mom) + 1;
75       if (bar_i > current_bar_i) 
76         {
77           if (current_bar_i) 
78             {
79               if (at_mom == Rational (bar_i - 1) * bar_mom)
80                 mudela_stream_r << "|";
81               mudela_stream_r << "\n% ";
82               mudela_stream_r << String_convert::i2dec_str (bar_i, 0, ' ');
83               mudela_stream_r << '\n';
84             }
85           LOGOUT (NORMAL_ver) << "[" << bar_i << "]" << flush; 
86           current_bar_i = bar_i;
87         }
88
89       mudela_stream_r << *i->car_;
90       if (Mudela_key* k = dynamic_cast<Mudela_key*> (i->car_))
91         mudela_staff_l_->mudela_key_l_ = mudela_score_l_g->mudela_key_l_ = k;
92     }
93
94   if (mudela_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
95     mudela_stream_r << '\n';
96
97   mudela_stream_r << "} ";
98 }
99
100