]> git.donarmstrong.com Git - lilypond.git/blob - lily/bend-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / bend-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2014 Han-Wen Nienhuys
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "item.hh"
22 #include "moment.hh"
23 #include "spanner.hh"
24 #include "stream-event.hh"
25
26 #include "translator.icc"
27
28 class Bend_engraver : public Engraver
29 {
30 public:
31   TRANSLATOR_DECLARATIONS (Bend_engraver);
32   DECLARE_ACKNOWLEDGER (note_head);
33
34 protected:
35   DECLARE_TRANSLATOR_LISTENER (bend_after);
36   void finalize ();
37   void process_music ();
38   void stop_translation_timestep ();
39   void start_translation_timestep ();
40   void stop_fall ();
41
42 private:
43   Moment stop_moment_;
44   Stream_event *fall_event_;
45   Spanner *fall_;
46   Spanner *last_fall_;
47   Grob *note_head_;
48 };
49
50 void
51 Bend_engraver::finalize ()
52 {
53   // We shouldn't end a spanner on the last musical column of a piece because then
54   // it would extend past the last breakable column of the piece.
55   if (last_fall_)
56     last_fall_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
57 }
58
59 void
60 Bend_engraver::stop_fall ()
61 {
62   bool bar = scm_is_string (get_property ("whichBar"));
63
64   fall_->set_bound (RIGHT, unsmob_grob (bar
65                                         ? get_property ("currentCommandColumn")
66                                         : get_property ("currentMusicalColumn")));
67   last_fall_ = fall_;
68   fall_ = 0;
69   note_head_ = 0;
70   fall_event_ = 0;
71 }
72
73 void
74 Bend_engraver::stop_translation_timestep ()
75 {
76   if (fall_ && !fall_->get_bound (LEFT))
77     {
78       fall_->set_bound (LEFT, note_head_);
79       fall_->set_parent (note_head_, Y_AXIS);
80     }
81 }
82
83 void
84 Bend_engraver::start_translation_timestep ()
85 {
86   last_fall_ = 0;
87
88   if (fall_ && now_mom ().main_part_ >= stop_moment_.main_part_)
89     {
90       stop_fall ();
91     }
92 }
93
94 void
95 Bend_engraver::acknowledge_note_head (Grob_info info)
96 {
97   if (!fall_event_)
98     return;
99
100   if (note_head_ && fall_)
101     {
102       stop_fall ();
103     }
104
105   note_head_ = info.grob ();
106   stop_moment_ = now_mom () + get_event_length (info.event_cause (),
107                                                 now_mom ());
108 }
109
110 Bend_engraver::Bend_engraver ()
111 {
112   fall_ = 0;
113   last_fall_ = 0;
114   note_head_ = 0;
115   fall_event_ = 0;
116 }
117
118 IMPLEMENT_TRANSLATOR_LISTENER (Bend_engraver, bend_after);
119 void
120 Bend_engraver::listen_bend_after (Stream_event *ev)
121 {
122   ASSIGN_EVENT_ONCE (fall_event_, ev);
123 }
124
125 void
126 Bend_engraver::process_music ()
127 {
128   if (fall_event_ && !fall_)
129     {
130       fall_ = make_spanner ("BendAfter", fall_event_->self_scm ());
131       fall_->set_property ("delta-position",
132                            scm_from_double (robust_scm2double (fall_event_->get_property ("delta-step"), 0)));
133     }
134 }
135
136 ADD_ACKNOWLEDGER (Bend_engraver, note_head);
137
138 ADD_TRANSLATOR (Bend_engraver,
139                 /* doc */
140                 "Create fall spanners.",
141
142                 /* create */
143                 "BendAfter ",
144
145                 /* read */
146                 "",
147
148                 /* write */
149                 ""
150                );