]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/pitch.cc
trem fix
[lilypond.git] / lily / pitch.cc
index aa7774debce072ce1de914f0da4af462446dfc61..fa06546afee4eeca96dc7c51a81bf628a66de17c 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 #include "pitch.hh"
@@ -154,13 +154,13 @@ Pitch::str () const
   if (alteration_i_)
     s += String (accname[alteration_i_ + 2]);
 
-  if (octave_i_ > 0)
+  if (octave_i_ >= 0)
     {
       int o = octave_i_ + 1;
       while (o--)
        s += "'";
     }
-  else if (octave_i_ <0)
+  else if (octave_i_ < 0)
     {
       int o = (-octave_i_) - 1;
       while (o--)
@@ -219,28 +219,29 @@ 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 ();
 }
 
 /****************************************************************/
 
 
 IMPLEMENT_TYPE_P (Pitch, "pitch?");
-IMPLEMENT_UNSMOB (Pitch, pitch);
+
 SCM
 Pitch::mark_smob (SCM)
 {
@@ -248,12 +249,10 @@ Pitch::mark_smob (SCM)
 }
 
 IMPLEMENT_SIMPLE_SMOBS (Pitch);
-
-
 int
 Pitch::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Pitch  *r = (Pitch *) gh_cdr (s);
+  Pitch  *r = (Pitch *) ly_cdr (s);
      
   scm_puts ("#<Pitch ", port);
   scm_display (ly_str02scm (r->str ().ch_C ()), port);
@@ -265,8 +264,8 @@ Pitch::print_smob (SCM s, SCM port, scm_print_state *)
 SCM
 Pitch::equal_p (SCM a , SCM b)
 {
-  Pitch  *p = (Pitch *) gh_cdr (a);
-  Pitch  *q = (Pitch *) gh_cdr (b);  
+  Pitch  *p = (Pitch *) ly_cdr (a);
+  Pitch  *q = (Pitch *) ly_cdr (b);  
 
   bool eq = p->notename_i_ == q->notename_i_
     && p->octave_i_ == q->octave_i_
@@ -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_;
 }
+