]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-arpeggio-engraver.cc
* flower/include/pqueue.hh: Derive from std::vector.
[lilypond.git] / lily / span-arpeggio-engraver.cc
1 /*
2   span-arpeggio-engraver.cc -- implement Span_arpeggio_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Han-Wen Nienhuys <hanwen@xs4all.nl>
9 */
10
11 #include "engraver.hh"
12 #include "arpeggio.hh"
13 #include "pointer-group-interface.hh"
14 #include "side-position-interface.hh"
15 #include "staff-symbol-referencer.hh"
16
17 /**
18    Make arpeggios that span multiple staves.  Catch arpeggios, and span a
19    Span_arpeggio over them if we find more than two arpeggios.
20 */
21 class Span_arpeggio_engraver : public Engraver
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Span_arpeggio_engraver);
25   DECLARE_ACKNOWLEDGER (arpeggio);
26
27 protected:
28   void process_acknowledged ();
29   void stop_translation_timestep ();
30
31 private:
32   Item *span_arpeggio_;
33   Link_array__Grob_ arpeggios_;
34 };
35
36 Span_arpeggio_engraver::Span_arpeggio_engraver ()
37 {
38   span_arpeggio_ = 0;
39 }
40
41 void
42 Span_arpeggio_engraver::acknowledge_arpeggio (Grob_info info)
43 {
44   if (info.origin_contexts (this).size ()) // huh? what's this test for? 
45     arpeggios_.push_back (info.grob ());
46 }
47
48 void
49 Span_arpeggio_engraver::process_acknowledged ()
50 {
51   /*
52     connectArpeggios is slightly brusque; we should really read a grob
53     property of the caught non-span arpeggios. That way, we can have
54
55     both non-connected and connected arps in one pianostaff.
56
57   */
58   if (!span_arpeggio_ && arpeggios_.size () > 1
59       && to_boolean (get_property ("connectArpeggios")))
60     span_arpeggio_ = make_item ("Arpeggio", SCM_EOL);
61 }
62
63 void
64 Span_arpeggio_engraver::stop_translation_timestep ()
65 {
66   if (span_arpeggio_)
67     {
68       /*
69         we do this very late, to make sure we also catch `extra'
70         side-pos support like accidentals.
71       */
72       for (vsize j = 0; j < arpeggios_.size (); j++)
73         {
74           extract_grob_set (arpeggios_[j], "stems", stems);
75           for (vsize i = stems.size (); i--;)
76             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("stems"),
77                                                stems[i]);
78
79           extract_grob_set (arpeggios_[j], "side-support-elements", sses);
80           for (vsize i = sses.size (); i--;)
81             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("side-support-elements"),
82                                                sses[i]);
83
84           /*
85             we can't kill the children, since we don't want to the
86             previous note to bump into the span arpeggio; so we make
87             it transparent.  */
88           arpeggios_[j]->set_property ("transparent", SCM_BOOL_T);
89         }
90
91       span_arpeggio_ = 0;
92     }
93   arpeggios_.clear ();
94 }
95
96 #include "translator.icc"
97
98 ADD_ACKNOWLEDGER (Span_arpeggio_engraver, arpeggio);
99 ADD_TRANSLATOR (Span_arpeggio_engraver,
100                 /* doc */ "",
101                 /* create */ "Arpeggio",
102                 /* accept */ "",
103                 /* read */ "connectArpeggios",
104                 /* write */ "");