]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/self-aligment-interface.cc (set_align_self): new function
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 2 Nov 2005 11:54:22 +0000 (11:54 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 2 Nov 2005 11:54:22 +0000 (11:54 +0000)
(set_center_parent): new function.

* lily/side-position-interface.cc (set_axis): new function.

* lily/new-fingering-engraver.cc (position_scripts): use drul for
generic code.

* scm/define-grob-properties.scm (all-user-grob-properties):
remove [XY]-offset-callbacks add [YX]-offset

17 files changed:
ChangeLog
lily/beam.cc
lily/dynamic-engraver.cc
lily/fingering-engraver.cc
lily/grob-closure.cc [new file with mode: 0644]
lily/grob-property.cc
lily/grob.cc
lily/hara-kiri-engraver.cc
lily/hara-kiri-group-spanner.cc
lily/include/hara-kiri-group-spanner.hh
lily/include/self-alignment-interface.hh
lily/new-fingering-engraver.cc
lily/self-aligment-interface.cc
lily/side-position-interface.cc
lily/staff-symbol-referencer.cc
scm/define-grob-properties.scm
scm/define-grobs.scm

index 4adb008565ed1c97098fa0c681561c64a12d7264..1588f098f910db7a0b0bf2be82571a9f59fe75eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-11-02  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/self-aligment-interface.cc (set_align_self): new function
+       (set_center_parent): new function.
+
+       * lily/side-position-interface.cc (set_axis): new function.
+
+       * lily/new-fingering-engraver.cc (position_scripts): use drul for
+       generic code. 
+
        * scm/define-grob-properties.scm (all-user-grob-properties):
        remove [XY]-offset-callbacks add [YX]-offset
        
index 591af1a147327a57290bba3dbfd388d5e56ef036..f779b2c87eeef607630adcab088ff57f7d886c93 100644 (file)
@@ -1403,7 +1403,6 @@ ADD_INTERFACE (Beam,
               "length-fraction "
               "least-squares-dy "
               "neutral-direction "
-              "position-callbacks "
               "positions "
               "quant-score "
               "shorten "
index 3a0d5ba042914ad3775104cc638d1748422521e3..73cb94aaa8721759271d768a8bf1c306bc5e270d 100644 (file)
@@ -398,8 +398,7 @@ Dynamic_engraver::acknowledge_note_column (Grob_info info)
        {
          Grob *head = heads[0];
          script_->set_parent (head, X_AXIS);
-         script_->set_property ("self-X-offset",
-                                Self_alignment_interface::centered_on_x_parent_proc);
+         Self_alignment_interface::set_center_parent (script_, X_AXIS);
        }
     }
 
index 0997b19a0f7501c0a3e2fe4075afa26d44bc725f..db90fd68014653efdeff694c0b84991d9f9d6409 100644 (file)
@@ -90,8 +90,8 @@ Fingering_engraver::make_script (Direction d, Music *r, int i)
     fingerings for chords need different settings.
   */
   Side_position_interface::set_axis (fingering, Y_AXIS);
-  fingering->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc);
-  fingering->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc);
+  Self_alignment_interface::set_align_self (fingering, X_AXIS);
+  Self_alignment_interface::set_center_parent (fingering, X_AXIS);
 
   // Hmm
   int priority = 200;
diff --git a/lily/grob-closure.cc b/lily/grob-closure.cc
new file mode 100644 (file)
index 0000000..c1610e8
--- /dev/null
@@ -0,0 +1,87 @@
+#include "grob.hh"
+#include "simple-closure.hh"
+
+/*
+  UGH : todo -> to different file.
+ */
+
+SCM
+axis_offset_symbol (Axis a)
+{
+  return a == X_AXIS
+    ? ly_symbol2scm ("X-offset")
+    : ly_symbol2scm ("Y-offset");
+}
+
+SCM
+axis_parent_positioning (Axis a)
+{
+  return (a == X_AXIS)
+    ? Grob::x_parent_positioning_proc
+    : Grob::y_parent_positioning_proc;
+}
+
+
+
+/*
+  Replace
+
+  (orig-proc GROB)
+
+  by
+
+  (+ (PROC GROB) (orig-proc GROB))
+  
+*/
+void
+add_offset_callback (Grob *g, SCM proc, Axis a)
+{
+  SCM data = g->get_property_data (axis_offset_symbol (a));
+  if (ly_is_procedure (data))
+    data = ly_make_simple_closure (scm_list_1  (data));
+  else if (is_simple_closure (data))
+    data = simple_closure_expression (data);
+  else if (!scm_is_number (data))
+    g->internal_set_property (axis_offset_symbol (a),
+                             proc);
+  else
+    {
+      SCM plus = ly_lily_module_constant ("+");
+      SCM expr = scm_list_3 (plus,
+                            ly_make_simple_closure (scm_list_1 (proc)),
+                            data);
+      g->internal_set_property (axis_offset_symbol (a),
+                               ly_make_simple_closure (expr));
+    }
+}
+
+
+/*
+  replace
+
+  (orig-proc GROB)
+
+  by
+
+  (PROC GROB (orig-proc GROB)) 
+
+*/
+void
+chain_offset_callback (Grob *g, SCM proc, Axis a)
+{
+  SCM data = g->get_property_data (axis_offset_symbol (a));
+
+  if (ly_is_procedure (data))
+    data = ly_make_simple_closure (scm_list_1  (data));
+  else if (is_simple_closure (data))
+    data = simple_closure_expression (data);
+  else if (!scm_is_number (data))
+    data = scm_from_int (0);
+  
+  SCM expr = scm_list_2 (proc, data);
+  g->internal_set_property (axis_offset_symbol (a),
+                           
+                           // twice: one as a wrapper for grob property routines,
+                           // once for the actual delayed binding. 
+                           ly_make_simple_closure (ly_make_simple_closure (expr)));
+}
index 38306c536b01fe84367e13b16c2545259f3d166c..c9d0ea8aaeb87801ef0315586b9d6b2f741fc1f8 100644 (file)
@@ -60,6 +60,7 @@ Grob::internal_set_property (SCM sym, SCM v)
   if (do_internal_type_checking_global)
     {
       if (!ly_is_procedure (v)
+         && !is_simple_closure (v)
          && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
        abort ();
       check_interfaces_for_property (this, sym);
@@ -87,6 +88,7 @@ Grob::get_property_data (SCM sym) const
     {
       SCM val = scm_cdr (handle);
       if (!ly_is_procedure (val)
+         && !is_simple_closure (val)
          && !type_check_assignment (sym, val, 
                                  ly_symbol2scm ("backend-type?")))
        abort ();
index 89be56aa1936f4c50ce6b10c43ee8acb64bd0cdc..7cbdac4a81ce1f618dc48785c473427cbf2a5d0b 100644 (file)
@@ -630,9 +630,9 @@ ADD_INTERFACE (Grob, "grob-interface",
 
               /* properties */
               "X-extent "
-              "X-offset-callbacks "
+              "X-offset "
               "Y-extent "
-              "Y-offset-callbacks "
+              "Y-offset "
               "after-line-breaking "
               "axis-group-parent-X "
               "axis-group-parent-Y "
@@ -653,88 +653,3 @@ ADD_INTERFACE (Grob, "grob-interface",
               "transparent "
               );
 
-
-#include "simple-closure.hh"
-
-/*
-  UGH : todo -> to different file.
- */
-
-SCM
-axis_offset_symbol (Axis a)
-{
-  return a == X_AXIS
-    ? ly_symbol2scm ("X-offset")
-    : ly_symbol2scm ("Y-offset");
-}
-
-SCM
-axis_parent_positioning (Axis a)
-{
-  return (a == X_AXIS)
-    ? Grob::x_parent_positioning_proc
-    : Grob::y_parent_positioning_proc;
-}
-
-
-
-/*
-  Replace
-
-  (orig-proc GROB)
-
-  by
-
-  (+ (PROC GROB) (orig-proc GROB))
-  
-*/
-void
-add_offset_callback (Grob *g, SCM proc, Axis a)
-{
-  SCM data = g->get_property_data (axis_offset_symbol (a));
-
-  if (ly_is_procedure (data))
-    data = ly_make_simple_closure (scm_list_1  (data));
-  else if (is_simple_closure (data))
-    data = simple_closure_expression (data);
-  else if (!scm_is_number (data))
-    data = scm_from_int (0);
-
-  SCM plus = ly_lily_module_constant ("+");
-  SCM expr = scm_list_3 (plus,
-                        ly_make_simple_closure (scm_list_1 (proc)),
-                        data);
-  g->internal_set_property (axis_offset_symbol (a),
-                           ly_make_simple_closure (expr));
-}
-
-
-/*
-  replace
-
-  (orig-proc GROB)
-
-  by
-
-  (PROC GROB (orig-proc GROB)) 
-
-*/
-void
-chain_offset_callback (Grob *g, SCM proc, Axis a)
-{
-  SCM data = g->get_property_data (axis_offset_symbol (a));
-
-  if (ly_is_procedure (data))
-    data = ly_make_simple_closure (scm_list_1  (data));
-  else if (is_simple_closure (data))
-    data = simple_closure_expression (data);
-  else if (!scm_is_number (data))
-    data = scm_from_int (0);
-  
-  SCM expr = scm_list_2 (proc, data);
-  g->internal_set_property (axis_offset_symbol (a),
-                           
-                           // twice: one as a wrapper for grob property routines,
-                           // once for the actual delayed binding. 
-                           ly_make_simple_closure (ly_make_simple_closure (expr)));
-}
index a704fa91f8c22c8ee520a66bd3bdedbb4bd260f4..ea0356526d633ef73cfc7852efa563ab66a11d0b 100644 (file)
@@ -46,7 +46,7 @@ Hara_kiri_engraver::start_translation_timestep ()
 void
 Hara_kiri_engraver::add_element (Grob *e)
 {
-  Hara_kiri_group_spanner::add_element (staffline_, e);
+  Axis_group_engraver::add_element (e);
 }
 
 Spanner *
index 3e2417f8ebd24da14465aba1f00c0211f666fef1..9a205ffd8e2fcbf460d039eb1d6a9fe599d64a02 100644 (file)
@@ -81,12 +81,6 @@ Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM smob, SCM axis)
   return scm_from_double (0.0);
 }
 
-void
-Hara_kiri_group_spanner::add_element (Grob *me, Grob *e)
-{
-  Axis_group_interface::add_element (me, e);
-}
-
 void
 Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
 {
index a14f8feeac606538bbf436c6e2b74ad8c758d6bb..ff4ddae2aae5e280c79cb84036441903825dbf62 100644 (file)
@@ -18,7 +18,6 @@ public:
   DECLARE_SCHEME_CALLBACK (force_hara_kiri_callback, (SCM, SCM));
   DECLARE_SCHEME_CALLBACK (y_extent, (SCM smob));
   DECLARE_SCHEME_CALLBACK (force_hara_kiri_in_parent_callback, (SCM, SCM));
-  static void add_element (Grob *me, Grob *e);
   static bool has_interface (Grob *);
   static void consider_suicide (Grob *me);
   static void add_interesting_item (Grob *me, Grob *n);
index c9438a764b3e47101f9104bd8d5f56a42dd34134..bd1f1096c46208c8ce385775e3b402996f378703 100644 (file)
@@ -18,6 +18,8 @@ struct Self_alignment_interface
   static SCM aligned_on_self (Grob *me, Axis a);
   static SCM centered_on_parent (Grob *me, Axis a);
   static SCM aligned_on_parent (Grob *me, Axis a);
+  static void set_center_parent (Grob *me, Axis a);
+  static void set_align_self (Grob *me, Axis a);
   
   DECLARE_SCHEME_CALLBACK (x_aligned_on_self, (SCM element));
   DECLARE_SCHEME_CALLBACK (y_aligned_on_self, (SCM element));
index 0285faec334d08276c34e3bb7b235440ca9050e5..028febae81601801f6a5a9109f456702d558b746 100644 (file)
@@ -267,43 +267,36 @@ New_fingering_engraver::position_scripts (SCM orientations,
       f->set_parent (ft.head_, X_AXIS);
       f->set_parent (ft.head_, Y_AXIS);
 
-      f->set_property ("self-Y-offset",Self_alignment_interface::y_aligned_on_self_proc);
-      f->set_property ("Y-offset",  Self_alignment_interface::centered_on_y_parent_proc);
-      f->set_property ("X-offset",  Side_position_interface::x_aligned_side_proc);
+
+      Self_alignment_interface::set_align_self (f, Y_AXIS);
+      Self_alignment_interface::set_center_parent (f, Y_AXIS);
+      Side_position_interface::set_axis (f, X_AXIS);
 
       f->set_property ("direction", scm_from_int (hordir));
     }
 
   int finger_prio = 200;
-  for (int i = 0; i < up.size (); i++)
-    {
-      Finger_tuple ft = up[i];
-      Grob *f = ft.script_;
-      f->set_parent (ft.head_, X_AXIS);
-      f->set_property ("script-priority",
-                      scm_from_int (finger_prio + ft.position_));
-
-      f->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc);
-      f->set_property ("Y-offset", Side_position_interface::y_aligned_side_proc);
-      f->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc);
-      
-      f->set_property ("direction", scm_from_int (UP));
-    }
 
-  for (int i = 0; i < down.size (); i++)
+  Direction d = DOWN;
+  Drul_array< Array<Finger_tuple> > vertical (down, up);
+  do
     {
-      Finger_tuple ft = down[i];
-      Grob *f = ft.script_;
-      f->set_parent (ft.head_, X_AXIS);
-      f->set_property ("script-priority",
-                      scm_from_int (finger_prio + down.size () - ft.position_));
-
-      f->set_property ("self-X-offset", Self_alignment_interface::x_aligned_on_self_proc);
-      f->set_property ("X-offset", Self_alignment_interface::centered_on_x_parent_proc);
-      f->set_property ("Y-offset", Side_position_interface::y_aligned_side_proc);
-
-      f->set_property ("direction", scm_from_int (DOWN));
+      for (int i = 0; i < vertical[d].size (); i++)
+       {
+         Finger_tuple ft = vertical[d][i];
+         Grob *f = ft.script_;
+         f->set_parent (ft.head_, X_AXIS);
+         f->set_property ("script-priority",
+                          scm_from_int (finger_prio + d * ft.position_));
+
+         Self_alignment_interface::set_align_self (f, X_AXIS);
+         Self_alignment_interface::set_center_parent (f, X_AXIS);
+         Side_position_interface::set_axis (f, Y_AXIS);
+      
+         f->set_property ("direction", scm_from_int (d));
+       }
     }
+  while (flip (&d) != DOWN);
 }
 
 void
index ed66d30ef1a87ef8482e42b7ea53972453d5e7b4..17ec37b91f9562bbeaed31438f5ac55f7913469d 100644 (file)
@@ -110,23 +110,39 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
   return scm_from_double (x);
 }
 
+void
+Self_alignment_interface::set_center_parent (Grob *me, Axis a)
+{
+  add_offset_callback (me,
+                      (a==X_AXIS) ? centered_on_x_parent_proc : centered_on_y_parent_proc,
+                      a);
+}
+
+void
+Self_alignment_interface::set_align_self (Grob *me, Axis a)
+{
+  add_offset_callback (me,
+                      (a==X_AXIS) ? x_aligned_on_self_proc : y_aligned_on_self_proc,
+                      a);
+}
+
 ADD_INTERFACE (Self_alignment_interface, "self-alignment-interface",
               "Position this object on itself and/or on its parent. To this end, the following functions "
               " are provided: \n"
               "@table @code \n"
-              "@item Self_alignment_interface::aligned_on_self\n"
+              "@item Self_alignment_interface::[xy]_aligned_on_self\n"
               "  Align self on reference point, using @code{self-alignment-X} and "
               "@code{self-alignment-Y}."
-              "@item Self_alignment_interface::aligned_on_parent\n"
-              "@item Self_alignment_interface::centered_on_parent\n"
+              "@item Self_alignment_interface::aligned_on_[xy]_parent\n"
+              "@item Self_alignment_interface::centered_on_[xy]_parent\n"
               "  Shift the object so its own reference point is centered on the  "
               " extent of the parent \n"
-              "@item Self_alignment_interface::centered_on_other_axis_parent\n"
-              " For X-axis, center on the Y-parent, and vice versa.\n "
               "@end table\n",
 
 
               /* porperties */
               "self-alignment-X "
+              "self-X-offset "
+              "self-Y-offset "
               "self-alignment-Y ");
 
index 498818f44756969eeece3a4c5d9d867d9233b8e3..454333156877c61ee763243259defa03472a7869 100644 (file)
@@ -212,10 +212,11 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
 void
 Side_position_interface::set_axis (Grob *me, Axis a)
 {
-  me->internal_set_property (axis_offset_symbol (a),
-                   (a==X_AXIS)
-                   ? x_aligned_side_proc
-                   : y_aligned_side_proc);
+  add_offset_callback (me,
+                      (a==X_AXIS)
+                      ? x_aligned_side_proc
+                      : y_aligned_side_proc,
+                      a);
 }
 
 // ugh. doesn't catch all variants. 
index 1a729e1e0f77c70b82d269da1694f53636458a0b..22fb460ed181c4ce0b695a8b3bcea09ac1753c23 100644 (file)
@@ -169,5 +169,7 @@ ADD_INTERFACE (Staff_symbol_referencer, "staff-symbol-referencer-interface",
               "symbol. "
               "These usually have @code{Staff_symbol_referencer::callback} "
               "in their @code{Y-offset-callbacks}. ",
+
+              /* properties */
               "staff-position");
 
index b8c25f9bcd6f74041ada6f0acc67162f2b5d73d1..4fcac63c7c622013966f95ee30113b87341c224e 100644 (file)
@@ -25,6 +25,8 @@
      (X-offset ,number? "The horizontal amount that this object is moved relative to its X-parent")
      (Y-offset ,number? "The vertical amount that this object is moved
 relative to its X-parent")
+     (self-X-offset ,number? "")
+     (self-Y-offset ,number? "")
      (accidentals ,list? "List of alteration numbers")
      (alteration-alist ,list? "List of @code{(@var{pitch}
 . @var{accidental})} pairs for key signature.")
@@ -539,6 +541,7 @@ entries @code{name} and @code{interfaces}.")
      (chord-tremolo ,boolean? "if set, this beam is a tremolo. ")
      (begin-of-line-visible ,boolean? "Used for marking ChordNames that should only show changes.")
 
+     (quantize-position ,boolean? "If set, a vertical alignment is aligned to be within staff spaces.")
      (quant-score ,string? "Beam quanting score -- can be stored for
 debugging")
      
index 0be194a4b3008f670d45371e8f90bd4a1528acd2..8ae9054ac61194c1e9867f1ffbb664c1a21da081 100644 (file)
        (X-extent . ,Axis_group_interface::width)
        (meta . ((class . Spanner)
                 (interfaces . (axis-group-interface
+                               hara-kiri-group-interface
                                vertically-spaceable-interface))))))
 
     (VocalName