#include "clef.hh"
#include "pitch.hh"
+#include "translator.icc"
+
/*
TODO: The representation of key sigs is all fucked.
*/
class Key_engraver : public Engraver
{
void create_key (bool);
- void read_ev (Music const *r);
+ void read_event (Music const *r);
- Music *key_ev_;
+ Music *key_event_;
Item *item_;
Item *cancellation_;
public:
protected:
virtual void initialize ();
virtual void finalize ();
- virtual bool try_music (Music *ev);
+ virtual bool try_music (Music *event);
void stop_translation_timestep ();
void process_music ();
Key_engraver::Key_engraver ()
{
- key_ev_ = 0;
+ key_event_ = 0;
item_ = 0;
cancellation_ = 0;
}
void
-Key_engraver::create_key (bool def)
+Key_engraver::create_key (bool is_default)
{
if (!item_)
{
- item_ = make_item ("KeySignature", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
+ item_ = make_item ("KeySignature", key_event_ ? key_event_->self_scm () : SCM_EOL);
item_->set_property ("c0-position",
get_property ("middleCPosition"));
if (to_boolean (get_property ("printKeyCancellation"))
&& !scm_is_eq (last, key))
{
- cancellation_ = make_item ("KeyCancellation", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
- cancellation_->set_property ("old-accidentals", last);
+ cancellation_ = make_item ("KeyCancellation", key_event_ ? key_event_->self_scm () : SCM_EOL);
+ cancellation_->set_property ("accidentals", last);
cancellation_->set_property ("c0-position",
get_property ("middleCPosition"));
}
- item_->set_property ("new-accidentals", key);
+ item_->set_property ("accidentals", key);
}
- if (!def)
+ if (!is_default)
{
- SCM vis = get_property ("explicitKeySignatureVisibility");
- if (ly_is_procedure (vis))
- item_->set_property ("break-visibility", vis);
+ SCM visibility = get_property ("explicitKeySignatureVisibility");
+ item_->set_property ("break-visibility", visibility);
}
}
bool
-Key_engraver::try_music (Music *ev)
+Key_engraver::try_music (Music *event)
{
- if (ev->is_mus_type ("key-change-event"))
+ if (event->is_mus_type ("key-change-event"))
{
/* do this only once, just to be on the safe side. */
- if (!key_ev_)
+ if (!key_event_)
{
- key_ev_ = ev;
- read_ev (key_ev_);
+ key_event_ = event;
+ read_event (key_event_);
}
return true;
}
void
Key_engraver::process_music ()
{
- if (key_ev_
+ if (key_event_
|| get_property ("lastKeySignature") != get_property ("keySignature"))
create_key (false);
}
item_ = 0;
context ()->set_property ("lastKeySignature", get_property ("keySignature"));
cancellation_ = 0;
- key_ev_ = 0;
+ key_event_ = 0;
}
void
-Key_engraver::read_ev (Music const *r)
+Key_engraver::read_event (Music const *r)
{
SCM p = r->get_property ("pitch-alist");
if (!scm_is_pair (p))
context ()->set_property ("tonic", p.smobbed_copy ());
}
-#include "translator.icc"
ADD_ACKNOWLEDGER (Key_engraver,clef);
ADD_ACKNOWLEDGER (Key_engraver,bar_line);
+
ADD_TRANSLATOR (Key_engraver,
/* descr */ "",
/* creats*/ "KeySignature",
// Find the c in the range -4 through 2
int from_bottom_pos = c0p + 4;
- from_bottom_pos = from_bottom_pos%7;
- from_bottom_pos = (from_bottom_pos + 7)%7; // Precaution to get positive.
+ from_bottom_pos = from_bottom_pos % 7;
+ from_bottom_pos = (from_bottom_pos + 7) % 7; // Precaution to get positive.
int c0 = from_bottom_pos - 4;
if ((alter < 0 && ((p > FLAT_TOP_PITCH) || (p + c0 > 4)) && (p + c0 > 1))
SCM
Key_signature_interface::print (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Item *me = dynamic_cast<Item*> (unsmob_grob (smob));
Real inter = Staff_symbol_referencer::staff_space (me) / 2.0;
style = "";
}
- SCM newas = me->get_property ("new-accidentals");
+ SCM newas = me->get_property ("accidentals");
Stencil mol;
SCM c0s = me->get_property ("c0-position");
the cancellation signature.
*/
+ int last_pos = -1000;
Font_metric *fm = Font_interface::get_default_font (me);
for (SCM s = newas; scm_is_pair (s); s = scm_cdr (s))
{
SCM what = scm_caar (s);
int pos = alteration_pos (what, alteration, c0p);
acc.translate_axis (pos * inter, Y_AXIS);
- mol.add_at_edge (X_AXIS, LEFT, acc, 0, 0);
- }
- }
-
- Item *it = dynamic_cast<Item *> (me);
- if (it->break_status_dir () != RIGHT)
- {
- SCM old = me->get_property ("old-accidentals");
-
- Stencil natural;
- if (scm_is_pair (old))
- natural = Font_interface::get_default_font (me)->
- find_by_name (String ("accidentals.") + style + String ("0"));
-
- int last_pos = -100;
- for (; scm_is_pair (old); old = scm_cdr (old))
- {
- SCM found = scm_assoc (scm_caar (old), newas);
- if (found == SCM_BOOL_F
- || scm_cdr (found) != scm_cdar (old))
- {
- SCM what = scm_caar (old);
- int alteration = 0;
- int pos = alteration_pos (what, alteration, c0p);
- Stencil m = natural;
- m.translate_axis (pos * inter, Y_AXIS);
/*
The natural sign (unlike flat & sharp)
has vertical edges on both sides. A little padding is
needed to prevent collisions.
*/
- Real padding = 0.0;
- if (last_pos < pos + 2
- && last_pos > pos - 6)
- padding = 0.3;
-
- mol.add_at_edge (X_AXIS, LEFT, m, padding, 0);
- last_pos = pos;
- }
+ Real padding = 0.0;
+ if (alteration == 0
+ && last_pos < pos + 2
+ && last_pos > pos - 6)
+ padding = 0.3;
+
+ mol.add_at_edge (X_AXIS, LEFT, acc, padding, 0);
+ last_pos = pos;
}
}
ADD_INTERFACE (Key_signature_interface, "key-signature-interface",
"A group of accidentals, to be printed as signature sign.",
- "style c0-position old-accidentals new-accidentals");
+ "style c0-position accidentals");