]> git.donarmstrong.com Git - lilypond.git/blob - lily/fall-engraver.cc
(process_music): delta-pitch -> delta-step.
[lilypond.git] / lily / fall-engraver.cc
1 /*
2   fall-engraver.cc -- implement Fall_engraver
3
4   (c) 2006 Han-Wen Nienhuys
5
6   
7 */
8
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "spanner.hh"
12
13 class Fall_engraver : public Engraver
14 {
15 public:
16   TRANSLATOR_DECLARATIONS (Fall_engraver);
17   DECLARE_ACKNOWLEDGER (note_head);
18
19 protected:
20   virtual bool try_music (Music *event);
21   void process_music ();
22   void stop_translation_timestep ();
23   void start_translation_timestep ();
24   void stop_fall ();
25   
26 private:
27   Moment stop_moment_;
28   Music *fall_event_;
29   Spanner *fall_;
30   Grob *note_head_;
31 };
32
33 void
34 Fall_engraver::stop_fall ()
35 {
36   bool bar = scm_is_string (get_property ("whichBar"));
37   
38   
39   fall_->set_bound (RIGHT, unsmob_grob (
40                                         bar
41                                         ? get_property ("currentCommandColumn")
42                                         : get_property ("currentMusicalColumn")));
43   fall_ = 0;
44   note_head_ = 0;
45   fall_event_ = 0;
46 }
47
48 void
49 Fall_engraver::stop_translation_timestep ()
50 {
51   if (fall_ && !fall_->get_bound (LEFT)) 
52     {
53       fall_->set_bound (LEFT, note_head_);
54       fall_->set_parent (note_head_,  Y_AXIS);
55     }
56 }
57
58 void
59 Fall_engraver::start_translation_timestep ()
60 {
61   if (fall_ && now_mom ().main_part_ >= stop_moment_.main_part_)
62     {
63       stop_fall ();
64     }
65 }
66
67 void
68 Fall_engraver::acknowledge_note_head (Grob_info info)
69 {
70   if (!fall_event_)
71     return;
72   
73   if (note_head_ && fall_)
74     {
75       stop_fall ();
76     }
77
78   note_head_ = info.grob ();
79   stop_moment_ = now_mom () + info.music_cause ()->get_length ();
80 }
81
82 Fall_engraver::Fall_engraver ()
83 {
84   fall_ = 0;
85   note_head_ = 0;
86   fall_event_ = 0;
87 }
88
89 bool
90 Fall_engraver::try_music (Music *r)
91 {
92   fall_event_ = r;
93   return true;
94 }
95
96 void
97 Fall_engraver::process_music ()
98 {
99   if (fall_event_ && !fall_)
100     {
101       fall_ = make_spanner ("BendAfter", fall_event_->self_scm ());
102       fall_->set_property ("delta-step",
103                            scm_from_double (robust_scm2double (fall_event_->get_property ("delta-pitch"), 0) * 0.5));
104     }
105 }
106
107 #include "translator.icc"
108
109
110 ADD_ACKNOWLEDGER (Fall_engraver, note_head);
111
112
113 ADD_TRANSLATOR (Fall_engraver,
114                 /* doc */ "Create fall spanners.",
115                 /* create */ "BendAfter",
116                 /* accept */ "bend-after-event",
117                 /* read */ "",
118                 /* write */ "");