- SCM copy = m;
- if (unsmob_music (m))
- {
- Music *mcopy = unsmob_music (m)->clone ();
- copy = mcopy->unprotect ();
- }
- else if (scm_is_pair (m))
- copy = scm_cons (ly_music_deep_copy (scm_car (m)),
- ly_music_deep_copy (scm_cdr (m)));
- return copy;
+ m = music_deep_copy (m);
+
+ if (SCM_UNBNDP (origin))
+ return m;
+
+ if (Music *mus = unsmob<Music> (origin))
+ origin = mus->get_property ("origin");
+
+ if (scm_is_false (origin) || scm_is_null (origin))
+ return m;
+
+ LY_ASSERT_SMOB (Input, origin, 2);
+
+ set_origin (m, origin);
+ return m;
+}
+
+LY_DEFINE (ly_set_origin_x, "ly:set-origin!",
+ 1, 1, 0, (SCM m, SCM origin),
+ "This sets the origin given in @var{origin} to @var{m}. "
+ " @var{m} will typically be a music expression or a list"
+ " of music. List structures are searched recursively,"
+ " but recursion stops at the changed music expressions"
+ " themselves. "
+ " @var{origin} is generally of type @code{ly:input-location?},"
+ " defaulting to @code{(*location*)}. Other valid values for"
+ " @code{origin} are a music expression which is then used as"
+ " the source of location information, or @code{#f}"
+ " or @code{'()} in which case no action is performed. "
+ " The return value is @var{m} itself.")
+{
+ if (SCM_UNBNDP (origin))
+ origin = scm_fluid_ref (Lily::f_location);
+ else if (Music *mus = unsmob<Music> (origin))
+ origin = mus->get_property ("origin");
+
+ if (scm_is_false (origin) || scm_is_null (origin))
+ return m;
+
+ LY_ASSERT_SMOB (Input, origin, 2);
+
+ set_origin (m, origin);
+ return m;