2 cluster-engraver.cc -- implement Cluster_engraver
4 (c) 2002--2009 Juergen Reuter <reuter@ipd.uka.de>
6 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "note-head.hh"
12 #include "note-column.hh"
13 #include "pointer-group-interface.hh"
15 #include "stream-event.hh"
18 #include "translator.icc"
20 class Cluster_spanner_engraver
: public Engraver
24 TRANSLATOR_DECLARATIONS (Cluster_spanner_engraver
);
25 DECLARE_TRANSLATOR_LISTENER (cluster_note
);
26 DECLARE_ACKNOWLEDGER (note_column
);
27 void stop_translation_timestep ();
28 virtual void process_music ();
29 virtual void finalize ();
31 vector
<Stream_event
*> cluster_notes_
;
34 void typeset_grobs ();
36 Spanner
*finished_spanner_
;
39 Cluster_spanner_engraver::Cluster_spanner_engraver ()
42 finished_spanner_
= 0;
47 Cluster_spanner_engraver::finalize ()
50 finished_spanner_
= spanner_
;
56 Cluster_spanner_engraver::typeset_grobs ()
58 if (finished_spanner_
)
60 if (!finished_spanner_
->get_bound (RIGHT
))
62 finished_spanner_
->set_bound (RIGHT
,
63 finished_spanner_
->get_bound (LEFT
));
67 finished_spanner_
= 0;
72 IMPLEMENT_TRANSLATOR_LISTENER (Cluster_spanner_engraver
, cluster_note
);
74 Cluster_spanner_engraver::listen_cluster_note (Stream_event
*ev
)
76 cluster_notes_
.push_back (ev
);
80 Cluster_spanner_engraver::process_music ()
82 if (cluster_notes_
.size ())
84 SCM c0scm
= get_property ("middleCPosition");
86 int c0
= scm_is_number (c0scm
) ? scm_to_int (c0scm
) : 0;
90 for (vsize i
= 0; i
< cluster_notes_
.size (); i
++)
92 Pitch
*pit
= unsmob_pitch (cluster_notes_
[i
]->get_property ("pitch"));
94 int p
= (pit
? pit
->steps () : 0) + c0
;
100 beacon_
= make_item ("ClusterSpannerBeacon", cluster_notes_
[0]->self_scm ());
101 beacon_
->set_property ("positions",
102 scm_cons (scm_from_int (pmin
),
103 scm_from_int (pmax
)));
106 if (beacon_
&& !spanner_
)
107 spanner_
= make_spanner ("ClusterSpanner", cluster_notes_
[0]->self_scm ());
109 if (beacon_
&& spanner_
)
111 add_bound_item (spanner_
, beacon_
);
112 Pointer_group_interface::add_grob (spanner_
, ly_symbol2scm ("columns"), beacon_
);
117 Cluster_spanner_engraver::stop_translation_timestep ()
120 cluster_notes_
.clear ();
124 Cluster_spanner_engraver::acknowledge_note_column (Grob_info info
)
126 if (!beacon_
&& Note_column::has_interface (info
.grob ()))
128 finished_spanner_
= spanner_
;
133 ADD_ACKNOWLEDGER (Cluster_spanner_engraver
, note_column
);
134 ADD_TRANSLATOR (Cluster_spanner_engraver
,
136 "Engrave a cluster using @code{Spanner} notation.",
140 "ClusterSpannerBeacon ",