X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flocal-key-item.cc;h=7541177600ffa58bb77430b695391c3330b07d84;hb=949737e17ed7cbc231a3c08e45d32897a636d94d;hp=425982120c0b839ffa42324bb59f2a614cf1361d;hpb=daee8243ff1c66bc714455a2d265ab02f03546ec;p=lilypond.git diff --git a/lily/local-key-item.cc b/lily/local-key-item.cc index 425982120c..7541177600 100644 --- a/lily/local-key-item.cc +++ b/lily/local-key-item.cc @@ -1,93 +1,137 @@ +/* + local-key-item.cc -- implement Local_key_item, Musical_pitch + + source file of the GNU LilyPond music typesetter + + (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 "musicalrequest.hh" -#include "notehead.hh" +#include "musical-request.hh" +#include "note-head.hh" #include "misc.hh" - - -Local_key_item::Local_key_item(int i) +Local_key_item::Local_key_item () { - c0_position = i; } void -Local_key_item::add(Item*head_l) +Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural) { - 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? */ -void -Local_key_item::add(Melodic_req*m_l) -{ - add(m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_); + 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 (int o, int p , int a) +Local_key_item::do_pre_processing() { - Local_acc l; - l.octave = o; - l.name = p; - l.acc = a; - accs.push(l); + accidental_arr_.sort (Local_key_cautionary_tuple::compare); + Note_head_side::do_pre_processing (); } -void -Local_key_item::do_pre_processing() +Molecule +Local_key_item::accidental (int j, bool cautionary, bool natural) const { - accs.sort(Local_acc::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::brew_molecule_p()const +Local_key_item::do_brew_molecule_p() const { - Molecule* output = new Molecule; - Molecule*octmol = 0; - int lastoct = -100; - for (int i = 0; i < accs.size(); i++) { - // do one octave - if (accs[i].octave != lastoct) { - if (octmol){ - Real dy =lastoct*7*paper()->internote(); - octmol->translate(Offset(0, dy)); - output->add(*octmol); - delete octmol; + 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_arr_.size(); i++) + { + Musical_pitch p (accidental_arr_[i].pitch_); + // do one octave + if (p.octave_i_ != lastoct) + { + if (octave_mol_p) + { + Real dy =lastoct*7* note_distance; + octave_mol_p->translate_axis (dy, Y_AXIS); + output->add_molecule (*octave_mol_p); + delete octave_mol_p; } - octmol= new Molecule; + octave_mol_p= new Molecule; } - lastoct = accs[i].octave; - Symbol s =paper()->lookup_p_->accidental(accs[i].acc); - Atom a(s); - Real dy = (accs[i].name + c0_position) * paper()->internote(); - a.translate(Offset(0,dy)); + + 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_)); - octmol->add_right(a); + m.translate_axis (dy, Y_AXIS); + octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0); } - if (octmol){ - Real dy =lastoct*7*paper()->internote(); - octmol->translate(Offset(0, dy)); - output->add(*octmol); - delete octmol; + if (octave_mol_p) + { + 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_arr_.size()) + { + Drul_array pads; - Interval head_width=itemlist_width(support_items_); - output->translate(Offset(-output->extent().x.right + head_width.left ,0)); - - return output; + /* + 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); + } + + return output; } -int -Local_acc::compare(Local_acc&a, Local_acc&b) -{ - if (a.octave - b.octave) - return a.octave - b.octave; - if (a.name - b.name) - return a.name - b.name; - - assert(false); -};