]> git.donarmstrong.com Git - lilypond.git/blob - lily/laissez-vibrer-engraver.cc
Issue 4957: parser.yy: loc_on_music -> loc_on_copy
[lilypond.git] / lily / laissez-vibrer-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22 #include "item.hh"
23 #include "pointer-group-interface.hh"
24 #include "stream-event.hh"
25
26 #include "translator.icc"
27
28 class Laissez_vibrer_engraver : public Engraver
29 {
30   Stream_event *event_;
31   Grob *lv_column_;
32   vector<Grob *> lv_ties_;
33
34   void stop_translation_timestep ();
35   void acknowledge_note_head (Grob_info);
36 protected:
37   void listen_laissez_vibrer (Stream_event *);
38 public:
39   TRANSLATOR_DECLARATIONS (Laissez_vibrer_engraver);
40 };
41
42 Laissez_vibrer_engraver::Laissez_vibrer_engraver ()
43 {
44   event_ = 0;
45   lv_column_ = 0;
46 }
47
48 void
49 Laissez_vibrer_engraver::stop_translation_timestep ()
50 {
51   event_ = 0;
52   lv_column_ = 0;
53   lv_ties_.clear ();
54 }
55
56 void
57 Laissez_vibrer_engraver::listen_laissez_vibrer (Stream_event *ev)
58 {
59   ASSIGN_EVENT_ONCE (event_, ev);
60 }
61
62 void
63 Laissez_vibrer_engraver::acknowledge_note_head (Grob_info inf)
64 {
65   /* use the heard event_ for all note heads, or an individual event for just
66    * a single note head (attached as an articulation inside a chord) */
67   Stream_event *tie_ev = event_;
68   Grob *head = inf.grob ();
69   Stream_event *note_ev = unsmob<Stream_event> (head->get_property ("cause"));
70   if (!tie_ev && note_ev && note_ev->in_event_class ("note-event"))
71     {
72       SCM articulations = note_ev->get_property ("articulations");
73       for (SCM s = articulations; !tie_ev && scm_is_pair (s); s = scm_cdr (s))
74         {
75           Stream_event *ev = unsmob<Stream_event> (scm_car (s));
76           if (ev && ev->in_event_class ("laissez-vibrer-event"))
77             tie_ev = ev;
78         }
79     }
80
81   if (!tie_ev)
82     return;
83
84   SCM cause = tie_ev->self_scm ();
85
86   if (!lv_column_)
87     lv_column_ = make_item ("LaissezVibrerTieColumn", cause);
88
89   Grob *lv_tie = make_item ("LaissezVibrerTie", cause);
90   lv_tie->set_object ("note-head", head->self_scm ());
91
92   Pointer_group_interface::add_grob (lv_column_, ly_symbol2scm ("ties"),
93                                      lv_tie);
94
95   if (is_direction (unsmob<Stream_event> (cause)->get_property ("direction")))
96     {
97       Direction d = to_dir (unsmob<Stream_event> (cause)->get_property ("direction"));
98       lv_tie->set_property ("direction", scm_from_int (d));
99     }
100
101   lv_tie->set_parent (lv_column_, Y_AXIS);
102
103   lv_ties_.push_back (lv_tie);
104 }
105
106 void
107 Laissez_vibrer_engraver::boot ()
108 {
109   ADD_LISTENER (Laissez_vibrer_engraver, laissez_vibrer);
110   ADD_ACKNOWLEDGER (Laissez_vibrer_engraver, note_head);
111 }
112
113 ADD_TRANSLATOR (Laissez_vibrer_engraver,
114                 /* doc */
115                 "Create laissez vibrer items.",
116
117                 /* create */
118                 "LaissezVibrerTie "
119                 "LaissezVibrerTieColumn ",
120
121                 /* read */
122                 "",
123
124                 /* write */
125                 ""
126                );