Doc: Perform fold on itely files for linelength
[lilypond/patrick.git] / lily / ledger-line-engraver.cc
blobbd0a323e97221bbe2bf1bab7bab3945c00d0febe
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "pointer-group-interface.hh"
21 #include "spanner.hh"
22 #include "engraver.hh"
23 #include "staff-symbol.hh"
25 class Ledger_line_engraver : public Engraver
27 Spanner *span_;
28 vector<Grob*> ledgered_grobs_;
30 public:
31 TRANSLATOR_DECLARATIONS (Ledger_line_engraver);
33 protected:
34 virtual void finalize ();
35 void process_music ();
37 DECLARE_ACKNOWLEDGER (ledgered);
38 DECLARE_ACKNOWLEDGER (staff_symbol);
40 void start_spanner ();
41 void stop_spanner ();
42 void stop_translation_timestep ();
45 Ledger_line_engraver::Ledger_line_engraver ()
47 span_ = 0;
50 void
51 Ledger_line_engraver::start_spanner ()
53 assert (!span_);
55 span_ = make_spanner ("LedgerLineSpanner", SCM_EOL);
56 span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
59 void
60 Ledger_line_engraver::stop_translation_timestep ()
62 if (span_)
64 for (vsize i = 0; i < ledgered_grobs_.size (); i++)
66 if (!to_boolean (ledgered_grobs_[i]->get_property ("no-ledgers")))
67 Pointer_group_interface::add_grob (span_,
68 ly_symbol2scm ("note-heads"),
69 ledgered_grobs_[i]);
73 ledgered_grobs_.clear ();
76 void
77 Ledger_line_engraver::process_music ()
80 Need to do this, otherwise the first note might miss ledgers.
82 if (!span_)
83 start_spanner ();
86 void
87 Ledger_line_engraver::finalize ()
89 stop_spanner ();
92 void
93 Ledger_line_engraver::stop_spanner ()
95 if (span_)
97 span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
98 Pointer_group_interface::set_ordered (span_, ly_symbol2scm ("elements"), false);
99 span_ = 0;
103 void
104 Ledger_line_engraver::acknowledge_staff_symbol (Grob_info s)
106 Spanner *sym = dynamic_cast<Spanner *> (s.grob ());
108 if (!span_
109 || (span_->get_bound (LEFT) != sym->get_bound (LEFT)))
111 stop_spanner ();
112 start_spanner ();
116 void
117 Ledger_line_engraver::acknowledge_ledgered (Grob_info s)
119 ledgered_grobs_.push_back (s.grob ());
122 #include "translator.icc"
124 ADD_ACKNOWLEDGER (Ledger_line_engraver, ledgered);
125 ADD_ACKNOWLEDGER (Ledger_line_engraver, staff_symbol);
126 ADD_TRANSLATOR (Ledger_line_engraver,
127 /* doc */
128 "Create the spanner to draw ledger lines, and notices"
129 " objects that need ledger lines.",
131 /* create */
132 "LedgerLineSpanner ",
134 /* read */
137 /* write */