Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / cluster-engraver.cc
blobbf25dce7b52408781f817fefd430bb2b141df53d
1 /*
2 cluster-engraver.cc -- implement Cluster_engraver
4 (c) 2002--2009 Juergen Reuter <reuter@ipd.uka.de>
6 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
10 #include "spanner.hh"
11 #include "note-head.hh"
12 #include "note-column.hh"
13 #include "pointer-group-interface.hh"
14 #include "pitch.hh"
15 #include "stream-event.hh"
16 #include "item.hh"
18 #include "translator.icc"
20 class Cluster_spanner_engraver : public Engraver
23 protected:
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 ();
30 private:
31 vector<Stream_event*> cluster_notes_;
32 Item *beacon_;
34 void typeset_grobs ();
35 Spanner *spanner_;
36 Spanner *finished_spanner_;
39 Cluster_spanner_engraver::Cluster_spanner_engraver ()
41 spanner_ = 0;
42 finished_spanner_ = 0;
43 beacon_ = 0;
46 void
47 Cluster_spanner_engraver::finalize ()
49 typeset_grobs ();
50 finished_spanner_ = spanner_;
51 spanner_ = 0;
52 typeset_grobs ();
55 void
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;
69 beacon_ = 0;
72 IMPLEMENT_TRANSLATOR_LISTENER (Cluster_spanner_engraver, cluster_note);
73 void
74 Cluster_spanner_engraver::listen_cluster_note (Stream_event *ev)
76 cluster_notes_.push_back (ev);
79 void
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;
87 int pmax = INT_MIN;
88 int pmin = INT_MAX;
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;
96 pmax = max (pmax, p);
97 pmin = min (pmin, p);
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_);
116 void
117 Cluster_spanner_engraver::stop_translation_timestep ()
119 typeset_grobs ();
120 cluster_notes_.clear ();
123 void
124 Cluster_spanner_engraver::acknowledge_note_column (Grob_info info)
126 if (!beacon_ && Note_column::has_interface (info.grob ()))
128 finished_spanner_ = spanner_;
129 spanner_ = 0;
133 ADD_ACKNOWLEDGER (Cluster_spanner_engraver, note_column);
134 ADD_TRANSLATOR (Cluster_spanner_engraver,
135 /* doc */
136 "Engrave a cluster using @code{Spanner} notation.",
138 /* create */
139 "ClusterSpanner "
140 "ClusterSpannerBeacon ",
142 /* read */
145 /* write */