#include "musical-request.hh"
#include "command-request.hh"
-#include "local-key-item.hh"
#include "item.hh"
#include "tie.hh"
#include "rhythmic-head.hh"
#include "engraver-group-engraver.hh"
-
-#include "staff-symbol-referencer.hh"
+#include "accidental-placement.hh"
#include "side-position-interface.hh"
#include "engraver.hh"
#include "arpeggio.hh"
*/
+struct Accidental_entry {
+ bool done_;
+ Note_req * melodic_;
+ Grob * accidental_;
+ Translator_group *origin_;
+ Grob* head_;
+ Accidental_entry();
+};
+
+Accidental_entry::Accidental_entry()
+{
+ done_ = false;
+ melodic_ =0;
+ accidental_ = 0;
+ origin_ = 0;
+ head_ = 0;
+}
struct Accidental_engraver : Engraver {
- Item *key_item_p_;
protected:
TRANSLATOR_DECLARATIONS (Accidental_engraver);
virtual void process_music ();
virtual void acknowledge_grob (Grob_info);
virtual void stop_translation_timestep ();
virtual void initialize ();
- virtual void create_grobs ();
+ virtual void process_acknowledged_grobs ();
virtual void finalize ();
public:
This is not a property, and it is not protected. This poses a
very small risk of the value being GC'd from under us.
-
- Oh well.
*/
SCM last_keysig_;
store all information before we can really create the accidentals.
*/
Link_array<Grob> arpeggios_;
+
+ Grob * accidental_placement_;
- Link_array<Note_req> mel_l_arr_;
- Link_array<Grob> head_l_arr_;
- Link_array<Item> forced_l_arr_;
- Link_array<Grob> tie_l_arr_;
- Link_array<Translator_group> origin_l_arr_;
+
+ /*
+ The next
+ */
+ Array<Accidental_entry> accidental_arr_;
+
+ Link_array<Grob> tie_arr_;
+
};
+static void set_property_on_children (Translator_group * trans, const char * sym, SCM val)
+{
+ trans->set_property (sym, val);
+ for (SCM p = trans -> trans_group_list_; gh_pair_p (p); p = ly_cdr(p)) {
+ Translator_group *trg = dynamic_cast<Translator_group*> (unsmob_translator (ly_car (p)));
+ set_property_on_children(trg,sym,ly_deep_copy(val));
+ }
+}
+
Accidental_engraver::Accidental_engraver ()
{
- key_item_p_ = 0;
+ accidental_placement_ = 0;
last_keysig_ = SCM_EOL;
}
trans_ -> set_property ("localKeySignature", ly_deep_copy (last_keysig_));
trans_ = trans_->daddy_trans_l_;
}
- daddy_trans_l_->set_children_property ("localKeySignature", last_keysig_);
+ set_property_on_children (daddy_trans_l_,"localKeySignature", last_keysig_);
}
/*
*/
static int
-number_accidentals (SCM sig, Note_req * note_l, SCM curbarnum, SCM lazyness,
+number_accidentals (SCM sig, Note_req * note_l, Pitch *pitch, SCM curbarnum, SCM lazyness,
bool ignore_octave_b)
{
- Pitch *pitch = unsmob_pitch (note_l->get_mus_property ("pitch"));
int n = pitch->notename_i_;
int o = pitch->octave_i_;
int a = pitch->alteration_i_;
}
static int
-number_accidentals (Note_req * note_l, Translator_group * origin_l,
+number_accidentals (Note_req * note_l, Pitch *pitch, Translator_group * origin_l,
SCM accidentals, SCM curbarnum)
{
int number = 0;
if (same_octave_b || any_octave_b)
{
int n = number_accidentals
- (localsig, note_l, curbarnum, lazyness, any_octave_b);
+ (localsig, note_l, pitch, curbarnum, lazyness, any_octave_b);
diff = diff || (n < 0);
number = max (number, abs (n));
}
}
void
-Accidental_engraver::create_grobs ()
+Accidental_engraver::process_acknowledged_grobs ()
{
- if (!key_item_p_ && mel_l_arr_.size ())
+ if (accidental_arr_.size () && !accidental_arr_.top().done_)
{
//SCM localsig = get_property ("localKeySignature");
SCM accidentals = get_property ("autoAccidentals");
SCM barnum = get_property ("currentBarNumber");
bool extra_natural_b = get_property ("extraNatural") == SCM_BOOL_T;
- for (int i = 0; i < mel_l_arr_.size (); i++)
+ for (int i = 0; i < accidental_arr_.size (); i++)
{
- Grob * support_l = head_l_arr_[i];
- Note_req * note_l = mel_l_arr_[i];
- Translator_group * origin_l = origin_l_arr_[i];
-
- int num = number_accidentals (note_l, origin_l, accidentals, barnum);
- int num_caut = number_accidentals (note_l, origin_l, cautionaries, barnum);
+ if (accidental_arr_[i].done_ )
+ continue;
+ accidental_arr_[i].done_ = true;
+ Grob * support_l = accidental_arr_[i].head_;
+ Note_req * note_l = accidental_arr_[i].melodic_;
+ Translator_group * origin_l = accidental_arr_[i].origin_;
+
+ Pitch * pitch = unsmob_pitch (note_l->get_mus_property ("pitch"));
+ int num = number_accidentals (note_l, pitch, origin_l, accidentals, barnum);
+ int num_caut = number_accidentals (note_l, pitch, origin_l, cautionaries, barnum);
bool cautionary = to_boolean (note_l->get_mus_property ("cautionary"));
- if (abs (num_caut)>abs (num))
+ if (abs (num_caut) > abs (num))
{
num = num_caut;
cautionary = true;
Grob *tie_break_reminder = 0;
bool tie_changes = false;
- for (int j = 0; j < tie_l_arr_.size (); j++)
- if (support_l == Tie::head (tie_l_arr_[j], RIGHT))
+ for (int j = 0; j < tie_arr_.size (); j++)
+ if (support_l == Tie::head (tie_arr_[j], RIGHT))
{
tie_changes = different;
Maybe check property noTieBreakForceAccidental? */
if (different)
- tie_break_reminder = tie_l_arr_[j];
+ tie_break_reminder = tie_arr_[j];
break;
}
if (num)
{
- if (!key_item_p_)
- {
- key_item_p_ = new Item (get_property ("Accidentals"));
+ Grob * a = new Item (get_property ("Accidental"));
+ a->set_parent (support_l, Y_AXIS);
- SCM c0 = get_property ("centralCPosition");
- if (gh_number_p (c0))
- Staff_symbol_referencer::set_position (key_item_p_, gh_scm2int (c0));
-
- announce_grob (key_item_p_, SCM_EOL);
+ if (!accidental_placement_)
+ {
+ accidental_placement_ = new Item (get_property ("AccidentalPlacement"));
+ announce_grob (accidental_placement_, a->self_scm());
}
+
+ Accidental_placement::add_accidental (accidental_placement_, a);
+ announce_grob (a, SCM_EOL);
+
+
+ SCM accs = gh_cons (gh_int2scm (pitch->alteration_i_), SCM_EOL);
+ if (num == 2 && extra_natural_b)
+ accs = gh_cons (gh_int2scm (0), accs);
+
+ /* TODO:
+
+ add cautionary option in accidental.
+ */
+ if (cautionary)
+ {
+ a->set_grob_property ("cautionary", SCM_BOOL_T);
+ }
+
+ if (tie_break_reminder)
+ {
+ // TODO.
+ a->set_grob_property ("tie", tie_break_reminder->self_scm());
+ }
- Local_key_item::add_pitch (key_item_p_, *unsmob_pitch (note_l->get_mus_property ("pitch")),
- cautionary,
- num == 2 && extra_natural_b,
- tie_break_reminder);
- Side_position_interface::add_support (key_item_p_, support_l);
- support_l->set_grob_property ("accidental-grob", key_item_p_->self_scm ());
+ support_l->set_grob_property ("accidental-grob", a->self_scm ());
+
+ a->set_grob_property ("accidentals", accs);
+ accidental_arr_[i].accidental_ = a;
+ /*
+ We add the accidentals to the support of the arpeggio, so it is put left of the
+ accidentals.
+
+ */
+ for (int i = 0; i < arpeggios_.size (); i++)
+ Side_position_interface::add_support (arpeggios_[i], a);
}
always do the correct thing?
*/
- Pitch *pitch = unsmob_pitch (note_l->get_mus_property ("pitch"));
+
int n = pitch->notename_i_;
int o = pitch->octave_i_;
int a = pitch->alteration_i_;
*/
- Translator_group * trans_ = origin_l_arr_[i];
- while (trans_)
+
+ while (origin_l)
{
- SCM localsig = trans_->get_property ("localKeySignature");
+ SCM localsig = origin_l->get_property ("localKeySignature");
if (tie_changes)
{
/*
localsig = ly_assoc_front_x
(localsig, on_s, gh_cons (gh_int2scm (a), barnum));
}
- trans_->set_property ("localKeySignature", localsig);
- trans_ = trans_->daddy_trans_l_;
+ origin_l->set_property ("localKeySignature", localsig);
+ origin_l = origin_l->daddy_trans_l_;
}
}
}
-
-
- if (key_item_p_)
- {
- /*
- We add the accidentals to the support of the arpeggio, so it is put left of the
- accidentals.
-
- */
- for (int i = 0; i < arpeggios_.size (); i++)
- Side_position_interface::add_support (arpeggios_[i], key_item_p_);
-
- arpeggios_.clear ();
- }
}
void
void
Accidental_engraver::stop_translation_timestep ()
{
- if (key_item_p_)
+ for (int i = 0; i < accidental_arr_.size(); i++)
{
- for (int i = 0; i < head_l_arr_.size (); i++)
- Side_position_interface::add_support (key_item_p_, head_l_arr_[i]);
-
- typeset_grob (key_item_p_);
- key_item_p_ = 0;
+ Grob *a = accidental_arr_[i].accidental_;
+ if (a)
+ {
+ typeset_grob (a);
+ }
}
-
- mel_l_arr_.clear ();
+ if (accidental_placement_)
+ typeset_grob(accidental_placement_);
+ accidental_placement_ = 00;
+
+ accidental_arr_.clear();
arpeggios_.clear ();
- tie_l_arr_.clear ();
- head_l_arr_.clear ();
- forced_l_arr_.clear ();
- origin_l_arr_.clear ();
+ tie_arr_.clear ();
}
void
if (note_l && Rhythmic_head::has_interface (info.grob_l_))
{
- mel_l_arr_.push (note_l);
- head_l_arr_.push (info.grob_l_);
- origin_l_arr_.push (info.origin_trans_l_->daddy_trans_l_);
+ Accidental_entry entry ;
+ entry.head_ = info.grob_l_;
+ entry.origin_ = info.origin_trans_l_->daddy_trans_l_;
+ entry.melodic_ = note_l;
+
+ accidental_arr_.push (entry);
}
else if (Tie::has_interface (info.grob_l_))
{
- tie_l_arr_.push (info.grob_l_);
+ tie_arr_.push (info.grob_l_);
}
else if (Arpeggio::has_interface (info.grob_l_))
{
trans_ -> set_property ("localKeySignature", ly_deep_copy (sig));
trans_ = trans_->daddy_trans_l_;
}
- daddy_trans_l_->set_children_property ("localKeySignature", sig);
+ set_property_on_children(daddy_trans_l_,"localKeySignature", sig);
last_keysig_ = sig;
}
events. Due to interaction with ties (which don't come together
with note heads), this needs to be in a context higher than Tie_engraver.",
- "Accidentals",
+ "Accidental",
"rhythmic-head-interface tie-interface arpeggio-interface",
"localKeySignature extraNatural autoAccidentals autoCautionaries",
"localKeySignature");