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