Hi,

In the attached snippet, the call to ly:set-default-scale has no
effect on the midi result, both in the stable and development
versions.

I believe that this is due to Pitches being constructed before
the new default_global_scale is set (see files lily/pitch.cc and
lily/scale.cc), so that they keep a pointer to the old Scale,
created in scm/lily.scm:387.

This looks bad, because as ly:set-default-scale is called, the
old object gets unprotected.

In fact, by applying the change described in the attached file
diff.txt, I obtained the results I expected (set-scale-test-mine.midi),
which only confirms my suspicions. (The last c is 6 tones higher,
because an octave is hard-coded as 6 tones, but that is another
issue).

This leads me to the following questions:

1. Is the current behaviour the desired one?
2. Is it a bug?
3. Do we really have a problem with garbage collection?
    (I observe no consequences)

By the way, there is actually an alternative solution, which would be
to make Pitch objects use default_global_scale directly, instead of
storing its value as an internal field during initialisation. This leads
me to the related question:

4. What is the purpose of the non-static scale_ field in the Pitch class?

I look forward to and would very much appreciate any thoughts on
these from anybody acquainted with this code.

Kind regards,
Felipe
diff --git a/lily/scale.cc b/lily/scale.cc
index e3fe7ba..a14d8b3 100644
--- a/lily/scale.cc
+++ b/lily/scale.cc
@@ -89,9 +89,11 @@ LY_DEFINE (ly_set_default_scale, "ly:set-default-scale",
 
   Scale *s = Scale::unsmob (scale);
   if (default_global_scale)
-    default_global_scale->unprotect ();
-  default_global_scale = s;
-  s->protect ();
+    *default_global_scale = *s;
+  else {
+    default_global_scale = s;
+    s->protect ();
+  }
   
   return SCM_UNSPECIFIED;
 }
\version "2.12.1"

#(ly:set-default-scale (ly:make-scale '#(0 0 0 0 0 0 0)))

m = \relative c' { c d e f g a b c}

\score {
  \m
  \midi { }
}

Attachment: set-scale-test-mine.midi
Description: MIDI audio

_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to