]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-engraver.cc
release: 1.1.47
[lilypond.git] / lily / tuplet-engraver.cc
1 /*   
2   auto-plet-engraver.cc --  implement Auto_plet_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "tuplet-engraver.hh"
11 #include "command-request.hh"
12 #include "tuplet-spanner.hh"
13 #include "note-column.hh"
14 #include "time-scaled-music.hh"
15 #include "beam.hh"
16 #include "music-list.hh"
17
18 bool
19 Tuplet_engraver::do_try_music (Music *r)
20 {
21   if (Time_scaled_music * c = dynamic_cast<Time_scaled_music *> (r))
22     {
23       Music *el = c->element_l ();
24       if (!dynamic_cast<Request_chord*> (el))
25         {
26           time_scaled_music_arr_.push (c);
27           stop_moments_.push (now_mom () + c->length_mom ());
28         }
29       return true;
30     }
31   return false;
32 }
33
34 void
35 Tuplet_engraver::do_process_requests ()
36 {
37   int dir = 0;
38   Scalar prop = get_property ("tupletDirection", 0);
39   if (prop.isnum_b())
40     dir = (int)prop;
41   int visibility = 3;
42   prop = get_property ("tupletVisibility", 0);
43   if (prop.isnum_b())
44     visibility = (int)prop;
45
46   for (int i= started_span_p_arr_.size ();
47        i < time_scaled_music_arr_.size (); i++)
48     {
49       Tuplet_spanner* glep = new Tuplet_spanner;
50       started_span_p_arr_.push (glep);
51       glep->number_str_ = to_str (time_scaled_music_arr_[i]->den_i_);
52       glep->set_elt_property(tuplet_visibility_scm_sym,
53                              gh_int2scm (visibility));
54       if (dir != 0)
55         glep->set_elt_property(dir_forced_scm_sym, gh_int2scm (dir));
56       announce_element (Score_element_info (glep, time_scaled_music_arr_ [i]));
57     }
58 }
59
60 void
61 Tuplet_engraver::acknowledge_element (Score_element_info i)
62 {
63   if (Note_column *nc = dynamic_cast<Note_column *> (i.elem_l_))
64     {
65       for (int j =0; j  <started_span_p_arr_.size (); j++)
66         started_span_p_arr_[j]->add_column (nc);
67     }
68   else if (Beam *b = dynamic_cast<Beam *> (i.elem_l_))
69     {
70       for (int j = 0; j < started_span_p_arr_.size (); j++)
71         started_span_p_arr_[j]->add_beam (b);
72     }
73 }
74
75 void
76 Tuplet_engraver::do_post_move_processing ()
77 {
78   Moment now = now_mom ();
79   for (int i= started_span_p_arr_.size (); i--; )
80     {
81       if (now >= stop_moments_[i])
82         {
83           typeset_element (started_span_p_arr_[i]);
84           started_span_p_arr_.del (i);
85           stop_moments_.del(i);
86           time_scaled_music_arr_.del(i);
87         }
88     }
89 }
90
91 void
92 Tuplet_engraver::do_removal_processing ()
93 {
94   for (int i=0; i < started_span_p_arr_.size (); i++)
95     {
96       typeset_element (started_span_p_arr_[i]);
97     }  
98 }
99
100 ADD_THIS_TRANSLATOR(Tuplet_engraver);
101