]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-arpeggio-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / span-arpeggio-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 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 "item.hh"
25 #include "pointer-group-interface.hh"
26 #include "separation-item.hh"
27 #include "side-position-interface.hh"
28 #include "staff-symbol-referencer.hh"
29
30 #include "translator.icc"
31
32 /**
33    Make arpeggios that span multiple staves.  Catch arpeggios, and span a
34    Span_arpeggio over them if we find more than two arpeggios.
35 */
36 class Span_arpeggio_engraver : public Engraver
37 {
38 public:
39   TRANSLATOR_DECLARATIONS (Span_arpeggio_engraver);
40   void acknowledge_arpeggio (Grob_info);
41   void acknowledge_note_column (Grob_info);
42
43 protected:
44   void process_acknowledged ();
45   void stop_translation_timestep ();
46
47 private:
48   Item *span_arpeggio_;
49   vector<Grob *> arpeggios_;
50   vector<Grob *> note_columns_;
51 };
52
53 Span_arpeggio_engraver::Span_arpeggio_engraver (Context *c)
54   : Engraver (c)
55 {
56   span_arpeggio_ = 0;
57 }
58
59 void
60 Span_arpeggio_engraver::acknowledge_arpeggio (Grob_info info)
61 {
62   if (info.origin_contexts (this).size ()) // huh? what's this test for?
63     arpeggios_.push_back (info.grob ());
64 }
65
66 void
67 Span_arpeggio_engraver::acknowledge_note_column (Grob_info info)
68 {
69   note_columns_.push_back (info.grob ());
70 }
71
72 void
73 Span_arpeggio_engraver::process_acknowledged ()
74 {
75   /*
76     connectArpeggios is slightly brusque; we should really read a grob
77     property of the caught non-span arpeggios. That way, we can have
78
79     both non-connected and connected arps in one pianostaff.
80
81   */
82   if (!span_arpeggio_ && arpeggios_.size () > 1
83       && to_boolean (get_property ("connectArpeggios")))
84     span_arpeggio_ = make_item ("Arpeggio", SCM_EOL);
85
86   if (span_arpeggio_)
87     {
88       for (vsize i = 0; i < note_columns_.size (); i++)
89         Separation_item::add_conditional_item (note_columns_[i], span_arpeggio_);
90       note_columns_.clear ();
91     }
92 }
93
94 void
95 Span_arpeggio_engraver::stop_translation_timestep ()
96 {
97   if (span_arpeggio_)
98     {
99       /*
100         we do this very late, to make sure we also catch `extra'
101         side-pos support like accidentals.
102       */
103       for (vsize j = 0; j < arpeggios_.size (); j++)
104         {
105           extract_grob_set (arpeggios_[j], "stems", stems);
106           for (vsize i = 0; i < stems.size (); i++)
107             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("stems"),
108                                                stems[i]);
109
110           extract_grob_set (arpeggios_[j], "side-support-elements", sses);
111           for (vsize i = 0; i < sses.size (); i++)
112             Pointer_group_interface::add_grob (span_arpeggio_, ly_symbol2scm ("side-support-elements"),
113                                                sses[i]);
114
115           /*
116             we can't kill the children, since we don't want to the
117             previous note to bump into the span arpeggio; so we make
118             it transparent.  */
119           arpeggios_[j]->set_property ("transparent", SCM_BOOL_T);
120         }
121
122       span_arpeggio_->set_parent (arpeggios_[0]->get_parent (Y_AXIS), Y_AXIS);
123       span_arpeggio_ = 0;
124     }
125   arpeggios_.clear ();
126   note_columns_.clear ();
127 }
128
129 void
130 Span_arpeggio_engraver::boot ()
131 {
132   ADD_ACKNOWLEDGER (Span_arpeggio_engraver, arpeggio);
133   ADD_ACKNOWLEDGER (Span_arpeggio_engraver, note_column);
134 }
135
136 ADD_TRANSLATOR (Span_arpeggio_engraver,
137                 /* doc */
138                 "Make arpeggios that span multiple staves.",
139
140                 /* create */
141                 "Arpeggio ",
142
143                 /* read */
144                 "connectArpeggios ",
145
146                 /* write */
147                 ""
148                );