Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / horizontal-bracket-engraver.cc
blob52ec11e1d75a36b5a2e7a13c5d461b9faed9d81c
1 /*
2 horizontal-bracket-engraver.cc -- implement
3 Horizontal_bracket_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 2002--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
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"
19 #include "translator.icc"
21 class Horizontal_bracket_engraver : public Engraver
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_;
30 void stop_translation_timestep ();
31 void process_music ();
32 DECLARE_ACKNOWLEDGER (note_column);
33 DECLARE_TRANSLATOR_LISTENER (note_grouping);
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.",
42 /* create */
43 "HorizontalBracket ",
45 /* read */
46 "",
48 /* write */
52 Horizontal_bracket_engraver::Horizontal_bracket_engraver ()
54 pop_count_ = 0;
55 push_count_ = 0;
58 IMPLEMENT_TRANSLATOR_LISTENER (Horizontal_bracket_engraver, note_grouping);
59 void
60 Horizontal_bracket_engraver::listen_note_grouping (Stream_event *ev)
62 Direction d = to_dir (ev->get_property ("span-direction"));
64 if (d == STOP)
66 pop_count_++;
67 if (pop_count_ > bracket_stack_.size ())
68 ev->origin ()->warning (_ ("do not have that many brackets"));
70 else
72 push_count_++;
73 events_.push_back (ev);
76 if (pop_count_ && push_count_)
77 ev->origin ()->warning (_ ("conflicting note group events"));
80 void
81 Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi)
83 for (vsize i = 0; i < bracket_stack_.size (); i++)
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 ());
93 void
94 Horizontal_bracket_engraver::process_music ()
96 for (vsize k = 0; k < push_count_; k++)
98 Spanner *sp = make_spanner ("HorizontalBracket", events_[k]->self_scm ());
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);
107 void
108 Horizontal_bracket_engraver::stop_translation_timestep ()
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;