]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
* lily/side-position-interface.cc (out_of_staff): also do
[lilypond.git] / lily / ottava-engraver.cc
1 /*
2   text-spanner-engraver.cc -- implement Ottava_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2003 Han-Wen Nienhuys
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "protected-scm.hh"
11 #include "note-column.hh"
12 #include "item.hh"
13 #include "side-position-interface.hh"
14 #include "engraver.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   virtual void acknowledge_grob (Grob_info);
23   virtual void process_music ();
24   virtual void stop_translation_timestep ();
25 private:
26   Spanner *span_;
27   Spanner *finished_;
28   
29   Protected_scm last_ottavation_;
30   
31   void typeset_all ();
32 };
33
34
35 Ottava_spanner_engraver::Ottava_spanner_engraver ()
36 {
37   finished_ = 0;
38   span_ =0;
39   last_ottavation_ = SCM_EOL;
40 }
41
42 void
43 Ottava_spanner_engraver::process_music ()
44 {
45   SCM ott = get_property ("ottavation");
46   if (ott != last_ottavation_)
47     {
48       finished_= span_;
49       span_ = 0;
50       if (gh_string_p (ott))
51         {
52           span_  = new Spanner (get_property ("OttavaSpanner"));
53           span_->set_grob_property ("edge-text", gh_cons (ott, SCM_EOL));
54           announce_grob (span_, SCM_EOL);
55
56           SCM c0 (get_property ("centralCPosition"));
57           SCM oc0 (get_property ("originalCentralCPosition"));
58           if (scm_less_p (oc0, c0) == SCM_BOOL_T)
59             span_->set_grob_property ("direction", gh_int2scm (DOWN));
60         }
61     }
62   last_ottavation_ = ott;
63 }
64
65 void
66 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
67 {
68   Item *it = dynamic_cast<Item*> (info.grob_);
69   if (span_ && it && Note_column::has_interface (info.grob_))
70     {
71       Side_position_interface::add_support (span_, it);
72       if (!span_->get_bound (LEFT))
73         span_->set_bound (LEFT, it);
74       span_->set_bound (RIGHT, it);
75     }
76 }
77
78 void
79 Ottava_spanner_engraver::typeset_all ()
80 {  
81   if (finished_)
82     {
83       Direction d = LEFT;
84       do
85         {
86           if (!finished_->get_bound (RIGHT))
87             {
88               Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
89               finished_->set_bound (d, e);
90             }
91         }
92       while (flip (&d) != LEFT);
93       
94       typeset_grob (finished_);
95       finished_ = 0;
96     }
97 }
98
99 void
100 Ottava_spanner_engraver::stop_translation_timestep ()
101 {
102   if (span_ && !span_->get_bound (LEFT))
103     {
104       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
105       span_->set_bound (LEFT, e);
106     }
107
108   typeset_all ();
109 }
110
111 void
112 Ottava_spanner_engraver::finalize ()
113 {
114   typeset_all ();
115   if (span_)
116     finished_ = span_;
117   typeset_all();
118 }
119
120 ENTER_DESCRIPTION(Ottava_spanner_engraver,
121 /* descr */       "Create a text spanner when the ottavation property changes..",
122 /* creats*/       "OttavaSpanner",
123 /* accepts */     "",
124 /* acks  */      "note-column-interface",
125 /* reads */       "ottavation",
126 /* write */       "");