]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/pitch.cc
mutopia move
[lilypond.git] / lily / pitch.cc
index d160841e9c27c6686e0888d49690d1cce9f834d1..06c19f5473d3953570ea13d177cd61e8ab7b0ec1 100644 (file)
@@ -7,7 +7,7 @@
   
  */
 #include "pitch.hh"
-#include "debug.hh"
+#include "warn.hh"
 #include "main.hh"
 #include "ly-smobs.icc"
 
@@ -219,21 +219,22 @@ Pitch::down_to (int notename)
     }
   notename_i_ = notename;
 }
-
-///MAKE_SCHEME_CALLBACK (Pitch, transpose, 2);
-///transpose_proc?
-SCM
-Pitch::transpose (SCM p, SCM delta)
-{
-  Pitch t = *unsmob_pitch (p);
-  t.transpose (*unsmob_pitch (delta));
-  return t.smobbed_copy ();
-}
-
-static SCM
-pitch_transpose (SCM p, SCM delta)
+LY_DEFINE(ly_pitch_transpose,
+         "ly-transpose-pitch", 2, 0, 0,
+         (SCM p, SCM delta),
+         "Transpose @var{p} by the amount @var{delta}, where @var{delta} is the
+pitch that central C is transposed to.
+")
 {
-  return Pitch::transpose (p, delta);
+  Pitch* t = unsmob_pitch (p);
+  Pitch *d = unsmob_pitch (delta);
+  SCM_ASSERT_TYPE(t, p, SCM_ARG1, __FUNCTION__, "pitch")  ;
+  SCM_ASSERT_TYPE(d, delta, SCM_ARG1, __FUNCTION__, "pitch")  ;
+
+  Pitch tp =*t;
+  tp.transpose (*d);
+  return tp.smobbed_copy ();
 }
 
 /****************************************************************/
@@ -248,8 +249,6 @@ Pitch::mark_smob (SCM)
 }
 
 IMPLEMENT_SIMPLE_SMOBS (Pitch);
-
-
 int
 Pitch::print_smob (SCM s, SCM port, scm_print_state *)
 {
@@ -292,80 +291,83 @@ Pitch::less_p (SCM p1, SCM p2)
   should add optional args
  */
 
-static SCM
-make_pitch (SCM o, SCM n, SCM a)
+LY_DEFINE(make_pitch, "make-pitch", 3, 0, 0, 
+         (SCM o, SCM n, SCM a),
+         "
+@var{octave} is specified by an integer, zero for the octave containing
+middle C.  @var{note} is a number from 0 to 6, with 0 corresponding to C
+and 6 corresponding to B.  The shift is zero for a natural, negative for
+flats, or positive for sharps.
+
+")
 {
+  SCM_ASSERT_TYPE(gh_number_p(o), o, SCM_ARG1, __FUNCTION__, "number");
+  SCM_ASSERT_TYPE(gh_number_p(n), n, SCM_ARG2, __FUNCTION__, "number");
+  SCM_ASSERT_TYPE(gh_number_p(a), a, SCM_ARG3, __FUNCTION__, "number");
+
   Pitch p (gh_scm2int (o), gh_scm2int (n), gh_scm2int (a));
   return p.smobbed_copy ();
 }
 
-static SCM
-pitch_octave (SCM pp)
+
+LY_DEFINE(pitch_octave, "pitch-octave", 1, 0, 0, 
+         (SCM pp),
+         "extract the octave from pitch @var{p}.")
 {
   Pitch *p = unsmob_pitch (pp);
-  int q = 0;
-  if (!p)
-    warning ("Not a pitch");
-  else
-    q = p->octave_i ();
+   SCM_ASSERT_TYPE(p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
+  int q = p->octave_i ();
 
   return gh_int2scm (q);
 }
 
-static SCM
-pitch_alteration (SCM pp)
+LY_DEFINE(pitch_alteration, "pitch-alteration", 1, 0, 0, 
+         (SCM pp),
+         "extract the alteration from pitch  @var{p}.")
 {
   Pitch *p = unsmob_pitch (pp);
-  int q = 0;
-  if (!p)
-    warning ("Not a pitch");
-  else
-    q = p->alteration_i ();
+  SCM_ASSERT_TYPE(p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
+  int     q = p->alteration_i ();
 
   return gh_int2scm (q);
 }
 
-static SCM
-pitch_notename (SCM pp)
+LY_DEFINE(pitch_notename, "pitch-notename", 1, 0, 0, 
+         (SCM pp),
+         "extract the note name from pitch  @var{pp}.")
 {
   Pitch *p = unsmob_pitch (pp);
-  int q = 0;
-  if (!p)
-    warning ("Not a pitch");
-  else
-    q = p->notename_i ();
+  SCM_ASSERT_TYPE(p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
+  int q  = p->notename_i ();
 
   return gh_int2scm (q);
 }
 
-static SCM
-pitch_semitones (SCM pp)
+LY_DEFINE(pitch_semitones,  "pitch-semitones", 1, 0, 0, 
+         (SCM pp),
+         "calculate the number of semitones of @var{p} from central C.")
 {
   Pitch *p = unsmob_pitch (pp);
-  int q = 0;
-  if (!p)
-    warning ("Not a pitch");
-  else
-    q = p->steps ();
+  SCM_ASSERT_TYPE(p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
+  int q = p->semitone_pitch ();
+  
+  // Was :
+  //
+  //int q = p->steps ();
+  //
+  // As the function is called "pitch_semitones", I assume it was a mistake !
+  // Jiba
 
   return gh_int2scm (q);
 }
 
-static void
-add_funcs ()
+LY_DEFINE(pitch_less, "pitch<?", 2,0,0, (SCM p1, SCM p2),
+         "Is @var{p1} lower than @var{p2}? This uses lexicographic ordening.")
 {
-  // should take list?: (make-pitch ' (octave name accidental))
-  scm_c_define_gsubr ("make-pitch", 3, 0, 0, (Scheme_function_unknown)make_pitch);
-
-  scm_c_define_gsubr ("pitch-octave", 1, 0, 0, (Scheme_function_unknown)pitch_octave);
-  scm_c_define_gsubr ("pitch-notename", 1, 0, 0, (Scheme_function_unknown)pitch_notename);
-  scm_c_define_gsubr ("pitch-alteration", 1, 0, 0, (Scheme_function_unknown)pitch_alteration);
-  scm_c_define_gsubr ("pitch-semitones", 1, 0, 0, (Scheme_function_unknown)pitch_semitones);
-  scm_c_define_gsubr ("Pitch::transpose", 2, 0, 0, (Scheme_function_unknown) pitch_transpose);
+  return Pitch::less_p (ly_car (p1),  ly_car (p2));
 }
 
-ADD_SCM_INIT_FUNC (pitch, add_funcs);
-
 SCM
 Pitch::smobbed_copy ()const
 {
@@ -390,3 +392,4 @@ Pitch::alteration_i () const
 {
   return alteration_i_;
 }
+