X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fspan-bar.cc;h=54b5ef953c8348ab85b31ae8dd3b206982a7f15c;hb=422004486569407b8809da7f3c7053c1e4767bff;hp=d16081928e05ef99ccc6aa6dd639420610667e32;hpb=ee513a2f7d18fc8d43e1c291350ed81856b0192d;p=lilypond.git diff --git a/lily/span-bar.cc b/lily/span-bar.cc index d16081928e..54b5ef953c 100644 --- a/lily/span-bar.cc +++ b/lily/span-bar.cc @@ -5,154 +5,153 @@ (c) 1997--2000 Han-Wen Nienhuys */ -#include "dimension-cache.hh" + #include "span-bar.hh" #include "lookup.hh" #include "dimensions.hh" #include "paper-def.hh" #include "molecule.hh" #include "warn.hh" +#include "axis-group-interface.hh" #include "group-interface.hh" - +#include "score-element.hh" +#include "bar.hh" void -Span_bar::add_bar (Score_element*b) +Span_bar::add_bar (Score_element*me, Score_element*b) { - Group_interface gi (this); + Pointer_group_interface gi (me); gi.add_element (b); - add_dependency (b); + me->add_dependency (b); } - Interval -Span_bar::width_callback (Dimension_cache const * c) +Span_bar::width_callback (Score_element *se, Axis ) { - Span_bar* s= dynamic_cast (c->element_l ()); - String gl = ly_scm2string (s->get_elt_property ("glyph")); + String gl = ly_scm2string (se->get_elt_property ("glyph")); - /*urg. + /* + urg. */ - Molecule m = s->compound_barline (gl, 40 PT); + Molecule m = Bar::compound_barline (se, gl, 40 PT); return m.extent (X_AXIS); } -void -Span_bar::before_line_breaking () +MAKE_SCHEME_CALLBACK(Span_bar,before_line_breaking); +SCM +Span_bar::before_line_breaking (SCM smob) { - Bar::before_line_breaking (); - - evaluate_empty (); - - // set_empty (false, Y_AXIS); // a hack to make mark scripts work. + evaluate_empty (unsmob_element (smob)); + evaluate_glyph (unsmob_element (smob)); + + /* + no need to call Bar::before_line_breaking (), because the info + in ELEMENTS already has been procced by Bar::before_line_breaking(). + */ + return SCM_UNSPECIFIED; +} + +Real +Span_bar::center_on_spanned_callback (Score_element * me, Axis a) +{ + assert (a == Y_AXIS); + Interval i (get_spanned_interval (me)); + + /* + Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so + we have to translate ourselves to be in the center of the + interval that we span. */ + + return i.center (); } void -Span_bar::after_line_breaking () +Span_bar::evaluate_empty (Score_element*me) { - Bar::after_line_breaking (); - SCM s = get_elt_property ("collapse-height"); - if (gh_number_p (s) - && get_spanned_interval ().length () < gh_scm2double (s)) + /* + TODO: filter all hara-kiried out of ELEMENS list, and then + optionally do suicide. Call this cleanage function from + center_on_spanned_callback() as well. + + */ + if (!gh_pair_p (me->get_elt_property ("elements"))) { - set_elt_property ("transparent", SCM_BOOL_T); - set_empty (X_AXIS); - set_empty (Y_AXIS); + me->suicide (); } - - Interval i (get_spanned_interval ()); - translate_axis (i.center (), Y_AXIS); } void -Span_bar::evaluate_empty () -{ - if (!gh_pair_p (get_elt_property ("elements"))) - { - set_elt_property ("transparent", SCM_BOOL_T); - set_empty (X_AXIS); - set_empty (Y_AXIS); - } - - SCM gl = get_elt_property ("glyph"); +Span_bar::evaluate_glyph (Score_element*me) +{ + SCM elts = me->get_elt_property ("elements"); + Score_element * b = unsmob_element (gh_car (elts)); + SCM glsym =ly_symbol2scm ("glyph"); + SCM gl =b ->get_elt_property (glsym); if (!gh_string_p (gl)) { - set_elt_property ("transparent", SCM_BOOL_T); - set_empty (X_AXIS); - set_empty (Y_AXIS); + me->suicide (); + return ; } - else { - String type_str = ly_scm2string (gl); - if (type_str == "|:") + + String type = ly_scm2string (gl); + + if (type == "|:") { - type_str= ".|"; + type = ".|"; } - else if (type_str== ":|") + else if (type== ":|") { - type_str= "|."; + type = "|."; } - else if (type_str== ":|:") + else if (type== ":|:") { - type_str= ".|."; + type = ".|."; } - } - /* - uhh. should do something with type_str ?!! - */ + gl = ly_str02scm (type.ch_C()); + if (scm_equal_p (me->get_elt_property (glsym), gl) != SCM_BOOL_T) + me->set_elt_property (glsym, gl); } Interval -Span_bar::get_spanned_interval () const +Span_bar::get_spanned_interval (Score_element*me) { - Interval y_int; - - for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s)) - { - Score_element *bar = unsmob_element ( gh_car (s)); - - if (!bar) - continue; - - Score_element*common = common_refpoint (bar, Y_AXIS); - - Interval iv (bar->extent(Y_AXIS)); - if (!iv.empty_b ()) - { - Real y = bar->relative_coordinate (common, Y_AXIS) - - relative_coordinate (common, Y_AXIS); - - y_int.unite (y + iv); - } - } - - return y_int; + return Axis_group_interface::group_extent_callback (me, Y_AXIS); } -Interval -Span_bar::height_callback (Dimension_cache const *c) + +MAKE_SCHEME_CALLBACK(Span_bar,get_bar_size); +SCM +Span_bar::get_bar_size (SCM smob) { - Span_bar * s= dynamic_cast (c->element_l ()); - return s->get_spanned_interval (); + Score_element* me = unsmob_element (smob); + Interval iv (get_spanned_interval (me)); + if (iv.empty_b ()) + { + /* + This happens if the bars are hara-kiried from under us. + */ + me->suicide (); + return gh_double2scm (-1); + } + return gh_double2scm (iv.length ()); } - -Real -Span_bar::get_bar_size () const +void +Span_bar::set_interface (Score_element *me) { - Interval iv (get_spanned_interval ()); - if (iv.empty_b ()) - { - programming_error("Huh? My children deflated (FIXME)"); - iv = Interval (0,0); - } - return iv.length (); + Bar::set_interface (me); + + Pointer_group_interface(me).set_interface (); + me->set_extent_callback (width_callback, X_AXIS); + me->add_offset_callback (center_on_spanned_callback, Y_AXIS); + me->set_interface (ly_symbol2scm ("span-bar-interface")); + me->set_extent_callback (0, Y_AXIS); } -Span_bar::Span_bar () +bool +Span_bar::has_interface (Score_element*m) { - group (this).set_interface (); - dim_cache_[X_AXIS]->set_callback (width_callback); - dim_cache_[Y_AXIS]->set_callback (height_callback); + return m && m->has_interface (ly_symbol2scm ("span-bar-interface")); } -