]> git.donarmstrong.com Git - lilypond.git/blob - lily/part-combine-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / part-combine-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   Han-Wen Nienhuys <hanwen@xs4all.nl>
7
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.
12
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.
17
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/>.
20 */
21
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"
29
30 #include "translator.icc"
31
32 class Part_combine_engraver : public Engraver
33 {
34   TRANSLATOR_DECLARATIONS (Part_combine_engraver);
35
36 protected:
37   void acknowledge_note_head (Grob_info);
38   void acknowledge_stem (Grob_info);
39
40   void listen_part_combine (Stream_event *);
41   void listen_note (Stream_event *);
42   void process_music ();
43   void stop_translation_timestep ();
44   void create_item (Stream_event *ev);
45
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_;
52 };
53
54 void
55 Part_combine_engraver::listen_part_combine (Stream_event *ev)
56 {
57   ASSIGN_EVENT_ONCE (new_event_, ev);
58   // If two events occur at the same moment, discard the second as the
59   // warning indicates:
60   waiting_event_ = new_event_;
61 }
62
63 void
64 Part_combine_engraver::listen_note (Stream_event *)
65 {
66   note_found_ = true;
67 }
68
69 Part_combine_engraver::Part_combine_engraver (Context *c)
70   : Engraver (c)
71 {
72   text_ = 0;
73   new_event_ = 0;
74   waiting_event_ = 0;
75   note_found_ = false;
76 }
77
78 void
79 Part_combine_engraver::create_item (Stream_event *ev)
80 {
81   SCM what = scm_car (ev->get_property ("class"));
82   SCM text = SCM_EOL;
83   if (scm_is_eq (what, ly_symbol2scm ("solo-one-event")))
84     text = get_property ("soloText");
85   else if (scm_is_eq (what, ly_symbol2scm ("solo-two-event")))
86     text = get_property ("soloIIText");
87   else if (scm_is_eq (what, ly_symbol2scm ("unisono-event")))
88     text = get_property ("aDueText");
89
90   if (Text_interface::is_markup (text))
91     {
92       text_ = make_item ("CombineTextScript", ev->self_scm ());
93       text_->set_property ("text", text);
94     }
95 }
96
97 void
98 Part_combine_engraver::process_music ()
99 {
100   if (waiting_event_
101       && to_boolean (get_property ("printPartCombineTexts")))
102     {
103       if (note_found_ || !to_boolean (get_property ("partCombineTextsOnNote")))
104         {
105           create_item (waiting_event_);
106           waiting_event_ = 0;
107         }
108     }
109 }
110
111 void
112 Part_combine_engraver::acknowledge_note_head (Grob_info i)
113 {
114   if (text_)
115     {
116       Grob *t = text_;
117       Side_position_interface::add_support (t, i.grob ());
118       if (Side_position_interface::get_axis (t) == X_AXIS
119           && !t->get_parent (Y_AXIS))
120         t->set_parent (i.grob (), Y_AXIS);
121     }
122 }
123
124 void
125 Part_combine_engraver::acknowledge_stem (Grob_info i)
126 {
127   if (text_)
128     Side_position_interface::add_support (text_, i.grob ());
129 }
130
131 void
132 Part_combine_engraver::stop_translation_timestep ()
133 {
134   text_ = 0;
135   new_event_ = 0;
136   note_found_ = false;
137 }
138
139 void
140 Part_combine_engraver::boot ()
141 {
142   ADD_LISTENER (Part_combine_engraver, part_combine);
143   ADD_LISTENER (Part_combine_engraver, note);
144   ADD_ACKNOWLEDGER (Part_combine_engraver, note_head);
145   ADD_ACKNOWLEDGER (Part_combine_engraver, stem);
146 }
147
148 ADD_TRANSLATOR (Part_combine_engraver,
149                 /* doc */
150                 "Part combine engraver for orchestral scores: Print markings"
151                 " @q{a2}, @q{Solo}, @q{Solo II}, and @q{unisono}.",
152
153                 /* create */
154                 "CombineTextScript ",
155
156                 /* read */
157                 "printPartCombineTexts "
158                 "partCombineTextsOnNote "
159                 "soloText "
160                 "soloIIText "
161                 "aDueText ",
162
163                 /* write */
164                 ""
165                );