(all-grob-descriptions): remove gap from
[lilypond.git] / lily / horizontal-bracket-engraver.cc
blob99836973b4ccc5066650211ae193f20d9dfdd82b
1 /*
2 horizontal-bracket-engraver.cc -- implement
3 Horizontal_bracket_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 */
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
13 #include "note-column.hh"
14 #include "group-interface.hh"
16 class Horizontal_bracket_engraver : public Engraver
18 public:
19 TRANSLATOR_DECLARATIONS (Horizontal_bracket_engraver);
20 Link_array<Spanner> bracket_stack_;
21 Link_array<Music> events_;
22 int pop_count_;
23 int push_count_;
25 virtual bool try_music (Music*);
26 virtual void stop_translation_timestep ();
27 virtual void process_music ();
28 virtual void acknowledge_grob (Grob_info);
31 ENTER_DESCRIPTION (Horizontal_bracket_engraver,
32 "Create horizontal brackets over notes for musical analysis purposes.",
33 "HorizontalBracket",
34 "note-grouping-event",
35 "note-column-interface",
36 "",
37 "");
39 Horizontal_bracket_engraver::Horizontal_bracket_engraver ()
41 pop_count_ = 0;
42 push_count_ = 0;
46 bool
47 Horizontal_bracket_engraver::try_music (Music *m)
49 if (m->is_mus_type ("note-grouping-event"))
51 Direction d = to_dir (m->get_property ("span-direction"));
53 if (d == STOP)
55 pop_count_ ++;
56 if (pop_count_ > bracket_stack_.size ())
57 m->origin ()->warning (_("Don't have that many brackets."));
59 else
61 push_count_++;
62 events_.push (m);
65 if (pop_count_ && push_count_)
66 m->origin ()->warning (_("Conflicting note group events."));
68 return true;
70 return false;
73 void
74 Horizontal_bracket_engraver::acknowledge_grob (Grob_info gi)
76 if (Note_column::has_interface (gi.grob_))
78 for (int i = 0; i < bracket_stack_.size (); i++)
80 Side_position_interface::add_support (bracket_stack_[i], gi.grob_);
81 Pointer_group_interface::add_grob (bracket_stack_[i],
82 ly_symbol2scm ("columns"), gi.grob_);
83 add_bound_item (bracket_stack_[i],
84 gi.grob_);
89 void
90 Horizontal_bracket_engraver::process_music ()
92 for (int k = 0; k < push_count_; k++)
94 Spanner * sp = make_spanner ("HorizontalBracket");
96 announce_grob (sp, events_[k]->self_scm ());
97 for (int i = 0; i < bracket_stack_.size (); i++)
100 sp is the smallest, it should be added to the bigger brackets.
102 Side_position_interface::add_support (bracket_stack_[i], sp);
104 bracket_stack_.push (sp);
109 void
110 Horizontal_bracket_engraver::stop_translation_timestep ()
112 for (int i = pop_count_; i--;)
114 if (bracket_stack_.size ())
115 typeset_grob (bracket_stack_.pop ());
117 pop_count_ = 0;
118 push_count_ = 0;