]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-arpeggio-engraver.cc
adb465b382f2426f1cfcdaa1005f9c49ecd71934
[lilypond.git] / lily / span-arpeggio-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2011 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8   LilyPond is free software: you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 3 of the License, or
11   (at your option) any later version.
12
13   LilyPond is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "engraver.hh"
23 #include "arpeggio.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26 #include "staff-symbol-referencer.hh"
27 #include "item.hh"
28
29 /**
30    Make arpeggios that span multiple staves.  Catch arpeggios, and span a
31    Span_arpeggio over them if we find more than two arpeggios.
32 */
33 class Span_arpeggio_engraver : public Engraver
34 {
35 public:
36   TRANSLATOR_DECLARATIONS (Span_arpeggio_engraver);
37   DECLARE_ACKNOWLEDGER (arpeggio);
38
39 protected:
40   void process_acknowledged ();
41   void stop_translation_timestep ();
42
43 private:
44   Item *span_arpeggio_;
45   vector<Grob*> arpeggios_;
46 };
47
48 Span_arpeggio_engraver::Span_arpeggio_engraver ()
49 {
50   span_arpeggio_ = 0;
51 }
52
53 void
54 Span_arpeggio_engraver::acknowledge_arpeggio (Grob_info info)
55 {
56   if (info.origin_contexts (this).size ()) // huh? what's this test for? 
57     arpeggios_.push_back (info.grob ());
58 }
59
60 void
61 Span_arpeggio_engraver::process_acknowledged ()
62 {
63   /*
64     connectArpeggios is slightly brusque; we should really read a grob
65     property of the caught non-span arpeggios. That way, we can have
66
67     both non-connected and connected arps in one pianostaff.
68
69   */
70   if (!span_arpeggio_ && arpeggios_.size () > 1
71       && to_boolean (get_property ("connectArpeggios")))
72     {
73       span_arpeggio_ = make_item ("Arpeggio", SCM_EOL);
74       span_arpeggio_->set_property ("cross-staff", SCM_BOOL_T);
75     }
76 }
77
78 void
79 Span_arpeggio_engraver::stop_translation_timestep ()
80 {
81   if (span_arpeggio_)
82     {
83       /*
84         we do this very late, to make sure we also catch `extra'
85         side-pos support like accidentals.
86       */
87       for (vsize j = 0; j < arpeggios_.size (); j++)
88         {
89           extract_grob_set (arpeggios_[j], "stems", stems);
90           for (vsize i = 0; i < stems.size (); i++)
91             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("stems"),
92                                                stems[i]);
93
94           extract_grob_set (arpeggios_[j], "side-support-elements", sses);
95           for (vsize i = 0; i < sses.size (); i++)
96             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("side-support-elements"),
97                                                sses[i]);
98
99           /*
100             we can't kill the children, since we don't want to the
101             previous note to bump into the span arpeggio; so we make
102             it transparent.  */
103           arpeggios_[j]->set_property ("transparent", SCM_BOOL_T);
104         }
105
106
107       span_arpeggio_->set_parent (arpeggios_[0]->get_parent (Y_AXIS), Y_AXIS);
108       span_arpeggio_ = 0;
109     }
110   arpeggios_.clear ();
111 }
112
113 #include "translator.icc"
114
115 ADD_ACKNOWLEDGER (Span_arpeggio_engraver, arpeggio);
116 ADD_TRANSLATOR (Span_arpeggio_engraver,
117                 /* doc */
118                 "Make arpeggios that span multiple staves.",
119
120                 /* create */
121                 "Arpeggio ",
122
123                 /* read */
124                 "connectArpeggios ",
125
126                 /* write */
127                 ""
128                 );