Format and improve documentation of internal grob properties.
[lilypond.git] / lily / ledger-line-engraver.cc
blobecff48a7b86bcc457c9f41725a6b61caacd5126c
1 /*
2 ledger-line-engraver.cc -- implement Ledger_line_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "pointer-group-interface.hh"
10 #include "spanner.hh"
11 #include "engraver.hh"
12 #include "staff-symbol.hh"
14 class Ledger_line_engraver : public Engraver
16 Spanner *span_;
17 vector<Grob*> ledgered_grobs_;
19 public:
20 TRANSLATOR_DECLARATIONS (Ledger_line_engraver);
22 protected:
23 virtual void finalize ();
24 void process_music ();
26 DECLARE_ACKNOWLEDGER (ledgered);
27 DECLARE_ACKNOWLEDGER (staff_symbol);
29 void start_spanner ();
30 void stop_spanner ();
31 void stop_translation_timestep ();
34 Ledger_line_engraver::Ledger_line_engraver ()
36 span_ = 0;
39 void
40 Ledger_line_engraver::start_spanner ()
42 assert (!span_);
44 span_ = make_spanner ("LedgerLineSpanner", SCM_EOL);
45 span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
48 void
49 Ledger_line_engraver::stop_translation_timestep ()
51 if (span_)
53 for (vsize i = 0; i < ledgered_grobs_.size (); i++)
55 if (!to_boolean (ledgered_grobs_[i]->get_property ("no-ledgers")))
56 Pointer_group_interface::add_grob (span_,
57 ly_symbol2scm ("note-heads"),
58 ledgered_grobs_[i]);
62 ledgered_grobs_.clear ();
65 void
66 Ledger_line_engraver::process_music ()
69 Need to do this, otherwise the first note might miss ledgers.
71 if (!span_)
72 start_spanner ();
75 void
76 Ledger_line_engraver::finalize ()
78 stop_spanner ();
81 void
82 Ledger_line_engraver::stop_spanner ()
84 if (span_)
86 span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
87 Pointer_group_interface::set_ordered (span_, ly_symbol2scm ("elements"), false);
88 span_ = 0;
92 void
93 Ledger_line_engraver::acknowledge_staff_symbol (Grob_info s)
95 Spanner *sym = dynamic_cast<Spanner *> (s.grob ());
97 if (!span_
98 || (span_->get_bound (LEFT) != sym->get_bound (LEFT)))
100 stop_spanner ();
101 start_spanner ();
105 void
106 Ledger_line_engraver::acknowledge_ledgered (Grob_info s)
108 ledgered_grobs_.push_back (s.grob ());
111 #include "translator.icc"
113 ADD_ACKNOWLEDGER (Ledger_line_engraver, ledgered);
114 ADD_ACKNOWLEDGER (Ledger_line_engraver, staff_symbol);
115 ADD_TRANSLATOR (Ledger_line_engraver,
116 "Creates the spanner to draw ledger lines, and notices objects that need ledger lines",
117 /* create */ "LedgerLineSpanner",
118 /* read */ "",
119 /* write */ "")