]> git.donarmstrong.com Git - lilypond.git/blob - lily/measure-grouping-engraver.cc
* scm/define-grob-properties.scm: remove 'type
[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--2003 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 process_music ();
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, unsmob_grob (get_property ("currentCommandColumn")));
34       typeset_grob (grouping_);
35       grouping_->suicide ();
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::process_music ()
52 {
53   Moment now = now_mom();
54   if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
55     {
56       grouping_->set_bound (RIGHT,
57                             unsmob_grob (get_property ("currentMusicalColumn")));
58       typeset_grob (grouping_);
59       grouping_ = 0;
60     }
61   
62   if (now.grace_part_)
63     return; 
64   
65   SCM grouping = get_property ("beatGrouping");
66   if (gh_pair_p (grouping))
67     {
68       Moment *measpos = unsmob_moment (get_property ("measurePosition"));
69       Rational mp = measpos->main_part_;
70       
71       Moment * beatlen = unsmob_moment (get_property ("beatLength"));
72       Rational bl = beatlen->main_part_;
73         
74       Rational where (0);
75       for (SCM s = grouping; gh_pair_p (s);
76            where += Rational (gh_scm2int (gh_car (s))) * bl,
77            s = gh_cdr (s)
78            )
79         {
80           int grouplen = gh_scm2int (gh_car(s));
81           if (where == mp)
82             {
83               if (grouping_)
84                 {
85                   programming_error ("Huh, last grouping not finished yet.");
86                   continue;
87                 }
88               
89               grouping_ = new Spanner (get_property ("MeasureGrouping"));
90               grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
91               announce_grob (grouping_, SCM_EOL);
92
93
94               stop_grouping_mom_ = now.main_part_ + Rational(grouplen - 1) * bl ;
95               top_engraver ()->add_moment_to_process (Moment (stop_grouping_mom_));
96
97               if (grouplen == 3)
98                 grouping_->set_grob_property ("style", ly_symbol2scm ("triangle"));
99               else
100                 grouping_->set_grob_property ("style", ly_symbol2scm ("bracket"));
101               
102               break ; 
103             }
104         }
105     }
106 }
107 Measure_grouping_engraver::Measure_grouping_engraver()
108 {
109   grouping_ = 0;
110 }
111
112 ENTER_DESCRIPTION(Measure_grouping_engraver,
113 /* descr */       "Creates Measure_grouping objects using beatGrouping property",
114 /* creats*/       "MeasureGrouping",
115 /* accepts */     "",
116 /* acks  */      "note-column-interface",
117 /* reads */       "beatGrouping beatLength measurePosition currentMusicalColumn",
118 /* write */       "");