]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/scale.cc
Release: bump Welcome versions.
[lilypond.git] / lily / scale.cc
index eeea8f8a42956ebef98411fdeb7ba7c579d5448e..02c1dc5f8e2daca09b480ac977049c66e70d68e3 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2006--2011 Han-Wen Nienhuys <hanwen@lilypond.org>
+  Copyright (C) 2006--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
       2007--2008 Rune Zedeler
       2008       Joe Neeman <joeneeman@gmail.com>
 
@@ -20,8 +20,8 @@
 */
 
 #include "scale.hh"
+#include "protected-scm.hh"
 
-#include "ly-smobs.icc"
 
 /*
   todo: put string <-> pitch here too.
@@ -54,41 +54,38 @@ LY_DEFINE (ly_make_scale, "ly:make-scale",
 
   SCM_ASSERT_TYPE (type_ok, steps, SCM_ARG1, __FUNCTION__, "vector of rational");
 
-  Scale *s = new Scale (tones);
+  return (new Scale (tones))->unprotect ();
+}
 
-  SCM retval = s->self_scm ();
-  s->unprotect ();
+Scale *default_global_scale = 0;
+Protected_scm default_global_scale_scm (SCM_BOOL_F);
 
-  return retval;
-}
+// TODO: This is somewhat fishy: pitches protect their scale via a
+// mark_smob hook.  But since pitches are of Simple_smob variety, they
+// are unknown to GUILE unless a smobbed_copy has been created.  So
+// changing the default scale might cause some existing pitches to
+// lose their scale's protection.
 
 LY_DEFINE (ly_default_scale, "ly:default-scale",
            0, 0, 0, (),
            "Get the global default scale.")
 {
-  return default_global_scale
-         ? default_global_scale->self_scm ()
-         : SCM_BOOL_F;
+  return default_global_scale_scm;
 }
 
-Scale *default_global_scale = 0;
-
 LY_DEFINE (ly_set_default_scale, "ly:set-default-scale",
            1, 0, 0, (SCM scale),
-           "Set the global default scale. This determines the tuning of"
+           "Set the global default scale.  This determines the tuning of"
            " pitches with no accidentals or key signatures.  The first"
-           " pitch is C. Alterations are calculated relative to this"
+           " pitch is C.  Alterations are calculated relative to this"
            " scale.  The number of pitches in this scale determines the"
            " number of scale steps that make up an octave.  Usually the"
            " 7-note major scale.")
 {
   LY_ASSERT_SMOB (Scale, scale, 1);
 
-  Scale *s = Scale::unsmob (scale);
-  if (default_global_scale)
-    default_global_scale->unprotect ();
-  default_global_scale = s;
-  s->protect ();
+  default_global_scale_scm = scale;
+  default_global_scale = unsmob<Scale> (scale);
 
   return SCM_UNSPECIFIED;
 }
@@ -134,20 +131,7 @@ Scale::normalize_step (int step) const
   return ret;
 }
 
-int
-Scale::print_smob (SCM /* x */,
-                   SCM port,
-                   scm_print_state *)
-{
-  scm_puts ("#<Scale>", port);
-  return 1;
-}
 
-SCM
-Scale::mark_smob (SCM)
-{
-  return SCM_UNSPECIFIED;
-}
 
 Scale::Scale (vector<Rational> const &tones)
 {
@@ -157,6 +141,7 @@ Scale::Scale (vector<Rational> const &tones)
 }
 
 Scale::Scale (Scale const &src)
+  : Smob<Scale> ()
 {
   step_tones_ = src.step_tones_;
   smobify_self ();
@@ -165,6 +150,3 @@ Scale::Scale (Scale const &src)
 Scale::~Scale ()
 {
 }
-
-IMPLEMENT_SMOBS (Scale);
-IMPLEMENT_DEFAULT_EQUAL_P (Scale);