]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/music.cc
* scripts/abc2ly.py (try_parse_comment): idem.
[lilypond.git] / lily / music.cc
index 191f42a1b725d82e00a3ba84470749f18efe2730..4d71d99d98e6bfd8069936ccd88600834d563d3b 100644 (file)
@@ -8,8 +8,10 @@
 
 #include "music.hh"
 
+#include "context.hh"
+#include "dispatcher.hh"
 #include "duration.hh"
-#include "input-smob.hh"
+#include "input.hh"
 #include "international.hh"
 #include "ly-smobs.icc"
 #include "main.hh"
 #include "warn.hh"
 
 /*
-  Music is anything that has duration and supports both time compression
-  and transposition.
+  Music is anything that has (possibly zero) duration and supports
+  both time compression and transposition.
 
   In Lily, everything that can be thought to have a length and a pitch
-  (which has a duration which can be transposed) is considered "music",
+  (which has a duration which can be transposed) is considered "music".
 */
 bool
 Music::internal_is_music_type (SCM k) const
@@ -182,15 +184,18 @@ Music::compress (Moment factor)
     set_property ("duration", d->compressed (factor.main_part_).smobbed_copy ());
 }
 
-void
-Music::transpose (Pitch delta)
+/*
+TODO: make transposition non-destructive
+*/
+SCM
+transpose_mutable (SCM alist, Pitch delta)
 {
-  if (to_boolean (get_property ("untransposable")))
-    return;
+  SCM retval = SCM_EOL;
 
-  for (SCM s = this->get_property_alist (true); scm_is_pair (s); s = scm_cdr (s))
+  for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
     {
       SCM entry = scm_car (s);
+      SCM prop = scm_car (entry);
       SCM val = scm_cdr (entry);
 
       if (Pitch *p = unsmob_pitch (val))
@@ -204,21 +209,29 @@ Music::transpose (Pitch delta)
                           delta.to_string ()));
            }
        }
+      else if (prop == ly_symbol2scm ("element"))
+       {
+         if (Music *m = unsmob_music (val))
+           m->transpose (delta);
+       }
+      else if (prop == ly_symbol2scm ("elements"))
+       transpose_music_list (val, delta);
+      else if (prop == ly_symbol2scm ("pitch-alist") &&
+              scm_is_pair (val))
+       entry = scm_cons (prop, ly_transpose_key_alist (val, delta.smobbed_copy ()));
+      retval = scm_cons (entry, retval);
     }
 
-  SCM elt = get_property ("element");
-
-  if (Music *m = unsmob_music (elt))
-    m->transpose (delta);
+  return scm_reverse_x (retval, SCM_EOL);
+}
 
-  transpose_music_list (get_property ("elements"), delta);
+void
+Music::transpose (Pitch delta)
+{
+  if (to_boolean (get_property ("untransposable")))
+    return;
 
-  /*
-    UGH - how do this more generically?
-  */
-  SCM pa = get_property ("pitch-alist");
-  if (scm_is_pair (pa))
-    set_property ("pitch-alist", ly_transpose_key_alist (pa, delta.smobbed_copy ()));
+  mutable_property_alist_ = transpose_mutable (mutable_property_alist_, delta);
 }
 
 void
@@ -234,6 +247,62 @@ Music::origin () const
   return ip ? ip : &dummy_input_global;
 }
 
+/*
+  ES TODO: This method should probably be reworked or junked.
+*/
+Stream_event *
+Music::to_event () const
+{
+  /* UGH. Temp hack */
+  SCM orig_sym = get_property ("name");
+  char out[200];
+  string in = ly_symbol2string (orig_sym);
+  /* don't add '-' before first character */
+  out[0] = tolower (in[0]);
+  size_t outpos = 1;
+  for (size_t inpos = 1; inpos < in.size () && outpos < 190; inpos++)
+    {
+      if (isupper (in[inpos]))
+       out[outpos++] = '-';
+      out[outpos++] = tolower (in[inpos]);      
+    }
+  out[outpos] = 0;
+  SCM class_name = ly_symbol2scm (out);
+
+  // catch mistakes.
+  if (!internal_is_music_type (class_name))
+    {
+      programming_error ("Not a music type");
+    }
+
+  Stream_event *e = new Stream_event (class_name, mutable_property_alist_);
+  Moment length = get_length ();
+  if (length.to_bool ())
+    e->set_property ("length", length.smobbed_copy ());
+
+  /*
+    ES TODO: This is a temporary fix. Stream_events should not be
+    aware of music.
+  */
+  e->set_property ("music-cause", self_scm ());
+  return e;
+}
+
+void
+Music::send_to_context (Context *c)
+{
+  /*
+    TODO: This is a work-in-progress solution. Send the event so it
+    can be read both by old-style translators and the new ones.
+  */
+  send_stream_event (c, "OldMusicEvent", origin (),
+                    ly_symbol2scm("music"), self_scm (), 0);
+
+  Stream_event *ev = to_event ();
+  c->event_source ()->broadcast (ev);
+  ev->unprotect ();
+}
+
 Music *
 make_music_by_name (SCM sym)
 {