]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
Add a space-to-barline property to allow looser spacing of clefs.
[lilypond.git] / lily / ottava-engraver.cc
1 /*
2   ottova-engraver.cc -- implement Ottava_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2007 Han-Wen Nienhuys
7 */
8
9 #include "protected-scm.hh"
10 #include "note-column.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
13 #include "spanner.hh"
14 #include "item.hh"
15
16 class Ottava_spanner_engraver : public Engraver
17 {
18 public:
19   TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);
20 protected:
21   virtual void finalize ();
22
23   DECLARE_ACKNOWLEDGER (note_column);
24
25   void process_music ();
26   void stop_translation_timestep ();
27   virtual void derived_mark () const;
28 private:
29   Spanner *span_;
30   Spanner *finished_;
31
32   SCM last_ottavation_;
33
34   void typeset_all ();
35 };
36
37 void
38 Ottava_spanner_engraver::derived_mark () const
39 {
40   scm_gc_mark (last_ottavation_);
41 }
42
43 Ottava_spanner_engraver::Ottava_spanner_engraver ()
44 {
45   finished_ = 0;
46   span_ = 0;
47   last_ottavation_ = SCM_EOL;
48 }
49
50 void
51 Ottava_spanner_engraver::process_music ()
52 {
53   SCM ott = get_property ("ottavation");
54   if (ott != last_ottavation_)
55     {
56       finished_ = span_;
57       span_ = 0;
58       if (scm_is_string (ott))
59         {
60           span_ = make_spanner ("OttavaBracket", SCM_EOL);
61           span_->set_property ("text", ott);
62
63           SCM c0 (get_property ("middleCPosition"));
64           SCM oc0 (get_property ("originalMiddleCPosition"));
65           if (scm_less_p (oc0, c0) == SCM_BOOL_T)
66             span_->set_property ("direction", scm_from_int (DOWN));
67         }
68     }
69   last_ottavation_ = ott;
70 }
71
72 void
73 Ottava_spanner_engraver::acknowledge_note_column (Grob_info info)
74 {
75   Item *it = info.item ();
76   if (span_ && it)
77     {
78       Side_position_interface::add_support (span_, it);
79
80       if (!span_->get_bound (LEFT))
81         span_->set_bound (LEFT, it);
82       span_->set_bound (RIGHT, it);
83     }
84 }
85
86 void
87 Ottava_spanner_engraver::typeset_all ()
88 {
89   if (finished_)
90     {
91       Direction d = LEFT;
92       do
93         {
94           if (!finished_->get_bound (RIGHT))
95             {
96               Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
97               finished_->set_bound (d, e);
98             }
99         }
100       while (flip (&d) != LEFT);
101
102       finished_ = 0;
103     }
104 }
105
106 void
107 Ottava_spanner_engraver::stop_translation_timestep ()
108 {
109   if (span_ && !span_->get_bound (LEFT))
110     {
111       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
112       span_->set_bound (LEFT, e);
113     }
114
115   typeset_all ();
116 }
117
118 void
119 Ottava_spanner_engraver::finalize ()
120 {
121   typeset_all ();
122   if (span_)
123     finished_ = span_;
124   typeset_all ();
125   last_ottavation_ = SCM_EOL;
126 }
127
128 #include "translator.icc"
129
130 ADD_ACKNOWLEDGER (Ottava_spanner_engraver, note_column);
131
132 ADD_TRANSLATOR (Ottava_spanner_engraver,
133                 /* doc */ "Create a text spanner when the ottavation property changes..",
134                 /* create */ "OttavaBracket",
135                 /* read */ "ottavation "
136                 "originalMiddleCPosition "
137                 "currentMusicalColumn "
138                 
139                 ,
140                 
141                 /* write */ "");