]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket-engraver.cc
Fix \lyricsto Staff = "sop" syntax
[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 class Horizontal_bracket_engraver : public Engraver
32 {
33 public:
34   TRANSLATOR_DECLARATIONS (Horizontal_bracket_engraver);
35   vector<Spanner *> bracket_stack_;
36   vector<Stream_event *> events_;
37   vsize pop_count_;
38   vsize push_count_;
39
40   void stop_translation_timestep ();
41   void process_music ();
42   void acknowledge_note_column (Grob_info);
43   void listen_note_grouping (Stream_event *);
44 };
45
46 Horizontal_bracket_engraver::Horizontal_bracket_engraver ()
47 {
48   pop_count_ = 0;
49   push_count_ = 0;
50 }
51
52 void
53 Horizontal_bracket_engraver::listen_note_grouping (Stream_event *ev)
54 {
55   Direction d = to_dir (ev->get_property ("span-direction"));
56
57   if (d == STOP)
58     {
59       pop_count_++;
60       if (pop_count_ > bracket_stack_.size ())
61         ev->origin ()->warning (_ ("do not have that many brackets"));
62     }
63   else
64     {
65       push_count_++;
66       events_.push_back (ev);
67     }
68
69   if (pop_count_ && push_count_)
70     ev->origin ()->warning (_ ("conflicting note group events"));
71 }
72
73 void
74 Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi)
75 {
76   for (vsize i = 0; i < bracket_stack_.size (); i++)
77     {
78       Side_position_interface::add_support (bracket_stack_[i], gi.grob ());
79       Pointer_group_interface::add_grob (bracket_stack_[i],
80                                          ly_symbol2scm ("columns"), gi.grob ());
81       add_bound_item (bracket_stack_[i],
82                       gi.grob ());
83     }
84 }
85
86 void
87 Horizontal_bracket_engraver::process_music ()
88 {
89   for (vsize k = 0; k < push_count_; k++)
90     {
91       Spanner *sp = make_spanner ("HorizontalBracket", events_[k]->self_scm ());
92
93       for (vsize i = 0; i < bracket_stack_.size (); i++)
94         /* sp is the smallest, it should be added to the bigger brackets.  */
95         Side_position_interface::add_support (bracket_stack_[i], sp);
96       bracket_stack_.push_back (sp);
97     }
98 }
99
100 void
101 Horizontal_bracket_engraver::stop_translation_timestep ()
102 {
103   for (vsize i = pop_count_; i--;)
104     if (bracket_stack_.size ())
105       bracket_stack_.pop_back ();
106   pop_count_ = 0;
107   push_count_ = 0;
108   events_.clear ();
109 }
110
111 void
112 Horizontal_bracket_engraver::boot ()
113 {
114   ADD_LISTENER (Horizontal_bracket_engraver, note_grouping);
115   ADD_ACKNOWLEDGER (Horizontal_bracket_engraver, note_column);
116 }
117
118 ADD_TRANSLATOR (Horizontal_bracket_engraver,
119                 /* doc */
120                 "Create horizontal brackets over notes for musical analysis"
121                 " purposes.",
122
123                 /* create */
124                 "HorizontalBracket ",
125
126                 /* read */
127                 "",
128
129                 /* write */
130                 ""
131                );