]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/clef-item.cc
release: 0.1.59
[lilypond.git] / lily / clef-item.cc
index 920d2c5512fda8c06d55f21e120f2fb036416fc9..0d1a185923be893a1f6285b01b96f221f6f32f7c 100644 (file)
@@ -6,6 +6,7 @@
   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
 */
 
+#include <ctype.h>
 #include "clef-item.hh"
 #include "string.hh"
 #include "molecule.hh"
@@ -34,19 +35,96 @@ Clef_item::Clef_item()
   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)
 {
-  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_engraver const &k)
 {
@@ -56,12 +134,12 @@ Clef_item::read (Clef_engraver const &k)
 Molecule*
 Clef_item::brew_molecule_p() const
 {
-  String t = type_;
+  String t = symbol_;
   if  (change_b_)
     t += "_change";
-  Symbol s = paper()->lookup_l ()->clef (t);
+  Atom s = paper()->lookup_l ()->clef (t);
   Molecule*output = new Molecule (Atom (s));
-  output->translate (paper()->internote_f () * y_off, Y_AXIS);
+  output->translate_axis (paper()->internote_f () * y_position_i_, Y_AXIS);
   return output;
 }