]> git.donarmstrong.com Git - lilypond.git/blob - lily/ottava-engraver.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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--2004 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
14 class Ottava_spanner_engraver : public Engraver
15 {
16 public:
17   TRANSLATOR_DECLARATIONS (Ottava_spanner_engraver);  
18 protected:
19   virtual void finalize ();
20   virtual void acknowledge_grob (Grob_info);
21   virtual void process_music ();
22   virtual void stop_translation_timestep ();
23   virtual void derived_mark () const;
24 private:
25   Spanner *span_;
26   Spanner *finished_;
27   
28   SCM last_ottavation_;
29   
30   void typeset_all ();
31 };
32
33 void
34 Ottava_spanner_engraver::derived_mark () const
35 {
36   scm_gc_mark (last_ottavation_ );
37 }
38
39 Ottava_spanner_engraver::Ottava_spanner_engraver ()
40 {
41   finished_ = 0;
42   span_ =0;
43   last_ottavation_ = SCM_EOL;
44 }
45
46 void
47 Ottava_spanner_engraver::process_music ()
48 {
49   SCM ott = get_property ("ottavation");
50   if (ott != last_ottavation_)
51     {
52       finished_= span_;
53       span_ = 0;
54       if (scm_is_string (ott))
55         {
56           span_  = make_spanner ("OttavaBracket", SCM_EOL);
57           span_->set_property ("text", ott);
58           
59
60           SCM c0 (get_property ("middleCPosition"));
61           SCM oc0 (get_property ("originalCentralCPosition"));
62           if (scm_less_p (oc0, c0) == SCM_BOOL_T)
63             span_->set_property ("direction", scm_int2num (DOWN));
64         }
65     }
66   last_ottavation_ = ott;
67 }
68
69 void
70 Ottava_spanner_engraver::acknowledge_grob (Grob_info info)
71 {
72   Item *it = dynamic_cast<Item*> (info.grob_);
73   if (span_ && it && Note_column::has_interface (info.grob_))
74     {
75       Side_position_interface::add_support (span_, it);
76
77       if (!span_->get_bound (LEFT))
78         span_->set_bound (LEFT, it);
79       span_->set_bound (RIGHT, it);
80     }
81 }
82
83 void
84 Ottava_spanner_engraver::typeset_all ()
85 {  
86   if (finished_)
87     {
88       Direction d = LEFT;
89       do
90         {
91           if (!finished_->get_bound (RIGHT))
92             {
93               Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
94               finished_->set_bound (d, e);
95             }
96         }
97       while (flip (&d) != LEFT);
98       
99       finished_ = 0;
100     }
101 }
102
103 void
104 Ottava_spanner_engraver::stop_translation_timestep ()
105 {
106   if (span_ && !span_->get_bound (LEFT))
107     {
108       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
109       span_->set_bound (LEFT, e);
110     }
111
112   typeset_all ();
113 }
114
115 void
116 Ottava_spanner_engraver::finalize ()
117 {
118   typeset_all ();
119   if (span_)
120     finished_ = span_;
121   typeset_all ();
122   last_ottavation_ = SCM_EOL;
123 }
124
125 ENTER_DESCRIPTION (Ottava_spanner_engraver,
126 /* descr */       "Create a text spanner when the ottavation property changes..",
127 /* creats*/       "OttavaBracket",
128 /* accepts */     "",
129 /* acks  */      "note-column-interface",
130 /* reads */       "ottavation",
131 /* write */       "");