]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/clef-item.cc
release: 0.1.59
[lilypond.git] / lily / clef-item.cc
index 055b282b2ef59806f90a8280abbd44ad2cc8afaf..0d1a185923be893a1f6285b01b96f221f6f32f7c 100644 (file)
   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
 */
 
+#include <ctype.h>
 #include "clef-item.hh"
 #include "string.hh"
 #include "molecule.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
-#include "clef-reg.hh"
+#include "clef-grav.hh"
 
 
+void
+Clef_item::do_pre_processing()
+{
+  change_b_ = ! (break_status_i() == 1);
+
+  if (default_b_)
+    {
+      set_empty(break_status_i() != 1);
+      transparent_b_ = (break_status_i() != 1);
+    }
+}
 
 Clef_item::Clef_item()
 {
-    change = true;
-    read("violin");
+  breakable_b_ =true;
+  default_b_ = false;
+  change_b_ = true;
+  read ("violin");
 }
 
+/*
+ * Convert input clef string to 
+ * a clef symbol and a line position.
+ * This would be better done in the lexer (more efficient)
+ * or as a table-lookup.
+ */
 void
-Clef_item::read(String t)
+Clef_item::read (String t)
 {
-    type_= t;
-    if (type_ == "violin")
-       y_off = 2;
-    if (type_ == "alto")
-       y_off = 4;
-    if (type_ == "tenor")
-       y_off = 6;
-    if (type_ == "bass")
-       y_off = 6;
+  symbol_= t;
+  if (t == "violin") 
+    {
+      y_position_i_ = -2;
+    }
+  else if (t == "bass") 
+    {
+      y_position_i_ = 2;
+    }
+  else if (t == "G" || t == "G2" || t == "treble")
+    {
+      symbol_ = "violin";
+      y_position_i_ = -2;
+    }
+  else if (t == "french" || t == "G1") 
+    {
+      symbol_="violin";
+      y_position_i_ = -4;
+    }
+  else if (t == "soprano" || t == "C1") 
+    {
+      symbol_="alto";
+      y_position_i_ = -4;
+    }
+  else if (t == "mezzosoprano" || t == "C2")
+    {
+      symbol_ = "alto";
+      y_position_i_ = -2;
+    }
+  else if (t == "alto") 
+    {
+      symbol_ = "alto";
+      y_position_i_ = 0;
+    }
+  else if (t == "C3")
+    {
+      symbol_ = "alto";
+      y_position_i_ = 0;
+  }
+  else if (t == "tenor" || t == "C4") 
+  {
+      symbol_ = "alto";
+      y_position_i_ = 2;
+    }
+  else if (t == "baritone" || t == "C5")
+    {
+      symbol_ = "alto";
+      y_position_i_ = 4;
+    }
+  else if (t == "varbaritone" || t == "F3")
+    {
+      symbol_ = "bass";
+      y_position_i_ = 0;
+    }
+  else if (t == "F" || t == "F4")
+    {
+      symbol_ = "bass";
+      y_position_i_ = 2;
+    }
+  else if (t == "subbass")
+    {
+      symbol_ = "bass";
+      y_position_i_ = 4;
+    }
+  else if (isdigit(t[1]))
+         switch (t[0])
+         { // we've already dealt with plain F, G  or C clef 
+                 // position 0 is line 3.        
+         case 'G':
+         case 'g':
+                 symbol_ = "violin";
+                 y_position_i_ =   2 * (t[1] - '0') - 6;
+                 break;
+         case 'F':
+         case 'f':
+                 symbol_ = "bass";
+                 y_position_i_ = 2 * (t[1] - '0') - 6;
+                 break;
+         }
 }
+
 void
-Clef_item::read(Clef_register const &k)
+Clef_item::read (Clef_engraver const &k)
 {
-    read(k.clef_type_str_);
+  read (k.clef_type_str_);
 }
 
 Molecule*
-Clef_item::brew_molecule_p()const
+Clef_item::brew_molecule_p() const
 {
-    String t = type_;
-    if  (change)
-       t += "_change";
-    Symbol s = paper()->lookup_l()->clef(t);
-    Molecule*output = new Molecule(Atom(s));
-    output->translate(Offset(0, paper()->internote_f() * y_off));
-    return output;
+  String t = symbol_;
+  if  (change_b_)
+    t += "_change";
+  Atom s = paper()->lookup_l ()->clef (t);
+  Molecule*output = new Molecule (Atom (s));
+  output->translate_axis (paper()->internote_f () * y_position_i_, Y_AXIS);
+  return output;
 }
 
-IMPLEMENT_STATIC_NAME(Clef_item);
+
+IMPLEMENT_IS_TYPE_B1(Clef_item,Item);