2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2011--2015 Mike Solomon <mike@mikesolomon.org>
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.
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.
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/>.
20 #include "engraver.hh"
22 #include "international.hh"
23 #include "pointer-group-interface.hh"
25 #include "stream-event.hh"
29 #include "translator.icc"
33 class Concurrent_hairpin_engraver : public Engraver
36 TRANSLATOR_DECLARATIONS (Concurrent_hairpin_engraver);
39 DECLARE_ACKNOWLEDGER (hairpin);
40 DECLARE_END_ACKNOWLEDGER (hairpin);
42 void stop_translation_timestep ();
46 vector<Grob *> arriving_hairpins_;
47 vector<Grob *> departing_hairpins_;
48 vector<Grob *> hairpins_hanging_out_;
51 Concurrent_hairpin_engraver::Concurrent_hairpin_engraver ()
56 Concurrent_hairpin_engraver::acknowledge_hairpin (Grob_info info)
58 arriving_hairpins_.push_back (info.grob ());
62 Concurrent_hairpin_engraver::acknowledge_end_hairpin (Grob_info info)
64 departing_hairpins_.push_back (info.grob ());
68 Concurrent_hairpin_engraver::stop_translation_timestep ()
70 for (vsize i = 0; i < departing_hairpins_.size (); i++)
71 for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
72 if (departing_hairpins_[i] == hairpins_hanging_out_[j])
74 hairpins_hanging_out_.erase (hairpins_hanging_out_.begin () + j);
77 if (arriving_hairpins_.size ())
79 if (arriving_hairpins_.size () > 1)
80 for (vsize i = 0; i < arriving_hairpins_.size () - 1; i++)
81 for (vsize j = i + 1; j < arriving_hairpins_.size (); j++)
83 Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[j]);
84 Pointer_group_interface::add_grob (arriving_hairpins_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
87 for (vsize i = 0; i < arriving_hairpins_.size (); i++)
88 for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
90 Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), hairpins_hanging_out_[j]);
91 Pointer_group_interface::add_grob (hairpins_hanging_out_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
94 hairpins_hanging_out_.insert (hairpins_hanging_out_.end (), arriving_hairpins_.begin (), arriving_hairpins_.end ());
95 arriving_hairpins_.resize (0);
96 departing_hairpins_.resize (0);
100 Concurrent_hairpin_engraver::finalize ()
102 hairpins_hanging_out_.resize (0);
105 ADD_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
106 ADD_END_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
108 ADD_TRANSLATOR (Concurrent_hairpin_engraver,
110 "Collect concurrent hairpins.",