WEB: Found more hardcoded names, yay! Fix linking to essay, images in essay.
[lilypond/patrick.git] / lily / bend-engraver.cc
blob3a08a4553298b8998d67658cdf615e1e2ceadb93
1 /*
2 bend-engraver.cc -- implement Bend_engraver
4 (c) 2006--2009 Han-Wen Nienhuys
7 */
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "moment.hh"
12 #include "spanner.hh"
13 #include "stream-event.hh"
15 #include "translator.icc"
17 class Bend_engraver : public Engraver
19 public:
20 TRANSLATOR_DECLARATIONS (Bend_engraver);
21 DECLARE_ACKNOWLEDGER (note_head);
23 protected:
24 DECLARE_TRANSLATOR_LISTENER (bend_after);
25 void finalize ();
26 void process_music ();
27 void stop_translation_timestep ();
28 void start_translation_timestep ();
29 void stop_fall ();
31 private:
32 Moment stop_moment_;
33 Stream_event *fall_event_;
34 Spanner *fall_;
35 Spanner *last_fall_;
36 Grob *note_head_;
39 void
40 Bend_engraver::finalize ()
42 // We shouldn't end a spanner on the last musical column of a piece because then
43 // it would extend past the last breakable column of the piece.
44 if (last_fall_)
45 last_fall_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
48 void
49 Bend_engraver::stop_fall ()
51 bool bar = scm_is_string (get_property ("whichBar"));
54 fall_->set_bound (RIGHT, unsmob_grob (bar
55 ? get_property ("currentCommandColumn")
56 : get_property ("currentMusicalColumn")));
57 last_fall_ = fall_;
58 fall_ = 0;
59 note_head_ = 0;
60 fall_event_ = 0;
63 void
64 Bend_engraver::stop_translation_timestep ()
66 if (fall_ && !fall_->get_bound (LEFT))
68 fall_->set_bound (LEFT, note_head_);
69 fall_->set_parent (note_head_, Y_AXIS);
73 void
74 Bend_engraver::start_translation_timestep ()
76 last_fall_ = 0;
78 if (fall_ && now_mom ().main_part_ >= stop_moment_.main_part_)
80 stop_fall ();
84 void
85 Bend_engraver::acknowledge_note_head (Grob_info info)
87 if (!fall_event_)
88 return;
90 if (note_head_ && fall_)
92 stop_fall ();
95 note_head_ = info.grob ();
96 stop_moment_ = now_mom () + get_event_length (info.event_cause (),
97 now_mom ());
100 Bend_engraver::Bend_engraver ()
102 fall_ = 0;
103 last_fall_ = 0;
104 note_head_ = 0;
105 fall_event_ = 0;
108 IMPLEMENT_TRANSLATOR_LISTENER (Bend_engraver, bend_after);
109 void
110 Bend_engraver::listen_bend_after (Stream_event *ev)
112 ASSIGN_EVENT_ONCE (fall_event_, ev);
115 void
116 Bend_engraver::process_music ()
118 if (fall_event_ && !fall_)
120 fall_ = make_spanner ("BendAfter", fall_event_->self_scm ());
121 fall_->set_property ("delta-position",
122 scm_from_double (robust_scm2double (fall_event_->get_property ("delta-step"), 0)));
126 ADD_ACKNOWLEDGER (Bend_engraver, note_head);
128 ADD_TRANSLATOR (Bend_engraver,
129 /* doc */
130 "Create fall spanners.",
132 /* create */
133 "BendAfter ",
135 /* read */
138 /* write */