Jan Nieuwenhuizen <janneke@gnu.org>
TODO: This is way too hairy
+
+ TODO: fix naming.
+
+ Stem-end, chord-start, etc. is all confusing naming.
*/
-#include <math.h> // m_pi
+#include <math.h> // rint
#include "lookup.hh"
#include "directional-element-interface.hh"
Real
-Stem::chord_start_f (Grob*me)
+Stem::chord_start_y (Grob*me)
{
return head_positions (me)[get_direction (me)]
* Staff_symbol_referencer::staff_space (me)/2.0;
me->set_grob_property ("stem-end-position", gh_double2scm (se));
}
-int
-Stem::type_i (Grob*me)
-{
- return first_head (me) ? Rhythmic_head::balltype_i (first_head (me)) : 2;
-}
/*
Note head that determines hshift for upstems
return extremal_heads (me)[-d];
}
+/*
+ The note head opposite to the first head.
+ */
+Grob*
+Stem::last_head (Grob*me)
+{
+ Direction d = get_direction (me);
+ if (!d)
+ return 0;
+ return extremal_heads (me)[d];
+}
+
/*
START is part where stem reaches `last' head.
*/
bool
Stem::invisible_b (Grob*me)
{
- return ! (head_count (me) && Rhythmic_head::balltype_i (support_head (me)) >= 1);
+ return ! (head_count (me) && Note_head::balltype_i (support_head (me)) >= 1);
}
Direction
Real
Stem::get_default_stem_end_position (Grob*me)
{
+ SCM up_to_staff = me->get_grob_property ("up-to-staff");
+ if (to_boolean(up_to_staff))
+ {
+ int line_count = Staff_symbol_referencer::line_count (me);
+
+ Direction dir = get_direction (me);
+
+ return dir* (line_count + 3.5);
+ }
+
bool grace_b = to_boolean (me->get_grob_property ("grace"));
SCM s;
Array<Real> a;
Real shorten_f = a[ ((duration_log (me) - 2) >? 0) <? (a.size () - 1)] * 2;
/* On boundary: shorten only half */
- if (abs (chord_start_f (me)) == 0.5)
+ if (abs (chord_start_y (me)) == 0.5)
shorten_f *= 0.5;
/* URGURGURG
/* stems in unnatural (forced) direction should be shortened,
according to [Roush & Gourlay] */
- if (chord_start_f (me)
+ if (chord_start_y (me)
&& (get_direction (me) != get_default_dir (me)))
length_f -= shorten_f;
Direction d = get_direction (me);
- Real y1 = Staff_symbol_referencer::position_f (first_head (me));
+
+ Real y1;
+
+ /*
+ This is required to avoid stems passing in tablature chords...
+ */
+
+
+ /*
+ TODO: make the stem start a direction ?
+
+ */
+ if (to_boolean (me->get_grob_property ("avoid-note-head")))
+ {
+ y1 = Staff_symbol_referencer::position_f (last_head (me));
+ }
+ else
+ {
+ y1 = Staff_symbol_referencer::position_f (first_head (me));
+ }
+
Real y2 = stem_end_position (me);
Interval stem_y (y1 <? y2,y2 >? y1);
Real r=0;
- if (invisible_b (me))
+ if (head_count (me) == 0)
{
return gh_double2scm (0.0);
}
{
Interval head_wid = Note_head::head_extent(f, X_AXIS);
- Real attach =
- Note_head::stem_attachment_coordinate(f, X_AXIS);
+
+ Real attach =0.0;
+
+ if (invisible_b (me))
+ {
+ attach = 0.0;
+ }
+ else
+ attach = Note_head::stem_attachment_coordinate(f, X_AXIS);
Direction d = get_direction (me);
Stem_info
Stem::calc_stem_info (Grob*me)
{
+ SCM up_to_staff = me->get_grob_property ("up-to-staff");
+ if (gh_scm2bool(up_to_staff)) {
+
+ // Up-to-staff : the stem end out of the staff.
+
+ /*
+ FIXME: duplicate code.
+ */
+ int line_count = Staff_symbol_referencer::line_count (me);
+
+ Stem_info si ;
+
+ Direction dir = get_direction (me);
+
+ si.ideal_y_ = dir* (line_count + 1.5);
+ si.dir_ = dir;
+ si.shortest_y_ = si.ideal_y_;
+
+ return si;
+ }
+
SCM scm_info = me->get_grob_property ("stem-info");
if (gh_pair_p (scm_info ))
{
Stem_info si ;
- si.ideal_y = gh_scm2double (gh_car (scm_info));
- si.max_y = gh_scm2double (gh_cadr (scm_info));
- si.min_y = gh_scm2double (gh_caddr (scm_info));
+ si.dir_ = Directional_element_interface::get(me);
+ si.ideal_y_ = gh_scm2double (gh_car (scm_info));
+ si.shortest_y_ = gh_scm2double (gh_cadr (scm_info));
return si;
}
-
- Grob * beam = beam_l (me);
-
- Direction beam_dir = Directional_element_interface::get (beam);
- if (!beam_dir)
- {
- programming_error ("Beam dir not set.");
- beam_dir = UP;
- }
-
+ Direction mydir = Directional_element_interface::get (me);
Real staff_space = Staff_symbol_referencer::staff_space (me);
Real half_space = staff_space / 2;
-
+
+ Grob * beam = beam_l (me);
int multiplicity = Beam::get_multiplicity (beam);
Real interbeam_f = Beam::get_interbeam (beam);
Real thick = gh_scm2double (beam->get_grob_property ("thickness"));
- Stem_info info;
- info.ideal_y = chord_start_f (me);
-
- // for simplicity, we calculate as if dir == UP
- info.ideal_y *= beam_dir;
+
+ Real ideal_y = chord_start_y (me);
+
+ /* from here on, calculate as if dir == UP */
+ ideal_y *= mydir;
+
SCM grace_prop = me->get_grob_property ("grace");
-
+
bool grace_b = to_boolean (grace_prop);
Array<Real> a;
Real stem_length = a[multiplicity <? (a.size () - 1)] * staff_space;
- if (!beam_dir || (beam_dir == Directional_element_interface::get (me)))
- /* normal beamed stem */
- {
- if (multiplicity)
- {
- info.ideal_y += thick + (multiplicity - 1) * interbeam_f;
- }
- info.min_y = info.ideal_y;
- info.max_y = 1000; // INT_MAX;
+ Grob *fvs = Beam::first_visible_stem (beam);
- info.ideal_y += stem_length;
- info.min_y += minimum_length;
+ /*
+ Let's hope people don't use kneed tremolo beams.
+ */
+ Direction first_dir = fvs ? Directional_element_interface::get(fvs) : mydir;
- /*
- lowest beam of (UP) beam must never be lower than second staffline
+ // FIXME, hairy. see beam::calc_stem_y, for knees it's not trival
+ // to calculate where secondary, ternary beams will go.
+ if (multiplicity && first_dir == mydir)
+ ideal_y += thick + (multiplicity - 1) * interbeam_f;
- Hmm, reference (Wanske?)
+ ideal_y += stem_length;
+
+
+ Real shortest_y = ideal_y -stem_length + minimum_length;
- Although this (additional) rule is probably correct,
- I expect that highest beam (UP) should also never be lower
- than middle staffline, just as normal stems.
+ /*
+ lowest beam of (UP) beam must never be lower than second staffline
+
+ Hmm, reference (Wanske?)
+
+ Although this (additional) rule is probably correct,
+ I expect that highest beam (UP) should also never be lower
+ than middle staffline, just as normal stems.
- */
- bool no_extend_b = to_boolean (me->get_grob_property ("no-stem-extend"));
- if (!grace_b && !no_extend_b)
- {
- /* highest beam of (UP) beam must never be lower than middle
- staffline
- lowest beam of (UP) beam must never be lower than second staffline
- */
- info.min_y =
- info.min_y >? 0
- >? (- 2 * half_space - thick
- + (multiplicity > 0) * thick
- + interbeam_f * (multiplicity - 1));
- }
- }
- else
- /* knee */
+ */
+ bool no_extend_b = to_boolean (me->get_grob_property ("no-stem-extend"));
+ if (!grace_b && !no_extend_b)
{
- info.ideal_y -= thick;
- info.max_y = info.ideal_y;
- info.min_y = - 1000 ; // INT_MAX;
-
- info.ideal_y -= stem_length;
- info.max_y -= minimum_length;
+ /* highest beam of (UP) beam must never be lower than middle
+ staffline
+ lowest beam of (UP) beam must never be lower than second staffline
+ */
+ shortest_y =
+ shortest_y >? 0
+ >? (- 2 * half_space - thick
+ + (multiplicity > 0) * thick
+ + interbeam_f * (multiplicity - 1));
}
+
- info.ideal_y = (info.max_y <? info.ideal_y) >? info.min_y;
+ ideal_y = ideal_y >? shortest_y;
s = beam->get_grob_property ("shorten");
if (gh_number_p (s))
- info.ideal_y -= gh_scm2double (s);
+ ideal_y -= gh_scm2double (s);
Grob *common = me->common_refpoint (beam, Y_AXIS);
- Real interstaff_f = beam_dir *
+
+ /*
+ UGH -> THIS CAUSES ASYMETRY: the same beam can start/end on
+ different staffs.
+
+ TODO: the beam calculation should probably also use
+ relative_coordinate() for the Y positions of all beams.
+
+
+ */
+ Real interstaff_f = mydir *
(me->relative_coordinate (common, Y_AXIS)
- beam->relative_coordinate (common, Y_AXIS));
- info.ideal_y += interstaff_f;
- info.min_y += interstaff_f;
- info.max_y += interstaff_f ;
+ ideal_y += interstaff_f;
+ shortest_y += interstaff_f;
+ ideal_y *= mydir;
+ shortest_y *= mydir;
+
me->set_grob_property ("stem-info",
- scm_list_n (gh_double2scm (info.ideal_y),
- gh_double2scm (info.max_y),
- gh_double2scm (info.min_y),
+ scm_list_n (gh_double2scm (ideal_y),
+ gh_double2scm (shortest_y),
SCM_UNDEFINED));
+
+ Stem_info si;
+ si.dir_ = mydir;
+ si.shortest_y_ = shortest_y;
+ si.ideal_y_ = ideal_y;
- return info;
+ return si;
}
ADD_INTERFACE (Stem,"stem-interface",
"A stem",
- "adjust-if-on-staffline thickness stem-info beamed-lengths beamed-minimum-lengths lengths beam stem-shorten duration-log beaming neutral-direction stem-end-position support-head note-heads direction length style no-stem-extend flag-style dir-forced");
+ "up-to-staff avoid-note-head adjust-if-on-staffline thickness stem-info beamed-lengths beamed-minimum-lengths lengths beam stem-shorten duration-log beaming neutral-direction stem-end-position support-head note-heads direction length style no-stem-extend flag-style dir-forced");