]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-translator.cc
ce04be40a97f4e25c60fab59d08b3c8348994cb4
[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--1998 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 #include "multi-measure-rest.hh"
15
16 Timing_translator::Timing_translator ()
17 {
18   default_grouping_ = Rhythmic_grouping (MInterval (0, 1), 4); // ugh
19 }
20
21 bool
22 Timing_translator::do_try_request(Request*r)
23 {
24   Command_req * c = r->command();
25   if (!(c && c->timing()))
26     return false;
27   for (int i=0; i < timing_req_l_arr_.size (); i++)
28     {
29       if (timing_req_l_arr_[i]->equal_b(r))
30         return true;
31       if (timing_req_l_arr_[i]->name() == r->name())
32         {
33           r->warning (_("conflicting timing request"));
34           return false;
35         }
36     }
37
38   timing_req_l_arr_.push(c->timing());
39   return true;
40 }
41
42 Meter_change_req*
43 Timing_translator::meter_req_l() const
44 {
45   Meter_change_req *m_l=0;
46   for (int i=0; !m_l && i < timing_req_l_arr_.size (); i++)
47     {
48       m_l=timing_req_l_arr_[i]->meterchange();
49     }
50   return m_l;
51 }
52
53 void
54 Timing_translator::do_process_requests()
55 {
56   for (int i=0; i < timing_req_l_arr_.size (); i++)
57     {
58       Timing_req * tr_l = timing_req_l_arr_[i];
59       Meter_change_req *m_l = tr_l->meterchange();
60       if (m_l)
61         {
62           int b_i= m_l->beats_i_;
63           int o_i = m_l->one_beat_i_;
64           if (! time_.allow_meter_change_b())
65             tr_l->warning (_("Meter change not allowed here"));
66           else
67             {
68               time_.set_meter (b_i, o_i);
69               default_grouping_ =
70                 Rhythmic_grouping (MInterval (0,Moment (b_i, o_i)), b_i);
71             }
72         }
73       else if (tr_l->partial())
74         {
75           Moment m = tr_l->partial()->duration_;
76           String error = time_.try_set_partial_str (m);
77           if (error.length_i ())
78             {
79               tr_l->warning (error);
80             }
81           else
82             time_.setpartial (m);
83         }
84       else if (tr_l->barcheck())
85         {
86           if (time_.whole_in_measure_)
87             {
88               tr_l ->warning (_("Barcheck failed"));
89
90               time_.whole_in_measure_ = 0; // resync
91               time_.error_b_ = true;
92             }
93
94         }
95       else if (tr_l->cadenza())
96         {
97           time_.set_cadenza (tr_l->cadenza()->on_b_);
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
118   bool allbars = ! get_property ("SkipBars").to_bool ();
119   if (!time_.cadenza_b_ && allbars)
120     global_l->add_moment_to_process (time_.next_bar_moment ());
121 }
122
123 IMPLEMENT_IS_TYPE_B1(Timing_translator, Translator);
124 ADD_THIS_TRANSLATOR(Timing_translator);
125
126 void
127 Timing_translator::do_creation_processing()
128 {
129   time_.when_ = now_moment ();
130 }
131
132 void
133 Timing_translator::do_post_move_processing()
134 {
135   time_.add (now_moment ()  - time_.when_);
136 }
137
138 void
139 Timing_translator::do_print () const
140 {
141 #ifndef NPRINT
142   time_.print ();
143   default_grouping_.print ();
144 #endif
145 }