]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/scale.cc
Imported Upstream version 2.16.0
[lilypond.git] / lily / scale.cc
index 5de25f5c43c3df00f09fe9750146e91d3640890e..c4b3ccf2c5f5e963dda69f0678a3e5876bf7725d 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--2012 Han-Wen Nienhuys <hanwen@lilypond.org>
       2007--2008 Rune Zedeler
       2008       Joe Neeman <joeneeman@gmail.com>
 
 
 /*
   todo: put string <-> pitch here too.
-
 */
 LY_DEFINE (ly_make_scale, "ly:make-scale",
-          1, 0, 0, (SCM steps),
-          "Create a scale."
-          "  The argument is a vector of rational numbers, each of which"
-          " represents the number of 200 cent tones of a pitch above the"
-          " tonic.")
+           1, 0, 0, (SCM steps),
+           "Create a scale."
+           "  The argument is a vector of rational numbers, each of which"
+           " represents the number of 200 cent tones of a pitch above the"
+           " tonic.")
 {
   bool type_ok = scm_is_vector (steps);
 
-  vector<Rational> tones; 
+  vector<Rational> tones;
   if (type_ok)
     {
       int len = scm_c_vector_length (steps);
-      for (int i = 0 ; i < len; i++)
-       {
-         SCM step = scm_c_vector_ref (steps, i);
-         type_ok = type_ok && scm_is_rational (step);
-         if (type_ok)
-           {
-             Rational from_c (scm_to_int (scm_numerator (step)),
-                              scm_to_int (scm_denominator (step)));
-             tones.push_back (from_c);
-           }
-       }
+      for (int i = 0; i < len; i++)
+        {
+          SCM step = scm_c_vector_ref (steps, i);
+          type_ok = type_ok && scm_is_rational (step);
+          if (type_ok)
+            {
+              Rational from_c (scm_to_int (scm_numerator (step)),
+                               scm_to_int (scm_denominator (step)));
+              tones.push_back (from_c);
+            }
+        }
     }
-  
-  
+
   SCM_ASSERT_TYPE (type_ok, steps, SCM_ARG1, __FUNCTION__, "vector of rational");
 
   Scale *s = new Scale (tones);
 
-  SCM retval =  s->self_scm ();
+  SCM retval = s->self_scm ();
   s->unprotect ();
-  
+
   return retval;
 }
 
 LY_DEFINE (ly_default_scale, "ly:default-scale",
-          0, 0, 0, (),
-          "Get the global default scale.")
+           0, 0, 0, (),
+           "Get the global default scale.")
 {
   return default_global_scale
-    ? default_global_scale->self_scm ()
-    : SCM_BOOL_F;
+         ? default_global_scale->self_scm ()
+         : SCM_BOOL_F;
 }
 
-
-Scale * default_global_scale = 0;
+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"
-          " pitches with no accidentals or key signatures.  The first"
-          " 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.")
+           1, 0, 0, (SCM scale),
+           "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"
+           " 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);
 
@@ -92,7 +89,7 @@ LY_DEFINE (ly_set_default_scale, "ly:set-default-scale",
     default_global_scale->unprotect ();
   default_global_scale = s;
   s->protect ();
-  
+
   return SCM_UNSPECIFIED;
 }
 
@@ -110,7 +107,7 @@ Scale::tones_at_step (int step, int octave) const
   octave += (step - normalized_step) / step_count ();
 
   // There are 6 tones in an octave.
-  return step_tones_[normalized_step] + Rational (octave*6);
+  return step_tones_[normalized_step] + Rational (octave * 6);
 }
 
 Rational
@@ -122,7 +119,7 @@ Scale::step_size (int step) const
   // scale (6 is the number of tones of the octave above the
   // first note).
   if (normalized_step + 1 == step_count ())
-    return Rational(6) - step_tones_[normalized_step];
+    return Rational (6) - step_tones_[normalized_step];
 
   return step_tones_[normalized_step + 1] - step_tones_[normalized_step];
 }
@@ -139,10 +136,10 @@ Scale::normalize_step (int step) const
 
 int
 Scale::print_smob (SCM /* x */,
-                  SCM port,
-                  scm_print_state *)
+                   SCM port,
+                   scm_print_state *)
 {
-  scm_puts ("#<Scale>", port); 
+  scm_puts ("#<Scale>", port);
   return 1;
 }
 
@@ -165,7 +162,6 @@ Scale::Scale (Scale const &src)
   smobify_self ();
 }
 
-
 Scale::~Scale ()
 {
 }