2 cluster-engraver.cc -- implement Cluster_engraver
4 (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
6 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "note-head.hh"
13 #include "note-column.hh"
14 #include "group-interface.hh"
16 class Cluster_spanner_engraver
: public Engraver
20 TRANSLATOR_DECLARATIONS (Cluster_spanner_engraver
);
21 virtual bool try_music (Music
*);
22 virtual void process_music ();
23 virtual void acknowledge_grob (Grob_info
);
24 virtual void stop_translation_timestep ();
25 virtual void finalize ();
27 Link_array
<Music
> cluster_notes_
;
30 void typeset_grobs ();
32 Spanner
* finished_spanner_
;
35 Cluster_spanner_engraver::Cluster_spanner_engraver ()
38 finished_spanner_
= 0;
43 Cluster_spanner_engraver::finalize ()
46 finished_spanner_
= spanner_
;
52 Cluster_spanner_engraver::typeset_grobs ()
54 if (finished_spanner_
)
56 typeset_grob (finished_spanner_
);
57 finished_spanner_
= 0;
62 typeset_grob (beacon_
);
68 Cluster_spanner_engraver::try_music (Music
*m
)
70 if (m
->is_mus_type ("cluster-note-event"))
72 cluster_notes_
.push (m
);
79 Cluster_spanner_engraver::process_music ()
81 if (cluster_notes_
.size ())
83 SCM c0scm
= get_property ("middleCPosition");
85 int c0
= gh_number_p (c0scm
) ? gh_scm2int (c0scm
) : 0;
89 for (int i
= 0; i
<cluster_notes_
.size (); i
++)
91 Pitch
*pit
=unsmob_pitch (cluster_notes_
[i
]->get_property ("pitch"));
93 int p
=( pit
? pit
->steps () : 0) + c0
;
99 beacon_
= make_item ("ClusterSpannerBeacon");
100 beacon_
->set_property ("positions",
101 scm_cons (gh_int2scm (pmin
),
103 announce_grob (beacon_
, cluster_notes_
[0]->self_scm ());
106 if (beacon_
&& !spanner_
)
108 spanner_
= make_spanner ("ClusterSpanner");
109 announce_grob (spanner_
, cluster_notes_
[0]->self_scm ());
112 if (beacon_
&& spanner_
)
114 add_bound_item (spanner_
, beacon_
);
115 Pointer_group_interface::add_grob (spanner_
, ly_symbol2scm ("columns"), beacon_
);
121 Cluster_spanner_engraver::stop_translation_timestep ()
125 cluster_notes_
.clear ();
130 Cluster_spanner_engraver::acknowledge_grob (Grob_info info
)
132 if (!beacon_
&& Note_column::has_interface (info
.grob_
))
134 finished_spanner_
= spanner_
;
139 ENTER_DESCRIPTION (Cluster_spanner_engraver
,
140 /* descr */ "Engraves a cluster using Spanner notation ",
141 /* creats*/ "ClusterSpanner ClusterSpannerBeacon",
142 /* accepts */ "cluster-note-event",
143 /* acks */ "note-column-interface",