]> git.donarmstrong.com Git - lilypond.git/blob - lily/laissez-vibrer-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[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 using std::vector;
29
30 class Laissez_vibrer_engraver : public Engraver
31 {
32   Stream_event *event_;
33   Grob *lv_column_;
34   vector<Grob *> lv_ties_;
35
36   void stop_translation_timestep ();
37   DECLARE_ACKNOWLEDGER (note_head);
38 protected:
39   DECLARE_TRANSLATOR_LISTENER (laissez_vibrer);
40 public:
41   TRANSLATOR_DECLARATIONS (Laissez_vibrer_engraver);
42 };
43
44 Laissez_vibrer_engraver::Laissez_vibrer_engraver ()
45 {
46   event_ = 0;
47   lv_column_ = 0;
48 }
49
50 void
51 Laissez_vibrer_engraver::stop_translation_timestep ()
52 {
53   event_ = 0;
54   lv_column_ = 0;
55   lv_ties_.clear ();
56 }
57
58 IMPLEMENT_TRANSLATOR_LISTENER (Laissez_vibrer_engraver, laissez_vibrer);
59 void
60 Laissez_vibrer_engraver::listen_laissez_vibrer (Stream_event *ev)
61 {
62   ASSIGN_EVENT_ONCE (event_, ev);
63 }
64
65 void
66 Laissez_vibrer_engraver::acknowledge_note_head (Grob_info inf)
67 {
68   /* use the heard event_ for all note heads, or an individual event for just
69    * a single note head (attached as an articulation inside a chord) */
70   Stream_event *tie_ev = event_;
71   Grob *head = inf.grob ();
72   Stream_event *note_ev = unsmob<Stream_event> (head->get_property ("cause"));
73   if (!tie_ev && note_ev && note_ev->in_event_class ("note-event"))
74     {
75       SCM articulations = note_ev->get_property ("articulations");
76       for (SCM s = articulations; !tie_ev && scm_is_pair (s); s = scm_cdr (s))
77         {
78           Stream_event *ev = unsmob<Stream_event> (scm_car (s));
79           if (ev && ev->in_event_class ("laissez-vibrer-event"))
80             tie_ev = ev;
81         }
82     }
83
84   if (!tie_ev)
85     return;
86
87   SCM cause = tie_ev->self_scm ();
88
89   if (!lv_column_)
90     lv_column_ = make_item ("LaissezVibrerTieColumn", cause);
91
92   Grob *lv_tie = make_item ("LaissezVibrerTie", cause);
93   lv_tie->set_object ("note-head", head->self_scm ());
94
95   Pointer_group_interface::add_grob (lv_column_, ly_symbol2scm ("ties"),
96                                      lv_tie);
97
98   if (is_direction (unsmob<Stream_event> (cause)->get_property ("direction")))
99     {
100       Direction d = to_dir (unsmob<Stream_event> (cause)->get_property ("direction"));
101       lv_tie->set_property ("direction", scm_from_int (d));
102     }
103
104   lv_tie->set_parent (lv_column_, Y_AXIS);
105
106   lv_ties_.push_back (lv_tie);
107 }
108
109 ADD_ACKNOWLEDGER (Laissez_vibrer_engraver, note_head);
110 ADD_TRANSLATOR (Laissez_vibrer_engraver,
111                 /* doc */
112                 "Create laissez vibrer items.",
113
114                 /* create */
115                 "LaissezVibrerTie "
116                 "LaissezVibrerTieColumn ",
117
118                 /* read */
119                 "",
120
121                 /* write */
122                 ""
123                );