]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-column.cc
Doc: LM - correct @example for Tweak Command
[lilypond.git] / lily / note-column.cc
index 28a0b13d77e0a0c808054245a0cc7e2e715dbd44..dcca364e172b4887e06250670c25afa6ef12a14b 100644 (file)
@@ -61,7 +61,7 @@ Item *
 Note_column::get_stem (Grob *me)
 {
   SCM s = me->get_object ("stem");
-  return unsmob_item (s);
+  return Item::unsmob (s);
 }
 
 Item *
@@ -71,7 +71,7 @@ Note_column::get_flag (Grob *me)
   if (stem)
     {
       SCM s = stem->get_object ("flag");
-      return unsmob_item (s);
+      return Item::unsmob (s);
     }
   return 0;
 }
@@ -107,7 +107,10 @@ Note_column::dir (Grob *me)
         return (Direction)sign (head_positions_interval (me).center ());
     }
 
-  programming_error ("note column without heads and stem");
+  if (has_interface (me))
+    programming_error ("Note_column without heads and stem");
+  else
+    programming_error ("dir() given grob without Note_column interface");
   return CENTER;
 }
 
@@ -158,22 +161,29 @@ Note_column::first_head (Grob *me)
 
 /*
   Return extent of the noteheads in the "main column",
-  i.e. excluding any suspended noteheads.
+  (i.e. excluding any suspended noteheads), or extent
+  of the rest (if there are no heads).
 */
 Interval
-Note_column::calc_main_heads_extent (Grob *me)
+Note_column::calc_main_extent (Grob *me)
 {
-  if (get_stem (me))
-    return first_head (me)->extent (me, X_AXIS);
-  else
-    {
-      // no stems => no suspended noteheads.
-      extract_grob_set (me, "note-heads", heads);
-      if (heads.size())
-        return heads[0]->extent (me, X_AXIS);
-      else
-        return Interval (0, 0);
-    }
+    Grob *main_head = 0;
+    if (get_stem (me))
+        main_head = first_head (me);
+    else
+      {
+        // no stems => no suspended noteheads.
+        extract_grob_set (me, "note-heads", heads);
+        if (heads.size())
+        main_head = heads[0];
+      }
+    Grob *main_item = main_head
+            ? main_head
+            : Grob::unsmob (me->get_object ("rest"));
+
+    return main_item
+            ? main_item->extent (me, X_AXIS)
+            : Interval (0, 0);
 }
 
 /*