Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / part-combine-engraver.cc
blobf12cfbad95de5324622307e5c0f4cff712076e6f
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "engraver.hh"
23 #include "note-head.hh"
24 #include "side-position-interface.hh"
25 #include "stem.hh"
26 #include "stream-event.hh"
27 #include "text-interface.hh"
28 #include "item.hh"
30 #include "translator.icc"
32 class Part_combine_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Part_combine_engraver);
36 protected:
37 DECLARE_ACKNOWLEDGER (note_head);
38 DECLARE_ACKNOWLEDGER (stem);
40 DECLARE_TRANSLATOR_LISTENER (part_combine);
41 DECLARE_TRANSLATOR_LISTENER (note);
42 void process_music ();
43 void stop_translation_timestep ();
44 void create_item (Stream_event *ev);
46 private:
47 Item *text_;
48 Stream_event *new_event_; // Event happened at this moment
49 bool note_found_;
50 // Event possibly from an earlier moment waiting to create a text:
51 Stream_event *waiting_event_;
54 IMPLEMENT_TRANSLATOR_LISTENER (Part_combine_engraver, part_combine);
55 void
56 Part_combine_engraver::listen_part_combine (Stream_event *ev)
58 ASSIGN_EVENT_ONCE (new_event_, ev);
59 // If two events occur at the same moment, discard the second as the
60 // warning indicates:
61 waiting_event_ = new_event_;
64 IMPLEMENT_TRANSLATOR_LISTENER (Part_combine_engraver, note);
65 void
66 Part_combine_engraver::listen_note (Stream_event *)
68 note_found_ = true;
71 Part_combine_engraver::Part_combine_engraver ()
73 text_ = 0;
74 new_event_ = 0;
75 waiting_event_ = 0;
76 note_found_ = false;
79 void
80 Part_combine_engraver::create_item (Stream_event *ev)
82 SCM what = ev->get_property ("class");
83 SCM text = SCM_EOL;
84 if (what == ly_symbol2scm ("solo-one-event"))
85 text = get_property ("soloText");
86 else if (what == ly_symbol2scm ("solo-two-event"))
87 text = get_property ("soloIIText");
88 else if (what == ly_symbol2scm ("unisono-event"))
89 text = get_property ("aDueText");
91 if (Text_interface::is_markup (text))
93 text_ = make_item ("CombineTextScript", ev->self_scm ());
94 text_->set_property ("text", text);
98 void
99 Part_combine_engraver::process_music ()
101 if (waiting_event_
102 && to_boolean (get_property ("printPartCombineTexts")))
104 if (note_found_ || !to_boolean (get_property ("partCombineTextsOnNote")))
106 create_item (waiting_event_);
107 waiting_event_ = 0;
112 void
113 Part_combine_engraver::acknowledge_note_head (Grob_info i)
115 if (text_)
117 Grob *t = text_;
118 Side_position_interface::add_support (t, i.grob ());
119 if (Side_position_interface::get_axis (t) == X_AXIS
120 && !t->get_parent (Y_AXIS))
121 t->set_parent (i.grob (), Y_AXIS);
125 void
126 Part_combine_engraver::acknowledge_stem (Grob_info i)
128 if (text_)
129 Side_position_interface::add_support (text_, i.grob ());
132 void
133 Part_combine_engraver::stop_translation_timestep ()
135 text_ = 0;
136 new_event_ = 0;
137 note_found_ = false;
140 ADD_ACKNOWLEDGER (Part_combine_engraver, note_head);
141 ADD_ACKNOWLEDGER (Part_combine_engraver, stem);
142 ADD_TRANSLATOR (Part_combine_engraver,
143 /* doc */
144 "Part combine engraver for orchestral scores: Print markings"
145 " @q{a2}, @q{Solo}, @q{Solo II}, and @q{unisono}.",
147 /* create */
148 "CombineTextScript ",
150 /* read */
151 "printPartCombineTexts "
152 "partCombineTextsOnNote "
153 "soloText "
154 "soloIIText "
155 "aDueText ",
157 /* write */