]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-translator.cc
release: 0.1.24
[lilypond.git] / lily / timing-translator.cc
1
2 /*
3   timing-translator.cc -- implement Timing_translator
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 */
9
10 #include "timing-translator.hh"
11 #include "command-request.hh"
12 #include "translator-group.hh"
13 #include "global-translator.hh"
14
15 Timing_translator::Timing_translator()
16 {
17   default_grouping_ = Rhythmic_grouping (MInterval (0,4),4); // ugh
18 }
19
20 bool
21 Timing_translator::do_try_request(Request*r)
22 {
23   Command_req * c = r->command();
24   if (!(c && c->timing()))
25     return false;
26   for (int i=0; i < timing_req_l_arr_.size (); i++)
27     {
28       if (timing_req_l_arr_[i]->equal_b(r))
29         return true;
30       if (timing_req_l_arr_[i]->name() == r->name())
31         {
32           r->warning (_("conflicting timing request"));
33           return false;
34         }
35     }
36
37   timing_req_l_arr_.push(c->timing());
38   return true;
39 }
40
41 Meter_change_req*
42 Timing_translator::meter_req_l() const
43 {
44   Meter_change_req *m_l=0;
45   for (int i=0; !m_l && i < timing_req_l_arr_.size (); i++)
46     {
47       m_l=timing_req_l_arr_[i]->meterchange();
48     }
49   return m_l;
50 }
51
52 void
53 Timing_translator::do_process_requests()
54 {
55   for (int i=0; i < timing_req_l_arr_.size (); i++)
56     {
57       Timing_req * tr_l = timing_req_l_arr_[i];
58       Meter_change_req *m_l = tr_l->meterchange();
59       if (m_l)
60         {
61           int b_i= m_l->beats_i_;
62           int o_i = m_l->one_beat_i_;
63           if (! time_.allow_meter_change_b())
64             tr_l->warning (_("Meter change not allowed here"));
65           else
66             {
67               time_.set_meter (b_i, o_i);
68               default_grouping_ =
69                 Rhythmic_grouping (MInterval (0,Moment (b_i, o_i)), b_i);
70             }
71         }
72       else if (tr_l->partial())
73         {
74           Moment m = tr_l->partial()->duration_;
75           String error = time_.try_set_partial_str (m);
76           if (error.length_i ())
77             {
78               tr_l->warning (error);
79             }
80           else
81             time_.setpartial (m);
82         }
83       else if (tr_l->barcheck())
84         {
85           if (time_.whole_in_measure_)
86             {
87               tr_l ->warning (_("Barcheck failed"));
88
89               time_.whole_in_measure_ = 0; // resync
90               time_.error_b_ = true;
91             }
92
93         }
94       else if (tr_l->cadenza())
95         {
96           time_.set_cadenza (tr_l->cadenza()->on_b_);
97
98         }
99       else if (tr_l->measuregrouping())
100         {
101           default_grouping_ =
102             parse_grouping (tr_l->measuregrouping()->beat_i_arr_,
103                             tr_l->measuregrouping()->elt_length_arr_);
104
105         }
106     }
107 }
108
109
110 void
111 Timing_translator::do_pre_move_processing()
112 {
113   timing_req_l_arr_.set_size (0);
114   Global_translator *global_l =
115     daddy_trans_l_->ancestor_l (100)->global_l (); // ugh 100.
116
117   if (!time_.cadenza_b_)
118     global_l->add_moment_to_process (time_.next_bar_moment ());
119 }
120
121 IMPLEMENT_IS_TYPE_B1(Timing_translator, Translator);
122 ADD_THIS_TRANSLATOR(Timing_translator);
123
124 void
125 Timing_translator::do_creation_processing()
126 {
127   time_.when_ = now_moment ();
128 }
129
130 void
131 Timing_translator::do_post_move_processing()
132 {
133   time_.add (now_moment ()  - time_.when_);
134 }