]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/musical-pitch.cc
release: 1.3.93
[lilypond.git] / lily / musical-pitch.cc
index eaf7ab5b7ae01e26659c65e4241a93951abaeb15..5a834db780a0f6d28a521edd612e8f47905b979f 100644 (file)
@@ -3,14 +3,50 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 #include "musical-pitch.hh"
 #include "debug.hh"
 #include "main.hh"
 
-String Musical_pitch::name_str_arr_arr_[7][5];
+int
+compare (Array<Musical_pitch>* left, Array<Musical_pitch>* right)
+{
+  assert (left);
+  assert (right);
+  
+  if (left->size () == right->size ())
+    {
+      for (int i = 0; i < left->size (); i++)
+       {
+         int r = Musical_pitch::compare ((*left)[i], (*right)[i]);
+         if (r)
+           return r;
+       }
+    }
+  else
+    return 1;
+
+  return 0;
+}
+
+SCM
+Musical_pitch::to_scm ()const
+{
+  return gh_list (gh_int2scm (octave_i_),
+                 gh_int2scm (notename_i_),
+                 gh_int2scm (accidental_i_),
+                 SCM_UNDEFINED);
+}
+
+
+Musical_pitch::Musical_pitch (SCM s)
+{
+  octave_i_ = gh_scm2int (gh_car (s));
+  notename_i_ = gh_scm2int (gh_cadr (s));
+  accidental_i_ = gh_scm2int (gh_caddr (s));
+}
 
 Musical_pitch::Musical_pitch (int n, int a, int o)
 {
@@ -19,13 +55,6 @@ Musical_pitch::Musical_pitch (int n, int a, int o)
   octave_i_ = o;
 }
 
-void
-Musical_pitch::print () const
-{
-#ifndef NPRINT
-  DOUT << str ();
-#endif
-}
 
 int
 Musical_pitch::compare (Musical_pitch const &m1, Musical_pitch const &m2)
@@ -80,16 +109,28 @@ Musical_pitch::transpose (Musical_pitch delta)
   accidental_i_ -= delta_acc;
 }
 
+
+#if 0
+// nice test for internationalisation strings
+char const *accname[] = {"double flat", "flat", "natural",
+                        "sharp" , "double sharp"};
+#else
+char const *accname[] = {"eses", "es", "", "is" , "isis"};
+#endif
+
 String
 Musical_pitch::str () const
 {
-  String s = name_str_arr_arr_[notename_i_ % 7][accidental_i_ + 2];
+  int n = (notename_i_ + 2) % 7;
+  String s = to_str (char(n + 'a'));
+  if (accidental_i_)
+    s += String (accname[accidental_i_ + 2]);
 
   if (octave_i_ > 0)
     {
       int o = octave_i_ + 1;
       while (o--)
-       s += to_str ('\'');
+       s += "'";
     }
   else if (octave_i_ <0)
     {
@@ -97,6 +138,8 @@ Musical_pitch::str () const
       while (o--)
        s += to_str (',');
     }
+
+
   return s;
 }