]> git.donarmstrong.com Git - lilypond.git/blob - lily/concurrent-hairpin-engraver.cc
Bring dev/johngourlay/issue-4751 up to date with respect to staging.
[lilypond.git] / lily / concurrent-hairpin-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011--2015 Mike Solomon <mike@mikesolomon.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "engraver.hh"
21
22 #include "international.hh"
23 #include "pointer-group-interface.hh"
24 #include "spanner.hh"
25 #include "stream-event.hh"
26 #include "warn.hh"
27 #include "item.hh"
28
29 #include "translator.icc"
30
31 class Concurrent_hairpin_engraver : public Engraver
32 {
33 public:
34   TRANSLATOR_DECLARATIONS (Concurrent_hairpin_engraver);
35
36 protected:
37   void acknowledge_hairpin (Grob_info);
38   void acknowledge_end_hairpin (Grob_info);
39
40   void stop_translation_timestep ();
41   void finalize ();
42
43 private:
44   vector<Grob *> arriving_hairpins_;
45   vector<Grob *> departing_hairpins_;
46   vector<Grob *> hairpins_hanging_out_;
47 };
48
49 Concurrent_hairpin_engraver::Concurrent_hairpin_engraver ()
50 {
51 }
52
53 void
54 Concurrent_hairpin_engraver::acknowledge_hairpin (Grob_info info)
55 {
56   arriving_hairpins_.push_back (info.grob ());
57 }
58
59 void
60 Concurrent_hairpin_engraver::acknowledge_end_hairpin (Grob_info info)
61 {
62   departing_hairpins_.push_back (info.grob ());
63 }
64
65 void
66 Concurrent_hairpin_engraver::stop_translation_timestep ()
67 {
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])
71         {
72           hairpins_hanging_out_.erase (hairpins_hanging_out_.begin () + j);
73           break;
74         }
75   if (arriving_hairpins_.size ())
76     {
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++)
80             {
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]);
83             }
84
85       for (vsize i = 0; i < arriving_hairpins_.size (); i++)
86         for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
87           {
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]);
90           }
91     }
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);
95 }
96
97 void
98 Concurrent_hairpin_engraver::finalize ()
99 {
100   hairpins_hanging_out_.resize (0);
101 }
102
103
104 void
105 Concurrent_hairpin_engraver::boot ()
106 {
107   ADD_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
108   ADD_END_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
109 }
110
111 ADD_TRANSLATOR (Concurrent_hairpin_engraver,
112                 /* doc */
113                 "Collect concurrent hairpins.",
114
115                 /* create */
116                 "",
117
118                 /* read */
119                 "",
120
121                 /* write */
122                 ""
123                );