* lily/ledger-line-engraver.cc: new file.
[lilypond.git] / lily / cluster-engraver.cc
bloba65ee86cbf39d72fcb0447bfe01a56c63f58ec50
1 /*
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>
7 */
9 #include "engraver.hh"
10 #include "item.hh"
11 #include "spanner.hh"
12 #include "note-head.hh"
13 #include "note-column.hh"
14 #include "group-interface.hh"
16 class Cluster_spanner_engraver : public Engraver
19 protected:
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 ();
26 private:
27 Link_array<Music> cluster_notes_;
28 Item* beacon_;
30 void typeset_grobs ();
31 Spanner *spanner_;
32 Spanner * finished_spanner_ ;
35 Cluster_spanner_engraver::Cluster_spanner_engraver ()
37 spanner_ = 0;
38 finished_spanner_ = 0;
39 beacon_ = 0;
42 void
43 Cluster_spanner_engraver::finalize ()
45 typeset_grobs ();
46 finished_spanner_ = spanner_;
47 spanner_ = 0;
48 typeset_grobs ();
51 void
52 Cluster_spanner_engraver::typeset_grobs ()
54 finished_spanner_ = 0;
55 beacon_ = 0;
58 bool
59 Cluster_spanner_engraver::try_music (Music *m)
61 if (m->is_mus_type ("cluster-note-event"))
63 cluster_notes_.push (m);
64 return true;
66 return false;
69 void
70 Cluster_spanner_engraver::process_music ()
72 if (cluster_notes_.size ())
74 SCM c0scm = get_property ("middleCPosition");
76 int c0 = ly_c_number_p (c0scm) ? ly_scm2int (c0scm) : 0;
77 int pmax = INT_MIN;
78 int pmin = INT_MAX;
80 for (int i = 0; i <cluster_notes_.size (); i++)
82 Pitch *pit =unsmob_pitch (cluster_notes_[i]->get_property ("pitch"));
84 int p =( pit ? pit->steps () : 0) + c0;
86 pmax = pmax >? p;
87 pmin = pmin <? p;
90 beacon_ = make_item ("ClusterSpannerBeacon", cluster_notes_[0]->self_scm ());
91 beacon_->set_property ("positions",
92 scm_cons (scm_int2num (pmin),
93 scm_int2num (pmax)));
96 if (beacon_ && !spanner_)
98 spanner_ = make_spanner ("ClusterSpanner", cluster_notes_[0]->self_scm () );
101 if (beacon_ && spanner_)
103 add_bound_item (spanner_, beacon_);
104 Pointer_group_interface::add_grob (spanner_, ly_symbol2scm ("columns"), beacon_);
109 void
110 Cluster_spanner_engraver::stop_translation_timestep ()
112 typeset_grobs ();
114 cluster_notes_.clear ();
118 void
119 Cluster_spanner_engraver::acknowledge_grob (Grob_info info)
121 if (!beacon_ && Note_column::has_interface (info.grob_))
123 finished_spanner_ = spanner_;
124 spanner_ = 0;
128 ENTER_DESCRIPTION (Cluster_spanner_engraver,
129 /* descr */ "Engraves a cluster using Spanner notation ",
130 /* creats*/ "ClusterSpanner ClusterSpannerBeacon",
131 /* accepts */ "cluster-note-event",
132 /* acks */ "note-column-interface",
133 /* reads */ "",
134 /* write */ "");