]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/staff-margin-engraver.cc
patch::: 1.3.32.hwn2
[lilypond.git] / lily / staff-margin-engraver.cc
index 9b51b97c7c0fae918ee9c9548b4e74387224ae4e..8aecb00f3a45c941fa38577ea3b01eac08c05fbb 100644 (file)
@@ -3,33 +3,29 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "staff-margin-engraver.hh"
-#include "script.hh"
-#include "text-def.hh"
-#include "paper-def.hh"
-#include "command-request.hh"
 #include "bar.hh"
-#include "stem.hh"
-#include "time-description.hh"
-
+#include "timing-translator.hh"
+#include "text-item.hh"
+#include "side-position-interface.hh"
+#include "staff-symbol-referencer.hh"
 
 ADD_THIS_TRANSLATOR (Staff_margin_engraver);
 
 Staff_margin_engraver::Staff_margin_engraver ()
 {
-  script_p_ = 0;
+  axis_ = X_AXIS;
+  type_ = "margin";
 }
 
 
-
 /*
     TODO
-    fix alignment/support
 
-    should be able to set whole paragraph (multiple lines, centre) to
+    should be able to set whole paragraph (multiple lines, center) to
     left (right?) of staff, e.g.:
                     ______
                    |_______
@@ -38,54 +34,43 @@ Staff_margin_engraver::Staff_margin_engraver ()
                   |______________
 */
 void
-Staff_margin_engraver::acknowledge_element (Score_element_info i)
+Staff_margin_engraver::acknowledge_element (Score_element_info inf)
 {
-  Item * it =  dynamic_cast <Item *> (i.elem_l_);
-
-  if (!it
-      || script_p_ 
-      || !(dynamic_cast<Bar *> (it))
-      || (i.origin_grav_l_arr_.size() != 1))
+  Item *i = cast_to_interesting_item (inf.elem_l_);
+  if (!i || inf.origin_trans_l_arr (this).size() != 1)
     return;
 
-  String string = get_property ("instrument");
-  String str = get_property ("instr");
-  if (now_moment () > Moment (0))
-    string = str;
 
-  if (!string.length_i ())
-    return;
+  SCM long_name = get_property ("instrument");
+  SCM short_name = get_property ("instr");
 
-  script_p_ = new Script;
-  script_p_->axis_ = X_AXIS;
-  
-  Text_def *td_p =new Text_def;
-  td_p->align_dir_ = LEFT;
-  td_p->text_str_ = string;
-  // huh?
-  script_p_->dir_ = RIGHT;
-  script_p_->specs_p_ = td_p;
-  script_p_->breakable_b_ = true;
+  if (now_mom () > Moment (0))
+    long_name = short_name;
 
-  
-  Scalar pri = get_property ("marginBreakPriority");
-  if (pri.length_i () && pri.isnum_b ())
-    {
-      script_p_->break_priority_i_ = int (pri);
-    }
-  else
-    script_p_ ->break_priority_i_ = it->break_priority_i_;
-
-  announce_element (Score_element_info (script_p_, 0));
-}
-
-void
-Staff_margin_engraver::do_pre_move_processing ()
-{
-  if (script_p_) 
+  if (gh_string_p (long_name))
     {
-      typeset_element (script_p_);
-      script_p_ =0;
+      create_items (0);
+      text_p_->set_elt_property ("text", long_name);
+      text_p_->set_elt_property ("direction", gh_int2scm (LEFT));
+      Bar_script_engraver::attach_script_to_item (i);
+
+      /*
+    UGH. ignores font size settings.
+   */
+      Interval iv(text_p_->extent (Y_AXIS));
+      text_p_->translate_axis (- iv.center (),  Y_AXIS);
+
+      Real staff_space = Staff_symbol_referencer_interface (text_p_).staff_space ();
+      SCM s = get_property ("staffMarginHorizontalPadding");
+      if (gh_number_p (s))
+       {
+         text_p_->translate_axis (gh_scm2double (s) * staff_space, X_AXIS);
+       }
+      s = get_property ("staffMarginVerticalPadding");
+      if (gh_number_p (s))
+       {
+         text_p_->translate_axis (gh_scm2double (s) * staff_space, Y_AXIS);
+       }
     }
 }