]> git.donarmstrong.com Git - lilypond.git/blob - lily/ledger-line-engraver.cc
(Module): idem.
[lilypond.git] / lily / ledger-line-engraver.cc
1 /*
2   ledger-line-engraver.cc -- implement Ledger_line_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "pointer-group-interface.hh"
10 #include "spanner.hh"
11 #include "engraver.hh"
12 #include "staff-symbol.hh"
13
14 class Ledger_line_engraver : public Engraver
15 {
16   Spanner *span_;
17   vector<Grob*> ledgered_grobs_;
18   
19 public:
20   TRANSLATOR_DECLARATIONS (Ledger_line_engraver);
21
22 protected:
23   virtual void finalize ();
24   void process_music ();
25
26   DECLARE_ACKNOWLEDGER (ledgered);
27   DECLARE_ACKNOWLEDGER (staff_symbol);
28
29   void start_spanner ();
30   void stop_spanner ();
31   void stop_translation_timestep ();
32 };
33
34 Ledger_line_engraver::Ledger_line_engraver ()
35 {
36   span_ = 0;
37 }
38
39 void
40 Ledger_line_engraver::start_spanner ()
41 {
42   assert (!span_);
43
44   span_ = make_spanner ("LedgerLineSpanner", SCM_EOL);
45   span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
46 }
47
48 void
49 Ledger_line_engraver::stop_translation_timestep ()
50 {
51   if (span_)
52     {
53       for (vsize i = 0; i < ledgered_grobs_.size (); i++)
54         {
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]);
59         }
60     }
61
62   ledgered_grobs_.clear ();
63 }
64
65 void
66 Ledger_line_engraver::process_music ()
67 {
68   /*
69     Need to do this, otherwise the first note might miss ledgers. 
70   */
71   if (!span_)
72     start_spanner ();
73 }
74
75 void
76 Ledger_line_engraver::finalize ()
77 {
78   stop_spanner ();
79 }
80
81 void
82 Ledger_line_engraver::stop_spanner ()
83 {
84   if (span_)
85     {
86       span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
87       Pointer_group_interface::set_ordered (span_, ly_symbol2scm ("elements"), false);
88       span_ = 0;
89     }
90 }
91
92 void
93 Ledger_line_engraver::acknowledge_staff_symbol (Grob_info s)
94 {
95   Spanner *sym = dynamic_cast<Spanner *> (s.grob ());
96
97   if (!span_
98       || (span_->get_bound (LEFT) != sym->get_bound (LEFT)))
99     {
100       stop_spanner ();
101       start_spanner ();
102     }
103 }
104
105 void
106 Ledger_line_engraver::acknowledge_ledgered (Grob_info s)
107 {
108   ledgered_grobs_.push_back (s.grob ());
109 }
110
111 #include "translator.icc"
112
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 */ "")