]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
(make-ottava-set): bugfixes: also
[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     }
57
58   last_ottavation_ = ott;
59 }
60
61 void
62 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
63 {
64   Item *it = dynamic_cast<Item*> (info.grob_);
65   if (span_ && it && Note_column::has_interface (info.grob_))
66     {
67       Side_position_interface::add_support (span_, it);
68       if (!span_->get_bound (LEFT))
69         span_->set_bound (LEFT, it);
70       span_->set_bound (RIGHT, it);
71     }
72 }
73
74 void
75 Ottava_spanner_engraver::typeset_all ()
76 {  
77   if (finished_)
78     {
79       Side_position_interface::add_staff_support (finished_);
80
81       Direction d = LEFT;
82       do
83         {
84           if (!finished_->get_bound (RIGHT))
85             {
86               Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
87               finished_->set_bound (d, e);
88             }
89         }
90       while (flip (&d) != LEFT);
91       
92       typeset_grob (finished_);
93       finished_ = 0;
94     }
95 }
96
97 void
98 Ottava_spanner_engraver::stop_translation_timestep ()
99 {
100   if (span_ && !span_->get_bound (LEFT))
101     {
102       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
103       span_->set_bound (LEFT, e);
104     }
105
106   typeset_all ();
107 }
108
109 void
110 Ottava_spanner_engraver::finalize ()
111 {
112   typeset_all ();
113   if (span_)
114     finished_ = span_;
115   typeset_all();
116 }
117
118 ENTER_DESCRIPTION(Ottava_spanner_engraver,
119 /* descr */       "Create a text spanner when the ottavation property changes..",
120 /* creats*/       "OttavaSpanner",
121 /* accepts */     "",
122 /* acks  */      "note-column-interface",
123 /* reads */       "ottavation",
124 /* write */       "");