From: Han-Wen Nienhuys Date: Fri, 23 Jul 2004 14:55:15 +0000 (+0000) Subject: (print): new file. Set limits to X-Git-Tag: release/2.3.8~6 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=d723ce514c396386a1d8d3b5b96299389f3b9179;p=lilypond.git (print): new file. Set limits to ledger line length to avoid clashes. --- diff --git a/ChangeLog b/ChangeLog index 4bba2c09a1..ec7e0d88b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2004-07-23 Han-Wen Nienhuys + * lily/include/pitch-interval.hh (Pitch>): new file. + + * lily/pitch-interval.cc (add_point): new file. + * lily/ledger-line-engraver.cc: new file. * lily/ledger-line-spanner.cc (print): new file. Set limits to diff --git a/lily/ambitus-engraver.cc b/lily/ambitus-engraver.cc index bd8fd0104d..9985bf97c9 100644 --- a/lily/ambitus-engraver.cc +++ b/lily/ambitus-engraver.cc @@ -4,6 +4,9 @@ source file of the GNU LilyPond music typesetter (c) 2002--2004 Juergen Reuter + + Han-Wen Nienhuys set_property ("accidental-grob", accidentals_[d]->self_scm ()); + Side_position_interface::add_support (accidentals_[d], heads_[d]); } while (flip (&d) != DOWN); + ambitus_->set_parent (heads_[DOWN], X_AXIS); is_typeset_ = true; } } @@ -166,7 +124,7 @@ Ambitus_engraver::finalize () do { Pitch p = pitch_interval_[d]; - heads_[d]->set_property ("position", + heads_[d]->set_property ("staff-position", scm_from_int (start_c0_ + p.steps ())); diff --git a/lily/ambitus.cc b/lily/ambitus.cc index 34b017d9e1..44953bd4ca 100644 --- a/lily/ambitus.cc +++ b/lily/ambitus.cc @@ -15,132 +15,7 @@ #include "font-interface.hh" #include "output-def.hh" #include "lookup.hh" - -/* - UGH UGH UGH - - This does 3 things at one: - - - acc positioning - - drawing accidentals - - drawing note heads - - It confuses interpretation & formatting. - - UGH. - --hwn. - */ - -/* - * TODO: note-head collision handling - * - * TODO: accidentals collision handling - * - * TODO: alternative representation: adding the ambitus as text script - * to the instrument name (e.g. "Soprano (c^1 - f^2)"). - * - * FIXME: Accidentals are too close at the note heads (it seems that - * the extent of the ledger lines is ignored). - * - * TODO: If (depending on breakAlignOrder) ambitus is put behind - * key-signature, then do not repeat accidentals that already appear - * in the key signature. - * - * FIXME: A staff containing more than a single context will result in - * multiple ambitus grobs per staff. This is basically ok, but there is - * currently no proper collision handling for this case. - * - * TODO: make ignore_octave and force_accidental of function - * number_accidentals accessible via grob properties. - */ - -/** - Given a pitch and a key_signature, decide what accidentals to show. - - Possible return values: - - 0: do not show any accidental - 1: show pitch->alteration_ only - 2: show pitch->get_alteration, preceded by a natural sign - - UGH: code duplication! See accidental-engraver. - - */ -static int -number_accidentals (SCM key_signature, Pitch *pitch, - bool ignore_octave_b, bool force_accidental) -{ - int notename = pitch->get_notename (); - int octave = pitch->get_octave (); - int alteration = pitch->get_alteration (); - - if (force_accidental) // ignore key signature - return 1; - - -#if DEBUG_AMBITUS - scm_display (key_signature, scm_current_output_port ()); -#endif - - SCM prev; - if (ignore_octave_b) - prev = ly_assoc_cdr (scm_int2num (notename), key_signature); - else - prev = scm_assoc (scm_cons (scm_int2num (octave), scm_int2num (notename)), - key_signature); - - /* should really be true unless prev == SCM_BOOL_F */ - if (ly_c_pair_p (prev) && ly_c_pair_p (ly_cdr (prev))) - { - prev = scm_cons (ly_car (prev), ly_cadr (prev)); - } - - /* If an accidental was not found */ - if (prev == SCM_BOOL_F) - prev = scm_assoc (scm_int2num (notename), key_signature); - - SCM prev_acc = (prev == SCM_BOOL_F) ? scm_int2num (0) : ly_cdr (prev); - int sig_alteration = ly_c_number_p (prev_acc) ? ly_scm2int (prev_acc) : 0; - - if (alteration == sig_alteration) // no accidental at all needed - return 0; - - if ((alteration == 0) && (sig_alteration != 0)) // need ordinary natural - return 2; - - if (sig_alteration == 0) // use pitch's alteration - return 1; - - return 2; -} - - - -void -add_accidentals (Item *me, Stencil *head, int num_acc, - Pitch *pitch, String accidentals_style, Real yoffs) -{ - if (!num_acc) - return; - if (pitch->get_alteration ()) - { - Stencil accidental (Font_interface::get_default_font (me)-> - find_by_name (String ("accidentals-") + - accidentals_style + - to_string (pitch->get_alteration ()))); - accidental.translate_axis (yoffs, Y_AXIS); - head->add_at_edge (X_AXIS, LEFT, accidental, 0.1, 0); - } - if (num_acc == 2) - { - Stencil natural (Font_interface::get_default_font (me)-> - find_by_name (String ("accidentals-") + - accidentals_style + - to_string ("0"))); - natural.translate_axis (yoffs, Y_AXIS); - head->add_at_edge (X_AXIS, LEFT, natural, 0.1, 0); - } -} +#include "group-interface.hh" MAKE_SCHEME_CALLBACK (Ambitus,print,1); SCM @@ -149,87 +24,46 @@ Ambitus::print (SCM smob) Item *me = (Item*) unsmob_grob (smob); Stencil stencil; - SCM scm_note_head_style = me->get_property ("note-head-style"); - String note_head_style; - if (ly_c_symbol_p (scm_note_head_style)) - { - String note_head_style = - ly_symbol2string (scm_note_head_style); - } - else - { - note_head_style = String ("noteheads-2"); - } - if (Font_interface::get_default_font (me)->find_by_name (note_head_style).is_empty ()) - { - String message = "Ambitus: no such note head: `" + note_head_style + "'"; - me->warning (_ (message.to_str0 ())); - return SCM_EOL; - } - - /* - FIXME: Use positions. - */ - int p_min, p_max; - Slice posns = get_positions(me); - - p_min = posns[LEFT]; - p_max = posns[RIGHT]; - - // create heads - Stencil head_min = - Font_interface::get_default_font (me)->find_by_name (note_head_style); - head_min.translate_axis (0.5*p_min, Y_AXIS); - Stencil head_max = - Font_interface::get_default_font (me)->find_by_name (note_head_style); - head_max.translate_axis (0.5*p_max, Y_AXIS); - // join heads - if (to_boolean (me->get_property ("join-heads")) && - ((p_max - p_min) >= 3)) + Link_array heads (Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-heads")); + if (to_boolean (me->get_property ("join-heads")) + && heads.size() > 1) { - Real linethickness = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); - Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); - Interval x_extent = 0.5 * Interval (-linethickness, +linethickness); - Interval y_extent = 0.5 * Interval (p_min + 1.35, p_max - 1.35); - Box line_box (x_extent, y_extent); - Stencil line = Lookup::round_filled_box (line_box, blotdiameter); - line.translate_axis (0.5 * head_min.extent (X_AXIS).length (), X_AXIS); - stencil.add_stencil (line); + Grob *common + = common_refpoint_of_array (heads.slice (0,2), me, Y_AXIS); + + Grob *minh = heads[0]; + Grob *maxh = heads[1]; + + if (minh->relative_coordinate (common, Y_AXIS) > + maxh->relative_coordinate (common, Y_AXIS)) + { + maxh = heads[0]; + minh = heads[0]; + } + + Real pad = 1.35; + Real pmax = maxh->relative_coordinate (common, Y_AXIS) - pad; + Real pmin = minh->relative_coordinate (common, Y_AXIS) + pad; + + if (pmin < pmax) + { + Real linethickness = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness")); + Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter")); + Interval x_extent = 0.5 * Interval (-linethickness, +linethickness); + Interval y_extent = 0.5 * Interval (pmin, pmax); + Box line_box (x_extent, y_extent); + + Stencil line = Lookup::round_filled_box (line_box, blotdiameter); + line.translate_axis (- me-> relative_coordinate (common, Y_AXIS), + Y_AXIS); + return line.smobbed_copy (); + } } - - // add accidentals - SCM key_signature = me->get_property ("key-signature"); - SCM scm_accidentals_style = me->get_property ("accidentals-style"); - String accidentals_style; - if (ly_c_symbol_p (scm_accidentals_style)) - { - accidentals_style = - ly_symbol2string (scm_accidentals_style); - } - else - { - accidentals_style = String (""); - } - - int num_acc; - Pitch *pitch_min = unsmob_pitch (me->get_property ("pitch-min")); - Pitch *pitch_max = unsmob_pitch (me->get_property ("pitch-max")); - num_acc = number_accidentals (key_signature, pitch_min, true, false); - add_accidentals (me, &head_min, num_acc, pitch_min, - accidentals_style, 0.5 * p_min); - num_acc = number_accidentals (key_signature, pitch_max, true, false); - add_accidentals (me, &head_max, num_acc, pitch_max, - accidentals_style, 0.5 * p_max); - - // add heads - stencil.add_stencil (head_min); - stencil.add_stencil (head_max); - - return stencil.smobbed_copy (); + return SCM_EOL; } ADD_INTERFACE (Ambitus, "ambitus-interface", - "An object that represents the pitch range of a voice.", - "c0-position pitch-min pitch-max accidentals note-head-style accidentals-style join-heads"); + "The line between note heads for a pitch range.", + "note-heads join-heads"); diff --git a/lily/ledger-line-spanner.cc b/lily/ledger-line-spanner.cc index 6bc1b830c6..ca54f00089 100644 --- a/lily/ledger-line-spanner.cc +++ b/lily/ledger-line-spanner.cc @@ -107,9 +107,8 @@ Ledger_line_spanner::print (SCM smob) { Spanner *me = dynamic_cast (unsmob_grob (smob)); Link_array heads (Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-heads")); - Link_array ambituses (Pointer_group_interface__extract_grobs (me, (Grob*)0, "ambituses")); - if (heads.is_empty () && ambituses.is_empty ()) + if (heads.is_empty ()) return SCM_EOL; Stencil ledgers; @@ -121,7 +120,6 @@ Ledger_line_spanner::print (SCM smob) { Axis a = Axis (i); common[a] = common_refpoint_of_array (heads, me, a); - common[a] = common_refpoint_of_array (ambituses, common[a], a); for (int i = heads.size (); i--; ) if (Grob * g = unsmob_grob (me->get_property ("accidental-grob"))) common[a] = common[a]->common_refpoint (g, a); @@ -237,30 +235,7 @@ Ledger_line_spanner::print (SCM smob) } } - /* create ledgers for ambitus. - TODO: split off separate function - - */ - for (int i = ambituses.size (); i--; ) - { - Item *a = dynamic_cast (ambituses[i]); - Interval x_ext = ambituses[i]->extent (common[X_AXIS], X_AXIS); - x_ext.widen (length_fraction * x_ext.length ()); - - Slice ps (Ambitus::get_positions (a)); - Direction d = DOWN; - do - { - if (abs (ps[d]) > interspaces + 1) - ledgers.add_stencil (brew_ledger_lines (staff, ps[d], interspaces, - halfspace, - ledgerlinethickness, - x_ext, 0.0)); - } - while (flip (&d) != DOWN); - } - ledgers.translate_axis (-me->relative_coordinate (common[X_AXIS], X_AXIS), X_AXIS); diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 373e46dbbd..00b9e655df 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -38,10 +38,8 @@ (breakable . #t) (break-align-symbol . ambitus) (print-function . ,Ambitus::print) - (font-family . music) - (note-head-style . "noteheads-2") - (break-visibility . ,begin-of-line-visible) (join-heads . #t) + (break-visibility . ,begin-of-line-visible) (space-alist . ( (clef . (extra-space . 0.0)) (key-signature . (extra-space . 0.0)) @@ -51,12 +49,23 @@ )) (meta . ((interfaces . (ambitus-interface staff-symbol-referencer-interface break-aligned-interface item-interface font-interface)))) )) + (AmbitusAccidental + . ( + (print-function . ,Accidental_interface::print) + (font-family . music) + (X-offset-callbacks . (,Side_position_interface::aligned_side)) + (direction . -1) + (cautionary-style . parentheses) + (after-line-breaking-callback . ,Accidental_interface::after_line_breaking) (meta . ((interfaces . (item-interface accidental-interface font-interface)))) + )) (AmbitusNoteHead . ( + (duration-log . 2) (style . default) (breakable . #t) (print-function . ,Note_head::print) (break-align-symbol . ambitus) + (break-visibility . ,begin-of-line-visible) (glyph-name-procedure . ,find-notehead-symbol) (X-extent-callback . ,Note_head::extent) (Y-extent-callback . ,Note_head::extent)