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