X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flocal-key-item.cc;h=d18824b443a58c77df4ab3504b8ace86a5d517f9;hb=01e85a02b5866e42e2ef822797f3986f06289bc0;hp=92c6e2300afb482a8da4d651595c898e4adc6c5e;hpb=75be12aa75a535af753d6125bfc03da3ee303b36;p=lilypond.git diff --git a/lily/local-key-item.cc b/lily/local-key-item.cc index 92c6e2300a..d18824b443 100644 --- a/lily/local-key-item.cc +++ b/lily/local-key-item.cc @@ -3,62 +3,79 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ #include "local-key-item.hh" #include "molecule.hh" -#include "scalar.hh" +#include "staff-symbol-referencer.hh" #include "lookup.hh" #include "paper-def.hh" #include "musical-request.hh" #include "note-head.hh" #include "misc.hh" -Local_key_item::Local_key_item () -{ - c0_position_i_ = 0; -} void -Local_key_item::add_support (Item*head_l) +Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural) { - if (support_items_.find_l(head_l)) - return ; - support_items_.push (head_l); - add_dependency (head_l); + for (int i=0; i< accidental_arr_.size(); i++) + if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_)) + return; + /* maybe natural (and cautionary) should be modif. nonetheless? */ + + Local_key_cautionary_tuple t; + t.pitch_ = p; + t.cautionary_b_ = cautionary; + t.natural_b_ = natural; + accidental_arr_.push (t); } + + void -Local_key_item::add (Musical_pitch p) +Local_key_item::do_pre_processing() { - for (int i=0; i< accidental_pitch_arr_.size(); i++) - if (!Musical_pitch::compare (p, accidental_pitch_arr_[i])) - return; - - accidental_pitch_arr_.push (p); + accidental_arr_.sort (Local_key_cautionary_tuple::compare); } -void -Local_key_item::do_pre_processing() +Molecule +Local_key_item::accidental (int j, bool cautionary, bool natural) const { - accidental_pitch_arr_.sort (Musical_pitch::compare); + Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j))); + if (natural) + { + Molecule prefix = lookup_l ()->afm_find (String ("accidentals-0")); + m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0); + } + if (cautionary) + { + Molecule open = lookup_l ()->afm_find (String ("accidentals-(")); + Molecule close = lookup_l ()->afm_find (String ("accidentals-)")); + m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0); + m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0); + } + + return m; } Molecule* Local_key_item::do_brew_molecule_p() const { Molecule*output = new Molecule; - + Staff_symbol_referencer_interface si (this); + Real note_distance = si.staff_space ()/2; Molecule *octave_mol_p = 0; int lastoct = -100; - for (int i = 0; i < accidental_pitch_arr_.size(); i++) + + for (int i = 0; i < accidental_arr_.size(); i++) { + Musical_pitch p (accidental_arr_[i].pitch_); // do one octave - if (accidental_pitch_arr_[i].octave_i_ != lastoct) + if (p.octave_i_ != lastoct) { if (octave_mol_p) { - Real dy =lastoct*7*paper()->internote_f (); + Real dy =lastoct*7* note_distance; octave_mol_p->translate_axis (dy, Y_AXIS); output->add_molecule (*octave_mol_p); delete octave_mol_p; @@ -66,12 +83,15 @@ Local_key_item::do_brew_molecule_p() const octave_mol_p= new Molecule; } - lastoct = accidental_pitch_arr_[i].octave_i_; - Real dy = - (c0_position_i_ + accidental_pitch_arr_[i].notename_i_) - * paper()->internote_f (); - Molecule m (lookup_l ()->accidental (accidental_pitch_arr_[i].accidental_i_, - accidental_pitch_arr_[i].cautionary_b_)); + lastoct = p.octave_i_; + + SCM c0 = get_elt_property ("c0-position"); + Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_) + * note_distance; + + Molecule m (accidental (p.accidental_i_, + accidental_arr_[i].cautionary_b_, + accidental_arr_[i].natural_b_)); m.translate_axis (dy, Y_AXIS); octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0); @@ -79,45 +99,34 @@ Local_key_item::do_brew_molecule_p() const if (octave_mol_p) { - Real dy =lastoct*7*paper()->internote_f (); + Real dy =lastoct*7*note_distance; octave_mol_p->translate_axis (dy, Y_AXIS); output->add_molecule (*octave_mol_p); delete octave_mol_p; } - if (accidental_pitch_arr_.size()) + if (accidental_arr_.size()) { - Box b(Interval (0, paper()->internote_f ()), Interval (0,0)); - Molecule m (lookup_l ()->fill (b)); - output->add_at_edge (X_AXIS, RIGHT, m, 0); + Drul_array pads; + + /* + Use a cons? + */ + pads[RIGHT] = get_elt_property ("right-padding"); + pads[LEFT] = get_elt_property ("left-padding"); + + Direction d = LEFT; + do { + if (!gh_number_p (pads[d])) + continue; + + Box b(Interval (0, gh_scm2double (pads[d]) * note_distance), + Interval (0,0)); + Molecule m (lookup_l ()->fill (b)); + output->add_at_edge (X_AXIS, d, m, 0); + } while ( flip (&d)!= LEFT); } - Interval x_int; - for (int i=0; i < support_items_.size(); i++) - { - Dimension_cache *common = - common_group (support_items_[i], X_AXIS); - - Real x = support_items_[i]->relative_coordinate (common, X_AXIS) - - relative_coordinate (common, X_AXIS); - - x_int.unite (x + support_items_[i]->extent (X_AXIS)); - } - if (x_int.empty_b ()) - x_int = Interval(0,0); - - output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS); - return output; } - - -void -Local_key_item::do_substitute_dependency (Score_element*o,Score_element*n) -{ - Item* o_l = dynamic_cast (o); - Item* n_l = n?dynamic_cast (n):0; - - support_items_.substitute (o_l, n_l); -}