2 ambitus-engraver.cc -- implement Ambitus_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2009 Juergen Reuter <reuter@ipd.uka.de>
8 Han-Wen Nienhuys <hanwen@xs4all.nl
11 #include "engraver.hh"
13 #include "accidental-placement.hh"
14 #include "axis-group-interface.hh"
16 #include "note-head.hh"
17 #include "pitch-interval.hh"
18 #include "pointer-group-interface.hh"
19 #include "protected-scm.hh"
20 #include "side-position-interface.hh"
21 #include "separation-item.hh"
22 #include "staff-symbol-referencer.hh"
23 #include "stream-event.hh"
25 #include "translator.icc"
27 class Ambitus_engraver
: public Engraver
30 TRANSLATOR_DECLARATIONS (Ambitus_engraver
);
31 void process_music ();
32 void acknowledge_note_head (Grob_info
);
33 void stop_translation_timestep ();
34 virtual void finalize ();
35 virtual void derived_mark () const;
38 void create_ambitus ();
41 Drul_array
<Item
*> heads_
;
42 Drul_array
<Item
*> accidentals_
;
43 Drul_array
<Stream_event
*> causes_
;
44 Pitch_interval pitch_interval_
;
51 Ambitus_engraver::derived_mark () const
53 scm_gc_mark (start_key_sig_
);
57 Ambitus_engraver::create_ambitus ()
59 ambitus_
= make_item ("AmbitusLine", SCM_EOL
);
60 group_
= make_item ("Ambitus", SCM_EOL
);
64 heads_
[d
] = make_item ("AmbitusNoteHead", SCM_EOL
);
65 accidentals_
[d
] = make_item ("AmbitusAccidental", SCM_EOL
);
66 accidentals_
[d
]->set_parent (heads_
[d
], Y_AXIS
);
67 heads_
[d
]->set_object ("accidental-grob",
68 accidentals_
[d
]->self_scm ());
69 Axis_group_interface::add_element (group_
, heads_
[d
]);
70 Axis_group_interface::add_element (group_
, accidentals_
[d
]);
72 while (flip (&d
) != DOWN
);
74 ambitus_
->set_parent (heads_
[DOWN
], X_AXIS
);
75 Axis_group_interface::add_element (group_
, ambitus_
);
80 Ambitus_engraver::Ambitus_engraver ()
83 heads_
[LEFT
] = heads_
[RIGHT
] = 0;
84 accidentals_
[LEFT
] = accidentals_
[RIGHT
] = 0;
87 start_key_sig_
= SCM_EOL
;
91 Ambitus_engraver::process_music ()
94 * Ensure that ambitus is created in the very first timestep
101 Ambitus_engraver::stop_translation_timestep ()
103 if (ambitus_
&& !is_typeset_
)
106 * Evaluate middleCPosition not until now, since otherwise we
107 * may then oversee a clef that is defined in a staff context if
108 * we are in a voice context; middleCPosition would then be
111 start_c0_
= robust_scm2int (get_property ("middleCPosition"), 0);
112 start_key_sig_
= get_property ("keySignature");
119 Ambitus_engraver::acknowledge_note_head (Grob_info info
)
121 Stream_event
*nr
= info
.event_cause ();
122 if (nr
&& nr
->in_event_class ("note-event"))
124 Pitch pitch
= *unsmob_pitch (nr
->get_property ("pitch"));
125 Drul_array
<bool> expands
= pitch_interval_
.add_point (pitch
);
134 Ambitus_engraver::finalize ()
136 if (ambitus_
&& !pitch_interval_
.is_empty ())
138 Grob
*accidental_placement
=
139 make_item ("AccidentalPlacement",
140 accidentals_
[DOWN
]->self_scm ());
145 Pitch p
= pitch_interval_
[d
];
146 heads_
[d
]->set_property ("cause", causes_
[d
]->self_scm());
147 heads_
[d
]->set_property ("staff-position",
148 scm_from_int (start_c0_
151 SCM handle
= scm_assoc (scm_cons (scm_from_int (p
.get_octave ()),
152 scm_from_int (p
.get_notename ())),
155 if (handle
== SCM_BOOL_F
)
156 handle
= scm_assoc (scm_from_int (p
.get_notename ()),
159 Rational sig_alter
= (handle
!= SCM_BOOL_F
)
160 ? robust_scm2rational (scm_cdr (handle
), Rational (0)) : Rational (0);
162 if (sig_alter
== p
.get_alteration ())
164 accidentals_
[d
]->suicide ();
165 heads_
[d
]->set_object ("accidental-grob", SCM_EOL
);
169 accidentals_
[d
]->set_property ("alteration", ly_rational2scm (p
.get_alteration ()));
171 Separation_item::add_conditional_item (heads_
[d
], accidental_placement
);
172 Accidental_placement::add_accidental (accidental_placement
, accidentals_
[d
]);
174 while (flip (&d
) != DOWN
);
177 Pointer_group_interface::add_grob (ambitus_
, ly_symbol2scm ("note-heads"), heads_
[DOWN
]);
178 Pointer_group_interface::add_grob (ambitus_
, ly_symbol2scm ("note-heads"), heads_
[UP
]);
179 Axis_group_interface::add_element (group_
, accidental_placement
);
186 accidentals_
[d
]->suicide ();
187 heads_
[d
]->suicide ();
189 while (flip (&d
) != DOWN
);
191 ambitus_
->suicide ();
195 ADD_ACKNOWLEDGER (Ambitus_engraver
, note_head
);
196 ADD_TRANSLATOR (Ambitus_engraver
,
201 "AccidentalPlacement "