]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / horizontal-bracket-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 #include "international.hh"
22 #include "item.hh"
23 #include "note-column.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26 #include "spanner.hh"
27 #include "stream-event.hh"
28
29 #include "translator.icc"
30
31 using std::vector;
32
33 class Horizontal_bracket_engraver : public Engraver
34 {
35 public:
36   TRANSLATOR_DECLARATIONS (Horizontal_bracket_engraver);
37   vector<Spanner *> bracket_stack_;
38   vector<Stream_event *> events_;
39   vsize pop_count_;
40   vsize push_count_;
41
42   void stop_translation_timestep ();
43   void process_music ();
44   DECLARE_ACKNOWLEDGER (note_column);
45   DECLARE_TRANSLATOR_LISTENER (note_grouping);
46 };
47
48 Horizontal_bracket_engraver::Horizontal_bracket_engraver ()
49 {
50   pop_count_ = 0;
51   push_count_ = 0;
52 }
53
54 IMPLEMENT_TRANSLATOR_LISTENER (Horizontal_bracket_engraver, note_grouping);
55 void
56 Horizontal_bracket_engraver::listen_note_grouping (Stream_event *ev)
57 {
58   Direction d = to_dir (ev->get_property ("span-direction"));
59
60   if (d == STOP)
61     {
62       pop_count_++;
63       if (pop_count_ > bracket_stack_.size ())
64         ev->origin ()->warning (_ ("do not have that many brackets"));
65     }
66   else
67     {
68       push_count_++;
69       events_.push_back (ev);
70     }
71
72   if (pop_count_ && push_count_)
73     ev->origin ()->warning (_ ("conflicting note group events"));
74 }
75
76 void
77 Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi)
78 {
79   for (vsize i = 0; i < bracket_stack_.size (); i++)
80     {
81       Side_position_interface::add_support (bracket_stack_[i], gi.grob ());
82       Pointer_group_interface::add_grob (bracket_stack_[i],
83                                          ly_symbol2scm ("columns"), gi.grob ());
84       add_bound_item (bracket_stack_[i],
85                       gi.grob ());
86     }
87 }
88
89 void
90 Horizontal_bracket_engraver::process_music ()
91 {
92   for (vsize k = 0; k < push_count_; k++)
93     {
94       Spanner *sp = make_spanner ("HorizontalBracket", events_[k]->self_scm ());
95
96       for (vsize i = 0; i < bracket_stack_.size (); i++)
97         /* sp is the smallest, it should be added to the bigger brackets.  */
98         Side_position_interface::add_support (bracket_stack_[i], sp);
99       bracket_stack_.push_back (sp);
100     }
101 }
102
103 void
104 Horizontal_bracket_engraver::stop_translation_timestep ()
105 {
106   for (vsize i = pop_count_; i--;)
107     if (bracket_stack_.size ())
108       bracket_stack_.pop_back ();
109   pop_count_ = 0;
110   push_count_ = 0;
111   events_.clear ();
112 }
113
114 ADD_ACKNOWLEDGER (Horizontal_bracket_engraver, note_column);
115 ADD_TRANSLATOR (Horizontal_bracket_engraver,
116                 /* doc */
117                 "Create horizontal brackets over notes for musical analysis"
118                 " purposes.",
119
120                 /* create */
121                 "HorizontalBracket ",
122
123                 /* read */
124                 "",
125
126                 /* write */
127                 ""
128                );