]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-spanner.cc
release: 1.3.10
[lilypond.git] / lily / tuplet-spanner.cc
index 0d415a9dc1c783b579ee97d1aa931150a15bb101..3b9565ce1102e9e089ed74aa8cdc4e62d46f9c3e 100644 (file)
 /*
-  plet-spanner.cc -- implement Plet_spanner
+  plet-spanner.cc -- implement Tuplet_spanner
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c)  1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#include "atom.hh"
+#include "beam.hh"
 #include "box.hh"
 #include "debug.hh"
 #include "lookup.hh"
 #include "molecule.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
 #include "paper-def.hh"
 #include "tuplet-spanner.hh"
 #include "stem.hh"
-#include "text-def.hh"
 #include "note-column.hh"
+#include "dimensions.hh"
+#include "group-interface.hh"
+
 
-Plet_spanner::Plet_spanner ()
-{
-  visibility_i_ = 3;
 
-  tdef_p_.set_p(new Text_def);
-  tdef_p_->align_dir_ = CENTER;
-  tdef_p_->style_str_ = "italic";
+Tuplet_spanner::Tuplet_spanner ()
+{
+  /*
+    -> GUILE
+   */
+  parallel_beam_b_ = false;
+  set_elt_property ("beams", SCM_EOL);
+  set_elt_property ("columns", SCM_EOL);  
 }
 
+/*
+  TODO. 
+ */
 Molecule*
-Plet_spanner::brew_molecule_p () const
+Tuplet_spanner::do_brew_molecule_p () const
 {
   Molecule* mol_p = new Molecule;
 
-  if (column_arr_.size ()){
-    Real w = width ().length ();
-    Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_]
-      - column_arr_[0]->extent (Y_AXIS) [dir_];
-
+  // Default behaviour: number always, bracket when no beam!
+  bool bracket_visibility = !parallel_beam_b_;
+  bool number_visibility = true;
+  SCM visibility_sym =get_elt_property ("tuplet-visibility");
+  if (visibility_sym != SCM_UNDEFINED)
+    {
+      /*
+       ARG. Fixme.
+       */
+      
+      /* Property values:
+        0       show nothing
+        1       show number
+        2       show (number and bracket)-if-no-beam
+        3       show number, and bracket-if-no-beam
+        4       show number, and bracket
+      */
+      int value = gh_scm2int ((visibility_sym));
+      bracket_visibility = (value == 4 || (value > 1 && !parallel_beam_b_));
+      number_visibility = (value > 2 || value == 1 || 
+                          (value == 2 && !parallel_beam_b_));
+    }
   
-    Atom num (tdef_p_->get_atom (paper (), CENTER));
-    num.translate (Offset (w/2, dy/2));
-
-    if (visibility_i_ >= 1)
-      mol_p->add_atom (num);
+  if (gh_pair_p (get_elt_property ("columns")))
+    {
+      Link_array<Note_column> column_arr=
+       Group_interface__extract_elements (this, (Note_column*)0, "columns");
+       
+      Real ncw = column_arr.top ()->extent(X_AXIS).length ();
+      Real w = spanner_length () + ncw;
+      Molecule num (lookup_l ()->text ("italic",
+                                      number_str_, paper_l ()));
+      num.align_to (X_AXIS, CENTER);
+      num.translate_axis (w/2, X_AXIS);
+      Real interline = paper_l ()->get_var ("interline");
+      Real dy = column_arr.top ()->extent (Y_AXIS) [get_direction ()]
+       - column_arr[0]->extent (Y_AXIS) [get_direction ()];
+      num.align_to (Y_AXIS, CENTER);
+      num.translate_axis (get_direction () * interline, Y_AXIS);
+       
+      num.translate_axis (dy/2, Y_AXIS);
+    
+      Real thick = paper_l ()->get_var ("tuplet_thick");
+      if (bracket_visibility)      
+       {
+         Real gap = paper_l () -> get_var ("tuplet_spanner_gap");
+       
+         mol_p->add_molecule (lookup_l ()->tuplet_bracket (dy, w, thick, gap, interline, get_direction ()));
+       }
 
-    mol_p->add_atom (lookup_l ()->plet (dy, w, dir_));
-  }
+      if (number_visibility)
+       {
+         mol_p->add_molecule (num);
+       }
+      mol_p->translate_axis (get_direction () * interline, Y_AXIS);
+    }
   return mol_p;
 }
   
 void
-Plet_spanner::do_add_processing ()
+Tuplet_spanner::do_add_processing ()
 {
-  if (column_arr_.size ())
+  if (gh_pair_p (get_elt_property ("columns")))
     {
+      Link_array<Note_column> column_arr=
+       Group_interface__extract_elements (this, (Note_column*)0, "columns");
       
-      set_bounds (LEFT, column_arr_[0]);
-      set_bounds (RIGHT, column_arr_.top ());  
+      set_bounds (LEFT, column_arr[0]);
+      set_bounds (RIGHT, column_arr.top ());  
     }
 }
   
 void
-Plet_spanner::do_post_processing ()
+Tuplet_spanner::do_post_processing ()
 {
-    if (column_arr_.size())
-       translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
-}
+  Link_array<Note_column> column_arr=
+    Group_interface__extract_elements (this, (Note_column*)0, "columns");
+      
+
+  if (column_arr.size())
+    translate_axis (column_arr[0]->extent (Y_AXIS)[get_direction ()], Y_AXIS);
 
-void
-Plet_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
-{
-  if (Note_column *onc = dynamic_cast <Note_column *> (o))
-    column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
-}
   
-void
-Plet_spanner::set_default_dir ()
+  if (scm_ilength (get_elt_property ("beams")) == 1)
+    {
+      SCM bs = get_elt_property ("beams");
+      Score_element *b = unsmob_element (gh_car (bs));
+      Beam * beam_l = dynamic_cast<Beam*> (b);
+      if (!broken_b () 
+         && spanned_drul_[LEFT]->column_l () == beam_l->spanned_drul_[LEFT]->column_l ()
+         && spanned_drul_[RIGHT]->column_l () == beam_l->spanned_drul_[RIGHT]->column_l ())
+       parallel_beam_b_ = true;
+    }
+}
+
+
+Direction
+Tuplet_spanner::get_default_dir () const
 {
-  dir_ = UP;
-  for (int i=0; i < column_arr_.size (); i ++) 
+  Direction d = UP;
+  SCM dir_sym =get_elt_property ("dir-forced");
+  if (dir_sym != SCM_UNDEFINED) {
+    d= (Direction) gh_scm2int (dir_sym);
+    if (d != CENTER)
+      return d;
+  }
+
+  for (SCM s = get_elt_property ("columns"); gh_pair_p (s); s = gh_cdr (s))
     {
-      if (column_arr_[i]->dir_ < 0) 
+      Score_element * sc = unsmob_element (gh_car (s));
+      Note_column * nc = dynamic_cast<Note_column*> (sc);
+      if (nc->dir () < 0) 
        {
-         dir_ = DOWN;
+         d = DOWN;
          break;
        }
     }
+  
+  return d;
 }
 
+void
+Tuplet_spanner::add_beam (Beam *b)
+{
+  add_dependency (b);
+  Group_interface gi (this, "beams");
+  gi.add_element (b);
+}
 
 void
-Plet_spanner::add_column (Note_column*n)
+Tuplet_spanner::add_column (Note_column*n)
 {
-  column_arr_.push (n);
+  Group_interface gi (this, "columns");
+  gi.add_element (n);
+
   add_dependency (n);
 }
 
+