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