]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-arpeggio-engraver.cc
``slikken kreng''
[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--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "lily-guile.hh"
11 #include "item.hh"
12 #include "arpeggio.hh"
13 #include "group-interface.hh"
14 #include "side-position-interface.hh"
15 #include "staff-symbol-referencer.hh"
16
17
18 /** 
19   Make arpeggios that span multiple staves.  Catch arpeggios, and span a
20   Span_arpeggio over them if we find more than two arpeggios.
21   */
22 class Span_arpeggio_engraver : public Engraver
23 {
24 public:
25   TRANSLATOR_DECLARATIONS(Span_arpeggio_engraver);
26   
27 protected:
28   virtual void acknowledge_grob (Grob_info);
29   virtual void process_acknowledged_grobs ();
30   virtual void stop_translation_timestep ();
31
32 private:
33   Item *span_arpeggio_;
34   Link_array<Grob> arpeggios_;
35 };
36
37
38 Span_arpeggio_engraver::Span_arpeggio_engraver ()
39 {
40   span_arpeggio_ = 0;
41 }
42
43 void
44 Span_arpeggio_engraver::acknowledge_grob (Grob_info info)
45 {
46     if (info.origin_transes (this).size ()
47         && Arpeggio::has_interface (info.grob_))
48     {
49       arpeggios_.push (info.grob_);
50     }
51 }
52
53 void
54 Span_arpeggio_engraver::process_acknowledged_grobs ()
55 {
56   /*
57     connectArpeggios is slightly brusque; we should really read a elt
58     property of the caught non-span arpeggios. That way, we can have
59
60     both non-connected and connected arps in one pianostaff.
61     
62
63   */
64   if (!span_arpeggio_ && arpeggios_.size () > 1
65       && to_boolean (get_property ("connectArpeggios")))
66     {
67       span_arpeggio_ = new Item (get_property ("Arpeggio"));
68       announce_grob(span_arpeggio_, SCM_EOL);      
69     }
70 }
71
72 void
73 Span_arpeggio_engraver::stop_translation_timestep ()
74 {
75   if (span_arpeggio_) 
76     {
77       /*
78         we do this very late, to make sure we also catch `extra'
79         side-pos support like accidentals.
80        */
81       for (int i=0; i < arpeggios_.size (); i ++)
82         {
83           for (SCM s = arpeggios_[i]->get_grob_property ("stems");
84                gh_pair_p (s); s = ly_cdr (s))
85             Group_interface::add_thing (span_arpeggio_, ly_symbol2scm ("stems"), ly_car (s));
86           for (SCM s = arpeggios_[i]->get_grob_property ("side-support-elements");
87                gh_pair_p (s); s = ly_cdr (s))
88             Group_interface::add_thing (span_arpeggio_, ly_symbol2scm ("side-support-elements"), ly_car (s));
89
90           /*
91             we can't kill the children, since we don't want to the
92             previous note to bump into the span arpeggio; so we make
93             it transparent.  */
94           arpeggios_[i]->set_grob_property ("molecule-callback", SCM_EOL);
95         }
96       
97       typeset_grob (span_arpeggio_);
98       span_arpeggio_ = 0;
99     }
100   arpeggios_.clear ();
101 }
102
103
104
105 ENTER_DESCRIPTION(Span_arpeggio_engraver,
106 /* descr */       "",
107 /* creats*/       "Arpeggio",
108 /* acks  */       "arpeggio-interface",
109 /* reads */       "connectArpeggios",
110 /* write */       "");