]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/musical-pitch.cc
release: 1.3.93
[lilypond.git] / lily / musical-pitch.cc
index e7ffbd7014b1beeb45ec034c93da3bf76ae21274..5a834db780a0f6d28a521edd612e8f47905b979f 100644 (file)
@@ -3,34 +3,59 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998 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"
 
-Musical_pitch::Musical_pitch ()
+int
+compare (Array<Musical_pitch>* left, Array<Musical_pitch>* right)
 {
-  init ();
+  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;
 }
 
-void
-Musical_pitch::init ()
+SCM
+Musical_pitch::to_scm ()const
 {
-  notename_i_ = 0;
-  octave_i_ = 0;
-  accidental_i_ = 0;
+  return gh_list (gh_int2scm (octave_i_),
+                 gh_int2scm (notename_i_),
+                 gh_int2scm (accidental_i_),
+                 SCM_UNDEFINED);
 }
 
-void
-Musical_pitch::print () const
+
+Musical_pitch::Musical_pitch (SCM s)
 {
-#ifndef NPRINT
-  DOUT << str ();
-#endif
+  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)
+{
+  notename_i_ = n;
+  accidental_i_ = a;
+  octave_i_ = o;
+}
+
+
 int
 Musical_pitch::compare (Musical_pitch const &m1, Musical_pitch const &m2)
 {
@@ -101,8 +126,19 @@ Musical_pitch::str () const
   if (accidental_i_)
     s += String (accname[accidental_i_ + 2]);
 
-  if (octave_i_)
-    s  += String ((octave_i_> 0)? "^": "_") + to_str (octave_i_);
+  if (octave_i_ > 0)
+    {
+      int o = octave_i_ + 1;
+      while (o--)
+       s += "'";
+    }
+  else if (octave_i_ <0)
+    {
+      int o = (-octave_i_) - 1;
+      while (o--)
+       s += to_str (',');
+    }
+
 
   return s;
 }
@@ -131,25 +167,7 @@ Musical_pitch::to_relative_octave (Musical_pitch p)
   else
     n = down_pitch;
   
-  if (find_quarts_global_b)
-    {
-      int d = this->semitone_pitch () - n.semitone_pitch ();
-      if (d)
-       {
-         int i = 1 + (abs (d) - 1) / 12;
-         String quote_str = d < 0 ? to_str (',', i) : to_str ('\'', i);
-         Musical_pitch w = *this;
-         w.octave_i_ = 0;
-         String name_str = w.str ();
-         name_str + quote_str;
-         w.warning (_f ("Interval greater than quart, relative: %s", 
-           name_str + quote_str));
-         // don't actually do any relative stuff
-         n = *this;
-       }
-    }
-  else
-    n.octave_i_ += oct_mod;
+  n.octave_i_ += oct_mod;
 
   *this = n;
   return *this;