]> git.donarmstrong.com Git - lilypond.git/blob - lily/measure-grouping-engraver.cc
* lily/lookup.cc (triangle): new function.
[lilypond.git] / lily / measure-grouping-engraver.cc
1 /*   
2   measure-grouping-engraver.cc --  implement Measure_grouping_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7  */
8
9 #include "score-engraver.hh"
10 #include "spanner.hh"
11 #include "warn.hh"
12 #include "side-position-interface.hh"
13
14 class Measure_grouping_engraver : public Engraver
15 {
16 public:
17   TRANSLATOR_DECLARATIONS(Measure_grouping_engraver);
18
19 protected:
20   Spanner * grouping_;
21   Rational stop_grouping_mom_;
22
23   virtual void start_translation_timestep ();
24   virtual void finalize ();
25   virtual void acknowledge_grob (Grob_info);
26 };
27
28 void
29 Measure_grouping_engraver::finalize()
30 {
31   if (grouping_)
32     {
33       grouping_->set_bound (RIGHT,
34                             unsmob_grob (get_property ("currentCommandColumn")));
35       typeset_grob (grouping_);
36       grouping_= 0;
37     }
38 }
39
40
41 void
42 Measure_grouping_engraver::acknowledge_grob (Grob_info gi)
43 {
44   if (grouping_)
45     {
46       Side_position_interface::add_support (grouping_, gi.grob_);
47     }
48 }
49
50 void
51 Measure_grouping_engraver::start_translation_timestep ()
52 {
53   Moment now = now_mom();
54   if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
55     {
56       Side_position_interface::add_staff_support (grouping_);
57       grouping_->set_bound (RIGHT,
58                             unsmob_grob (get_property ("currentMusicalColumn")));
59       typeset_grob (grouping_);
60       grouping_ = 0;
61     }
62   
63   if (now.grace_part_)
64     return; 
65   
66   SCM grouping = get_property ("beatGrouping");
67   if (gh_pair_p (grouping))
68     {
69       Moment *measpos = unsmob_moment (get_property ("measurePosition"));
70       Rational mp = measpos->main_part_;
71       
72       Moment * beatlen = unsmob_moment (get_property ("beatLength"));
73       Rational bl = beatlen->main_part_;
74         
75       Rational where (0);
76       for (SCM s = grouping; gh_pair_p (s);
77            where += Rational (gh_scm2int (gh_car (s))) * bl,
78            s = gh_cdr (s)
79            )
80         {
81           int grouplen = gh_scm2int (gh_car(s));
82           if (where == mp)
83             {
84               if (grouping_)
85                 {
86                   programming_error ("Huh, last grouping not finished yet.");
87                   continue;
88                 }
89               
90               grouping_ = new Spanner (get_property ("MeasureGrouping"));
91               grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
92               announce_grob (grouping_, SCM_EOL);
93
94
95               stop_grouping_mom_ = now.main_part_ + Rational(grouplen - 1) * bl ;
96               top_engraver ()->add_moment_to_process (Moment (stop_grouping_mom_));
97
98               if (grouplen == 3)
99                 grouping_->set_grob_property ("type", ly_symbol2scm ("triangle"));
100               else
101                 grouping_->set_grob_property ("type", ly_symbol2scm ("bracket"));
102               
103               break ; 
104             }
105         }
106     }
107 }
108 Measure_grouping_engraver::Measure_grouping_engraver()
109 {
110   grouping_ = 0;
111 }
112
113 ENTER_DESCRIPTION(Measure_grouping_engraver,
114 /* descr */       "Creates Measure_grouping objects using beatGrouping property",
115 /* creats*/       "MeasureGrouping",
116 /* accepts */     "",
117 /* acks  */      "note-column-interface",
118 /* reads */       "beatGrouping beatLength measurePosition currentMusicalColumn",
119 /* write */       "");