]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam.cc
Merge branch 'master' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[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),
431                                                    commonx, X_AXIS)[RIGHT]
432                            + event_dir * break_overshoot[event_dir]);
433                     }
434                   else
435                     {
436                       Real notehead_width = 
437                         Stem::duration_log (segs[j].stem_) == 1
438                         ? 1.98
439                         : 1.32; // URG.
440
441
442                       if (inside_stem)
443                         {
444                           Grob *neighbor_stem = stems[segs[j].stem_index_ + event_dir];
445                           Real neighbor_stem_x
446                             = neighbor_stem->relative_coordinate (commonx, X_AXIS);
447
448                           notehead_width = min (notehead_width,
449                                                 fabs (neighbor_stem_x - segs[j].stem_x_)/2);
450                         }
451                       current.horizontal_[event_dir] += event_dir * notehead_width;
452                     }
453                 }
454               else
455                 {
456                   current.horizontal_[event_dir] += event_dir * segs[j].width_/2;
457                   if (segs[j].gapped_)
458                     {
459                       current.horizontal_[event_dir] -= event_dir * gap_length;
460
461                       if (Stem::is_invisible (segs[j].stem_))
462                         {
463                           /*
464                             Need to do this in case of whole notes. We don't want the
465                             heads to collide with the beams.
466                            */
467                           extract_grob_set (segs[j].stem_, "note-heads", heads);
468
469                           for (vsize k = 0; k < heads.size (); k ++)
470                             current.horizontal_[event_dir]
471                               = event_dir * min  (event_dir * current.horizontal_[event_dir],
472                                                   - gap_length/2
473                                                   + event_dir
474                                                     * heads[k]->extent (commonx,
475                                                                         X_AXIS)[-event_dir]);
476                         }
477                     }
478                 }
479
480               if (event_dir == RIGHT)
481                 {
482                   segments.push_back (current);
483                   current = Beam_segment ();
484                 }
485             }
486           while (flip (&event_dir) != LEFT);
487         }
488       
489     }
490
491   return segments;
492 }
493
494 MAKE_SCHEME_CALLBACK (Beam, print, 1);
495 SCM
496 Beam::print (SCM grob)
497 {
498   Spanner *me = unsmob_spanner (grob);
499   Grob *commonx = 0;
500   vector<Beam_segment> segments = get_beam_segments (me, &commonx);
501
502   Interval span;
503   if (normal_stem_count (me))
504     {
505       span[LEFT] = first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
506       span[RIGHT] = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
507     }
508   else
509     {
510       extract_grob_set (me, "stems", stems);      
511       span[LEFT] = stems[0]->relative_coordinate (commonx, X_AXIS);
512       span[RIGHT] = stems.back ()->relative_coordinate (commonx, X_AXIS);
513     }
514
515   Real blot = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
516
517   SCM posns = me->get_property ("quantized-positions");
518   Interval pos;
519   if (!is_number_pair (posns))
520     {
521       programming_error ("no beam positions?");
522       pos = Interval (0, 0);
523     }
524   else
525     pos = ly_scm2realdrul (posns);
526
527   scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
528
529   Real dy = pos[RIGHT] - pos[LEFT];
530   Real slope = (dy && span.length ()) ? dy / span.length ()  : 0;
531
532   Real thick = get_thickness (me);
533   Real beam_dy = get_beam_translation (me);
534
535   Direction feather_dir = to_dir (me->get_property ("grow-direction"));
536   
537   Stencil the_beam;
538   for (vsize i = 0; i < segments.size (); i ++)
539     {
540       Real local_slope = slope;
541       if (feather_dir)
542         {
543           local_slope += feather_dir * segments[i].vertical_count_ * beam_dy / span.length ();
544         }
545       
546       Stencil b = Lookup::beam (local_slope, segments[i].horizontal_.length (), thick, blot);
547
548       b.translate_axis (segments[i].horizontal_[LEFT], X_AXIS);
549       
550       b.translate_axis (local_slope
551                         * (segments[i].horizontal_[LEFT] - span.linear_combination (feather_dir))
552                         + pos.linear_combination (feather_dir)
553                         + beam_dy * segments[i].vertical_count_, Y_AXIS);
554       the_beam.add_stencil (b);      
555     }
556          
557 #if (DEBUG_BEAM_SCORING)
558   SCM quant_score = me->get_property ("quant-score");
559   SCM debug = me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-scoring"));
560   if (to_boolean (debug) && scm_is_string (quant_score))
561     {
562       extract_grob_set (me, "stems", stems);      
563
564       /*
565         This code prints the demerits for each beam. Perhaps this
566         should be switchable for those who want to twiddle with the
567         parameters.
568       */
569       string str;
570       SCM properties = Font_interface::text_font_alist_chain (me);
571
572       Direction stem_dir = stems.size () ? to_dir (stems[0]->get_property ("direction")) : UP;
573
574       Stencil score = *unsmob_stencil (Text_interface::interpret_markup
575                                     (me->layout ()->self_scm (), properties, quant_score));
576
577       if (!score.is_empty ())
578         the_beam.add_at_edge (Y_AXIS, stem_dir, score, 1.0);
579     }
580 #endif
581
582   the_beam.translate_axis (-me->relative_coordinate (commonx, X_AXIS), X_AXIS);
583   return the_beam.smobbed_copy ();
584 }
585  
586 Direction
587 Beam::get_default_dir (Grob *me)
588 {
589   extract_grob_set (me, "stems", stems);
590
591   Drul_array<Real> extremes (0.0, 0.0);
592   for (iterof (s, stems); s != stems.end (); s++)
593     {
594       Interval positions = Stem::head_positions (*s);
595       Direction d = DOWN;
596       do
597         {
598           if (sign (positions[d]) == d)
599             extremes[d] = d * max (d * positions[d], d * extremes[d]);
600         }
601       while (flip (&d) != DOWN);
602     }
603
604   Drul_array<int> total (0, 0);
605   Drul_array<int> count (0, 0);
606
607   bool force_dir = false;
608   for (vsize i = 0; i < stems.size (); i++)
609     {
610       Grob *s = stems[i];
611       Direction stem_dir = CENTER;
612       SCM stem_dir_scm = s->get_property_data ("direction");
613       if (is_direction (stem_dir_scm))
614         {
615           stem_dir = to_dir (stem_dir_scm);
616           force_dir = true;
617         }
618       else
619         stem_dir = to_dir (s->get_property ("default-direction"));
620
621       if (!stem_dir)
622         stem_dir = to_dir (s->get_property ("neutral-direction"));
623
624       if (stem_dir)
625         {
626           count[stem_dir] ++;
627           total[stem_dir] += max (int (- stem_dir * Stem::head_positions (s) [-stem_dir]), 0);
628         }
629     }
630
631
632   if (!force_dir)
633     {
634       if (abs (extremes[UP]) > -extremes[DOWN])
635         return DOWN;
636       else if (extremes[UP] < -extremes[DOWN])
637         return UP;
638     }
639   
640   Direction dir = CENTER;
641   Direction d = CENTER;
642   if ((d = (Direction) sign (count[UP] - count[DOWN])))
643     dir = d;
644   else if (count[UP]
645            && count[DOWN]
646            && (d = (Direction)  sign (total[UP] / count[UP] - total[DOWN]/count[DOWN])))
647     dir = d;
648   else if ((d = (Direction)  sign (total[UP] - total[DOWN])))
649     dir = d;
650   else
651     dir = to_dir (me->get_property ("neutral-direction"));
652   
653   return dir;
654 }
655
656 /* Set all stems with non-forced direction to beam direction.
657    Urg: non-forced should become `without/with unforced' direction,
658    once stem gets cleaned-up. */
659 void
660 Beam::set_stem_directions (Grob *me, Direction d)
661 {
662   extract_grob_set (me, "stems", stems);
663
664   for (vsize i = 0; i < stems.size (); i++)
665     {
666       Grob *s = stems[i];
667
668       SCM forcedir = s->get_property_data ("direction");
669       if (!to_dir (forcedir))
670         set_grob_direction (s, d);
671     }
672 }
673
674 /*
675   Only try horizontal beams for knees.  No reliable detection of
676   anything else is possible here, since we don't know funky-beaming
677   settings, or X-distances (slopes!)  People that want sloped
678   knee-beams, should set the directions manually.
679
680
681   TODO:
682
683   this routine should take into account the stemlength scoring
684   of a possible knee/nonknee beam.
685 */
686 void
687 Beam::consider_auto_knees (Grob *me)
688 {
689   SCM scm = me->get_property ("auto-knee-gap");
690   if (!scm_is_number (scm))
691     return;
692
693   Interval_set gaps;
694
695   gaps.set_full ();
696
697   extract_grob_set (me, "normal-stems", stems);
698
699   Grob *common = common_refpoint_of_array (stems, me, Y_AXIS);
700   Real staff_space = Staff_symbol_referencer::staff_space (me);
701
702   vector<Interval> head_extents_array;
703   for (vsize i = 0; i < stems.size (); i++)
704     {
705       Grob *stem = stems[i];
706
707       Interval head_extents = Stem::head_positions (stem);
708       if (!head_extents.is_empty ())
709         {
710           head_extents[LEFT] += -1;
711           head_extents[RIGHT] += 1;
712           head_extents *= staff_space * 0.5;
713
714           /*
715             We could subtract beam Y position, but this routine only
716             sets stem directions, a constant shift does not have an
717             influence.
718           */
719           head_extents += stem->pure_relative_y_coordinate (common, 0, INT_MAX);
720
721           if (to_dir (stem->get_property_data ("direction")))
722             {
723               Direction stemdir = to_dir (stem->get_property ("direction"));
724               head_extents[-stemdir] = -stemdir * infinity_f;
725             }
726         }
727       head_extents_array.push_back (head_extents);
728
729       gaps.remove_interval (head_extents);
730     }
731
732   Interval max_gap;
733   Real max_gap_len = 0.0;
734
735   for (vsize i = gaps.allowed_regions_.size () -1; i != VPOS ;i--)
736     {
737       Interval gap = gaps.allowed_regions_[i];
738
739       /*
740         the outer gaps are not knees.
741       */
742       if (isinf (gap[LEFT]) || isinf (gap[RIGHT]))
743         continue;
744
745       if (gap.length () >= max_gap_len)
746         {
747           max_gap_len = gap.length ();
748           max_gap = gap;
749         }
750     }
751
752   Real beam_translation = get_beam_translation (me);
753   Real beam_thickness = Beam::get_thickness (me);
754   int beam_count = Beam::get_beam_count (me);
755   Real height_of_beams = beam_thickness / 2
756     + (beam_count - 1) * beam_translation;
757   Real threshold = scm_to_double (scm) + height_of_beams;
758
759   if (max_gap_len > threshold)
760     {
761       int j = 0;
762       for (vsize i = 0; i < stems.size (); i++)
763         {
764           Grob *stem = stems[i];
765           Interval head_extents = head_extents_array[j++];
766
767           Direction d = (head_extents.center () < max_gap.center ())
768             ? UP : DOWN;
769
770           stem->set_property ("direction", scm_from_int (d));
771
772           head_extents.intersect (max_gap);
773           assert (head_extents.is_empty () || head_extents.length () < 1e-6);
774         }
775     }
776 }
777
778 /* Set stem's shorten property if unset.
779
780 TODO:
781 take some y-position (chord/beam/nearest?) into account
782 scmify forced-fraction
783
784 This is done in beam because the shorten has to be uniform over the
785 entire beam.
786 */
787
788
789
790 void
791 set_minimum_dy (Grob *me, Real *dy)
792 {
793   if (*dy)
794     {
795       /*
796         If dy is smaller than the smallest quant, we
797         get absurd direction-sign penalties.
798       */
799
800       Real ss = Staff_symbol_referencer::staff_space (me);
801       Real thickness = Beam::get_thickness (me) / ss;
802       Real slt = Staff_symbol_referencer::line_thickness (me) / ss;
803       Real sit = (thickness - slt) / 2;
804       Real inter = 0.5;
805       Real hang = 1.0 - (thickness - slt) / 2;
806
807       *dy = sign (*dy) * max (fabs (*dy),
808                               min (min (sit, inter), hang));
809     }
810 }
811
812   
813
814 MAKE_SCHEME_CALLBACK (Beam, calc_stem_shorten, 1)
815 SCM
816 Beam::calc_stem_shorten (SCM smob)
817 {
818   Grob *me = unsmob_grob (smob);
819   
820   /*
821     shortening looks silly for x staff beams
822   */
823   if (is_knee (me))
824     return scm_from_int (0);
825
826   Real forced_fraction = 1.0 * forced_stem_count (me)
827     / normal_stem_count (me);
828
829   int beam_count = get_beam_count (me);
830
831   SCM shorten_list = me->get_property ("beamed-stem-shorten");
832   if (shorten_list == SCM_EOL)
833     return scm_from_int (0);
834
835   Real staff_space = Staff_symbol_referencer::staff_space (me);
836
837   SCM shorten_elt
838     = robust_list_ref (beam_count -1, shorten_list);
839   Real shorten = scm_to_double (shorten_elt) * staff_space;
840
841   shorten *= forced_fraction;
842
843   
844   if (shorten)
845     return scm_from_double (shorten);
846
847   return scm_from_double (0.0);
848 }
849
850
851
852 /*
853   Compute a first approximation to the beam slope.
854 */
855 MAKE_SCHEME_CALLBACK (Beam, calc_least_squares_positions, 2);
856 SCM
857 Beam::calc_least_squares_positions (SCM smob, SCM posns)
858 {
859   (void) posns;
860   
861   Grob *me = unsmob_grob (smob);
862
863   int count = normal_stem_count (me);
864   Interval pos (0,0);
865   if (count < 1)
866     return ly_interval2scm (pos);
867
868   vector<Real> x_posns;
869   extract_grob_set (me, "normal-stems", stems);
870   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
871   Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS);
872
873   Real my_y = me->relative_coordinate (commony, Y_AXIS);
874
875   Grob *fvs = first_normal_stem (me);
876   Grob *lvs = last_normal_stem (me);
877
878   Interval ideal (Stem::get_stem_info (fvs).ideal_y_
879                   + fvs->relative_coordinate (commony, Y_AXIS) - my_y,
880                   Stem::get_stem_info (lvs).ideal_y_
881                   + lvs->relative_coordinate (commony, Y_AXIS) - my_y);
882
883   Real x0 = first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
884   for (vsize i = 0; i < stems.size (); i++)
885     {
886       Grob *s = stems[i];
887
888       Real x = s->relative_coordinate (commonx, X_AXIS) - x0;
889       x_posns.push_back (x);
890     }
891   Real dx = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS) - x0;
892
893   Real y = 0;
894   Real slope = 0;
895   Real dy = 0;
896   Real ldy = 0.0;
897   if (!ideal.delta ())
898     {
899       Interval chord (Stem::chord_start_y (stems[0]),
900                       Stem::chord_start_y (stems.back ()));
901
902       /* Simple beams (2 stems) on middle line should be allowed to be
903          slightly sloped.
904
905          However, if both stems reach middle line,
906          ideal[LEFT] == ideal[RIGHT] and ideal.delta () == 0.
907
908          For that case, we apply artificial slope */
909       if (!ideal[LEFT] && chord.delta () && count == 2)
910         {
911           /* FIXME. -> UP */
912           Direction d = (Direction) (sign (chord.delta ()) * UP);
913           pos[d] = get_thickness (me) / 2;
914           pos[-d] = -pos[d];
915         }
916       else
917         pos = ideal;
918
919       /*
920         For broken beams this doesn't work well. In this case, the
921         slope esp. of the first part of a broken beam should predict
922         where the second part goes.
923       */
924       ldy = pos[RIGHT] - pos[LEFT];
925     }
926   else
927     {
928       vector<Offset> ideals;
929       for (vsize i = 0; i < stems.size (); i++)
930         {
931           Grob *s = stems[i];
932           ideals.push_back (Offset (x_posns[i],
933                                Stem::get_stem_info (s).ideal_y_
934                                + s->relative_coordinate (commony, Y_AXIS)
935                                - my_y));
936         }
937
938       minimise_least_squares (&slope, &y, ideals);
939
940       dy = slope * dx;
941
942       set_minimum_dy (me, &dy);
943
944       ldy = dy;
945       pos = Interval (y, (y + dy));
946     }
947
948   /*
949     "position" is relative to the staff.
950   */
951   scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
952
953   me->set_property ("least-squares-dy",  scm_from_double (ldy));
954   return ly_interval2scm (pos);
955 }
956
957 /*
958   We can't combine with previous function, since check concave and
959   slope damping comes first.
960
961   TODO: we should use the concaveness to control the amount of damping
962   applied.
963 */
964 MAKE_SCHEME_CALLBACK (Beam, shift_region_to_valid, 2);
965 SCM
966 Beam::shift_region_to_valid (SCM grob, SCM posns)
967 {
968   Grob *me = unsmob_grob (grob);
969   /*
970     Code dup.
971   */
972   vector<Real> x_posns;
973   extract_grob_set (me, "stems", stems);
974   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
975   Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS);
976
977   Grob *fvs = first_normal_stem (me);
978
979   if (!fvs)
980     return posns;
981
982   Real x0 = fvs->relative_coordinate (commonx, X_AXIS);
983   for (vsize i = 0; i < stems.size (); i++)
984     {
985       Grob *s = stems[i];
986
987       Real x = s->relative_coordinate (commonx, X_AXIS) - x0;
988       x_posns.push_back (x);
989     }
990
991   Grob *lvs = last_normal_stem (me);
992   if (!lvs)
993     return posns;
994
995   Real dx = lvs->relative_coordinate (commonx, X_AXIS) - x0;
996
997   Drul_array<Real> pos = ly_scm2interval (posns);
998
999   scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
1000
1001   Real dy = pos[RIGHT] - pos[LEFT];
1002   Real y = pos[LEFT];
1003   Real slope = dx ? (dy / dx) : 0.0;
1004
1005   /*
1006     Shift the positions so that we have a chance of finding good
1007     quants (i.e. no short stem failures.)
1008   */
1009   Interval feasible_left_point;
1010   feasible_left_point.set_full ();
1011   for (vsize i = 0; i < stems.size (); i++)
1012     {
1013       Grob *s = stems[i];
1014       if (Stem::is_invisible (s))
1015         continue;
1016
1017       Direction d = get_grob_direction (s);
1018
1019       Real left_y
1020         = Stem::get_stem_info (s).shortest_y_
1021         - slope * x_posns [i];
1022
1023       /*
1024         left_y is now relative to the stem S. We want relative to
1025         ourselves, so translate:
1026       */
1027       left_y
1028         += + s->relative_coordinate (commony, Y_AXIS)
1029         - me->relative_coordinate (commony, Y_AXIS);
1030
1031       Interval flp;
1032       flp.set_full ();
1033       flp[-d] = left_y;
1034
1035       feasible_left_point.intersect (flp);
1036     }
1037
1038   if (feasible_left_point.is_empty ())
1039     warning (_ ("no viable initial configuration found: may not find good beam slope"));
1040   else if (!feasible_left_point.contains (y))
1041     {
1042       const int REGION_SIZE = 2; // UGH UGH
1043       if (isinf (feasible_left_point[DOWN]))
1044         y = feasible_left_point[UP] - REGION_SIZE;
1045       else if (isinf (feasible_left_point[UP]))
1046         y = feasible_left_point[DOWN]+ REGION_SIZE;
1047       else
1048         y = feasible_left_point.center ();
1049     }
1050
1051   pos = Drul_array<Real> (y, (y + dy));
1052   scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
1053
1054   return ly_interval2scm (pos);
1055 }
1056
1057 /* This neat trick is by Werner Lemberg,
1058    damped = tanh (slope)
1059    corresponds with some tables in [Wanske] CHECKME */
1060 MAKE_SCHEME_CALLBACK (Beam, slope_damping, 2);
1061 SCM
1062 Beam::slope_damping (SCM smob, SCM posns)
1063 {
1064   Grob *me = unsmob_grob (smob);
1065   Drul_array<Real> pos = ly_scm2interval (posns);
1066
1067   if (normal_stem_count (me) <= 1)
1068     return posns;
1069
1070   
1071   SCM s = me->get_property ("damping");
1072   Real damping = scm_to_double (s);
1073   Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0);
1074   if (concaveness >= 10000)
1075     {
1076       pos[LEFT] = pos[RIGHT];
1077       me->set_property ("least-squares-dy", scm_from_double (0));
1078       damping = 0;
1079     }
1080   
1081   if (damping)
1082     {
1083       scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
1084
1085       Real dy = pos[RIGHT] - pos[LEFT];
1086
1087       Grob *fvs = first_normal_stem (me);
1088       Grob *lvs = last_normal_stem (me);
1089
1090       Grob *commonx = fvs->common_refpoint (lvs, X_AXIS);
1091
1092       Real dx = last_normal_stem (me)->relative_coordinate (commonx, X_AXIS)
1093         - first_normal_stem (me)->relative_coordinate (commonx, X_AXIS);
1094
1095       Real slope = dy && dx ? dy / dx : 0;
1096
1097       slope = 0.6 * tanh (slope) / (damping + concaveness);
1098
1099       Real damped_dy = slope * dx;
1100
1101       set_minimum_dy (me, &damped_dy);
1102
1103       pos[LEFT] += (dy - damped_dy) / 2;
1104       pos[RIGHT] -= (dy - damped_dy) / 2;
1105
1106       scale_drul (&pos, 1 / Staff_symbol_referencer::staff_space (me));
1107     }
1108
1109   return ly_interval2scm (pos);
1110 }
1111
1112 /*
1113   Report slice containing the numbers that are both in (car BEAMING)
1114   and (cdr BEAMING)
1115 */
1116 Slice
1117 where_are_the_whole_beams (SCM beaming)
1118 {
1119   Slice l;
1120
1121   for (SCM s = scm_car (beaming); scm_is_pair (s); s = scm_cdr (s))
1122     {
1123       if (scm_c_memq (scm_car (s), scm_cdr (beaming)) != SCM_BOOL_F)
1124
1125         l.add_point (scm_to_int (scm_car (s)));
1126     }
1127
1128   return l;
1129 }
1130
1131 /* Return the Y position of the stem-end, given the Y-left, Y-right
1132    in POS for stem S.  This Y position is relative to S. */
1133 Real
1134 Beam::calc_stem_y (Grob *me, Grob *stem, Grob **common,
1135                    Real xl, Real xr, Direction feather_dir, 
1136                    Drul_array<Real> pos, bool french)
1137 {
1138   Real beam_translation = get_beam_translation (me);
1139   Direction stem_dir = get_grob_direction (stem);
1140
1141   Real dx = xr - xl;
1142   Real relx = dx ? (stem->relative_coordinate (common[X_AXIS], X_AXIS) - xl)/dx : 0;
1143   Real xdir = 2*relx-1;
1144
1145   Real stem_y = linear_combination(pos, xdir);
1146
1147   SCM beaming = stem->get_property ("beaming");
1148
1149   Slice beam_slice (french
1150                     ? where_are_the_whole_beams (beaming)
1151                     : Stem::beam_multiplicity (stem));
1152
1153   Interval beam_multiplicity(beam_slice[LEFT],
1154                              beam_slice[RIGHT]);
1155
1156   /*
1157     feather dir = 1 , relx 0->1 : factor 0 -> 1
1158     feather dir = 0 , relx 0->1 : factor 1 -> 1    
1159     feather dir = -1, relx 0->1 : factor 1 -> 0    
1160    */
1161   Real feather_factor = 1;
1162   if (feather_dir > 0)
1163     feather_factor = relx;
1164   else if (feather_dir < 0)
1165     feather_factor = 1 - relx;
1166   
1167   stem_y += feather_factor * beam_translation
1168     * beam_multiplicity[Direction(((french) ? DOWN : UP)*stem_dir)];
1169   Real id = me->relative_coordinate (common[Y_AXIS], Y_AXIS)
1170     - stem->relative_coordinate (common[Y_AXIS], Y_AXIS);
1171
1172   return stem_y + id;
1173 }
1174
1175 /*
1176   Hmm.  At this time, beam position and slope are determined.  Maybe,
1177   stem directions and length should set to relative to the chord's
1178   position of the beam.  */
1179 MAKE_SCHEME_CALLBACK (Beam, set_stem_lengths, 1); 
1180 SCM
1181 Beam::set_stem_lengths (SCM smob)
1182 {
1183   Grob *me = unsmob_grob (smob);
1184
1185   /* trigger callbacks. */
1186   (void) me->get_property ("direction");
1187   (void) me->get_property ("beaming");
1188
1189   SCM posns = me->get_property ("positions");
1190   
1191   extract_grob_set (me, "stems", stems);
1192   if (!stems.size ())
1193     return posns;
1194
1195   Grob *common[2];
1196   for (int a = 2; a--;)
1197     common[a] = common_refpoint_of_array (stems, me, Axis (a));
1198
1199   Drul_array<Real> pos = ly_scm2realdrul (posns);
1200   Real staff_space = Staff_symbol_referencer::staff_space (me);
1201   scale_drul (&pos, staff_space);
1202
1203   bool gap = false;
1204   Real thick = 0.0;
1205   if (robust_scm2int (me->get_property ("gap-count"), 0))
1206     {
1207       gap = true;
1208       thick = get_thickness (me);
1209     }
1210
1211   Grob *fvs = first_normal_stem (me);
1212   Grob *lvs = last_normal_stem (me);
1213
1214   Real xl = fvs ? fvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0;
1215   Real xr = lvs ? lvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0;
1216   Direction feather_dir = to_dir (me->get_property ("grow-direction"));
1217
1218   for (vsize i = 0; i < stems.size (); i++)
1219     {
1220       Grob *s = stems[i];
1221
1222       bool french = to_boolean (s->get_property ("french-beaming"));
1223       Real stem_y = calc_stem_y (me, s, common,
1224                                  xl, xr, feather_dir,
1225                                  pos, french && s != lvs && s!= fvs);
1226
1227       /*
1228         Make the stems go up to the end of the beam. This doesn't matter
1229         for normal beams, but for tremolo beams it looks silly otherwise.
1230       */
1231       if (gap
1232            && !Stem::is_invisible (s))
1233         stem_y += thick * 0.5 * get_grob_direction (s);
1234
1235       /*
1236         Do set_stemend for invisible stems too, so tuplet brackets
1237         have a reference point for sloping
1238        */
1239       Stem::set_stemend (s, 2 * stem_y / staff_space);
1240     }
1241
1242   return posns;
1243 }
1244
1245 void
1246 Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
1247 {
1248   extract_grob_set (me, "stems", stems);
1249
1250   Direction d = LEFT;
1251   for (vsize i = 0; i < stems.size (); i++)
1252     {
1253       /*
1254         Don't overwrite user settings.
1255       */
1256       do
1257         {
1258           Grob *stem = stems[i];
1259           SCM beaming_prop = stem->get_property ("beaming");
1260           if (beaming_prop == SCM_EOL
1261               || index_get_cell (beaming_prop, d) == SCM_EOL)
1262             {
1263               int count = beaming->beamlet_count (i, d);
1264               if (i > 0
1265                   && i + 1 < stems.size ()
1266                   && Stem::is_invisible (stem))
1267                 count = min (count, beaming->beamlet_count (i,-d));
1268
1269               if ( ((i == 0 && d == LEFT)
1270                     || (i == stems.size ()-1 && d == RIGHT))
1271                    && stems.size () > 1
1272                    && to_boolean (me->get_property ("clip-edges")))
1273                 count = 0;
1274
1275               Stem::set_beaming (stem, count, d);
1276             }
1277         }
1278       while (flip (&d) != LEFT);
1279     }
1280 }
1281
1282 int
1283 Beam::forced_stem_count (Grob *me)
1284 {
1285   extract_grob_set (me, "normal-stems", stems);
1286
1287   int f = 0;
1288   for (vsize i = 0; i < stems.size (); i++)
1289     {
1290       Grob *s = stems[i];
1291
1292       /* I can imagine counting those boundaries as a half forced stem,
1293          but let's count them full for now. */
1294       Direction defdir = to_dir (s->get_property ("default-direction"));
1295       
1296       if (abs (Stem::chord_start_y (s)) > 0.1
1297           && defdir
1298           && get_grob_direction (s) != defdir)
1299         f++;
1300     }
1301   return f;
1302 }
1303
1304 int
1305 Beam::normal_stem_count (Grob *me)
1306 {
1307   extract_grob_set (me, "normal-stems", stems);
1308   return stems.size ();
1309 }
1310
1311 Grob *
1312 Beam::first_normal_stem (Grob *me)
1313 {
1314   extract_grob_set (me, "normal-stems", stems);
1315   return stems.size () ? stems[0] : 0;
1316 }
1317
1318 Grob *
1319 Beam::last_normal_stem (Grob *me)
1320 {
1321   extract_grob_set (me, "normal-stems", stems);
1322   return stems.size () ? stems.back () : 0;
1323 }
1324
1325 /*
1326   [TODO]
1327
1328   handle rest under beam (do_post: beams are calculated now)
1329   what about combination of collisions and rest under beam.
1330
1331   Should lookup
1332
1333   rest -> stem -> beam -> interpolate_y_position ()
1334 */
1335 MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, rest_collision_callback, 2, 1, "");
1336 SCM
1337 Beam::rest_collision_callback (SCM smob, SCM prev_offset)
1338 {
1339   Grob *rest = unsmob_grob (smob);
1340   if (scm_is_number (rest->get_property ("staff-position")))
1341     return scm_from_int (0);
1342
1343   Real offset = robust_scm2double (prev_offset, 0.0);
1344   
1345   Grob *st = unsmob_grob (rest->get_object ("stem"));
1346   Grob *stem = st;
1347   if (!stem)
1348     return scm_from_double (0.0);
1349   Grob *beam = unsmob_grob (stem->get_object ("beam"));
1350   if (!beam
1351       || !Beam::has_interface (beam)
1352       || !Beam::normal_stem_count (beam))
1353     return scm_from_double (0.0);
1354
1355   Drul_array<Real> pos (robust_scm2drul (beam->get_property ("positions"),
1356                                          Drul_array<Real> (0,0)));
1357
1358   Real staff_space = Staff_symbol_referencer::staff_space (rest);
1359
1360   scale_drul (&pos, staff_space);
1361
1362   Real dy = pos[RIGHT] - pos[LEFT];
1363
1364   Drul_array<Grob*> visible_stems (first_normal_stem (beam),
1365                                    last_normal_stem (beam));
1366   extract_grob_set (beam, "stems", stems);
1367   
1368   Grob *common = common_refpoint_of_array (stems, beam, X_AXIS);
1369   
1370   Real x0 = visible_stems[LEFT]->relative_coordinate (common, X_AXIS);
1371   Real dx = visible_stems[RIGHT]->relative_coordinate (common, X_AXIS) - x0;
1372   Real slope = dy && dx ? dy / dx : 0;
1373
1374   Direction d = get_grob_direction (stem);
1375   Real stem_y = pos[LEFT]
1376     + (stem->relative_coordinate (common, X_AXIS) - x0) * slope;
1377
1378   Real beam_translation = get_beam_translation (beam);
1379   Real beam_thickness = Beam::get_thickness (beam);
1380
1381   /*
1382     TODO: this is not strictly correct for 16th knee beams.
1383   */
1384   int beam_count
1385     = Stem::beam_multiplicity (stem).length () + 1;
1386
1387   Real height_of_my_beams = beam_thickness / 2
1388     + (beam_count - 1) * beam_translation;
1389   Real beam_y = stem_y - d * height_of_my_beams;
1390
1391   Grob *common_y = rest->common_refpoint (beam, Y_AXIS);
1392
1393   /*
1394     TODO: this is dubious, because this call needs the info we're
1395     computing right now.
1396    */
1397   Interval rest_extent = rest->extent (common_y, Y_AXIS);
1398   rest_extent.translate (offset);
1399   
1400   Real rest_dim = rest_extent[d];
1401   Real minimum_distance
1402     = staff_space * (robust_scm2double (stem->get_property ("stemlet-length"), 0.0)
1403                      + robust_scm2double (rest->get_property ("minimum-distance"), 0.0));
1404
1405   Real shift = d * min (d * (beam_y - d * minimum_distance - rest_dim), 0.0);
1406
1407   shift /= staff_space;
1408   Real rad = Staff_symbol_referencer::line_count (rest) * staff_space / 2;
1409
1410   /* Always move discretely by half spaces */
1411   shift = ceil (fabs (shift * 2.0)) / 2.0 * sign (shift);
1412
1413   /* Inside staff, move by whole spaces*/
1414   if ((rest_extent[d] + staff_space * shift) * d
1415       < rad
1416       || (rest_extent[-d] + staff_space * shift) * -d
1417       < rad)
1418     shift = ceil (fabs (shift)) * sign (shift);
1419
1420   return scm_from_double (offset + staff_space * shift);
1421 }
1422
1423 bool
1424 Beam::is_knee (Grob *me)
1425 {
1426   SCM k = me->get_property ("knee");
1427   if (scm_is_bool (k))
1428     return ly_scm2bool (k);
1429
1430   bool knee = false;
1431   int d = 0;
1432   extract_grob_set (me, "stems", stems);
1433   for (vsize i = stems.size (); i--;)
1434     {
1435       Direction dir = get_grob_direction (stems[i]);
1436       if (d && d != dir)
1437         {
1438           knee = true;
1439           break;
1440         }
1441       d = dir;
1442     }
1443
1444   me->set_property ("knee", ly_bool2scm (knee));
1445
1446   return knee;
1447 }
1448
1449 bool
1450 Beam::is_cross_staff (Grob *me)
1451 {
1452   extract_grob_set (me, "stems", stems);
1453   Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (me);
1454   for (vsize i = 0; i < stems.size (); i++)
1455     if (Staff_symbol_referencer::get_staff_symbol (stems[i]) != staff_symbol)
1456       return true;
1457   return false;
1458 }
1459
1460 MAKE_SCHEME_CALLBACK (Beam, calc_cross_staff, 1)
1461 SCM
1462 Beam::calc_cross_staff (SCM smob)
1463 {
1464   return scm_from_bool (is_cross_staff (unsmob_grob (smob)));
1465 }
1466
1467 int
1468 Beam::get_direction_beam_count (Grob *me, Direction d)
1469 {
1470   extract_grob_set (me, "stems", stems);
1471   int bc = 0;
1472
1473   for (vsize i = stems.size (); i--;)
1474     {
1475       /*
1476         Should we take invisible stems into account?
1477       */
1478       if (get_grob_direction (stems[i]) == d)
1479         bc = max (bc, (Stem::beam_multiplicity (stems[i]).length () + 1));
1480     }
1481
1482   return bc;
1483 }
1484
1485 ADD_INTERFACE (Beam,
1486
1487                "A beam. \n\n"
1488                "The @code{thickness} property is the weight of beams, "
1489                "measured in staffspace.  The @code{direction} "
1490                "property is not user-serviceable. Use "
1491                "the @code{direction} property of @code{Stem} instead. "
1492
1493                ,
1494                
1495                /* properties */
1496                "auto-knee-gap "
1497                "beamed-stem-shorten "
1498                "beaming "
1499                "break-overshoot "
1500                "clip-edges "
1501                "concaveness "
1502                "damping "
1503                "details "
1504                "direction " 
1505                "gap "
1506                "gap-count "
1507                "grow-direction "
1508                "inspect-quants "
1509                "knee "
1510                "length-fraction "
1511                "least-squares-dy "
1512                "neutral-direction "
1513                "normal-stems "
1514                "positions "
1515                "quant-score "
1516                "quantized-positions "
1517                "shorten "
1518                "stems "
1519                "thickness "
1520                );