]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-spanner.cc
release: 1.3.62
[lilypond.git] / lily / tuplet-spanner.cc
index f68d175a0b88eaed4afc17e445e52233ec5a9204..5779209b150b1400c125ce706238c58829a9ae48 100644 (file)
 #include "directional-element-interface.hh"
 
 
-Tuplet_spanner::Tuplet_spanner ()
+Tuplet_spanner::Tuplet_spanner (SCM s)
+  : Spanner (s)
 {
-  set_elt_property ("beams", SCM_EOL);
-  set_elt_property ("columns", SCM_EOL);
+  set_elt_pointer ("beams", SCM_EOL);
+  set_elt_pointer ("columns", SCM_EOL);
 
   // ugh.
   set_elt_property ("delta-y", gh_int2scm (0));
@@ -34,8 +35,10 @@ Tuplet_spanner::Tuplet_spanner ()
 /*
   TODO. 
  */
-Molecule 
-Tuplet_spanner::do_brew_molecule () const
+
+GLUE_SCORE_ELEMENT(Tuplet_spanner,brew_molecule);
+SCM
+Tuplet_spanner::member_brew_molecule () const
 {
   Molecule  mol;
 
@@ -60,10 +63,10 @@ Tuplet_spanner::do_brew_molecule () const
   else if (bracket == ly_symbol2scm ("if-no-beam"))
     number_visibility = !par_beam;
   
-  if (gh_pair_p (get_elt_property ("columns")))
+  if (gh_pair_p (get_elt_pointer ("columns")))
     {
       Link_array<Note_column> column_arr=
-       Group_interface__extract_elements (this, (Note_column*)0, "columns");
+       Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
        
       Real ncw = column_arr.top ()->extent(X_AXIS).length ();
       Real w = spanner_length () + ncw;
@@ -88,36 +91,37 @@ Tuplet_spanner::do_brew_molecule () const
          mol.add_molecule (num);
        }
       
-      Real thick = paper_l ()->get_var ("tuplet_thick");
       if (bracket_visibility)      
        {
-         Real gap = paper_l () -> get_var ("tuplet_spanner_gap");
-         Real height = staff_space;
+         SCM ss = paper_l ()->get_scmvar ("staffspace");
+         SCM lt =  paper_l ()->get_scmvar ("stafflinethickness");
+         
+         SCM thick = get_elt_property ("thick");
+         SCM gap = get_elt_property ("number-gap");
+         
          SCM at =gh_list(ly_symbol2scm ("tuplet"),
-                                      gh_double2scm (height),
-                                      gh_double2scm (gap),
-                                      gh_double2scm (w),
-                                      gh_double2scm (dy),
-                                      gh_double2scm (thick),
-                                      gh_int2scm (dir),
-                                      SCM_UNDEFINED);
+                         ss,
+                         scm_product (gap, ss),
+                         gh_double2scm (w),
+                         gh_double2scm (dy),
+                         scm_product (thick, lt),
+                         gh_int2scm (dir),
+                         SCM_UNDEFINED);
 
          Box b;
          mol.add_molecule (Molecule (b, at));
        }
-
-      //mol.translate_axis (dir * staff_space, Y_AXIS);
     }
-  return mol;
+  return mol.create_scheme();
 }
   
 void
 Tuplet_spanner::do_add_processing ()
 {
-  if (gh_pair_p (get_elt_property ("columns")))
+  if (gh_pair_p (get_elt_pointer ("columns")))
     {
       Link_array<Note_column> column_arr=
-       Group_interface__extract_elements (this, (Note_column*)0, "columns");
+       Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
       
       set_bound (LEFT, column_arr[0]);
       set_bound (RIGHT, column_arr.top ());  
@@ -133,9 +137,11 @@ void
 Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
 {
   Link_array<Note_column> column_arr=
-    Group_interface__extract_elements (this, (Note_column*)0, "columns");
+    Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
 
+
+  Score_element * common = common_refpoint (get_elt_pointer ("columns"), Y_AXIS);
+  
   Direction d = directional_element (this).get ();
 
   /*
@@ -151,14 +157,17 @@ Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
   
   if (l < r)
     {
-      *dy = column_arr[r]->extent (Y_AXIS) [d]
-       - column_arr[l]->extent (Y_AXIS) [d];
+      *dy = column_arr[r]->extent (Y_AXIS) [d] + column_arr[r]->relative_coordinate (common, Y_AXIS)
+       - column_arr[l]->extent (Y_AXIS) [d] - column_arr[l]->relative_coordinate (common, Y_AXIS);
     }
   else
     * dy = 0;
 
 
   *offset = - d * infinity_f;
+
+  if (!column_arr.size ())
+    return;
   
   Real x0 = column_arr[0]->relative_coordinate (0, X_AXIS);
   Real x1 = column_arr.top ()->relative_coordinate (0, X_AXIS);
@@ -167,7 +176,9 @@ Tuplet_spanner::calc_position_and_height (Real *offset, Real * dy) const
   
   for (int i = 0; i < column_arr.size ();  i++)
     {
-      Real notey = column_arr[i]->extent (Y_AXIS)[d];
+      Real notey = column_arr[i]->extent (Y_AXIS)[d] +
+       column_arr[i]->relative_coordinate (common, Y_AXIS)
+       ;
       Real x = column_arr[i]->relative_coordinate (0, X_AXIS) - x0;
       Real tuplety =  *dy * x * factor;
 
@@ -183,7 +194,7 @@ void
 Tuplet_spanner::calc_dy (Real * dy) const
 {
   Link_array<Note_column> column_arr=
-    Group_interface__extract_elements (this, (Note_column*)0, "columns");
+    Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
 
  
   Direction d = directional_element (this).get ();
@@ -191,17 +202,17 @@ Tuplet_spanner::calc_dy (Real * dy) const
     - column_arr[0]->extent (Y_AXIS) [d];
 }
 
-void
-Tuplet_spanner::after_line_breaking ()
+GLUE_SCORE_ELEMENT(Tuplet_spanner,after_line_breaking);
+SCM
+Tuplet_spanner::member_after_line_breaking ()
 {
   Link_array<Note_column> column_arr=
-    Group_interface__extract_elements (this, (Note_column*)0, "columns");
+    Pointer_group_interface__extract_elements (this, (Note_column*)0, "columns");
 
   if (!column_arr.size ())
     {
-      set_elt_property ("transparent", SCM_BOOL_T);
-      set_extent_callback (0, X_AXIS);
-      set_extent_callback (0, Y_AXIS);
+      suicide ();
+      return SCM_UNDEFINED;
     }
 
   Direction d = directional_element (this).get ();
@@ -219,9 +230,9 @@ Tuplet_spanner::after_line_breaking ()
 
   translate_axis (offset, Y_AXIS);
   
-  if (scm_ilength (get_elt_property ("beams")) == 1)
+  if (scm_ilength (get_elt_pointer ("beams")) == 1)
     {
-      SCM bs = get_elt_property ("beams");
+      SCM bs = get_elt_pointer ("beams");
       Score_element *b = unsmob_element (gh_car (bs));
       Beam * beam_l = dynamic_cast<Beam*> (b);
       if (!broken_b () 
@@ -229,6 +240,7 @@ Tuplet_spanner::after_line_breaking ()
          && get_bound (RIGHT)->column_l () == beam_l->get_bound (RIGHT)->column_l ())
        set_elt_property ("parallel-beam", SCM_BOOL_T);
     }
+  return SCM_UNDEFINED;
 }
 
 
@@ -245,7 +257,7 @@ Tuplet_spanner::get_default_dir () const
     }
 
   d = UP ;
-  for (SCM s = get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = get_elt_pointer ("columns"); gh_pair_p (s); s = gh_cdr (s))
     {
       Score_element * sc = unsmob_element (gh_car (s));
       Note_column * nc = dynamic_cast<Note_column*> (sc);
@@ -263,14 +275,14 @@ void
 Tuplet_spanner::add_beam (Beam *b)
 {
   add_dependency (b);
-  Group_interface gi (this, "beams");
+  Pointer_group_interface gi (this, "beams");
   gi.add_element (b);
 }
 
 void
 Tuplet_spanner::add_column (Note_column*n)
 {
-  Group_interface gi (this, "columns");
+  Pointer_group_interface gi (this, "columns");
   gi.add_element (n);
 
   add_dependency (n);