]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/event.cc
2003 -> 2004
[lilypond.git] / lily / event.cc
index fad850caf4dc7dc7745fa30635bec485636b912a..dc2ca4b32826201068be5322f549973e4139910b 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "event.hh"
@@ -33,30 +33,50 @@ Event::compress (Moment m)
 void
 Event::transpose (Pitch delta)
 {
+  /*
+    TODO: should change music representation such that
+    _all_ pitch values are transposed automatically.
+   */
+  
   Pitch *p = unsmob_pitch (get_mus_property ("pitch"));
   if (!p)
     return ;
 
-  Pitch np = *p;
-  np.transpose (delta);
+  Pitch np = p->transposed (delta);
   
-  if (abs (np.alteration_) > 2)
+  if (abs (np.get_alteration ()) > DOUBLE_SHARP)
     {
-       warning (_f ("Transposition by %s makes accidental larger than two",
-         delta.string ()));
+       warning (_f ("Transposition by %s makes alteration larger than two",
+         delta.to_string ()));
     }
 
   set_mus_property ("pitch", np.smobbed_copy ());
 }
 
 Pitch
- Event::to_relative_octave (Pitch last)
+Event::to_relative_octave (Pitch last)
 {
   Pitch *old_pit = unsmob_pitch (get_mus_property ("pitch"));
   if (old_pit)
     {
       Pitch new_pit = *old_pit;
-      new_pit.to_relative_octave (last);
+      new_pit = new_pit.to_relative_octave (last);
+
+      SCM check = get_mus_property ("absolute-octave");
+      if (gh_number_p (check) &&
+         new_pit.get_octave () != gh_scm2int (check))
+       {
+         String s =_("Failed octave check, got: ");
+         s += new_pit.to_string ();
+         new_pit = Pitch (gh_scm2int (check),
+                          new_pit.get_notename (),
+                          new_pit.get_alteration ());
+
+         s += " expected ";
+         s += new_pit.to_string ();
+         origin ()->warning (s);
+       }
+      
       set_mus_property ("pitch", new_pit.smobbed_copy ());
   
       return new_pit;
@@ -70,7 +90,7 @@ Event::Event ()
 }
 
 ADD_MUSIC(Event);
-LY_DEFINE(music_duration_length, "music-duration-length", 1, 0,0,
+LY_DEFINE(ly_music_duration_length, "ly:music-duration-length", 1, 0,0,
          (SCM mus),
          "Extract the duration field from @var{mus}, and return the length.")
 {
@@ -92,7 +112,7 @@ LY_DEFINE(music_duration_length, "music-duration-length", 1, 0,0,
 }
 
 
-LY_DEFINE(music_duration_compress, "ly:music-duration-compress", 2, 0,0,
+LY_DEFINE(ly_music_duration_compress, "ly:music-duration-compress", 2, 0,0,
          (SCM mus, SCM factor),
          "Extract the duration field from @var{mus}, and compress it.")
 {
@@ -112,8 +132,11 @@ LY_DEFINE(music_duration_compress, "ly:music-duration-compress", 2, 0,0,
 /*
   This is hairy, since the scale in a key-change event may contain
   octaveless notes.
+
+
+  TODO: this should use ly:pitch. 
  */
-LY_DEFINE(transpose_key_alist, "ly:transpose-key-alist",
+LY_DEFINE(ly_transpose_key_alist, "ly:transpose-key-alist",
          2, 0,0, (SCM l, SCM pitch),
          "Make a new key alist of @var{l} transposed by pitch @var{pitch}")
 {
@@ -127,24 +150,24 @@ LY_DEFINE(transpose_key_alist, "ly:transpose-key-alist",
       if (gh_pair_p (key))
        {
          Pitch orig (gh_scm2int (ly_car (key)),
-                             gh_scm2int (ly_cdr (key)),
-                             gh_scm2int (alter));
+                     gh_scm2int (ly_cdr (key)),
+                     gh_scm2int (alter));
 
-         orig.transpose (*p);
+         orig =orig.transposed (*p);
 
          SCM key = gh_cons (scm_int2num (orig.get_octave ()),
-                            scm_int2num (orig.notename_));
+                            scm_int2num (orig.get_notename ()));
 
-         newlist = gh_cons (gh_cons (key, scm_int2num (orig.alteration_)),
+         newlist = gh_cons (gh_cons (key, scm_int2num (orig.get_alteration ())),
                             newlist);
        }
       else if (gh_number_p (key))
        {
          Pitch orig (0, gh_scm2int (key), gh_scm2int (alter));
-         orig.transpose (*p);
+         orig = orig.transposed (*p);
 
-         key =scm_int2num (orig.notename_);
-         alter = scm_int2num (orig.alteration_);
+         key =scm_int2num (orig.get_notename ());
+         alter = scm_int2num (orig.get_alteration());
          newlist = gh_cons (gh_cons (key, alter), newlist);
        }
     }
@@ -152,14 +175,16 @@ LY_DEFINE(transpose_key_alist, "ly:transpose-key-alist",
 }
 
 void
-Key_change_req::transpose (Pitch p)
+Key_change_ev::transpose (Pitch p)
 {
   SCM pa = get_mus_property ("pitch-alist");
 
-  set_mus_property ("pitch-alist", transpose_key_alist (pa, p.smobbed_copy()));
+  set_mus_property ("pitch-alist", ly_transpose_key_alist (pa, p.smobbed_copy()));
+  Pitch tonic = *unsmob_pitch (get_mus_property ("tonic"));
+  set_mus_property ("tonic",
+                   tonic.smobbed_copy ());
 }
 
-
 bool
 alist_equal_p (SCM a, SCM b)
 {
@@ -177,16 +202,4 @@ alist_equal_p (SCM a, SCM b)
     }
   return true;
 }
-
-bool
-Key_change_req::do_equal_b (Event const * m )const
-{
-  Key_change_req const * kc =dynamic_cast<Key_change_req const*> (m);
-
-  if(!kc)
-    return false;
-  return alist_equal_p (get_mus_property ("pitch-alist"),
-                       kc->get_mus_property ("pitch-alist"));
-}
-
-ADD_MUSIC (Key_change_req);
+ADD_MUSIC (Key_change_ev);