]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
* scm/define-grobs.scm: uniform naming for definitions and output
[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 }
40
41 void
42 Ottava_spanner_engraver::process_music ()
43 {
44   SCM ott = get_property ("ottavation");
45   if (ott != last_ottavation_)
46     {
47       finished_= span_;
48       span_ = 0;
49       if (gh_string_p (ott))
50         {
51           span_  = new Spanner (get_property ("OttavaSpanner"));
52           span_->set_grob_property ("edge-text", gh_cons (ott, SCM_EOL));
53           announce_grob (span_, SCM_EOL);
54         }
55     }
56
57   last_ottavation_ = ott;
58 }
59
60 void
61 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
62 {
63   Item *it = dynamic_cast<Item*> (info.grob_);
64   if (span_ && it && Note_column::has_interface (info.grob_))
65     {
66       Side_position_interface::add_support (span_, it);
67       if (!span_->get_bound (LEFT))
68         span_->set_bound (LEFT, it);
69       span_->set_bound (RIGHT, it);
70     }
71 }
72
73 void
74 Ottava_spanner_engraver::typeset_all ()
75 {  
76   if (finished_)
77     {
78       Side_position_interface::add_staff_support (finished_);
79
80       Direction d = LEFT;
81       do
82         {
83           if (!finished_->get_bound (RIGHT))
84             {
85               Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
86               finished_->set_bound (d, e);
87             }
88         }
89       while (flip (&d) != LEFT);
90       
91       typeset_grob (finished_);
92       finished_ = 0;
93     }
94 }
95
96 void
97 Ottava_spanner_engraver::stop_translation_timestep ()
98 {
99   if (span_ && !span_->get_bound (LEFT))
100     {
101       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
102       span_->set_bound (LEFT, e);
103     }
104
105   typeset_all ();
106 }
107
108 void
109 Ottava_spanner_engraver::finalize ()
110 {
111   typeset_all ();
112   if (span_)
113     finished_ = span_;
114   typeset_all();
115 }
116
117 ENTER_DESCRIPTION(Ottava_spanner_engraver,
118 /* descr */       "Create a text spanner when the ottavation property changes..",
119 /* creats*/       "OttavaSpanner",
120 /* accepts */     "",
121 /* acks  */      "note-column-interface",
122 /* reads */       "ottavation",
123 /* write */       "");