]> git.donarmstrong.com Git - lilypond.git/blob - lily/bend-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / bend-engraver.cc
1 /*
2   bend-engraver.cc -- implement Bend_engraver
3
4   (c) 2006--2008 Han-Wen Nienhuys
5
6   
7 */
8
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "moment.hh"
12 #include "spanner.hh"
13 #include "stream-event.hh"
14
15 #include "translator.icc"
16
17 class Bend_engraver : public Engraver
18 {
19 public:
20   TRANSLATOR_DECLARATIONS (Bend_engraver);
21   DECLARE_ACKNOWLEDGER (note_head);
22
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 ();
30   
31 private:
32   Moment stop_moment_;
33   Stream_event *fall_event_;
34   Spanner *fall_;
35   Spanner *last_fall_;
36   Grob *note_head_;
37 };
38
39 void
40 Bend_engraver::finalize ()
41 {
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")));
46 }
47
48 void
49 Bend_engraver::stop_fall ()
50 {
51   bool bar = scm_is_string (get_property ("whichBar"));
52   
53   
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;
61 }
62
63 void
64 Bend_engraver::stop_translation_timestep ()
65 {
66   if (fall_ && !fall_->get_bound (LEFT)) 
67     {
68       fall_->set_bound (LEFT, note_head_);
69       fall_->set_parent (note_head_,  Y_AXIS);
70     }
71 }
72
73 void
74 Bend_engraver::start_translation_timestep ()
75 {
76   last_fall_ = 0;
77
78   if (fall_ && now_mom ().main_part_ >= stop_moment_.main_part_)
79     {
80       stop_fall ();
81     }
82 }
83
84 void
85 Bend_engraver::acknowledge_note_head (Grob_info info)
86 {
87   if (!fall_event_)
88     return;
89   
90   if (note_head_ && fall_)
91     {
92       stop_fall ();
93     }
94
95   note_head_ = info.grob ();
96   stop_moment_ = now_mom () + get_event_length (info.event_cause (),
97                                                 now_mom ());
98 }
99
100 Bend_engraver::Bend_engraver ()
101 {
102   fall_ = 0;
103   last_fall_ = 0;
104   note_head_ = 0;
105   fall_event_ = 0;
106 }
107
108 IMPLEMENT_TRANSLATOR_LISTENER (Bend_engraver, bend_after);
109 void
110 Bend_engraver::listen_bend_after (Stream_event *ev)
111 {
112   ASSIGN_EVENT_ONCE (fall_event_, ev);
113 }
114
115 void
116 Bend_engraver::process_music ()
117 {
118   if (fall_event_ && !fall_)
119     {
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)));
123     }
124 }
125
126 ADD_ACKNOWLEDGER (Bend_engraver, note_head);
127
128 ADD_TRANSLATOR (Bend_engraver,
129                 /* doc */
130                 "Create fall spanners.",
131
132                 /* create */
133                 "BendAfter ",
134
135                 /* read */
136                 "",
137
138                 /* write */
139                 ""
140                 );