]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/chord.cc
string() -> to_string()
[lilypond.git] / lily / chord.cc
index e76549a49ef43dd7d4a6e5025997710bc8a4b917..169b15571321032ddd2edfc0439248ad74cecdca 100644 (file)
@@ -3,15 +3,15 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1999--2002 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c)  1999--2003 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "chord.hh"
-#include "musical-request.hh"
+#include "event.hh"
 #include "warn.hh"
-#include "debug.hh"
+
 #include "music-list.hh"
-#include "musical-request.hh"
+#include "event.hh"
 
 
 SCM
@@ -23,8 +23,8 @@ 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 scm_reverse_x (base, SCM_EOL);
 }
@@ -38,7 +38,7 @@ 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 scm_reverse_x (transposed, SCM_EOL);
@@ -60,7 +60,7 @@ 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);
     }
@@ -81,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)->get_notename ()
+             == unsmob_pitch (ly_car (i))->get_notename ())
            {
              member = ly_car (i);
              break;
@@ -104,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)->get_notename ()
+             == unsmob_pitch (ly_car (i))->get_notename ()
+             && unsmob_pitch (p)->get_alteration()
+             == unsmob_pitch (ly_car (i))->get_alteration())
            {
              member = ly_car (i);
              break;
@@ -123,14 +123,14 @@ 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)->get_notename ()
+    - unsmob_pitch (tonic)->get_notename ()
+    + (unsmob_pitch (p)->get_octave ()
+       - unsmob_pitch (tonic)->get_octave ()) * 7;
   while (i < 0)
     i += 7;
   i++;
-  return gh_int2scm (i);
+  return scm_int2num (i);
 }
 
 /*
@@ -165,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)->get_notename () == unsmob_pitch (p)->get_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)->get_notename ()
+                      - unsmob_pitch (tonic)-> get_notename () + 7) % 7;
+         last = ly_pitch_transpose (last, scm_vector_ref (thirds, scm_int2num (third)));
        }
       
       if (step > gh_scm2int (step_scm (tonic, last)))
@@ -177,10 +177,10 @@ 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,
-                                                     gh_int2scm (third)));
+             int third = (unsmob_pitch (last)->get_notename ()
+                          - unsmob_pitch (tonic)->get_notename () + 7) % 7;
+             last = ly_pitch_transpose (last, scm_vector_ref (thirds,
+                                                     scm_int2num (third)));
            }
        }
       else
@@ -189,7 +189,7 @@ Chord::missing_thirds (SCM pitches)
        }
     }
   
-  return lower_step (tonic, missing, gh_int2scm (7));
+  return lower_step (tonic, missing, scm_int2num (7));
 }
 
 /* Return PITCHES with PITCH added not as lowest note */
@@ -199,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);
@@ -211,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);
 }
 
@@ -239,19 +239,22 @@ 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;
+         dim_b = true;
+         Pitch t (0, p->get_notename(), p->get_alteration());
+         gh_set_car_x (i, t.smobbed_copy());
          dim_b = true;
        }
     }
+  
   add = transpose_pitches (tonic, add);
-  add = lower_step (tonic, add, gh_int2scm (7));
+  add = lower_step (tonic, add, scm_int2num (7));
   add = scm_sort_list (add, Pitch::less_p_proc);
   add = ly_unique (add);
   
   sub = transpose_pitches (tonic, sub);
-  sub = lower_step (tonic, sub, gh_int2scm (7));
+  sub = lower_step (tonic, sub, scm_int2num (7));
   sub = scm_sort_list (sub, Pitch::less_p_proc);
   
   /* default chord includes upto 5: <1, 3, 5>   */
@@ -264,8 +267,8 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
     tmp = ly_snoc (fifth, tmp);
   else if (dim_b)
     {
-      add = lower_step (tonic, add, gh_int2scm (5));
-      add = lower_step (tonic, add, gh_int2scm (7));
+      add = lower_step (tonic, add, scm_int2num (5));
+      add = lower_step (tonic, add, scm_int2num (7));
     }
 
   /* find missing thirds */
@@ -275,7 +278,7 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
 
   /* if dim modifier is given: lower all missing */
   if (dim_b)
-    missing = lower_step (tonic, missing, gh_int2scm (0));
+    missing = lower_step (tonic, missing, scm_int2num (0));
   
   /* if additions include any 3, don't add third */
   SCM third = ly_cadr (base_pitches (tonic));
@@ -284,7 +287,7 @@ Chord::tonic_add_sub_to_pitches (SCM tonic, SCM add, SCM sub)
 
   /* 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);
   
@@ -311,14 +314,14 @@ 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))->to_string ()));
 
   return pitches;
 }
 
 
 /* --Het lijkt me dat dit in het paarse gedeelte moet. */
-Simultaneous_music *
+Music *
 Chord::get_chord (SCM tonic, SCM add, SCM sub, SCM inversion, SCM bass, SCM dur)
 {
   SCM pitches = tonic_add_sub_to_pitches (tonic, add, sub);
@@ -331,7 +334,7 @@ Chord::get_chord (SCM tonic, SCM add, SCM sub, SCM inversion, SCM bass, SCM dur)
        {
          /* Then, delete and add as base note, ie: the inversion */
          pitches = scm_delete (s, pitches);
-         Note_req* n = new Note_req;
+         Music * n = make_music_by_name (ly_symbol2scm ("NoteEvent"));
          n->set_mus_property ("pitch", ly_car (add_below_tonic (s, pitches)));
          n->set_mus_property ("duration", dur);
          n->set_mus_property ("inversion", SCM_BOOL_T);
@@ -340,13 +343,13 @@ 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)->to_string ()));
     }
 
   /* Bass is easy, just add if requested */
   if (bass != SCM_EOL)
     {
-      Note_req* n = new Note_req;
+      Music * n = make_music_by_name (ly_symbol2scm ("NoteEvent"));
       n->set_mus_property ("pitch", ly_car (add_below_tonic (bass, pitches)));
       n->set_mus_property ("duration", dur);
       n->set_mus_property ("bass", SCM_BOOL_T);
@@ -356,14 +359,14 @@ Chord::get_chord (SCM tonic, SCM add, SCM sub, SCM inversion, SCM bass, SCM dur)
   
   for (SCM i = pitches; gh_pair_p (i); i = ly_cdr (i))
     {
-      Note_req* n = new Note_req;
+      Music * n = make_music_by_name(ly_symbol2scm ("NoteEvent"));
       n->set_mus_property ("pitch", ly_car (i));
       n->set_mus_property ("duration", dur);
       list = gh_cons (n->self_scm (), list);
       scm_gc_unprotect_object (n->self_scm ());
     }
 
-  Simultaneous_music*v = new Request_chord (SCM_EOL);
+  Music * v = make_music_by_name(ly_symbol2scm ("EventChord"));
   v->set_mus_property ("elements", list);
 
   return v;