From dfc51cf4a38b7b3497d357acc7b80283ae74262d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 20 Dec 1999 20:35:25 +0100 Subject: [PATCH] patch::: 1.3.15.jcn1 pl 14.hwn1jcn1 - chord-name uses scm members - bfs: knee with different mults, interstaff knee, auto-knee --- CHANGES | 4 ++ VERSION | 2 +- input/test/auto-isknee.ly | 26 +++++++++++ input/test/auto-knee.ly | 23 +++------- lily/beam.cc | 71 ++++++++++++++++-------------- lily/chord-name-engraver.cc | 3 +- lily/chord-name.cc | 88 +++++++++++++++++++++++++++++-------- lily/include/chord-name.hh | 8 +--- lily/lily-guile.cc | 2 + lily/stem.cc | 2 +- 10 files changed, 149 insertions(+), 80 deletions(-) create mode 100644 input/test/auto-isknee.ly diff --git a/CHANGES b/CHANGES index f0747050e8..87bebcbd4b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +pl 14.hwn1jcn1 + - chord-name uses scm members + - bfs: knee with different mults, interstaff knee, auto-knee + pl 14.hwn1 - specialize duration.cc for lily, move out of lib/ - stem cleanup diff --git a/VERSION b/VERSION index 531ec79331..538ce3a83b 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=15 -MY_PATCH_LEVEL= +MY_PATCH_LEVEL=jcn1 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/auto-isknee.ly b/input/test/auto-isknee.ly new file mode 100644 index 0000000000..f2b30b932a --- /dev/null +++ b/input/test/auto-isknee.ly @@ -0,0 +1,26 @@ + +\score { + \notes \context PianoStaff < + \context Staff = "up" { + \autochange Staff \relative c' { + [c8 e'] [c' c,,] + \stemdown + c'8 c c g, + g8 d' d d + \stemup + b8 c d e + } + } + \context Staff = "down" { + \clef bass; + s1*2 + } + > + \paper{ + \translator{ + \StaffContext + autoKneeGap = #13.0 + autoInterstaffKneeGap = #4.0 + } + } +} diff --git a/input/test/auto-knee.ly b/input/test/auto-knee.ly index e6541ec2ef..3a3fbf55d2 100644 --- a/input/test/auto-knee.ly +++ b/input/test/auto-knee.ly @@ -1,26 +1,13 @@ \score { - \notes \context PianoStaff < - \context Staff = "up" { - \autochange Staff \relative c' { - [c8 e'] [c' c,,] - \stemdown - c'8 c c g, - g8 d' d d - \stemup - b8 c d e - } - } - \context Staff = "down" { - \clef bass; - s1*2 - } - > + \context Staff \notes\relative c'{ +% \property Voice.autoKneeGap = #13 + [c8 e'] [c' c,,] + } \paper{ \translator{ \StaffContext - autoKneeGap = "13.0"; - autoInterstaffKneeGap = "4.0"; + autoKneeGap = #13 } } } diff --git a/lily/beam.cc b/lily/beam.cc index 3358453076..8620f8747c 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -207,9 +207,9 @@ Beam::auto_knee (String gap_str, bool interstaff_b) { bool is_b = (bool)(calc_interstaff_dist (stem (i), this) - calc_interstaff_dist (stem (i-1), this)); - int l_y = (int)(stem (i-1)->chord_start_f ()) + int l_y = (int)(stem (i-1)->head_positions()[get_direction ()]) + (int)calc_interstaff_dist (stem (i-1), this); - int r_y = (int)(stem (i)->chord_start_f ()) + int r_y = (int)(stem (i)->head_positions()[get_direction ()]) + (int)calc_interstaff_dist (stem (i), this); int gap_i = r_y - l_y; @@ -225,7 +225,7 @@ Beam::auto_knee (String gap_str, bool interstaff_b) { for (int i=0; i < stem_count (); i++) { - int y = (int)(stem (i)->chord_start_f ()) + int y = (int)(stem (i)->head_positions()[get_direction ()]) + (int)calc_interstaff_dist (stem (i), this); stem (i)->set_direction (y < knee_y ? UP : DOWN); stem (i)->set_elt_property ("dir-forced", SCM_BOOL_T); @@ -317,8 +317,9 @@ Beam::do_post_processing () set_stem_length (y, dy); y_shift = check_stem_length_f (y, dy); - Real internote_f = paper_l ()->get_var ("interline") / 2; - if (y_shift > internote_f / 4) + Staff_symbol_referencer_interface st (this); + Real half_space = st.staff_space () / 2; + if (y_shift > half_space / 4) { y += y_shift; @@ -327,7 +328,7 @@ Beam::do_post_processing () request quanting the other way. */ int quant_dir = 0; - if (abs (y_shift) > internote_f / 2) + if (abs (y_shift) > half_space / 2) quant_dir = sign (y_shift) * get_direction (); y = quantise_y_f (y, dy, quant_dir); set_stem_length (y, dy); @@ -421,11 +422,11 @@ Beam::calc_slope_damping_f (Real dy) const Real Beam::calc_stem_y_f (Stem* s, Real y, Real dy) const { - Real beam_f = gh_scm2double (get_elt_property ("beam-thickness")); - int multiplicity = get_multiplicity (); - + Real thick = gh_scm2double (get_elt_property ("beam-thickness")); + int beam_multiplicity = get_multiplicity (); + int stem_multiplicity = (s->flag_i () - 2) >? 0; - Real interbeam_f = paper_l ()->interbeam_f (multiplicity); + Real interbeam_f = paper_l ()->interbeam_f (beam_multiplicity); Real x0 = first_visible_stem ()->hpos_f (); Real dx = last_visible_stem ()->hpos_f () - x0; Real stem_y = (s->hpos_f () - x0) / dx * dy + y; @@ -433,8 +434,9 @@ Beam::calc_stem_y_f (Stem* s, Real y, Real dy) const /* knee */ if (get_direction () != s->get_direction ()) { - stem_y -= get_direction () * (beam_f / 2 - + (multiplicity - 1) * interbeam_f); + stem_y -= get_direction () + * (thick / 2 + (beam_multiplicity - 1 - stem_multiplicity)) + * interbeam_f; Staff_symbol_referencer_interface me (s); Staff_symbol_referencer_interface last (last_visible_stem ()); @@ -442,7 +444,7 @@ Beam::calc_stem_y_f (Stem* s, Real y, Real dy) const if ((s != first_visible_stem ()) && me.staff_symbol_l () != last.staff_symbol_l ()) stem_y += get_direction () - * (multiplicity - (s->flag_i () - 2) >? 0) * interbeam_f; + * (beam_multiplicity - stem_multiplicity) * interbeam_f; } return stem_y; } @@ -483,7 +485,8 @@ Beam::check_stem_length_f (Real y, Real dy) const void Beam::set_stem_length (Real y, Real dy) { - Real internote_f = paper_l ()->get_var ("interline") / 2; + Staff_symbol_referencer_interface st (this); + Real half_space = st.staff_space ()/2; for (int i=0; i < stem_count (); i++) { Stem* s = stem (i); @@ -493,7 +496,7 @@ Beam::set_stem_length (Real y, Real dy) Real stem_y = calc_stem_y_f (s, y, dy); /* caution: stem measures in staff-positions */ - s->set_stemend ((stem_y - calc_interstaff_dist (s, this)) / internote_f); + s->set_stemend ((stem_y + calc_interstaff_dist (s, this)) / half_space); } } @@ -501,9 +504,9 @@ Beam::set_stem_length (Real y, Real dy) [Ross] (simplification of) Try to set dy complying with: - zero - - beam_f / 2 + staffline_f / 2 - - beam_f + staffline_f - + n * interline + - thick / 2 + staffline_f / 2 + - thick + staffline_f + + n * staff_space TODO: get allowed-positions as scm list (aarg: from paper block) */ @@ -516,17 +519,17 @@ Beam::quantise_dy_f (Real dy) const return dy; Staff_symbol_referencer_interface st (this); - Real interline_f = st.staff_space (); + Real staff_space = st.staff_space (); Real staffline_f = paper_l ()->get_var ("stafflinethickness"); - Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));; + Real thick = gh_scm2double (get_elt_property ("beam-thickness"));; Array allowed_fraction (3); allowed_fraction[0] = 0; - allowed_fraction[1] = (beam_f / 2 + staffline_f / 2); - allowed_fraction[2] = (beam_f + staffline_f); + allowed_fraction[1] = (thick / 2 + staffline_f / 2); + allowed_fraction[2] = (thick + staffline_f); - allowed_fraction.push (interline_f); + allowed_fraction.push (staff_space); Interval iv = quantise_iv (allowed_fraction, abs (dy)); Real q = (abs (dy) - iv[SMALLER] <= iv[BIGGER] - abs (dy)) ? iv[SMALLER] @@ -564,14 +567,14 @@ Beam::quantise_y_f (Real y, Real dy, int quant_dir) hang straddle sit inter hang */ - Staff_symbol_referencer_interface sinf (this); - Real space = sinf.staff_space (); + Staff_symbol_referencer_interface st (this); + Real staff_space = st.staff_space (); Real staffline_f = paper_l ()->get_var ("stafflinethickness"); - Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));; + Real thick = gh_scm2double (get_elt_property ("beam-thickness"));; Real straddle = 0; - Real sit = beam_f / 2 - staffline_f / 2; - Real hang = space - beam_f / 2 + staffline_f / 2; + Real sit = thick / 2 - staffline_f / 2; + Real hang = staff_space - thick / 2 + staffline_f / 2; /* Put all allowed positions into an array. @@ -605,7 +608,7 @@ Beam::quantise_y_f (Real y, Real dy, int quant_dir) allowed_position.push (hang); } - allowed_position.push (space); + allowed_position.push (staff_space); Real up_y = get_direction () * y; Interval iv = quantise_iv (allowed_position, up_y); @@ -652,7 +655,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const Real interbeam_f = paper_l ()->interbeam_f (multiplicity); - Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));; + Real thick = gh_scm2double (get_elt_property ("beam-thickness"));; Real dy = interbeam_f; Real stemdx = staffline_f; @@ -687,7 +690,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const w = w/2 beam (dydx, w, beam_f); + a = lookup_l ()->beam (dydx, w, thick); a.translate (Offset (-w, -w * dydx)); for (int j = 0; j < lhalfs; j++) { @@ -703,7 +706,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const int rwholebeams= here->beam_count (RIGHT) beam_count (LEFT) ; Real w = next->hpos_f () - here->hpos_f (); - Molecule a = lookup_l ()->beam (dydx, w + stemdx, beam_f); + Molecule a = lookup_l ()->beam (dydx, w + stemdx, thick); a.translate_axis( - stemdx/2, X_AXIS); int j = 0; Real gap_f = 0; @@ -723,7 +726,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const // TODO: notehead widths differ for different types gap_f = nw_f / 2; w -= 2 * gap_f; - a = lookup_l ()->beam (dydx, w + stemdx, beam_f); + a = lookup_l ()->beam (dydx, w + stemdx, thick); } for (; j < rwholebeams; j++) @@ -738,7 +741,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const w = w/2 beam (dydx, w, beam_f); + a = lookup_l ()->beam (dydx, w, thick); for (; j < rwholebeams + rhalfs; j++) { diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc index fcc6031cbb..c22fd18a5b 100644 --- a/lily/chord-name-engraver.cc +++ b/lily/chord-name-engraver.cc @@ -72,7 +72,8 @@ Chord_name_engraver::do_process_requests () if (gh_boolean_p (chord_inversion)) find_inversion_b = gh_scm2bool (chord_inversion); - chord_name_p_ = new Chord_name (to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, find_inversion_b)); + chord_name_p_ = new Chord_name; + chord_name_p_->set (to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, find_inversion_b)); announce_element (Score_element_info (chord_name_p_, 0)); } diff --git a/lily/chord-name.cc b/lily/chord-name.cc index b190520b74..a202812d32 100644 --- a/lily/chord-name.cc +++ b/lily/chord-name.cc @@ -15,14 +15,59 @@ #include "lookup.hh" SCM -pitch2scm (Musical_pitch p) +to_scm (Musical_pitch p) { - return gh_cons (gh_int2scm (p.notename_i_), gh_int2scm (p.accidental_i_)); + return gh_list (gh_int2scm (p.notename_i_), gh_int2scm (p.accidental_i_), gh_int2scm (p.octave_i_), SCM_UNDEFINED); } -Chord_name::Chord_name (Chord const& c) +Musical_pitch +from_scm (SCM s) { - chord_ = c; + return Musical_pitch (gh_scm2int (gh_car (s)), + gh_scm2int (gh_cadr (s)), + gh_scm2int (gh_caddr (s))); +} + +templateSCM +array_to_scm (Array arr) +{ + SCM list = SCM_EOL; + for (int i = arr.size (); i--;) + list = gh_cons (to_scm (arr[i]), list); + return list; +} + +/* + Silly templates + Array scm_to_array (SCM s) + */ +templatevoid +scm_to_array (SCM s, Array* arr) +{ + for (; gh_pair_p (s); s= gh_cdr (s)) + arr->push (from_scm (gh_car (s))); +} + +/* + ugh, move to chord-name-engraver + + Hmm, why not represent complete chord as list? + ((tonic third fifth) (inversion bass)) + */ +void +Chord_name::set (Chord const& c) +{ + set_elt_property ("pitches", array_to_scm (c.pitch_arr_)); + if (c.inversion_b_) + set_elt_property ("inversion", to_scm (c.inversion_pitch_)); + if (c.bass_b_) + set_elt_property ("bass", to_scm (c.bass_pitch_)); +} + +SCM +notename2scm (Musical_pitch p) +{ + return gh_cons (gh_int2scm (p.notename_i_), gh_int2scm (p.accidental_i_)); } /* @@ -70,7 +115,7 @@ Chord_name::ly_text2molecule (SCM scm) const Molecule Chord_name::pitch2molecule (Musical_pitch p) const { - SCM name = scm_eval (gh_list (ly_symbol2scm ("user-pitch-name"), ly_quote_scm (pitch2scm (p)), SCM_UNDEFINED)); + SCM name = scm_eval (gh_list (ly_symbol2scm ("user-pitch-name"), ly_quote_scm (notename2scm (p)), SCM_UNDEFINED)); if (name != SCM_UNSPECIFIED) { @@ -121,7 +166,7 @@ Chord_name::user_chord_name (Array pitch_arr, Chord_mol* name_p) Chord::rebuild_transpose (&chord_type, diff_pitch (pitch_arr[0], Musical_pitch (0)), false); for (int i= chord_type.size (); i--; ) - chord = gh_cons (pitch2scm (chord_type[i]), chord); + chord = gh_cons (notename2scm (chord_type[i]), chord); SCM name = scm_eval (gh_list (ly_symbol2scm ("user-chord-name"), ly_quote_scm (chord), SCM_UNDEFINED)); if (gh_pair_p (name)) @@ -145,7 +190,7 @@ Chord_name::banter (Array pitch_arr, Chord_mol* name_p) const scale.push (Musical_pitch (i)); Musical_pitch tonic = pitch_arr[0]; - chord_.rebuild_transpose (&scale, tonic, true); + Chord::rebuild_transpose (&scale, tonic, true); /* Does chord include this step? -1 if flat @@ -214,10 +259,16 @@ Chord_name::banter (Array pitch_arr, Chord_mol* name_p) const } } +/* + TODO: + fix silly to-and-fro scm conversions + */ Molecule* Chord_name::do_brew_molecule_p () const { - Musical_pitch tonic = chord_.pitch_arr_[0]; + Array pitch_arr; + scm_to_array (get_elt_property ("pitches"), &pitch_arr); + Musical_pitch tonic = pitch_arr[0]; Chord_mol name; name.tonic_mol = pitch2molecule (tonic); @@ -230,17 +281,17 @@ Chord_name::do_brew_molecule_p () const maybe we should check all sub-lists of pitches, not just full list and base triad? */ - if (!user_chord_name (chord_.pitch_arr_, &name)) + if (!user_chord_name (pitch_arr, &name)) { /* else, check if user has listed base triad use user base name and add banter for remaining part */ - if ((chord_.pitch_arr_.size () > 2) - && user_chord_name (chord_.pitch_arr_.slice (0, 3), &name)) + if ((pitch_arr.size () > 2) + && user_chord_name (pitch_arr.slice (0, 3), &name)) { Array base = Chord::base_arr (tonic); - base.concat (chord_.pitch_arr_.slice (3, chord_.pitch_arr_.size ())); + base.concat (pitch_arr.slice (3, pitch_arr.size ())); banter (base, &name); } /* @@ -248,22 +299,23 @@ Chord_name::do_brew_molecule_p () const */ else { - banter (chord_.pitch_arr_, &name); + banter (pitch_arr, &name); } } - if (chord_.inversion_b_) + SCM s = get_elt_property ("inversion"); + if (s != SCM_UNDEFINED) { name.inversion_mol = lookup_l ()->text ("", "/", paper_l ()); - // zucht const& - Molecule mol = pitch2molecule (chord_.inversion_pitch_); + Molecule mol = pitch2molecule (from_scm (s)); name.inversion_mol.add_at_edge (X_AXIS, RIGHT, mol, 0); } - if (chord_.bass_b_) + s = get_elt_property ("bass"); + if (s != SCM_UNDEFINED) { name.bass_mol = lookup_l ()->text ("", "/", paper_l ()); - Molecule mol = pitch2molecule (chord_.bass_pitch_); + Molecule mol = pitch2molecule (from_scm (s)); name.bass_mol.add_at_edge (X_AXIS, RIGHT, mol, 0); } diff --git a/lily/include/chord-name.hh b/lily/include/chord-name.hh index 0089445694..04c20ffb18 100644 --- a/lily/include/chord-name.hh +++ b/lily/include/chord-name.hh @@ -33,13 +33,7 @@ public: bool user_chord_name (Array pitch_arr, Chord_mol* name_p) const; void banter (Array pitch_arr, Chord_mol* name_p) const; - Chord_name (Chord const& c); - - /* - ugh. Junkme, I must be elt property. - */ - - Chord chord_; + void set (Chord const& c); protected: virtual Molecule* do_brew_molecule_p () const; diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 21723f7713..3a32c03d69 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -197,6 +197,7 @@ index_set_cell (SCM s, Direction d, SCM v) return s; } +#if 0 SCM array_to_list (SCM *a , int l) { @@ -207,6 +208,7 @@ array_to_list (SCM *a , int l) } return list; } +#endif SCM ly_warning (SCM str) diff --git a/lily/stem.cc b/lily/stem.cc index b86b38c2d6..d1bb8f5553 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -563,7 +563,7 @@ Stem::calc_stem_info () const if (gh_number_p (s)) info.idealy_f_ -= gh_double2scm (s); - Real interstaff_f = beam_dir* calc_interstaff_dist (this, beam_l ()); + Real interstaff_f = -beam_dir* calc_interstaff_dist (this, beam_l ()); info.idealy_f_ += interstaff_f; info.miny_f_ += interstaff_f; -- 2.39.5