]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam.cc
Fix #303.
[lilypond.git] / lily / beam.cc
1 /*
2   beam.cc -- implement Beam
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 /*
11   TODO:
12
13   - Determine auto knees based on positions if it's set by the user.
14
15   - the code is littered with * and / staff_space calls for
16   #'positions. Consider moving to real-world coordinates?
17
18   Problematic issue is user tweaks (user tweaks are in staff-coordinates.)
19
20   Notes:
21
22   - Stems run to the Y-center of the beam.
23
24   - beam_translation is the offset between Y centers of the beam.
25 */
26
27 #include "beam.hh"
28
29 #include "beaming-pattern.hh"
30 #include "directional-element-interface.hh"
31 #include "main.hh"
32 #include "international.hh"
33 #include "interval-set.hh"
34 #include "item.hh"
35 #include "least-squares.hh"
36 #include "lookup.hh"
37 #include "misc.hh"
38 #include "output-def.hh"
39 #include "pointer-group-interface.hh"
40 #include "spanner.hh"
41 #include "staff-symbol-referencer.hh"
42 #include "stem.hh"
43 #include "warn.hh"
44 #include "grob-array.hh"
45
46 #if DEBUG_BEAM_SCORING
47 #include "text-interface.hh" // debug output.
48 #include "font-interface.hh" // debug output.
49 #endif
50
51 #include <map>
52
53
54 Beam_stem_segment::Beam_stem_segment ()
55 {
56   max_connect_ = 1000;          // infinity
57   stem_ = 0;
58   width_ = 0.0;
59   stem_x_ = 0.0;
60   rank_ = 0;
61   stem_index_ = 0;
62   dir_ = CENTER;
63 }
64
65 Beam_segment::Beam_segment ()
66 {
67   vertical_count_ = 0;
68 }
69
70 void
71 Beam::add_stem (Grob *me, Grob *s)
72 {
73   if (Stem::get_beam (s))
74     {
75       programming_error ("Stem already has beam");
76       return ;
77     }
78
79   Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), s);
80   s->set_object ("beam", me->self_scm ());
81   add_bound_item (dynamic_cast<Spanner *> (me), dynamic_cast<Item *> (s));
82 }
83
84 Real
85 Beam::get_thickness (Grob *me)
86 {
87   return robust_scm2double (me->get_property ("thickness"), 0)
88     * Staff_symbol_referencer::staff_space (me);
89 }
90
91 /* Return the translation between 2 adjoining beams. */
92 Real
93 Beam::get_beam_translation (Grob *me)
94 {
95   int beam_count = get_beam_count (me);
96   Real staff_space = Staff_symbol_referencer::staff_space (me);
97   Real line = Staff_symbol_referencer::line_thickness (me);
98   Real thickness = get_thickness (me);
99   Real fract = robust_scm2double (me->get_property ("length-fraction"), 1.0);
100   
101   Real beam_translation = beam_count < 4
102     ? (2 * staff_space + line - thickness) / 2.0
103     : (3 * staff_space + line - thickness) / 3.0;
104
105   return fract * beam_translation;
106 }
107
108 /* Maximum beam_count. */
109 int
110 Beam::get_beam_count (Grob *me)
111 {
112   int m = 0;
113
114   extract_grob_set (me, "stems", stems);
115   for (vsize i = 0; i < stems.size (); i++)
116     {
117       Grob *stem = stems[i];
118       m = max (m, (Stem::beam_multiplicity (stem).length () + 1));
119     }
120   return m;
121 }
122
123 MAKE_SCHEME_CALLBACK (Beam, calc_normal_stems, 1);
124 SCM
125 Beam::calc_normal_stems (SCM smob)
126 {
127   Grob *me = unsmob_grob (smob);
128   
129   extract_grob_set (me, "stems", stems);
130   SCM val = Grob_array::make_array ();
131   Grob_array *ga = unsmob_grob_array (val);
132   for (vsize i = 0; i < stems.size ();  i++)
133     if (Stem::is_normal_stem (stems[i]))
134       ga->add (stems[i]);
135   
136   return val;  
137 }
138
139 MAKE_SCHEME_CALLBACK (Beam, calc_direction, 1);
140 SCM
141 Beam::calc_direction (SCM smob)
142 {
143   Grob *me = unsmob_grob (smob);
144
145   /* Beams with less than 2 two stems don't make much sense, but could happen
146      when you do
147
148      r8[ c8 r8]
149
150   */
151
152   Direction dir = CENTER;
153
154   int count = normal_stem_count (me);
155   if (count < 2)
156     {
157       extract_grob_set (me, "stems", stems);
158       if (stems.size () == 0)
159         {
160           me->warning (_ ("removing beam with no stems"));
161           me->suicide ();
162
163           return SCM_UNSPECIFIED;
164         }
165       else 
166         {
167           Grob *stem = first_normal_stem (me);
168
169           /*
170             ugh: stems[0] case happens for chord tremolo.
171           */
172           dir = to_dir ((stem ? stem : stems[0])->get_property ("default-direction"));
173         }
174     }
175
176   if (count >= 1)
177     {
178       if (!dir)
179         dir = get_default_dir (me);
180       
181       consider_auto_knees (me);
182     }
183
184   if (dir)
185     {
186       set_stem_directions (me, dir);
187     }
188   
189   return scm_from_int (dir);
190 }
191
192
193
194 /* We want a maximal number of shared beams, but if there is choice, we
195  * take the one that is closest to the end of the stem. This is for
196  * situations like
197  *
198  *        x
199  *       |
200  *       |
201  *   |===|
202  *   |=
203  *   |
204  *  x
205  */
206 int
207 position_with_maximal_common_beams (SCM left_beaming, SCM right_beaming,
208                                     Direction left_dir,
209                                     Direction right_dir)
210 {
211   Slice lslice = int_list_to_slice (scm_cdr (left_beaming));
212
213   int best_count = 0;
214   int best_start = 0;
215   for (int i = lslice[-left_dir];
216        (i - lslice[left_dir]) * left_dir <= 0; i += left_dir)
217     {
218       int count = 0;
219       for (SCM s = scm_car (right_beaming); scm_is_pair (s); s = scm_cdr (s))
220         {
221           int k = -right_dir * scm_to_int (scm_car (s)) + i;
222           if (scm_c_memq (scm_from_int (k), left_beaming) != SCM_BOOL_F)
223             count++;
224         }
225
226       if (count >= best_count)
227         {
228           best_count = count;
229           best_start = i;
230         }
231     }
232
233   return best_start;
234 }
235
236 MAKE_SCHEME_CALLBACK (Beam, calc_beaming, 1)
237 SCM
238 Beam::calc_beaming (SCM smob)
239 {
240   Grob *me = unsmob_grob (smob);
241   
242   extract_grob_set (me, "stems", stems);
243
244   Slice last_int;
245   last_int.set_empty ();
246   
247   SCM last_beaming = scm_cons (SCM_EOL, scm_list_1 (scm_from_int (0)));
248   Direction last_dir = CENTER;
249   for (vsize i = 0; i < stems.size (); i++)
250     {
251       Grob *this_stem = stems[i];
252       SCM this_beaming = this_stem->get_property ("beaming");
253
254       Direction this_dir = get_grob_direction (this_stem);
255       if (scm_is_pair (last_beaming) && scm_is_pair (this_beaming))
256         {
257           int start_point = position_with_maximal_common_beams
258             (last_beaming, this_beaming,
259              last_dir ? last_dir : this_dir,
260              this_dir);
261
262           Direction d = LEFT;
263           Slice new_slice;
264           do
265             {
266               new_slice.set_empty ();
267               SCM s = index_get_cell (this_beaming, d);
268               for (; scm_is_pair (s); s = scm_cdr (s))
269                 {
270                   int new_beam_pos
271                     = start_point - this_dir * scm_to_int (scm_car (s));
272
273                   new_slice.add_point (new_beam_pos);
274                   scm_set_car_x (s, scm_from_int (new_beam_pos));
275                 }
276             }
277           while (flip (&d) != LEFT);
278
279           if (!new_slice.is_empty ())
280             last_int = new_slice;
281         }
282       else
283         {
284           /*
285             FIXME: what's this for? 
286            */
287           SCM s = scm_cdr (this_beaming);
288           for (; scm_is_pair (s); s = scm_cdr (s))
289             {
290               int np = -this_dir * scm_to_int (scm_car (s));
291               scm_set_car_x (s, scm_from_int (np));
292               last_int.add_point (np);
293             }
294         }
295       
296       if (scm_ilength (scm_cdr (this_beaming)) > 0)
297         {
298           last_beaming = this_beaming;
299           last_dir = this_dir;
300         }
301     }
302
303   return SCM_EOL;
304 }
305
306 bool
307 operator <(Beam_stem_segment const &a,
308            Beam_stem_segment const &b)
309 {
310   return a.rank_ < b.rank_;
311 }
312
313 typedef map<int, vector<Beam_stem_segment> >  Position_stem_segments_map; 
314
315 vector<Beam_segment>
316 Beam::get_beam_segments (Grob *me_grob, Grob **common)
317 {
318   /* ugh, this has a side-effect that we need to ensure that
319      Stem #'beaming is correct */
320   (void) me_grob->get_property ("beaming");
321
322   Spanner *me = dynamic_cast<Spanner*> (me_grob);
323
324   extract_grob_set (me, "stems", stems);
325   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
326
327   commonx = me->get_bound (LEFT)->common_refpoint (commonx, X_AXIS);
328   commonx = me->get_bound (RIGHT)->common_refpoint (commonx, X_AXIS);
329
330   *common = commonx;
331   
332   int gap_count = robust_scm2int (me->get_property ("gap-count"), 0);
333   Real gap_length = robust_scm2double (me->get_property ("gap"), 0.0);
334
335   Position_stem_segments_map stem_segments;
336   Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
337
338   Slice ranks;
339   
340   for (vsize i = 0; i < stems.size (); i++)
341     {
342       Grob *stem = stems[i];
343       Real stem_width = robust_scm2double (stem->get_property ("thickness"), 1.0) * lt;
344       Real stem_x = stem->relative_coordinate (commonx, X_AXIS);
345       SCM beaming = stem->get_property ("beaming");
346       Direction d = LEFT;
347       do
348         {
349           for (SCM s = index_get_cell (beaming, d);
350                scm_is_pair (s); s = scm_cdr (s))
351             {
352               if (!scm_is_integer (scm_car (s)))
353                 continue;
354
355               int beam_rank = scm_to_int (scm_car (s));
356               ranks.add_point (beam_rank);
357             }
358           
359           for (SCM s = index_get_cell (beaming, d);
360                scm_is_pair (s); s = scm_cdr (s))
361             {
362               if (!scm_is_integer (scm_car (s)))
363                 continue;
364           
365               int beam_rank = scm_to_int (scm_car (s));
366               Beam_stem_segment seg;
367               seg.stem_ = stem;
368               seg.stem_x_ = stem_x;
369               seg.rank_ = 2 * i  + (d+1)/2;
370               seg.width_ = stem_width;
371               seg.stem_index_ = i;
372               seg.dir_ = d;
373               seg.max_connect_ = robust_scm2int (stem->get_property ("max-beam-connect"), 1000);
374               
375               Direction stem_dir = get_grob_direction (stem);
376               
377               seg.gapped_
378                 = (stem_dir * beam_rank < (stem_dir * ranks[-stem_dir] + gap_count));
379               stem_segments[beam_rank].push_back (seg);
380             }
381         }
382       while (flip (&d) != LEFT);
383     }
384
385   Drul_array<Real> break_overshoot
386     = robust_scm2drul (me->get_property ("break-overshoot"),
387                        Drul_array<Real> (-0.5, 0.0));
388
389   vector<Beam_segment> segments;
390   for (Position_stem_segments_map::const_iterator i (stem_segments.begin ());
391        i != stem_segments.end (); i++)
392     {
393       vector<Beam_stem_segment> segs = (*i).second;
394       vector_sort (segs, less<Beam_stem_segment> ());
395
396       Beam_segment current;
397
398       int vertical_count =  (*i).first;
399       for (vsize j = 0; j < segs.size (); j++)
400         {
401           /*
402             event_dir == LEFT: left edge of a beamsegment.
403            */
404           Direction event_dir = LEFT;
405           do
406             {
407               bool on_bound = (event_dir == LEFT) ? j == 0 :
408                 j == segs.size () - 1;
409
410               bool inside_stem = (event_dir == LEFT)
411                         ? segs[j].stem_index_ > 0
412                         : segs[j].stem_index_ + 1  < stems.size () ;
413                       
414               bool event = on_bound
415                 || abs (segs[j].rank_ - segs[j+event_dir].rank_) > 1
416                 || (abs (vertical_count) >= segs[j].max_connect_
417                     || abs (vertical_count) >= segs[j + event_dir].max_connect_);
418               
419               if (!event)
420                 continue;
421
422               current.vertical_count_ = vertical_count;
423               current.horizontal_[event_dir] = segs[j].stem_x_;
424               if (segs[j].dir_ == event_dir)
425                 {
426                   if (on_bound
427                       && me->get_bound (event_dir)->break_status_dir ())
428                     {
429                       current.horizontal_[event_dir]
430                         = (robust_relative_extent (me->get_bound (event_dir), commonx, X_AXIS)[RIGHT]
431                            + event_dir * break_overshoot[event_dir]);
432                     }
433                   else
434                     {
435                       Real notehead_width = 
436                         Stem::duration_log (segs[j].stem_) == 1
437                         ? 1.98
438                         : 1.32; // URG.
439
440
441                       if (inside_stem)
442                         {
443                           Grob *neighbor_stem = stems[segs[j].stem_index_ + event_dir];
444                           Real neighbor_stem_x = neighbor_stem->relative_coordinate (commonx, X_AXIS);
445
446                           notehead_width = min (notehead_width,
447                                                 fabs (neighbor_stem_x - segs[j].stem_x_)/2);
448                         }
449                       current.horizontal_[event_dir] += event_dir * notehead_width;
450                     }
451                 }
452               else
453                 {
454                   current.horizontal_[event_dir] += event_dir * segs[j].width_/2;
455                   if (segs[j].gapped_)
456                     {
457                       current.horizontal_[event_dir] -= event_dir * gap_length;
458
459                       if (Stem::is_invisible (segs[j].stem_))
460                         {
461                           /*
462                             Need to do this in case of whole notes. We don't want the
463                             heads to collide with the beams.
464                            */
465                           extract_grob_set (segs[j].stem_, "note-heads", heads);
466
467                           for (vsize k = 0; k < heads.size (); k ++)
468                             current.horizontal_[event_dir]
469                               = event_dir * min  (event_dir * current.horizontal_[event_dir],
470                                                   - gap_length/2
471                                                   + event_dir * heads[k]->extent (commonx, X_AXIS)[-event_dir]);
472                         }
473                     }
474                 }
475
476               if (event_dir == RIGHT)
477                 {
478                   segments.push_back (current);
479                   current = Beam_segment ();
480                 }
481             }
482           while (flip (&event_dir) != LEFT);
483         }
484       
485     }
486
487   return segments;
488 }
489
490 MAKE_SCHEME_CALLBACK (Beam, print, 1);
491 SCM
492 Beam::print (SCM grob)
493 {
494   Spanner *me = unsmob_spanner (grob);
495   Grob *commonx = 0;
496   vector<Beam_segment> segments = get_beam_segments (me, &commonx);
497
498   Interval span;
499   if (normal_stem_count (me))
500     {
501       span[LEFT] = first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
502       span[RIGHT] = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
503     }
504   else
505     {
506       extract_grob_set (me, "stems", stems);      
507       span[LEFT] = stems[0]->relative_coordinate (commonx, X_AXIS);
508       span[RIGHT] = stems.back ()->relative_coordinate (commonx, X_AXIS);
509     }
510
511   Real blot = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
512
513   SCM posns = me->get_property ("quantized-positions");
514   Interval pos;
515   if (!is_number_pair (posns))
516     {
517       programming_error ("no beam positions?");
518       pos = Interval (0, 0);
519     }
520   else
521     pos = ly_scm2realdrul (posns);
522
523   scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
524
525   Real dy = pos[RIGHT] - pos[LEFT];
526   Real slope = (dy && span.length ()) ? dy / span.length ()  : 0;
527
528   Real thick = get_thickness (me);
529   Real beam_dy = get_beam_translation (me);
530
531   Direction feather_dir = to_dir (me->get_property ("grow-direction"));
532   
533   Stencil the_beam;
534   for (vsize i = 0; i < segments.size (); i ++)
535     {
536       Real local_slope = slope;
537       if (feather_dir)
538         {
539           local_slope += feather_dir * segments[i].vertical_count_ * beam_dy / span.length ();
540         }
541       
542       Stencil b = Lookup::beam (local_slope, segments[i].horizontal_.length (), thick, blot);
543
544       b.translate_axis (segments[i].horizontal_[LEFT], X_AXIS);
545       
546       b.translate_axis (local_slope
547                         * (segments[i].horizontal_[LEFT] - span.linear_combination (feather_dir))
548                         + pos.linear_combination (feather_dir)
549                         + beam_dy * segments[i].vertical_count_, Y_AXIS);
550       the_beam.add_stencil (b);      
551     }
552          
553 #if (DEBUG_BEAM_SCORING)
554   SCM quant_score = me->get_property ("quant-score");
555   SCM debug = me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-scoring"));
556   if (to_boolean (debug) && scm_is_string (quant_score))
557     {
558       extract_grob_set (me, "stems", stems);      
559
560       /*
561         This code prints the demerits for each beam. Perhaps this
562         should be switchable for those who want to twiddle with the
563         parameters.
564       */
565       string str;
566       SCM properties = Font_interface::text_font_alist_chain (me);
567
568       Direction stem_dir = stems.size () ? to_dir (stems[0]->get_property ("direction")) : UP;
569
570       Stencil score = *unsmob_stencil (Text_interface::interpret_markup
571                                     (me->layout ()->self_scm (), properties, quant_score));
572
573       if (!score.is_empty ())
574         the_beam.add_at_edge (Y_AXIS, stem_dir, score, 1.0);
575     }
576 #endif
577
578   the_beam.translate_axis (-me->relative_coordinate (commonx, X_AXIS), X_AXIS);
579   return the_beam.smobbed_copy ();
580 }
581  
582 Direction
583 Beam::get_default_dir (Grob *me)
584 {
585   extract_grob_set (me, "stems", stems);
586
587   Drul_array<Real> extremes (0.0, 0.0);
588   for (iterof (s, stems); s != stems.end (); s++)
589     {
590       Interval positions = Stem::head_positions (*s);
591       Direction d = DOWN;
592       do
593         {
594           if (sign (positions[d]) == d)
595             extremes[d] = d * max (d * positions[d], d * extremes[d]);
596         }
597       while (flip (&d) != DOWN);
598     }
599
600   Drul_array<int> total (0, 0);
601   Drul_array<int> count (0, 0);
602
603   bool force_dir = false;
604   for (vsize i = 0; i < stems.size (); i++)
605     {
606       Grob *s = stems[i];
607       Direction stem_dir = CENTER;
608       SCM stem_dir_scm = s->get_property_data ("direction");
609       if (is_direction (stem_dir_scm))
610         {
611           stem_dir = to_dir (stem_dir_scm);
612           force_dir = true;
613         }
614       else
615         stem_dir = to_dir (s->get_property ("default-direction"));
616
617       if (!stem_dir)
618         stem_dir = to_dir (s->get_property ("neutral-direction"));
619
620       if (stem_dir)
621         {
622           count[stem_dir] ++;
623           total[stem_dir] += max (int (- stem_dir * Stem::head_positions (s) [-stem_dir]), 0);
624         }
625     }
626
627
628   if (!force_dir)
629     {
630       if (abs (extremes[UP]) > -extremes[DOWN])
631         return DOWN;
632       else if (extremes[UP] < -extremes[DOWN])
633         return UP;
634     }
635   
636   Direction dir = CENTER;
637   Direction d = CENTER;
638   if ((d = (Direction) sign (count[UP] - count[DOWN])))
639     dir = d;
640   else if (count[UP]
641            && count[DOWN]
642            && (d = (Direction)  sign (total[UP] / count[UP] - total[DOWN]/count[DOWN])))
643     dir = d;
644   else if ((d = (Direction)  sign (total[UP] - total[DOWN])))
645     dir = d;
646   else
647     dir = to_dir (me->get_property ("neutral-direction"));
648   
649   return dir;
650 }
651
652 /* Set all stems with non-forced direction to beam direction.
653    Urg: non-forced should become `without/with unforced' direction,
654    once stem gets cleaned-up. */
655 void
656 Beam::set_stem_directions (Grob *me, Direction d)
657 {
658   extract_grob_set (me, "stems", stems);
659
660   for (vsize i = 0; i < stems.size (); i++)
661     {
662       Grob *s = stems[i];
663
664       SCM forcedir = s->get_property_data ("direction");
665       if (!to_dir (forcedir))
666         set_grob_direction (s, d);
667     }
668 }
669
670 /*
671   Only try horizontal beams for knees.  No reliable detection of
672   anything else is possible here, since we don't know funky-beaming
673   settings, or X-distances (slopes!)  People that want sloped
674   knee-beams, should set the directions manually.
675
676
677   TODO:
678
679   this routine should take into account the stemlength scoring
680   of a possible knee/nonknee beam.
681 */
682 void
683 Beam::consider_auto_knees (Grob *me)
684 {
685   SCM scm = me->get_property ("auto-knee-gap");
686   if (!scm_is_number (scm))
687     return;
688
689   Interval_set gaps;
690
691   gaps.set_full ();
692
693   extract_grob_set (me, "normal-stems", stems);
694
695   Grob *common = common_refpoint_of_array (stems, me, Y_AXIS);
696   Real staff_space = Staff_symbol_referencer::staff_space (me);
697
698   vector<Interval> head_extents_array;
699   for (vsize i = 0; i < stems.size (); i++)
700     {
701       Grob *stem = stems[i];
702
703       Interval head_extents = Stem::head_positions (stem);
704       if (!head_extents.is_empty ())
705         {
706           head_extents[LEFT] += -1;
707           head_extents[RIGHT] += 1;
708           head_extents *= staff_space * 0.5;
709
710           /*
711             We could subtract beam Y position, but this routine only
712             sets stem directions, a constant shift does not have an
713             influence.
714           */
715           head_extents += stem->pure_relative_y_coordinate (common, 0, INT_MAX);
716
717           if (to_dir (stem->get_property_data ("direction")))
718             {
719               Direction stemdir = to_dir (stem->get_property ("direction"));
720               head_extents[-stemdir] = -stemdir * infinity_f;
721             }
722         }
723       head_extents_array.push_back (head_extents);
724
725       gaps.remove_interval (head_extents);
726     }
727
728   Interval max_gap;
729   Real max_gap_len = 0.0;
730
731   for (vsize i = gaps.allowed_regions_.size () -1; i != VPOS ;i--)
732     {
733       Interval gap = gaps.allowed_regions_[i];
734
735       /*
736         the outer gaps are not knees.
737       */
738       if (isinf (gap[LEFT]) || isinf (gap[RIGHT]))
739         continue;
740
741       if (gap.length () >= max_gap_len)
742         {
743           max_gap_len = gap.length ();
744           max_gap = gap;
745         }
746     }
747
748   Real beam_translation = get_beam_translation (me);
749   Real beam_thickness = Beam::get_thickness (me);
750   int beam_count = Beam::get_beam_count (me);
751   Real height_of_beams = beam_thickness / 2
752     + (beam_count - 1) * beam_translation;
753   Real threshold = scm_to_double (scm) + height_of_beams;
754
755   if (max_gap_len > threshold)
756     {
757       int j = 0;
758       for (vsize i = 0; i < stems.size (); i++)
759         {
760           Grob *stem = stems[i];
761           Interval head_extents = head_extents_array[j++];
762
763           Direction d = (head_extents.center () < max_gap.center ())
764             ? UP : DOWN;
765
766           stem->set_property ("direction", scm_from_int (d));
767
768           head_extents.intersect (max_gap);
769           assert (head_extents.is_empty () || head_extents.length () < 1e-6);
770         }
771     }
772 }
773
774 /* Set stem's shorten property if unset.
775
776 TODO:
777 take some y-position (chord/beam/nearest?) into account
778 scmify forced-fraction
779
780 This is done in beam because the shorten has to be uniform over the
781 entire beam.
782 */
783
784
785
786 void
787 set_minimum_dy (Grob *me, Real *dy)
788 {
789   if (*dy)
790     {
791       /*
792         If dy is smaller than the smallest quant, we
793         get absurd direction-sign penalties.
794       */
795
796       Real ss = Staff_symbol_referencer::staff_space (me);
797       Real thickness = Beam::get_thickness (me) / ss;
798       Real slt = Staff_symbol_referencer::line_thickness (me) / ss;
799       Real sit = (thickness - slt) / 2;
800       Real inter = 0.5;
801       Real hang = 1.0 - (thickness - slt) / 2;
802
803       *dy = sign (*dy) * max (fabs (*dy),
804                               min (min (sit, inter), hang));
805     }
806 }
807
808   
809
810 MAKE_SCHEME_CALLBACK (Beam, calc_stem_shorten, 1)
811 SCM
812 Beam::calc_stem_shorten (SCM smob)
813 {
814   Grob *me = unsmob_grob (smob);
815   
816   /*
817     shortening looks silly for x staff beams
818   */
819   if (is_knee (me))
820     return scm_from_int (0);
821
822   Real forced_fraction = 1.0 * forced_stem_count (me)
823     / normal_stem_count (me);
824
825   int beam_count = get_beam_count (me);
826
827   SCM shorten_list = me->get_property ("beamed-stem-shorten");
828   if (shorten_list == SCM_EOL)
829     return scm_from_int (0);
830
831   Real staff_space = Staff_symbol_referencer::staff_space (me);
832
833   SCM shorten_elt
834     = robust_list_ref (beam_count -1, shorten_list);
835   Real shorten = scm_to_double (shorten_elt) * staff_space;
836
837   shorten *= forced_fraction;
838
839   
840   if (shorten)
841     return scm_from_double (shorten);
842
843   return scm_from_double (0.0);
844 }
845
846
847
848 /*
849   Compute a first approximation to the beam slope.
850 */
851 MAKE_SCHEME_CALLBACK (Beam, calc_least_squares_positions, 2);
852 SCM
853 Beam::calc_least_squares_positions (SCM smob, SCM posns)
854 {
855   (void) posns;
856   
857   Grob *me = unsmob_grob (smob);
858
859   int count = normal_stem_count (me);
860   Interval pos (0,0);
861   if (count < 1)
862     return ly_interval2scm (pos);
863
864   vector<Real> x_posns;
865   extract_grob_set (me, "normal-stems", stems);
866   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
867   Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS);
868
869   Real my_y = me->relative_coordinate (commony, Y_AXIS);
870
871   Grob *fvs = first_normal_stem (me);
872   Grob *lvs = last_normal_stem (me);
873
874   Interval ideal (Stem::get_stem_info (fvs).ideal_y_
875                   + fvs->relative_coordinate (commony, Y_AXIS) - my_y,
876                   Stem::get_stem_info (lvs).ideal_y_
877                   + lvs->relative_coordinate (commony, Y_AXIS) - my_y);
878
879   Real x0 = first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
880   for (vsize i = 0; i < stems.size (); i++)
881     {
882       Grob *s = stems[i];
883
884       Real x = s->relative_coordinate (commonx, X_AXIS) - x0;
885       x_posns.push_back (x);
886     }
887   Real dx = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS) - x0;
888
889   Real y = 0;
890   Real slope = 0;
891   Real dy = 0;
892   Real ldy = 0.0;
893   if (!ideal.delta ())
894     {
895       Interval chord (Stem::chord_start_y (stems[0]),
896                       Stem::chord_start_y (stems.back ()));
897
898       /* Simple beams (2 stems) on middle line should be allowed to be
899          slightly sloped.
900
901          However, if both stems reach middle line,
902          ideal[LEFT] == ideal[RIGHT] and ideal.delta () == 0.
903
904          For that case, we apply artificial slope */
905       if (!ideal[LEFT] && chord.delta () && count == 2)
906         {
907           /* FIXME. -> UP */
908           Direction d = (Direction) (sign (chord.delta ()) * UP);
909           pos[d] = get_thickness (me) / 2;
910           pos[-d] = -pos[d];
911         }
912       else
913         pos = ideal;
914
915       /*
916         For broken beams this doesn't work well. In this case, the
917         slope esp. of the first part of a broken beam should predict
918         where the second part goes.
919       */
920       ldy = pos[RIGHT] - pos[LEFT];
921     }
922   else
923     {
924       vector<Offset> ideals;
925       for (vsize i = 0; i < stems.size (); i++)
926         {
927           Grob *s = stems[i];
928           ideals.push_back (Offset (x_posns[i],
929                                Stem::get_stem_info (s).ideal_y_
930                                + s->relative_coordinate (commony, Y_AXIS)
931                                - my_y));
932         }
933
934       minimise_least_squares (&slope, &y, ideals);
935
936       dy = slope * dx;
937
938       set_minimum_dy (me, &dy);
939
940       ldy = dy;
941       pos = Interval (y, (y + dy));
942     }
943
944   /*
945     "position" is relative to the staff.
946   */
947   scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
948
949   me->set_property ("least-squares-dy",  scm_from_double (ldy));
950   return ly_interval2scm (pos);
951 }
952
953 /*
954   We can't combine with previous function, since check concave and
955   slope damping comes first.
956
957   TODO: we should use the concaveness to control the amount of damping
958   applied.
959 */
960 MAKE_SCHEME_CALLBACK (Beam, shift_region_to_valid, 2);
961 SCM
962 Beam::shift_region_to_valid (SCM grob, SCM posns)
963 {
964   Grob *me = unsmob_grob (grob);
965   /*
966     Code dup.
967   */
968   vector<Real> x_posns;
969   extract_grob_set (me, "stems", stems);
970   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
971   Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS);
972
973   Grob *fvs = first_normal_stem (me);
974
975   if (!fvs)
976     return posns;
977
978   Real x0 = fvs->relative_coordinate (commonx, X_AXIS);
979   for (vsize i = 0; i < stems.size (); i++)
980     {
981       Grob *s = stems[i];
982
983       Real x = s->relative_coordinate (commonx, X_AXIS) - x0;
984       x_posns.push_back (x);
985     }
986
987   Grob *lvs = last_normal_stem (me);
988   if (!lvs)
989     return posns;
990
991   Real dx = lvs->relative_coordinate (commonx, X_AXIS) - x0;
992
993   Drul_array<Real> pos = ly_scm2interval (posns);
994
995   scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
996
997   Real dy = pos[RIGHT] - pos[LEFT];
998   Real y = pos[LEFT];
999   Real slope = dx ? (dy / dx) : 0.0;
1000
1001   /*
1002     Shift the positions so that we have a chance of finding good
1003     quants (i.e. no short stem failures.)
1004   */
1005   Interval feasible_left_point;
1006   feasible_left_point.set_full ();
1007   for (vsize i = 0; i < stems.size (); i++)
1008     {
1009       Grob *s = stems[i];
1010       if (Stem::is_invisible (s))
1011         continue;
1012
1013       Direction d = get_grob_direction (s);
1014
1015       Real left_y
1016         = Stem::get_stem_info (s).shortest_y_
1017         - slope * x_posns [i];
1018
1019       /*
1020         left_y is now relative to the stem S. We want relative to
1021         ourselves, so translate:
1022       */
1023       left_y
1024         += + s->relative_coordinate (commony, Y_AXIS)
1025         - me->relative_coordinate (commony, Y_AXIS);
1026
1027       Interval flp;
1028       flp.set_full ();
1029       flp[-d] = left_y;
1030
1031       feasible_left_point.intersect (flp);
1032     }
1033
1034   if (feasible_left_point.is_empty ())
1035     warning (_ ("no viable initial configuration found: may not find good beam slope"));
1036   else if (!feasible_left_point.contains (y))
1037     {
1038       const int REGION_SIZE = 2; // UGH UGH
1039       if (isinf (feasible_left_point[DOWN]))
1040         y = feasible_left_point[UP] - REGION_SIZE;
1041       else if (isinf (feasible_left_point[UP]))
1042         y = feasible_left_point[DOWN]+ REGION_SIZE;
1043       else
1044         y = feasible_left_point.center ();
1045     }
1046
1047   pos = Drul_array<Real> (y, (y + dy));
1048   scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
1049
1050   return ly_interval2scm (pos);
1051 }
1052
1053 /* This neat trick is by Werner Lemberg,
1054    damped = tanh (slope)
1055    corresponds with some tables in [Wanske] CHECKME */
1056 MAKE_SCHEME_CALLBACK (Beam, slope_damping, 2);
1057 SCM
1058 Beam::slope_damping (SCM smob, SCM posns)
1059 {
1060   Grob *me = unsmob_grob (smob);
1061   Drul_array<Real> pos = ly_scm2interval (posns);
1062
1063   if (normal_stem_count (me) <= 1)
1064     return posns;
1065
1066   
1067   SCM s = me->get_property ("damping");
1068   Real damping = scm_to_double (s);
1069   Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0);
1070   if (concaveness >= 10000)
1071     {
1072       pos[LEFT] = pos[RIGHT];
1073       me->set_property ("least-squares-dy", scm_from_double (0));
1074       damping = 0;
1075     }
1076   
1077   if (damping)
1078     {
1079       scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
1080
1081       Real dy = pos[RIGHT] - pos[LEFT];
1082
1083       Grob *fvs = first_normal_stem (me);
1084       Grob *lvs = last_normal_stem (me);
1085
1086       Grob *commonx = fvs->common_refpoint (lvs, X_AXIS);
1087
1088       Real dx = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS)
1089         - first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
1090
1091       Real slope = dy && dx ? dy / dx : 0;
1092
1093       slope = 0.6 * tanh (slope) / (damping + concaveness);
1094
1095       Real damped_dy = slope * dx;
1096
1097       set_minimum_dy (me, &damped_dy);
1098
1099       pos[LEFT] += (dy - damped_dy) / 2;
1100       pos[RIGHT] -= (dy - damped_dy) / 2;
1101
1102       scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
1103     }
1104
1105   return ly_interval2scm (pos);
1106 }
1107
1108 /*
1109   Report slice containing the numbers that are both in (car BEAMING)
1110   and (cdr BEAMING)
1111 */
1112 Slice
1113 where_are_the_whole_beams (SCM beaming)
1114 {
1115   Slice l;
1116
1117   for (SCM s = scm_car (beaming); scm_is_pair (s); s = scm_cdr (s))
1118     {
1119       if (scm_c_memq (scm_car (s), scm_cdr (beaming)) != SCM_BOOL_F)
1120
1121         l.add_point (scm_to_int (scm_car (s)));
1122     }
1123
1124   return l;
1125 }
1126
1127 /* Return the Y position of the stem-end, given the Y-left, Y-right
1128    in POS for stem S.  This Y position is relative to S. */
1129 Real
1130 Beam::calc_stem_y (Grob *me, Grob *stem, Grob **common,
1131                    Real xl, Real xr,
1132                    Drul_array<Real> pos, bool french)
1133 {
1134   Real beam_translation = get_beam_translation (me);
1135
1136   Real r = stem->relative_coordinate (common[X_AXIS], X_AXIS) - xl;
1137   Real dy = pos[RIGHT] - pos[LEFT];
1138   Real dx = xr - xl;
1139   Real stem_y_beam0 = (dy && dx
1140                        ? r / dx
1141                        * dy
1142                        : 0) + pos[LEFT];
1143
1144   Direction my_dir = get_grob_direction (stem);
1145   SCM beaming = stem->get_property ("beaming");
1146
1147   Real stem_y = stem_y_beam0;
1148   if (french)
1149     {
1150       Slice bm = where_are_the_whole_beams (beaming);
1151       if (!bm.is_empty ())
1152         stem_y += beam_translation * bm[-my_dir];
1153     }
1154   else
1155     {
1156       Slice bm = Stem::beam_multiplicity (stem);
1157       if (!bm.is_empty ())
1158         stem_y += bm[my_dir] * beam_translation;
1159     }
1160
1161   Real id = me->relative_coordinate (common[Y_AXIS], Y_AXIS)
1162     - stem->relative_coordinate (common[Y_AXIS], Y_AXIS);
1163
1164   return stem_y + id;
1165 }
1166
1167 /*
1168   Hmm.  At this time, beam position and slope are determined.  Maybe,
1169   stem directions and length should set to relative to the chord's
1170   position of the beam.  */
1171 MAKE_SCHEME_CALLBACK (Beam, set_stem_lengths, 1); 
1172 SCM
1173 Beam::set_stem_lengths (SCM smob)
1174 {
1175   Grob *me = unsmob_grob (smob);
1176
1177   /* trigger callbacks. */
1178   (void) me->get_property ("direction");
1179   (void) me->get_property ("beaming");
1180
1181   SCM posns = me->get_property ("positions");
1182   
1183   extract_grob_set (me, "stems", stems);
1184   if (!stems.size ())
1185     return posns;
1186
1187   Grob *common[2];
1188   for (int a = 2; a--;)
1189     common[a] = common_refpoint_of_array (stems, me, Axis (a));
1190
1191   Drul_array<Real> pos = ly_scm2realdrul (posns);
1192   Real staff_space = Staff_symbol_referencer::staff_space (me);
1193   scale_drul (&pos, staff_space);
1194
1195   bool gap = false;
1196   Real thick = 0.0;
1197   if (robust_scm2int (me->get_property ("gap-count"), 0))
1198     {
1199       gap = true;
1200       thick = get_thickness (me);
1201     }
1202
1203   Grob *fvs = first_normal_stem (me);
1204   Grob *lvs = last_normal_stem (me);
1205
1206   Real xl = fvs ? fvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0;
1207   Real xr = lvs ? lvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0;
1208
1209   for (vsize i = 0; i < stems.size (); i++)
1210     {
1211       Grob *s = stems[i];
1212
1213       bool french = to_boolean (s->get_property ("french-beaming"));
1214       Real stem_y = calc_stem_y (me, s, common,
1215                                  xl, xr,
1216                                  pos, french && s != lvs && s!= fvs);
1217
1218       /*
1219         Make the stems go up to the end of the beam. This doesn't matter
1220         for normal beams, but for tremolo beams it looks silly otherwise.
1221       */
1222       if (gap
1223            && !Stem::is_invisible (s))
1224         stem_y += thick * 0.5 * get_grob_direction (s);
1225
1226       /*
1227         Do set_stemend for invisible stems too, so tuplet brackets
1228         have a reference point for sloping
1229        */
1230       Stem::set_stemend (s, 2 * stem_y / staff_space);
1231     }
1232
1233   return posns;
1234 }
1235
1236 void
1237 Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
1238 {
1239   extract_grob_set (me, "stems", stems);
1240
1241   Direction d = LEFT;
1242   for (vsize i = 0; i < stems.size (); i++)
1243     {
1244       /*
1245         Don't overwrite user settings.
1246       */
1247       do
1248         {
1249           Grob *stem = stems[i];
1250           SCM beaming_prop = stem->get_property ("beaming");
1251           if (beaming_prop == SCM_EOL
1252               || index_get_cell (beaming_prop, d) == SCM_EOL)
1253             {
1254               int count = beaming->beamlet_count (i, d);
1255               if (i > 0
1256                   && i + 1 < stems.size ()
1257                   && Stem::is_invisible (stem))
1258                 count = min (count, beaming->beamlet_count (i,-d));
1259
1260               if ( ((i == 0 && d == LEFT)
1261                     || (i == stems.size ()-1 && d == RIGHT))
1262                    && stems.size () > 1
1263                    && to_boolean (me->get_property ("clip-edges")))
1264                 count = 0;
1265
1266               Stem::set_beaming (stem, count, d);
1267             }
1268         }
1269       while (flip (&d) != LEFT);
1270     }
1271 }
1272
1273 int
1274 Beam::forced_stem_count (Grob *me)
1275 {
1276   extract_grob_set (me, "normal-stems", stems);
1277
1278   int f = 0;
1279   for (vsize i = 0; i < stems.size (); i++)
1280     {
1281       Grob *s = stems[i];
1282
1283       /* I can imagine counting those boundaries as a half forced stem,
1284          but let's count them full for now. */
1285       Direction defdir = to_dir (s->get_property ("default-direction"));
1286       
1287       if (abs (Stem::chord_start_y (s)) > 0.1
1288           && defdir
1289           && get_grob_direction (s) != defdir)
1290         f++;
1291     }
1292   return f;
1293 }
1294
1295 int
1296 Beam::normal_stem_count (Grob *me)
1297 {
1298   extract_grob_set (me, "normal-stems", stems);
1299   return stems.size ();
1300 }
1301
1302 Grob *
1303 Beam::first_normal_stem (Grob *me)
1304 {
1305   extract_grob_set (me, "normal-stems", stems);
1306   return stems.size () ? stems[0] : 0;
1307 }
1308
1309 Grob *
1310 Beam::last_normal_stem (Grob *me)
1311 {
1312   extract_grob_set (me, "normal-stems", stems);
1313   return stems.size () ? stems.back () : 0;
1314 }
1315
1316 /*
1317   [TODO]
1318
1319   handle rest under beam (do_post: beams are calculated now)
1320   what about combination of collisions and rest under beam.
1321
1322   Should lookup
1323
1324   rest -> stem -> beam -> interpolate_y_position ()
1325 */
1326 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, rest_collision_callback, 2, 1, "");
1327 SCM
1328 Beam::rest_collision_callback (SCM smob, SCM prev_offset)
1329 {
1330   Grob *rest = unsmob_grob (smob);
1331   if (scm_is_number (rest->get_property ("staff-position")))
1332     return scm_from_int (0);
1333
1334   Real offset = robust_scm2double (prev_offset, 0.0);
1335   
1336   Grob *st = unsmob_grob (rest->get_object ("stem"));
1337   Grob *stem = st;
1338   if (!stem)
1339     return scm_from_double (0.0);
1340   Grob *beam = unsmob_grob (stem->get_object ("beam"));
1341   if (!beam
1342       || !Beam::has_interface (beam)
1343       || !Beam::normal_stem_count (beam))
1344     return scm_from_double (0.0);
1345
1346   Drul_array<Real> pos (robust_scm2drul (beam->get_property ("positions"),
1347                                          Drul_array<Real> (0,0)));
1348
1349   Real staff_space = Staff_symbol_referencer::staff_space (rest);
1350
1351   scale_drul (&pos, staff_space);
1352
1353   Real dy = pos[RIGHT] - pos[LEFT];
1354
1355   Drul_array<Grob*> visible_stems (first_normal_stem (beam),
1356                                    last_normal_stem (beam));
1357   extract_grob_set (beam, "stems", stems);
1358   
1359   Grob *common = common_refpoint_of_array (stems, beam, X_AXIS);
1360   
1361   Real x0 = visible_stems[LEFT]->relative_coordinate (common, X_AXIS);
1362   Real dx = visible_stems[RIGHT]->relative_coordinate (common, X_AXIS) - x0;
1363   Real slope = dy && dx ? dy / dx : 0;
1364
1365   Direction d = get_grob_direction (stem);
1366   Real stem_y = pos[LEFT]
1367     + (stem->relative_coordinate (common, X_AXIS) - x0) * slope;
1368
1369   Real beam_translation = get_beam_translation (beam);
1370   Real beam_thickness = Beam::get_thickness (beam);
1371
1372   /*
1373     TODO: this is not strictly correct for 16th knee beams.
1374   */
1375   int beam_count
1376     = Stem::beam_multiplicity (stem).length () + 1;
1377
1378   Real height_of_my_beams = beam_thickness / 2
1379     + (beam_count - 1) * beam_translation;
1380   Real beam_y = stem_y - d * height_of_my_beams;
1381
1382   Grob *common_y = rest->common_refpoint (beam, Y_AXIS);
1383
1384   /*
1385     TODO: this is dubious, because this call needs the info we're
1386     computing right now.
1387    */
1388   Interval rest_extent = rest->extent (common_y, Y_AXIS);
1389   rest_extent.translate (offset);
1390   
1391   Real rest_dim = rest_extent[d];
1392   Real minimum_distance
1393     = staff_space * (robust_scm2double (stem->get_property ("stemlet-length"), 0.0)
1394                      + robust_scm2double (rest->get_property ("minimum-distance"), 0.0));
1395
1396   Real shift = d * min (d * (beam_y - d * minimum_distance - rest_dim), 0.0);
1397
1398   shift /= staff_space;
1399   Real rad = Staff_symbol_referencer::line_count (rest) * staff_space / 2;
1400
1401   /* Always move discretely by half spaces */
1402   shift = ceil (fabs (shift * 2.0)) / 2.0 * sign (shift);
1403
1404   /* Inside staff, move by whole spaces*/
1405   if ((rest_extent[d] + staff_space * shift) * d
1406       < rad
1407       || (rest_extent[-d] + staff_space * shift) * -d
1408       < rad)
1409     shift = ceil (fabs (shift)) * sign (shift);
1410
1411   return scm_from_double (offset + staff_space * shift);
1412 }
1413
1414 bool
1415 Beam::is_knee (Grob *me)
1416 {
1417   SCM k = me->get_property ("knee");
1418   if (scm_is_bool (k))
1419     return ly_scm2bool (k);
1420
1421   bool knee = false;
1422   int d = 0;
1423   extract_grob_set (me, "stems", stems);
1424   for (vsize i = stems.size (); i--;)
1425     {
1426       Direction dir = get_grob_direction (stems[i]);
1427       if (d && d != dir)
1428         {
1429           knee = true;
1430           break;
1431         }
1432       d = dir;
1433     }
1434
1435   me->set_property ("knee", ly_bool2scm (knee));
1436
1437   return knee;
1438 }
1439
1440 bool
1441 Beam::is_cross_staff (Grob *me)
1442 {
1443   extract_grob_set (me, "stems", stems);
1444   Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (me);
1445   for (vsize i = 0; i < stems.size (); i++)
1446     if (Staff_symbol_referencer::get_staff_symbol (stems[i]) != staff_symbol)
1447       return true;
1448   return false;
1449 }
1450
1451 MAKE_SCHEME_CALLBACK (Beam, calc_cross_staff, 1)
1452 SCM
1453 Beam::calc_cross_staff (SCM smob)
1454 {
1455   return scm_from_bool (is_cross_staff (unsmob_grob (smob)));
1456 }
1457
1458 int
1459 Beam::get_direction_beam_count (Grob *me, Direction d)
1460 {
1461   extract_grob_set (me, "stems", stems);
1462   int bc = 0;
1463
1464   for (vsize i = stems.size (); i--;)
1465     {
1466       /*
1467         Should we take invisible stems into account?
1468       */
1469       if (get_grob_direction (stems[i]) == d)
1470         bc = max (bc, (Stem::beam_multiplicity (stems[i]).length () + 1));
1471     }
1472
1473   return bc;
1474 }
1475
1476 ADD_INTERFACE (Beam,
1477
1478                "A beam. \n\n"
1479                "The @code{thickness} property is the weight of beams, "
1480                "measured in staffspace.  The @code{direction} "
1481                "property is not user-serviceable. Use "
1482                "the @code{direction} property of @code{Stem} instead. "
1483
1484                ,
1485                
1486                /* properties */
1487                "auto-knee-gap "
1488                "beamed-stem-shorten "
1489                "beaming "
1490                "break-overshoot "
1491                "clip-edges "
1492                "concaveness "
1493                "damping "
1494                "details "
1495                "direction " 
1496                "gap "
1497                "gap-count "
1498                "grow-direction "
1499                "inspect-quants "
1500                "knee "
1501                "length-fraction "
1502                "least-squares-dy "
1503                "neutral-direction "
1504                "normal-stems "
1505                "positions "
1506                "quant-score "
1507                "quantized-positions "
1508                "shorten "
1509                "stems "
1510                "thickness "
1511                );