]> git.donarmstrong.com Git - lilypond.git/blob - lily/tab-tie-follow-engraver.cc
Add tab-tie-follow-engraver
[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 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
30 #include "translator.icc"
31
32 /*
33    Change tab-note-head properties for a note_head at the right end of a tie
34 */
35 class Tab_tie_follow_engraver : public Engraver
36 {
37   vector<Grob*> ties_;
38   vector<Grob*> note_heads_;
39
40 public:
41   TRANSLATOR_DECLARATIONS (Tab_tie_follow_engraver);
42
43 protected:
44   DECLARE_ACKNOWLEDGER (tie);
45   DECLARE_ACKNOWLEDGER (tab_note_head);
46   void process_acknowledged ();
47
48   void stop_translation_timestep ();
49 };
50
51 Tab_tie_follow_engraver::Tab_tie_follow_engraver ()
52 {
53 }
54
55 void
56 Tab_tie_follow_engraver::acknowledge_tie (Grob_info info)
57 {
58    ties_.push_back (info.grob ());
59 }
60
61 void
62 Tab_tie_follow_engraver::acknowledge_tab_note_head (Grob_info info)
63 {
64   note_heads_.push_back (info.grob ());
65 }
66
67 void
68 Tab_tie_follow_engraver::process_acknowledged ()
69 {
70   if (ties_.size () && note_heads_.size ())
71     {
72       SCM proc = ly_lily_module_constant ("ly:spanner-bound");
73       for (vsize i = 0; i < ties_.size (); i++)
74         {
75           SCM right_bound = scm_call_2 (proc,
76                                         ties_[i]->self_scm (),
77                                         scm_from_int (RIGHT));
78
79           for (vsize k = 0; k < note_heads_.size (); k++)
80             if (right_bound == note_heads_[k]->self_scm ())
81               note_heads_[k]->set_property ("tie-follow", SCM_BOOL_T);
82          }
83     }
84 }
85
86 void
87 Tab_tie_follow_engraver::stop_translation_timestep ()
88 {
89   ties_.clear ();
90   note_heads_.clear();
91 }
92
93 ADD_ACKNOWLEDGER (Tab_tie_follow_engraver, tie);
94 ADD_ACKNOWLEDGER (Tab_tie_follow_engraver, tab_note_head);
95
96 ADD_TRANSLATOR (Tab_tie_follow_engraver,
97                 /* doc */
98                 "Adjust TabNoteHead properties when a tie is followed"
99                 " by a slur or glissando.",
100
101                 /* create */
102                 " ",
103
104                 /* read */
105                 " ",
106
107                 /* write */
108                 " "
109                 );
110