]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/chord.cc
release: 1.3.83
[lilypond.git] / lily / chord.cc
index 89d4c4590ede0f1299db3c0a6be06477a4806cbd..5cb2870461ee122a4a18c7c0a73470ca5b20a82a 100644 (file)
@@ -3,18 +3,33 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1999 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c)  1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "chord.hh"
 #include "musical-request.hh"
 #include "warn.hh"
 #include "debug.hh"
-#include "molecule.hh"
-#include "paper-def.hh"
-#include "lookup.hh"
+#include "music-list.hh"
+#include "musical-request.hh"
 
+int
+compare (Chord* left, Chord* right)
+{
+  assert (left);
+  assert (right);
+  
+  return !(left->inversion_b_ == right->inversion_b_
+          && left->bass_b_ == right->bass_b_
+          && !compare (&left->pitch_arr_, &right->pitch_arr_));
+}
+
+/*
+  FIXME: should use SCM iso. arrays and have-to-delete pointers.
 
+  FIXME: this contains memleaks.
+ */
+  
 /*
   construct from parser output
 */
@@ -45,7 +60,7 @@ to_chord (Musical_pitch tonic, Array<Musical_pitch>* add_arr_p, Array<Musical_pi
       int j = Chord::find_pitch_i (add_arr_p, (*add_arr_p)[i]);
       if ((j != -1) && (i != j))
         {
-           add_arr_p->get (i);
+         add_arr_p->get (i);
        } 
     }
 
@@ -211,13 +226,11 @@ Chord::Chord (Array<Musical_pitch> pitch_arr, Musical_pitch* inversion_p, Musica
     {
       inversion_pitch_ = *inversion_p;
       inversion_b_ = true;
-      delete inversion_p;
     }
   if (bass_p)
     {
       bass_pitch_ = *bass_p;
       bass_b_ = true;
-      delete bass_p;
     }
 }
   
@@ -231,6 +244,10 @@ Chord::Chord (Chord const& chord)
 }
   
 
+/*
+  JUNKME. 
+  do something smarter.
+ */
 Array<Musical_pitch>
 Chord::base_arr (Musical_pitch p)
 {
@@ -295,6 +312,10 @@ Chord::step_i (Musical_pitch tonic, Musical_pitch p)
   return i;
 }
 
+/*
+  JUNKME. 
+  do something smarter.
+ */
 Array<Musical_pitch>
 Chord::missing_thirds_pitch_arr (Array<Musical_pitch> const* pitch_arr_p)
 {
@@ -377,76 +398,6 @@ Chord::to_pitch_arr () const
   return pitch_arr;
 }
 
-void
-Chord::find_additions_and_subtractions (Array<Musical_pitch> pitch_arr, Array<Musical_pitch>* add_arr_p, Array<Musical_pitch>* sub_arr_p)
-{
-  Musical_pitch tonic = pitch_arr[0];
-  /*
-    construct an array of thirds for a normal chord
-   */
-  Array<Musical_pitch> all_arr;
-  all_arr.push (tonic);
-  if (step_i (tonic, pitch_arr.top ()) >= 5)
-    all_arr.push (pitch_arr.top ());
-  else
-    all_arr.push (base_arr (tonic).top ());
-  all_arr.concat (missing_thirds_pitch_arr (&all_arr));
-  all_arr.sort (Musical_pitch::compare);
-  
-  int i = 0;
-  int j = 0;
-  Musical_pitch last_extra = tonic;
-  while ((i < all_arr.size ()) || (j < pitch_arr.size ()))
-    {
-      Musical_pitch a = all_arr [i <? all_arr.size () - 1];
-      Musical_pitch p = pitch_arr[j <? pitch_arr.size () - 1];
-      /*
-        this pitch is present: do nothing, check next
-       */
-      if (a == p)
-       {
-         i++;
-         j++;
-         last_extra = tonic;
-       }
-      /*
-        found an extra pitch: chord addition
-       */
-      else if ((p < a) || (p.notename_i_ == a.notename_i_))
-       {
-         add_arr_p->push (p);
-         last_extra = p;
-         (j < pitch_arr.size ()) ? j++ : i++;
-       }
-      /*
-        a third is missing: chord subtraction
-       */
-      else
-       {
-         if (last_extra.notename_i_ != a.notename_i_)
-           sub_arr_p->push (a);
-         (i < all_arr.size ()) ? i++ : j++;
-         last_extra = tonic;
-       }
-    }
-      
-  /* add missing basic steps */
-  if (step_i (tonic, pitch_arr.top ()) < 3)
-    sub_arr_p->push (base_arr (tonic)[1]);
-  if (step_i (tonic, pitch_arr.top ()) < 5)
-    sub_arr_p->push (base_arr (tonic).top ());
-
-  /*
-    add highest addition, because it names chord, if greater than 5
-    or non-standard
-    (1, 3 and) 5 not additions: part of normal chord
-   */
-  if ((step_i (tonic, pitch_arr.top ()) > 5)
-       || pitch_arr.top ().accidental_i_)
-    add_arr_p->push (pitch_arr.top ());
-}
-
-
 /*
   This routine tries to guess tonic in a possibly inversed chord, ie
   <e g c'> should produce: C.
@@ -460,7 +411,7 @@ Chord::find_tonic_i (Array<Musical_pitch> const* pitch_arr_p)
     find tonic
     
     first try: base of longest line of thirds
-   */
+  */
   int tonic_i = 0;
   int longest_i = 0;
   for (int i = 0; i < pitch_arr_p->size (); i++)
@@ -497,7 +448,7 @@ Chord::find_tonic_i (Array<Musical_pitch> const* pitch_arr_p)
       {
        int gap = (*pitch_arr_p)[i].notename_i_
          - (*pitch_arr_p)[(i - 1 + pitch_arr_p->size ()) 
-         % pitch_arr_p->size ()].notename_i_;
+                         % pitch_arr_p->size ()].notename_i_;
        while (gap < 0)
          gap += 7;
        gap %= 7;
@@ -563,3 +514,59 @@ Chord::rebuild_with_bass (Array<Musical_pitch>* pitch_arr_p, int bass_i)
   pitch_arr_p->insert (bass, 0);
 }
 
+
+// junk me
+Simultaneous_music *
+get_chord (Musical_pitch tonic,
+                          Array<Musical_pitch>* add_arr_p,
+                          Array<Musical_pitch>* sub_arr_p,
+                          Musical_pitch* inversion_p,
+                          Musical_pitch* bass_p,
+                          Duration d)
+{
+
+  /*
+    UARGAUGRAGRUAUGRUINAGRAUGIRNA
+
+    ugh
+   */
+  Chord chord = to_chord (tonic, add_arr_p, sub_arr_p, inversion_p, bass_p);
+  inversion_p = 0;
+  bass_p = 0;
+
+  Tonic_req* t = new Tonic_req;
+  t->pitch_ = tonic;
+  SCM l = gh_cons (t->self_scm (), SCM_EOL);
+
+  //urg
+  if (chord.inversion_b_
+      && Chord::find_notename_i (&chord.pitch_arr_, chord.inversion_pitch_) > 0)
+    {
+      Inversion_req* i = new Inversion_req;
+      i->pitch_ = chord.inversion_pitch_;
+      l = gh_cons (i->self_scm (), l);
+    }
+
+  if (chord.bass_b_)
+    {
+      Bass_req* b = new Bass_req;
+      b->pitch_ = chord.bass_pitch_;
+      l = gh_cons (b->self_scm (), l);      
+    }
+
+  Array<Musical_pitch> pitch_arr = chord.to_pitch_arr ();
+  for (int i = pitch_arr.size (); --i >= 0;)
+    {
+      Musical_pitch p = pitch_arr[i];
+      Note_req* n = new Note_req;
+      n->pitch_ = p;
+      n->duration_ = d;
+      l = gh_cons (n->self_scm (), l);
+    }
+
+  Simultaneous_music*v = new Request_chord (l);
+
+  return v;
+}
+
+