]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-tie-follow-engraver.cc
Revert "Issue 4550 (2/2) Avoid "using namespace std;" in included files"
[lilypond.git] / lily / tab-tie-follow-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2010--2015 Carl D. Sorensen
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 <cctype>
21 #include <cstdio>
22
23 #include "engraver.hh"
24
25 using namespace std;
26
27 #include "context.hh"
28 #include "item.hh"
29 #include "spanner.hh"
30
31 #include "translator.icc"
32
33 using std::vector;
34
35 /*
36    Change tab-note-head properties when a tie is followed by a
37    slurs or glissando.
38 */
39 class Tab_tie_follow_engraver : public Engraver
40 {
41   vector<Spanner *> slurs_;
42   vector<Spanner *> glissandi_;
43   vector<Item *> note_heads_;
44
45 public:
46   TRANSLATOR_DECLARATIONS (Tab_tie_follow_engraver);
47
48 protected:
49   DECLARE_ACKNOWLEDGER (glissando);
50   DECLARE_ACKNOWLEDGER (slur);
51   DECLARE_ACKNOWLEDGER (tab_note_head);
52
53   void stop_translation_timestep ();
54 };
55
56 Tab_tie_follow_engraver::Tab_tie_follow_engraver ()
57 {
58 }
59
60 void
61 Tab_tie_follow_engraver::acknowledge_glissando (Grob_info info)
62 {
63   glissandi_.push_back (info.spanner ());
64 }
65
66 void
67 Tab_tie_follow_engraver::acknowledge_tab_note_head (Grob_info info)
68 {
69   note_heads_.push_back (info.item ());
70 }
71
72 void
73 Tab_tie_follow_engraver::acknowledge_slur (Grob_info info)
74 {
75   slurs_.push_back (info.spanner ());
76 }
77
78 void
79 Tab_tie_follow_engraver::stop_translation_timestep ()
80 {
81   for (vsize k = 0; k < note_heads_.size (); k++)
82     {
83       bool spanner_start = false;
84       for (vsize j = 0; j < slurs_.size (); j++)
85         {
86           Item *left_item = slurs_[j]->get_bound (LEFT);
87           if (left_item)
88             {
89               SCM left_cause = left_item->get_property ("cause");
90               Item *slur_cause = unsmob<Item> (left_cause);
91               if (slur_cause == note_heads_[k])
92                 {
93                   note_heads_[k]->set_property ("span-start", SCM_BOOL_T);
94                   spanner_start = true;
95                   break;
96                 }
97             }
98         }
99       if (!spanner_start)
100         for (vsize j = 0; j < glissandi_.size (); j++)
101           {
102             Item *left_bound = glissandi_[j]->get_bound (LEFT);
103             if (left_bound == note_heads_[k])
104               {
105                 note_heads_[k]->set_property ("span-start", SCM_BOOL_T);
106                 break;
107               }
108           }
109     }
110   slurs_.clear ();
111   glissandi_.clear ();
112   note_heads_.clear ();
113 }
114
115 ADD_ACKNOWLEDGER (Tab_tie_follow_engraver, slur);
116 ADD_ACKNOWLEDGER (Tab_tie_follow_engraver, glissando);
117 ADD_ACKNOWLEDGER (Tab_tie_follow_engraver, tab_note_head);
118
119 ADD_TRANSLATOR (Tab_tie_follow_engraver,
120                 /* doc */
121                 "Adjust TabNoteHead properties when a tie is followed"
122                 " by a slur or glissando.",
123
124                 /* create */
125                 " ",
126
127                 /* read */
128                 " ",
129
130                 /* write */
131                 " "
132                );