]> git.donarmstrong.com Git - lilypond.git/blob - lily/bend-engraver.cc
Imported Upstream version 2.14.2
[lilypond.git] / lily / bend-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2011 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   
65   fall_->set_bound (RIGHT, unsmob_grob (bar
66                                         ? get_property ("currentCommandColumn")
67                                         : get_property ("currentMusicalColumn")));
68   last_fall_ = fall_;
69   fall_ = 0;
70   note_head_ = 0;
71   fall_event_ = 0;
72 }
73
74 void
75 Bend_engraver::stop_translation_timestep ()
76 {
77   if (fall_ && !fall_->get_bound (LEFT)) 
78     {
79       fall_->set_bound (LEFT, note_head_);
80       fall_->set_parent (note_head_,  Y_AXIS);
81     }
82 }
83
84 void
85 Bend_engraver::start_translation_timestep ()
86 {
87   last_fall_ = 0;
88
89   if (fall_ && now_mom ().main_part_ >= stop_moment_.main_part_)
90     {
91       stop_fall ();
92     }
93 }
94
95 void
96 Bend_engraver::acknowledge_note_head (Grob_info info)
97 {
98   if (!fall_event_)
99     return;
100   
101   if (note_head_ && fall_)
102     {
103       stop_fall ();
104     }
105
106   note_head_ = info.grob ();
107   stop_moment_ = now_mom () + get_event_length (info.event_cause (),
108                                                 now_mom ());
109 }
110
111 Bend_engraver::Bend_engraver ()
112 {
113   fall_ = 0;
114   last_fall_ = 0;
115   note_head_ = 0;
116   fall_event_ = 0;
117 }
118
119 IMPLEMENT_TRANSLATOR_LISTENER (Bend_engraver, bend_after);
120 void
121 Bend_engraver::listen_bend_after (Stream_event *ev)
122 {
123   ASSIGN_EVENT_ONCE (fall_event_, ev);
124 }
125
126 void
127 Bend_engraver::process_music ()
128 {
129   if (fall_event_ && !fall_)
130     {
131       fall_ = make_spanner ("BendAfter", fall_event_->self_scm ());
132       fall_->set_property ("delta-position",
133                            scm_from_double (robust_scm2double (fall_event_->get_property ("delta-step"), 0)));
134     }
135 }
136
137 ADD_ACKNOWLEDGER (Bend_engraver, note_head);
138
139 ADD_TRANSLATOR (Bend_engraver,
140                 /* doc */
141                 "Create fall spanners.",
142
143                 /* create */
144                 "BendAfter ",
145
146                 /* read */
147                 "",
148
149                 /* write */
150                 ""
151                 );