]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/chord.cc
*** empty log message ***
[lilypond.git] / lily / chord.cc
index abe879cdbd299de24b8d79bc501b30d8bc27bcfa..5150bb0b3c4d087cd407daaaf3659c2b3e668507 100644 (file)
@@ -3,80 +3,17 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1999--2001 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c)  1999--2002 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "chord.hh"
 #include "musical-request.hh"
 #include "warn.hh"
-#include "debug.hh"
+
 #include "music-list.hh"
 #include "musical-request.hh"
 
-/* some SCM abbrevs
-
-   zijn deze nou handig?
-   zijn ze er al in scheme, maar heten ze anders? */
-
-
-/* Remove doubles from (sorted) list */
-SCM
-ly_unique (SCM list)
-{
-  SCM unique = SCM_EOL;
-  for (SCM i = list; gh_pair_p (i); i = ly_cdr (i))
-    {
-      if (!gh_pair_p (ly_cdr (i))
-         || !gh_equal_p (ly_car (i), gh_cadr (i)))
-       unique = gh_cons (ly_car (i), unique);
-    }
-  return gh_reverse (unique);
-}
-
-/* Hmm, rewrite this using ly_split_list? */
-SCM
-ly_remove_member (SCM s, SCM list)
-{
-  SCM removed = SCM_EOL;
-  for (SCM i = list; gh_pair_p (i); i = ly_cdr (i))
-    {
-      if (!gh_equal_p (ly_car (i), s))
-       removed = gh_cons (ly_car (i), removed);
-    }
-  return gh_reverse (removed);
-}
-
-/* tail add */
-SCM
-ly_snoc (SCM s, SCM list)
-{
-  return gh_append2 (list, scm_list_n (s, SCM_UNDEFINED));
-}
-
-
-/* Split list at member s, removing s.
-   Return (BEFORE . AFTER) */
-SCM
-ly_split_list (SCM s, SCM list)
-{
-  SCM before = SCM_EOL;
-  SCM after = list;
-  for (; gh_pair_p (after);)
-    {
-      SCM i = ly_car (after);
-      after = ly_cdr (after);
-      if (gh_equal_p (i, s))
-       break;
-      before = gh_cons (i, before);
-    }
-  return gh_cons (gh_reverse (before), after);
-}
 
-/*
-  JUNKME. 
-  do something smarter.
-  zoals?
- */
 SCM
 Chord::base_pitches (SCM tonic)
 {
@@ -86,10 +23,10 @@ Chord::base_pitches (SCM tonic)
   SCM minor = Pitch (0, 2, -1).smobbed_copy ();
 
   base = gh_cons (tonic, base);
-  base = gh_cons (Pitch::transpose (ly_car (base), major), base);
-  base = gh_cons (Pitch::transpose (ly_car (base), minor), base);
+  base = gh_cons (ly_pitch_transpose (ly_car (base), major), base);
+  base = gh_cons (ly_pitch_transpose (ly_car (base), minor), base);
 
-  return gh_reverse (base);
+  return scm_reverse_x (base, SCM_EOL);
 }
 
 SCM
@@ -101,10 +38,10 @@ Chord::transpose_pitches (SCM tonic, SCM pitches)
   SCM transposed = SCM_EOL;
   for (SCM i = pitches; gh_pair_p (i); i = ly_cdr (i))
     {
-      transposed = gh_cons (Pitch::transpose (tonic, ly_car (i)),
+      transposed = gh_cons (ly_pitch_transpose (tonic, ly_car (i)),
                            transposed);
     }
-  return gh_reverse (transposed);
+  return scm_reverse_x (transposed, SCM_EOL);
 }
 
 /*
@@ -123,11 +60,11 @@ Chord::lower_step (SCM tonic, SCM pitches, SCM step)
       if (gh_equal_p (step_scm (tonic, ly_car (i)), step)
          || gh_scm2int (step) == 0)
        {
-         p = Pitch::transpose (p, Pitch (0, 0, -1).smobbed_copy ());
+         p = ly_pitch_transpose (p, Pitch (0, 0, -1).smobbed_copy ());
        }
       lowered = gh_cons (p, lowered);
     }
-  return gh_reverse (lowered);
+  return scm_reverse_x (lowered, SCM_EOL);
 }
 
 /* Return member that has same notename, disregarding octave or alterations */
@@ -144,8 +81,8 @@ Chord::member_notename (SCM p, SCM pitches)
            Urg, eindelijk gevonden: () != #f, kan maar niet aan wennen.
            Anders kon iets korter...
           */
-         if (unsmob_pitch (p)->notename_i_
-             == unsmob_pitch (ly_car (i))->notename_i_)
+         if (unsmob_pitch (p)->notename_
+             == unsmob_pitch (ly_car (i))->notename_)
            {
              member = ly_car (i);
              break;
@@ -167,10 +104,10 @@ Chord::member_pitch (SCM p, SCM pitches)
     {
       for (SCM i = pitches; gh_pair_p (i); i = ly_cdr (i))
        {
-         if (unsmob_pitch (p)->notename_i_
-             == unsmob_pitch (ly_car (i))->notename_i_
-             && unsmob_pitch (p)->alteration_i_
-             == unsmob_pitch (ly_car (i))->alteration_i_)
+         if (unsmob_pitch (p)->notename_
+             == unsmob_pitch (ly_car (i))->notename_
+             && unsmob_pitch (p)->alteration_
+             == unsmob_pitch (ly_car (i))->alteration_)
            {
              member = ly_car (i);
              break;
@@ -186,10 +123,10 @@ SCM
 Chord::step_scm (SCM tonic, SCM p)
 {
   /* De Pitch intervaas is nog beetje sleutelgat? */
-  int i = unsmob_pitch (p)->notename_i_
-    - unsmob_pitch (tonic)->notename_i_
-    + (unsmob_pitch (p)->octave_i_
-       - unsmob_pitch (tonic)->octave_i_) * 7;
+  int i = unsmob_pitch (p)->notename_
+    - unsmob_pitch (tonic)->notename_
+    + (unsmob_pitch (p)->octave_
+       - unsmob_pitch (tonic)->octave_) * 7;
   while (i < 0)
     i += 7;
   i++;
@@ -217,7 +154,7 @@ Chord::missing_thirds (SCM pitches)
   for (int i=0; i < 7; i++)
     thirds = gh_cons (Pitch (0, 2, minormajor_a[i]).smobbed_copy (),
                      thirds);
-  thirds = scm_vector (gh_reverse (thirds));
+  thirds = scm_vector (scm_reverse_x (thirds, SCM_EOL));
   
   SCM tonic = ly_car (pitches);
   SCM last = tonic;
@@ -228,11 +165,11 @@ Chord::missing_thirds (SCM pitches)
       SCM p = ly_car (i);
       int step = gh_scm2int (step_scm (tonic, p));
       
-      if (unsmob_pitch (last)->notename_i_ == unsmob_pitch (p)->notename_i_)
+      if (unsmob_pitch (last)->notename_ == unsmob_pitch (p)->notename_)
        {
-         int third = (unsmob_pitch (last)->notename_i_
-                      - unsmob_pitch (tonic)-> notename_i_ + 7) % 7;
-         last = Pitch::transpose (last, scm_vector_ref (thirds, gh_int2scm (third)));
+         int third = (unsmob_pitch (last)->notename_
+                      - unsmob_pitch (tonic)-> notename_ + 7) % 7;
+         last = ly_pitch_transpose (last, scm_vector_ref (thirds, gh_int2scm (third)));
        }
       
       if (step > gh_scm2int (step_scm (tonic, last)))
@@ -240,9 +177,9 @@ Chord::missing_thirds (SCM pitches)
          while (step > gh_scm2int (step_scm (tonic, last)))
            {
              missing = gh_cons (last, missing);
-             int third = (unsmob_pitch (last)->notename_i_
-                          - unsmob_pitch (tonic)->notename_i_ + 7) % 7;
-             last = Pitch::transpose (last, scm_vector_ref (thirds,
+             int third = (unsmob_pitch (last)->notename_
+                          - unsmob_pitch (tonic)->notename_ + 7) % 7;
+             last = ly_pitch_transpose (last, scm_vector_ref (thirds,
                                                      gh_int2scm (third)));
            }
        }
@@ -262,7 +199,7 @@ Chord::add_above_tonic (SCM pitch, SCM pitches)
   /* Should we maybe first make sure that PITCH is below tonic? */
   if (pitches != SCM_EOL)
     while (Pitch::less_p (pitch, ly_car (pitches)) == SCM_BOOL_T)
-      pitch = Pitch::transpose (pitch, Pitch (1, 0, 0).smobbed_copy ());
+      pitch = ly_pitch_transpose (pitch, Pitch (1, 0, 0).smobbed_copy ());
    
   pitches = gh_cons (pitch, pitches);
   return scm_sort_list (pitches, Pitch::less_p_proc);
@@ -274,7 +211,7 @@ Chord::add_below_tonic (SCM pitch, SCM pitches)
 {
   if (pitches != SCM_EOL)
     while (Pitch::less_p (ly_car (pitches), pitch) == SCM_BOOL_T)
-      pitch = Pitch::transpose (pitch, Pitch (-1, 0, 0).smobbed_copy ());
+      pitch = ly_pitch_transpose (pitch, Pitch (-1, 0, 0).smobbed_copy ());
   return gh_cons (pitch, pitches);
 }
 
@@ -302,9 +239,9 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
        This chord modifier stuff should really be fixed
        Cmaj7 yields C 7/7-
       */
-      if (p->octave_i ()  == -100)
+      if (p->get_octave ()  == -100)
         {
-          p->octave_i_ = 0;
+          p->octave_ = 0;
          dim_b = true;
        }
     }
@@ -341,13 +278,13 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
     missing = lower_step (tonic, missing, gh_int2scm (0));
   
   /* if additions include any 3, don't add third */
-  SCM third = gh_cadr (base_pitches (tonic));
+  SCM third = ly_cadr (base_pitches (tonic));
   if (member_notename (third, add) != SCM_BOOL_F)
     missing = scm_delete (third, missing);
 
   /* if additions include any 4, assume sus4 and don't add third implicitely
      C-sus (4) = c f g (1 4 5) */
-  SCM sus = Pitch::transpose (tonic, Pitch (0, 3, 0).smobbed_copy ());
+  SCM sus = ly_pitch_transpose (tonic, Pitch (0, 3, 0).smobbed_copy ());
   if (member_notename (sus, add) != SCM_BOOL_F)
     missing = scm_delete (third, missing);
   
@@ -374,7 +311,7 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
   
   for (SCM i = sub; gh_pair_p (i); i = ly_cdr (i))
     warning (_f ("invalid subtraction: not part of chord: %s",
-                unsmob_pitch (ly_car (i))->str ()));
+                unsmob_pitch (ly_car (i))->string ()));
 
   return pitches;
 }
@@ -403,7 +340,7 @@ Chord::get_chord (SCM tonic, SCM add, SCM sub, SCM inversion, SCM bass, SCM dur)
        }
       else
        warning (_f ("invalid inversion pitch: not part of chord: %s",
-                    unsmob_pitch (inversion)->str ()));
+                    unsmob_pitch (inversion)->string ()));
     }
 
   /* Bass is easy, just add if requested */