]> git.donarmstrong.com Git - lilypond.git/blob - lily/measure-grouping-engraver.cc
* input/regression/new-markup-scheme.ly: oops. font-family=music
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7  */
8
9 #include "warn.hh"
10 #include "side-position-interface.hh"
11 #include "global-context.hh"
12 #include "engraver.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       grouping_->suicide ();
35       grouping_ = 0;
36     }
37 }
38
39
40 void
41 Measure_grouping_engraver::acknowledge_grob (Grob_info gi)
42 {
43   if (grouping_)
44     {
45       Side_position_interface::add_support (grouping_, gi.grob_);
46     }
47 }
48
49 void
50 Measure_grouping_engraver::process_music ()
51 {
52   Moment now = now_mom ();
53   if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
54     {
55       grouping_->set_bound (RIGHT,
56                             unsmob_grob (get_property ("currentMusicalColumn")));
57       
58       grouping_ = 0;
59     }
60   
61   if (now.grace_part_)
62     return; 
63   
64   SCM grouping = get_property ("beatGrouping");
65   if (scm_is_pair (grouping))
66     {
67       Moment *measpos = unsmob_moment (get_property ("measurePosition"));
68       Rational mp = measpos->main_part_;
69       
70       Moment * beatlen = unsmob_moment (get_property ("beatLength"));
71       Rational bl = beatlen->main_part_;
72         
73       Rational where (0);
74       for (SCM s = grouping; scm_is_pair (s);
75            where += Rational ((int) scm_to_int (scm_car (s))) * bl,
76            s = scm_cdr (s)
77            )
78         {
79           int grouplen = scm_to_int (scm_car (s));
80           if (where == mp)
81             {
82               if (grouping_)
83                 {
84                   programming_error ("Huh, last grouping not finished yet.");
85                   continue;
86                 }
87               
88               grouping_ = make_spanner ("MeasureGrouping", SCM_EOL);
89               grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
90               
91
92
93               stop_grouping_mom_ = now.main_part_ + Rational (grouplen - 1) * bl ;
94               get_global_context ()->add_moment_to_process (Moment (stop_grouping_mom_));
95
96               if (grouplen == 3)
97                 grouping_->set_property ("style", ly_symbol2scm ("triangle"));
98               else
99                 grouping_->set_property ("style", ly_symbol2scm ("bracket"));
100               
101               break ; 
102             }
103         }
104     }
105 }
106 Measure_grouping_engraver::Measure_grouping_engraver ()
107 {
108   grouping_ = 0;
109 }
110
111 ADD_TRANSLATOR (Measure_grouping_engraver,
112 /* descr */       "Creates MeasureGrouping to indicate beat subdivision.",
113 /* creats*/       "MeasureGrouping",
114 /* accepts */     "",
115 /* acks  */      "note-column-interface",
116 /* reads */       "beatGrouping beatLength measurePosition currentMusicalColumn",
117 /* write */       "");