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"
31 class Concurrent_hairpin_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Concurrent_hairpin_engraver);
37 void acknowledge_hairpin (Grob_info);
38 void acknowledge_end_hairpin (Grob_info);
40 void stop_translation_timestep ();
44 vector<Grob *> arriving_hairpins_;
45 vector<Grob *> departing_hairpins_;
46 vector<Grob *> hairpins_hanging_out_;
49 Concurrent_hairpin_engraver::Concurrent_hairpin_engraver ()
54 Concurrent_hairpin_engraver::acknowledge_hairpin (Grob_info info)
56 arriving_hairpins_.push_back (info.grob ());
60 Concurrent_hairpin_engraver::acknowledge_end_hairpin (Grob_info info)
62 departing_hairpins_.push_back (info.grob ());
66 Concurrent_hairpin_engraver::stop_translation_timestep ()
68 for (vsize i = 0; i < departing_hairpins_.size (); i++)
69 for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
70 if (departing_hairpins_[i] == hairpins_hanging_out_[j])
72 hairpins_hanging_out_.erase (hairpins_hanging_out_.begin () + j);
75 if (arriving_hairpins_.size ())
77 if (arriving_hairpins_.size () > 1)
78 for (vsize i = 0; i < arriving_hairpins_.size () - 1; i++)
79 for (vsize j = i + 1; j < arriving_hairpins_.size (); j++)
81 Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[j]);
82 Pointer_group_interface::add_grob (arriving_hairpins_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
85 for (vsize i = 0; i < arriving_hairpins_.size (); i++)
86 for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
88 Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), hairpins_hanging_out_[j]);
89 Pointer_group_interface::add_grob (hairpins_hanging_out_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
92 hairpins_hanging_out_.insert (hairpins_hanging_out_.end (), arriving_hairpins_.begin (), arriving_hairpins_.end ());
93 arriving_hairpins_.resize (0);
94 departing_hairpins_.resize (0);
98 Concurrent_hairpin_engraver::finalize ()
100 hairpins_hanging_out_.resize (0);
105 Concurrent_hairpin_engraver::boot ()
107 ADD_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
108 ADD_END_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
111 ADD_TRANSLATOR (Concurrent_hairpin_engraver,
113 "Collect concurrent hairpins.",