]> git.donarmstrong.com Git - lilypond.git/blob - lily/cluster-engraver.cc
Issue 4989/1: Fix Type1 (PFA) font embedding
[lilypond.git] / lily / cluster-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2015 Juergen Reuter <reuter@ipd.uka.de>
5   Han-Wen Nienhuys <hanwen@xs4all.nl>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22 #include "spanner.hh"
23 #include "note-head.hh"
24 #include "note-column.hh"
25 #include "pointer-group-interface.hh"
26 #include "pitch.hh"
27 #include "stream-event.hh"
28 #include "item.hh"
29
30 #include "translator.icc"
31
32 class Cluster_spanner_engraver : public Engraver
33 {
34
35 protected:
36   TRANSLATOR_DECLARATIONS (Cluster_spanner_engraver);
37   void listen_cluster_note (Stream_event *);
38   void acknowledge_note_column (Grob_info);
39   void stop_translation_timestep ();
40   virtual void process_music ();
41   virtual void finalize ();
42 private:
43   vector<Stream_event *> cluster_notes_;
44   Item *beacon_;
45
46   void typeset_grobs ();
47   Spanner *spanner_;
48   Spanner *finished_spanner_;
49 };
50
51 Cluster_spanner_engraver::Cluster_spanner_engraver ()
52 {
53   spanner_ = 0;
54   finished_spanner_ = 0;
55   beacon_ = 0;
56 }
57
58 void
59 Cluster_spanner_engraver::finalize ()
60 {
61   typeset_grobs ();
62   finished_spanner_ = spanner_;
63   spanner_ = 0;
64   typeset_grobs ();
65 }
66
67 void
68 Cluster_spanner_engraver::typeset_grobs ()
69 {
70   if (finished_spanner_)
71     {
72       if (!finished_spanner_->get_bound (RIGHT))
73         {
74           finished_spanner_->set_bound (RIGHT,
75                                         finished_spanner_->get_bound (LEFT));
76
77         }
78
79       finished_spanner_ = 0;
80     }
81   beacon_ = 0;
82 }
83
84 void
85 Cluster_spanner_engraver::listen_cluster_note (Stream_event *ev)
86 {
87   cluster_notes_.push_back (ev);
88 }
89
90 void
91 Cluster_spanner_engraver::process_music ()
92 {
93   if (cluster_notes_.size ())
94     {
95       SCM c0scm = get_property ("middleCPosition");
96
97       int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
98       int pmax = INT_MIN;
99       int pmin = INT_MAX;
100
101       for (vsize i = 0; i < cluster_notes_.size (); i++)
102         {
103           Pitch *pit = unsmob<Pitch> (cluster_notes_[i]->get_property ("pitch"));
104
105           int p = (pit ? pit->steps () : 0) + c0;
106
107           pmax = max (pmax, p);
108           pmin = min (pmin, p);
109         }
110
111       beacon_ = make_item ("ClusterSpannerBeacon", cluster_notes_[0]->self_scm ());
112       beacon_->set_property ("positions",
113                              scm_cons (scm_from_int (pmin),
114                                        scm_from_int (pmax)));
115     }
116
117   if (beacon_ && !spanner_)
118     spanner_ = make_spanner ("ClusterSpanner", cluster_notes_[0]->self_scm ());
119
120   if (beacon_ && spanner_)
121     {
122       add_bound_item (spanner_, beacon_);
123       Pointer_group_interface::add_grob (spanner_, ly_symbol2scm ("columns"), beacon_);
124     }
125 }
126
127 void
128 Cluster_spanner_engraver::stop_translation_timestep ()
129 {
130   typeset_grobs ();
131   cluster_notes_.clear ();
132 }
133
134 void
135 Cluster_spanner_engraver::acknowledge_note_column (Grob_info info)
136 {
137   if (!beacon_ && has_interface<Note_column> (info.grob ()))
138     {
139       finished_spanner_ = spanner_;
140       spanner_ = 0;
141     }
142 }
143
144 void
145 Cluster_spanner_engraver::boot ()
146 {
147   ADD_LISTENER (Cluster_spanner_engraver, cluster_note);
148   ADD_ACKNOWLEDGER (Cluster_spanner_engraver, note_column);
149 }
150
151 ADD_TRANSLATOR (Cluster_spanner_engraver,
152                 /* doc */
153                 "Engrave a cluster using @code{Spanner} notation.",
154
155                 /* create */
156                 "ClusterSpanner "
157                 "ClusterSpannerBeacon ",
158
159                 /* read */
160                 "",
161
162                 /* write */
163                 ""
164                );
165