]> git.donarmstrong.com Git - lilypond.git/commitdiff
use rational numbers for alteration field of Pitch.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 22 Dec 2006 18:06:47 +0000 (19:06 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 22 Dec 2006 18:06:47 +0000 (19:06 +0100)
34 files changed:
input/regression/GNUmakefile
input/regression/key-signature-scordatura.ly
input/regression/keys.ly
lily/accidental-engraver.cc
lily/accidental.cc
lily/align-interface.cc
lily/ambitus-engraver.cc
lily/guile-init.cc [new file with mode: 0644]
lily/include/audio-item.hh
lily/include/lily-guile.hh
lily/include/lily-proto.hh
lily/include/midi-item.hh
lily/include/pitch.hh
lily/include/scale.hh [new file with mode: 0644]
lily/key-engraver.cc
lily/key-performer.cc
lily/key-signature-interface.cc
lily/lily-guile.cc
lily/midi-item.cc
lily/midi-walker.cc
lily/music-scheme.cc
lily/music.cc
lily/note-performer.cc
lily/parser.yy
lily/pitch-scheme.cc
lily/pitch.cc
lily/pitched-trill-engraver.cc
lily/relative-octave-check.cc
lily/scale.cc
lily/tab-note-heads-engraver.cc
ly/engraver-init.ly
scm/chord-entry.scm
scm/lily-library.scm
scm/lily.scm

index df3a19a13b9f8eb384053f05651107f297b48d9e..461a2c3e6e2a755b3883ecf15bdd76081ccb68c2 100644 (file)
@@ -6,3 +6,14 @@ LOCALSTEPMAKE_TEMPLATES=lilypond ly lysdoc
 include $(depth)/make/stepmake.make
 TITLE=LilyPond Regression Tests
 
+
+test:
+       $(MAKE) out=test WWW ANTI_ALIAS_FACTOR=1
+
+
+CHECK_SOURCE=$(HOME)/vc/gub/target/linux-x86/build/lilypond-master-git.sv.gnu.org-lilypond.git/input/regression/out-test/
+RESULT_DIR=$(top-build-dir)/out/test-results/
+check:
+       rm -rf $(RESULT_DIR)
+       mkdir -p $(RESULT_DIR)
+       $(PYTHON) $(buildscript-dir)/output-distance.py --output-dir $(RESULT_DIR) $(CHECK_SOURCE) out-test/
index 456bc1a6290344f6873ae5b0bfd1e03e3732fd49..cfad4a74bfd579fd63fef6a60f36581c37b26be0 100644 (file)
@@ -11,9 +11,9 @@ key signatures can be set invidually per pitch.
 }
 \relative c'
 \new Staff {
-    \set Staff.keySignature = #'(((1 .  2) . 1) ((0 . 3) . -1))
+    \set Staff.keySignature = #`(((1 .  2) . ,SHARP) ((0 . 3) . ,FLAT))
     f8 a c e
-    \set Staff.keySignature = #'(((1 .  2) . -1) ((0 . 4) . 2))
+    \set Staff.keySignature = #`(((1 .  2) . ,FLAT) ((0 . 4) . ,DOUBLE-SHARP))
     e a, g a
 }
 
index 65ba2796e8b2d743d96f597b2dd0e2a31759946e..0a071d9bd6e55d7b7ab99f28bb5479de14747749 100644 (file)
@@ -25,7 +25,7 @@ are created also on a clef change.
     \break
     \key bes \major % \major
     c2 \clef alto c2   \key d \major \clef treble c2
-    \set Staff.keySignature = #'((2 . -1)  (6 . 3) (4 . -2))
+    \set Staff.keySignature = #`((2 . ,SEMI-FLAT)  (6 . ,THREE-Q-SHARP) (4 . ,FLAT))
     e2
 }
 
index a94f553d065576f2bcec2e2a3d5d4b714be10bf4..a325a017d6792f0713513054052f889b3b185a5f 100644 (file)
@@ -151,13 +151,13 @@ recent_enough (int bar_number, SCM alteration_def, SCM laziness)
   return (bar_number <= scm_to_int (scm_cdr (alteration_def)) + scm_to_int (laziness));
 }
 
-static int
+static Rational
 extract_alteration (SCM alteration_def)
 {
   if (scm_is_number (alteration_def))
-    return scm_to_int (alteration_def);
+    return ly_scm2rational (alteration_def);
   else if (scm_is_pair (alteration_def))
-    return scm_to_int (scm_car (alteration_def));
+    return ly_scm2rational (scm_car (alteration_def));
   else if (alteration_def == SCM_BOOL_F)
     return 0;
   else
@@ -215,13 +215,13 @@ number_accidentals_from_sig (bool *different, SCM sig, Pitch *pitch,
     }
   else
     {
-      int prev = extract_alteration (previous_alteration);
-      int alter = pitch->get_alteration ();
+      Rational prev = extract_alteration (previous_alteration);
+      Rational alter = pitch->get_alteration ();
 
       if (alter == prev)
        num = 0;
-      else if ((abs (alter) < abs (prev)
-               || prev * alter < 0) && alter != 0)
+      else if ((alter.abs () < prev.abs ()
+               || (prev * alter).sign () < 0) && alter.sign ())
        num = 2;
       *different = (alter != prev);
     }
@@ -376,7 +376,7 @@ Accidental_engraver::create_accidental (Accidental_entry *entry,
   else
     a = make_standard_accidental (note, support, entry->origin_engraver_);
 
-  SCM accs = scm_cons (scm_from_int (pitch->get_alteration ()),
+  SCM accs = scm_cons (scm_from_int (pitch->get_alteration () * Rational (4)),
                       SCM_EOL);
   if (restore_natural)
     {
@@ -489,7 +489,7 @@ Accidental_engraver::stop_translation_timestep ()
 
       int n = pitch->get_notename ();
       int o = pitch->get_octave ();
-      int a = pitch->get_alteration ();
+      Rational a = pitch->get_alteration ();
       SCM key = scm_cons (scm_from_int (o), scm_from_int (n));
 
       SCM localsig = SCM_EOL;
@@ -515,7 +515,7 @@ Accidental_engraver::stop_translation_timestep ()
                noteheads with the same notename.
              */
              localsig = ly_assoc_front_x (localsig, key,
-                                          scm_cons (scm_from_int (a),
+                                          scm_cons (ly_rational2scm (a),
                                                     scm_from_int (barnum)));
              change = true;
            }
index 060c97849dcc6dc7ad37924368580512b8c3c8c2..6b9718f61c9ef923c6aaf4aed9bc194a47fcd775 100644 (file)
@@ -251,9 +251,6 @@ Accidental_interface::print (SCM smob)
   return mol.smobbed_copy ();
 }
 
-/*
-  TODO: should move avoid-slur into item?
-*/
 ADD_INTERFACE (Accidental_interface,
               "a single accidental",
               "accidentals "
index 58cd7098ccda3385e49e70365db60c0978b24856..0bf83bf354fbdd73863368367937440f54547c29 100644 (file)
@@ -60,7 +60,7 @@ Align_interface::stretch_after_break (SCM grob)
       for (vsize i = 0; i < elems.size (); i++)
        elems[i]->relative_coordinate (common, Y_AXIS);
 
-      SCM details =  me_spanner->get_bound (LEFT)->get_property ("line-break-system-details");
+      SCM details = me_spanner->get_bound (LEFT)->get_property ("line-break-system-details");
       SCM extra_space_handle = scm_assoc (ly_symbol2scm ("fixed-alignment-extra-space"), details);
       
       Real extra_space = robust_scm2double (scm_is_pair (extra_space_handle)
index 5946b91c6d7c7c1f42226f0726272f0c8db8ac1b..8f617652bfdd55a161b4c2a62a9f9523817d4e43 100644 (file)
@@ -148,8 +148,8 @@ Ambitus_engraver::finalize ()
            handle = scm_assoc (scm_from_int (p.get_notename ()),
                                start_key_sig_);
 
-         int sig_alter = (handle != SCM_BOOL_F)
-           ? scm_to_int (scm_cdr (handle)) : 0;
+         Rational sig_alter = (handle != SCM_BOOL_F)
+           ? ly_scm2rational (scm_cdr (handle)) : Rational (0);
 
          if (sig_alter == p.get_alteration ())
            {
@@ -158,7 +158,7 @@ Ambitus_engraver::finalize ()
            }
          else
            {
-             SCM l = scm_list_1 (scm_from_int (p.get_alteration ()));
+             SCM l = scm_list_1 (scm_from_int (int (Real (Rational (4) * p.get_alteration ()))));
              accidentals_[d]->set_property ("accidentals", l);
            }
        }
diff --git a/lily/guile-init.cc b/lily/guile-init.cc
new file mode 100644 (file)
index 0000000..77fd7c5
--- /dev/null
@@ -0,0 +1,54 @@
+/* 
+  guile-init.cc -- implement GUILE init routines.
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
+  
+*/
+
+#include  "lily-guile.hh"
+#include  "main.hh"
+#include  "warn.hh"
+
+/*
+  INIT
+*/
+
+
+typedef void (*Void_fptr) ();
+vector<Void_fptr> *scm_init_funcs_;
+
+void add_scm_init_func (void (*f) ())
+{
+  if (!scm_init_funcs_)
+    scm_init_funcs_ = new vector<Void_fptr>;
+
+  scm_init_funcs_->push_back (f);
+}
+
+void
+ly_init_ly_module (void *)
+{
+  for (vsize i = scm_init_funcs_->size (); i--;)
+    (scm_init_funcs_->at (i)) ();
+
+  if (be_verbose_global)
+    {
+      progress_indication ("[");
+      scm_display (scm_c_eval_string ("(%search-load-path \"lily.scm\")"),
+                  scm_current_error_port ());
+      progress_indication ("]\n");
+    }
+
+  scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
+}
+
+SCM global_lily_module;
+
+void
+ly_c_init_guile ()
+{
+  global_lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
+  scm_c_use_module ("lily");
+}
index 11f3cd31f5b90f2211578e0ed5f80c44968f415b..43009195c3cf1db2608bcea5f918df9727a339ff 100644 (file)
@@ -55,7 +55,7 @@ public:
 class Audio_note : public Audio_item
 {
 public:
-  Audio_note (Pitch p, Moment m, bool tie_event, int transposing_i);
+  Audio_note (Pitch p, Moment m, bool tie_event, int transposing);
 
   void tie_to (Audio_note *);
 
index 621849edc6a01344922a1f270e858581d7419df2..c2cfb8ebfca2f9961bee9bdc0a4f8d1aaeb415a0 100644 (file)
@@ -45,6 +45,8 @@ string gulp_file_to_string (string fn, bool must_exist, int size);
 
 string ly_scm2string (SCM s);
 string ly_symbol2string (SCM);
+Rational ly_scm2rational (SCM);
+SCM ly_rational2scm (Rational);
 SCM ly_offset2scm (Offset);
 Offset ly_scm2offset (SCM);
 SCM ly_chain_assoc (SCM key, SCM achain);
index c3082aaddd429231183583e2b9cd009925b300e5..d0b7c65b64955fea347ced6948d09efe2a178e41 100644 (file)
@@ -135,6 +135,7 @@ class Property_iterator;
 class Rational;
 class Relative_octave_music;
 class Repeated_music;
+class Scale;
 class Scheme_hash_table;
 class Score;
 class Score_context;
index 6ec530f68cfd0d1a4dd85ce495618a2f13ade476..a7e7ceb5125f3dc85d1061d8ce86cf83c7ed8ce7 100644 (file)
@@ -135,7 +135,7 @@ public:
   DECLARE_CLASSNAME(Midi_note);
 
   Moment get_length () const;
-  int get_pitch () const;
+  int get_semitone_pitch () const;
   int get_fine_tuning () const;
   virtual string to_string () const;
 
index f50d2d531c69e8fe148c8ab1708c77982f5b3dab..0e3be73917886a59c632908038478616b6c1f78f 100644 (file)
 
 #include "lily-proto.hh"
 #include "smobs.hh"
-
-#include "std-vector.hh"
-
-struct Scale
-{
-  vector<int> step_semitones_;
-  Scale ();
-  Scale (Scale const&);
-  DECLARE_SMOBS (Scale);
-};
+#include "rational.hh"
 
 
 /** A "tonal" pitch. This is a pitch used in diatonal western music
@@ -30,35 +21,27 @@ struct Scale
     Pitch is lexicographically ordered by (octave, notename,
     alteration).
 
-
-    TODO:
-
-    - add indeterminate octaves, so it can be used as a key in keySigature
 */
 class Pitch
 {
-private:                               // fixme
-  /*
-    TODO: use SCM
-  */
-
-  int notename_;
-  int alteration_;
+private:
   int octave_;
+  int notename_;
+  Rational alteration_;
   Scale *scale_;
-  
+
   void transpose (Pitch);
   void up_to (int);
   void down_to (int);
-  void normalise ();
+  void normalize ();
 
 public:
-
   int get_octave () const;
   int get_notename () const;
-  int get_alteration () const;
+  Rational get_alteration () const;
 
-  Pitch (int octave, int notename, int accidental);
+  Pitch (int octave, int notename, Rational accidental);
+  Pitch (int octave, int notename);
   Pitch ();
 
   Pitch transposed (Pitch) const;
@@ -67,26 +50,38 @@ public:
   static int compare (Pitch const &, Pitch const &);
 
   int steps () const;
-  int semitone_pitch () const;
-  int quartertone_pitch () const;
+  Rational tone_pitch () const;
+  int rounded_semitone_pitch () const;
+  int rounded_quartertone_pitch () const;
+
   string to_string () const;
 
   DECLARE_SCHEME_CALLBACK (less_p, (SCM a, SCM b));
   DECLARE_SIMPLE_SMOBS (Pitch);
 };
 
-enum
-  {
-    DOUBLE_FLAT = -4,
-    THREE_Q_FLAT,
-    FLAT,
-    SEMI_FLAT,
-    NATURAL,
-    SEMI_SHARP,
-    SHARP,
-    THREE_Q_SHARP,
-    DOUBLE_SHARP,
-  };
+
+enum {
+  DOUBLE_FLAT = -4,
+  THREE_Q_FLAT,
+  FLAT,
+  SEMI_FLAT,
+  NATURAL,
+  SEMI_SHARP,
+  SHARP,
+  THREE_Q_SHARP,
+  DOUBLE_SHARP,
+};
+
+extern Rational  DOUBLE_FLAT_ALTERATION;
+extern Rational  THREE_Q_FLAT_ALTERATION;
+extern Rational  FLAT_ALTERATION;
+extern Rational  SEMI_FLAT_ALTERATION;
+extern Rational  NATURAL_ALTERATION;
+extern Rational  SEMI_SHARP_ALTERATION;
+extern Rational  SHARP_ALTERATION;
+extern Rational  THREE_Q_SHARP_ALTERATION;
+extern Rational  DOUBLE_SHARP_ALTERATION;
 
 SCM ly_pitch_diff (SCM pitch, SCM root);
 SCM ly_pitch_transpose (SCM p, SCM delta);
@@ -96,7 +91,6 @@ INSTANTIATE_COMPARE (Pitch, Pitch::compare);
 
 extern SCM pitch_less_proc;
 Pitch pitch_interval (Pitch const &from, Pitch const &to);
-extern Scale *default_global_scale;
 
 #endif /* MUSICAL_PITCH_HH */
 
diff --git a/lily/include/scale.hh b/lily/include/scale.hh
new file mode 100644 (file)
index 0000000..58bec89
--- /dev/null
@@ -0,0 +1,29 @@
+/* 
+  scale.hh -- declare Scale
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
+  
+*/
+
+#ifndef SCALE_HH
+#define SCALE_HH
+
+#include "smobs.hh"
+#include "rational.hh"
+#include "std-vector.hh"
+
+struct Scale
+{
+  vector<Rational> step_tones_;
+  Scale ();
+  Scale (Scale const&);
+  DECLARE_SMOBS (Scale);
+};
+
+extern Scale *default_global_scale;
+
+#endif /* SCALE_HH */
+
+
index 41cb7aed5095e1cc3383a56377a2c24c2272d0c2..54c9832cc8ebd74a00b3c44f540775d665706ad6 100644 (file)
 
 #include "translator.icc"
 
-/*
-  TODO: The representation  of key sigs is all fucked.
-*/
-
-/**
-   Make the key signature.
-*/
 class Key_engraver : public Engraver
 {
   void create_key (bool);
@@ -59,6 +52,24 @@ Key_engraver::Key_engraver ()
   cancellation_ = 0;
 }
 
+
+SCM
+make_qt_key (SCM rat_key)
+{
+  SCM qt_key = SCM_EOL;
+  SCM *tail = &qt_key;
+      
+  for (SCM s = rat_key; scm_is_pair (s); s = scm_cdr (s))
+    {
+      *tail = scm_cons (scm_cons (scm_caar (s),
+                                 scm_from_int (Rational (4)* ly_scm2rational (scm_cdar (s)))),
+                       SCM_EOL);
+      tail =  SCM_CDRLOC (*tail);
+    }
+
+  return qt_key;
+}
+
 void
 Key_engraver::create_key (bool is_default)
 {
@@ -83,10 +94,10 @@ Key_engraver::create_key (bool is_default)
          for (SCM s = last; scm_is_pair (s); s = scm_cdr (s))
            {
              SCM new_alter_pair = scm_assoc (scm_caar (s), key);
-             int old_alter = scm_to_int (scm_cdar (s));
+             Rational old_alter = ly_scm2rational (scm_cdar (s));
              if (new_alter_pair == SCM_BOOL_F
                  || extranatural
-                    && (scm_to_int(scm_cdr(new_alter_pair))-old_alter)*old_alter < 0)
+                 && (ly_scm2rational (scm_cdr (new_alter_pair)) - old_alter)*old_alter < Rational (0))
                {
                  *tail = scm_cons (scm_car (s), *tail);
                  tail = SCM_CDRLOC (*tail);
@@ -99,12 +110,14 @@ Key_engraver::create_key (bool is_default)
                                         key_event_
                                         ? key_event_->self_scm () : SCM_EOL);
              
-             cancellation_->set_property ("alteration-alist", restore);
+             cancellation_->set_property ("alteration-alist", make_qt_key (restore));
              cancellation_->set_property ("c0-position",
                                           get_property ("middleCPosition"));
            }
        }
-      item_->set_property ("alteration-alist", key);
+
+
+      item_->set_property ("alteration-alist", make_qt_key (key));
     }
 
   if (!is_default)
@@ -179,7 +192,7 @@ Key_engraver::read_event (Stream_event const *r)
     }
 
   for (SCM s = n; scm_is_pair (s); s = scm_cdr (s))
-    if (scm_to_int (scm_cdar (s)))
+    if (ly_scm2rational (scm_cdar (s)))
       accs = scm_cons (scm_car (s), accs);
 
   context ()->set_property ("keySignature", accs);
index 61e3592630577e782c5edc3478c177df7aa1b6bd..9bb8b11a48edcabdfbb3330ebb24d85a2f60bee0 100644 (file)
@@ -66,8 +66,8 @@ Key_performer::process_music ()
       SCM third = scm_assoc (scm_from_int (2),
                             c_pitchlist);
       bool minor = (scm_is_pair (third)
-                   && scm_is_integer (scm_cdr (third))
-                   && scm_to_int (scm_cdr (third)) == FLAT);
+                   && scm_is_number (scm_cdr (third))
+                   && ly_scm2rational (scm_cdr (third)) == FLAT_ALTERATION);
 
       audio_ = new Audio_key (scm_to_int (acc),
                              !minor);
@@ -96,5 +96,7 @@ Key_performer::listen_key_change (Stream_event *ev)
 }
 
 ADD_TRANSLATOR (Key_performer,
-               "", "",
-               "", "");
+               "",
+               "",
+               "",
+               "");
index 37f985697ea85844ec17ed41ea3ad01cb919f9f7..a6ff448943c92b5e7c68cd2522825c6258eca00a 100644 (file)
@@ -160,4 +160,8 @@ Key_signature_interface::print (SCM smob)
 
 ADD_INTERFACE (Key_signature_interface,
               "A group of accidentals, to be printed as signature sign.",
-              "style c0-position alteration-alist");
+
+              "c0-position "
+              "style "
+              "alteration-alist "
+              );
index d57a9f5730e7e936fdd7b2307aa49dc9359e20ea..182ed7e02a2dc4f4792c46731f242ca26160a03f 100644 (file)
@@ -30,8 +30,10 @@ using namespace std;
 #include "version.hh"
 #include "warn.hh"
 
-// #define TEST_GC
 
+/*
+  symbols/strings.
+ */
 SCM
 ly_to_symbol (SCM scm)
 {
@@ -46,12 +48,6 @@ ly_to_string (SCM scm)
                     scm_makfrom0str ("~S"), scm);
 }
 
-SCM
-ly_last (SCM list)
-{
-  return scm_car (scm_last_pair (list));
-}
-
 SCM
 ly_write2scm (SCM s)
 {
@@ -122,6 +118,9 @@ extern "C" {
   }
 };
 
+/*
+  STRINGS
+ */
 string
 ly_scm2string (SCM str)
 {
@@ -149,6 +148,10 @@ ly_scm2newstr (SCM str, size_t *lenp)
   return 0;
 }
 
+
+/*
+  PAIRS
+*/
 SCM
 index_get_cell (SCM s, Direction d)
 {
@@ -174,77 +177,62 @@ is_number_pair (SCM p)
     && scm_is_number (scm_car (p)) && scm_is_number (scm_cdr (p));
 }
 
-typedef void (*Void_fptr) ();
-vector<Void_fptr> *scm_init_funcs_;
 
-void add_scm_init_func (void (*f) ())
+unsigned int
+ly_scm_hash (SCM s)
 {
-  if (!scm_init_funcs_)
-    scm_init_funcs_ = new vector<Void_fptr>;
-
-  scm_init_funcs_->push_back (f);
+  return scm_ihashv (s, ~1u);
 }
 
-void
-ly_init_ly_module (void *)
-{
-  for (vsize i = scm_init_funcs_->size (); i--;)
-    (scm_init_funcs_->at (i)) ();
 
-  if (be_verbose_global)
+bool
+is_axis (SCM s)
+{
+  if (scm_is_number (s))
     {
-      progress_indication ("[");
-      scm_display (scm_c_eval_string ("(%search-load-path \"lily.scm\")"),
-                  scm_current_error_port ());
-      progress_indication ("]\n");
+      int i = scm_to_int (s);
+      return i == 0 || i == 1;
     }
-
-  scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
+  return false;
 }
 
-SCM global_lily_module;
-
-void
-ly_c_init_guile ()
+bool
+to_boolean (SCM s)
 {
-  global_lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
-  scm_c_use_module ("lily");
+  return scm_is_bool (s) && ly_scm2bool (s);
 }
 
-unsigned int
-ly_scm_hash (SCM s)
+/*
+  DIRECTIONS
+ */
+Direction
+to_dir (SCM s)
 {
-  return scm_ihashv (s, ~1u);
+  return scm_is_integer (s) ? (Direction) scm_to_int (s) : CENTER;
 }
 
-bool
-is_direction (SCM s)
+Direction
+robust_scm2dir (SCM d, Direction def)
 {
-  if (scm_is_number (s))
-    {
-      int i = scm_to_int (s);
-      return i >= -1 && i <= 1;
-    }
-  return false;
+  if (is_direction (d))
+    def = to_dir (d);
+  return def;
 }
 
 bool
-is_axis (SCM s)
+is_direction (SCM s)
 {
   if (scm_is_number (s))
     {
       int i = scm_to_int (s);
-      return i == 0 || i == 1;
+      return i >= -1 && i <= 1;
     }
   return false;
 }
 
-Direction
-to_dir (SCM s)
-{
-  return scm_is_integer (s) ? (Direction) scm_to_int (s) : CENTER;
-}
-
+/*
+  INTERVALS
+ */
 Interval
 ly_scm2interval (SCM p)
 {
@@ -264,32 +252,40 @@ ly_interval2scm (Drul_array<Real> i)
   return scm_cons (scm_from_double (i[LEFT]), scm_from_double (i[RIGHT]));
 }
 
-bool
-to_boolean (SCM s)
+
+Interval
+robust_scm2interval (SCM k, Drul_array<Real> v)
 {
-  return scm_is_bool (s) && ly_scm2bool (s);
+  Interval i;
+  i[LEFT] = v[LEFT];
+  i[RIGHT] = v[RIGHT];
+  if (is_number_pair (k))
+    i = ly_scm2interval (k);
+  return i;
 }
 
-/* Appendable list L: the cdr contains the list, the car the last cons
-   in the list.  */
-SCM
-appendable_list ()
+Drul_array<Real>
+robust_scm2drul (SCM k, Drul_array<Real> v)
 {
-  SCM s = scm_cons (SCM_EOL, SCM_EOL);
-  scm_set_car_x (s, s);
-
-  return s;
+  if (is_number_pair (k))
+    v = ly_scm2interval (k);
+  return v;
 }
 
-void
-appendable_list_append (SCM l, SCM elt)
+Drul_array<bool>
+robust_scm2booldrul (SCM k, Drul_array<bool> def)
 {
-  SCM newcons = scm_cons (elt, SCM_EOL);
-
-  scm_set_cdr_x (scm_car (l), newcons);
-  scm_set_car_x (l, newcons);
+  if (scm_is_pair (k))
+    {
+      def[LEFT] = to_boolean (scm_car (k));
+      def[RIGHT] = to_boolean (scm_cdr (k));
+    }
+  return def;
 }
 
+/*
+  OFFSET
+*/
 SCM
 ly_offset2scm (Offset o)
 {
@@ -303,6 +299,13 @@ ly_scm2offset (SCM s)
                 scm_to_double (scm_cdr (s)));
 }
 
+Offset
+robust_scm2offset (SCM k, Offset o)
+{
+  if (is_number_pair (k))
+    o = ly_scm2offset (k);
+  return o;
+}
 SCM
 ly_offsets2scm (vector<Offset> os)
 {
@@ -325,23 +328,12 @@ ly_scm2offsets (SCM s)
   return os;
 }
 
-SCM
-ly_deep_copy (SCM src)
-{
-  if (scm_is_pair (src))
-    return scm_cons (ly_deep_copy (scm_car (src)), ly_deep_copy (scm_cdr (src)));
-  else if (scm_is_vector (src))
-    {
-      int len = scm_c_vector_length (src);
-      SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
-      for (int i = 0;i < len; i++)
-       {
-         SCM si = scm_from_int (i);
-         scm_vector_set_x (nv, si, ly_deep_copy (scm_vector_ref (src, si)));
-       }
-    }
-  return src;
-}
+
+
+
+/*
+  ALIST
+*/
 
 /* looks the key up in the cdrs of the alist-keys
    - ignoring the car and ignoring non-pair keys.
@@ -373,27 +365,70 @@ ly_assoc_cdr (SCM key, SCM alist)
   return SCM_BOOL_F;
 }
 
+
+bool
+alist_equal_p (SCM a, SCM b)
+{
+  for (SCM s = a;
+       scm_is_pair (s); s = scm_cdr (s))
+    {
+      SCM key = scm_caar (s);
+      SCM val = scm_cdar (s);
+      SCM l = scm_assoc (key, b);
+
+      if (l == SCM_BOOL_F
+         || !ly_is_equal (scm_cdr (l), val))
+
+       return false;
+    }
+  return true;
+}
+
 SCM
-ly_string_array_to_scm (vector<string> a)
+ly_alist_vals (SCM alist)
 {
-  SCM s = SCM_EOL;
-  for (vsize i = a.size (); i ; i--)
-    s = scm_cons (ly_symbol2scm (a[i - 1].c_str ()), s);
-  return s;
+  SCM x = SCM_EOL;
+  for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p))
+    x = scm_cons (scm_cdar (p), x);
+  return x;
 }
 
-/* SYMBOLS is a whitespace separated list.  */
+/*
+  LISTS
+ */
+
+/* Return I-th element, or last elt L. If I < 0, then we take the first
+   element.
+
+   PRE: length (L) > 0  */
 SCM
-parse_symbol_list (char const *symbols)
+robust_list_ref (int i, SCM l)
 {
-  while (isspace (*symbols))
-    *symbols++;
-  string s = symbols;
-  replace_all (s, '\n', ' ');
-  replace_all (s, '\t', ' ');
-  return ly_string_array_to_scm (string_split (s, ' '));
+  while (i-- > 0 && scm_is_pair (scm_cdr (l)))
+    l = scm_cdr (l);
+  return scm_car (l);
 }
 
+
+SCM
+ly_deep_copy (SCM src)
+{
+  if (scm_is_pair (src))
+    return scm_cons (ly_deep_copy (scm_car (src)), ly_deep_copy (scm_cdr (src)));
+  else if (scm_is_vector (src))
+    {
+      int len = scm_c_vector_length (src);
+      SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
+      for (int i = 0;i < len; i++)
+       {
+         SCM si = scm_from_int (i);
+         scm_vector_set_x (nv, si, ly_deep_copy (scm_vector_ref (src, si)));
+       }
+    }
+  return src;
+}
+
+
 SCM
 ly_truncate_list (int k, SCM lst)
 {
@@ -412,6 +447,30 @@ ly_truncate_list (int k, SCM lst)
   return lst;
 }
 
+
+
+
+/* Appendable list L: the cdr contains the list, the car the last cons
+   in the list.  */
+SCM
+appendable_list ()
+{
+  SCM s = scm_cons (SCM_EOL, SCM_EOL);
+  scm_set_car_x (s, s);
+
+  return s;
+}
+
+void
+appendable_list_append (SCM l, SCM elt)
+{
+  SCM newcons = scm_cons (elt, SCM_EOL);
+
+  scm_set_cdr_x (scm_car (l), newcons);
+  scm_set_car_x (l, newcons);
+}
+
+
 string
 print_scm_val (SCM val)
 {
@@ -506,6 +565,7 @@ ly_unique (SCM list)
   return scm_reverse_x (unique, SCM_EOL);
 }
 
+
 static int
 scm_default_compare (void const *a, void const *b)
 {
@@ -545,13 +605,6 @@ ly_list_qsort_uniq_x (SCM lst)
   return lst;
 }
 
-/* tail add */
-SCM
-ly_snoc (SCM s, SCM list)
-{
-  return ly_append2 (list, scm_list_n (s, SCM_UNDEFINED));
-}
-
 /* Split list at member s, removing s.
    Return (BEFORE . AFTER)  */
 SCM
@@ -607,18 +660,6 @@ int_list_to_slice (SCM l)
   return s;
 }
 
-/* Return I-th element, or last elt L. If I < 0, then we take the first
-   element.
-
-   PRE: length (L) > 0  */
-SCM
-robust_list_ref (int i, SCM l)
-{
-  while (i-- > 0 && scm_is_pair (scm_cdr (l)))
-    l = scm_cdr (l);
-  return scm_car (l);
-}
-
 Real
 robust_scm2double (SCM k, double x)
 {
@@ -627,51 +668,6 @@ robust_scm2double (SCM k, double x)
   return x;
 }
 
-Direction
-robust_scm2dir (SCM d, Direction def)
-{
-  if (is_direction (d))
-    def = to_dir (d);
-  return def;
-}
-
-Interval
-robust_scm2interval (SCM k, Drul_array<Real> v)
-{
-  Interval i;
-  i[LEFT] = v[LEFT];
-  i[RIGHT] = v[RIGHT];
-  if (is_number_pair (k))
-    i = ly_scm2interval (k);
-  return i;
-}
-
-Drul_array<Real>
-robust_scm2drul (SCM k, Drul_array<Real> v)
-{
-  if (is_number_pair (k))
-    v = ly_scm2interval (k);
-  return v;
-}
-
-Drul_array<bool>
-robust_scm2booldrul (SCM k, Drul_array<bool> def)
-{
-  if (scm_is_pair (k))
-    {
-      def[LEFT] = to_boolean (scm_car (k));
-      def[RIGHT] = to_boolean (scm_cdr (k));
-    }
-  return def;
-}
-
-Offset
-robust_scm2offset (SCM k, Offset o)
-{
-  if (is_number_pair (k))
-    o = ly_scm2offset (k);
-  return o;
-}
 
 string
 robust_scm2string (SCM k, string s)
@@ -689,6 +685,22 @@ robust_scm2int (SCM k, int o)
   return o;
 }
 
+
+SCM
+ly_rational2scm (Rational r)
+{
+  return scm_divide (scm_from_int (r.numerator ()), scm_from_int (r.denominator ()));
+}
+
+
+Rational
+ly_scm2rational (SCM r)
+{
+  return Rational (scm_to_int (scm_numerator (r)),
+                  scm_to_int (scm_denominator (r)));
+}
+
+
 SCM
 alist_to_hashq (SCM alist)
 {
@@ -705,33 +717,6 @@ alist_to_hashq (SCM alist)
   return tab;
 }
 
-bool
-alist_equal_p (SCM a, SCM b)
-{
-  for (SCM s = a;
-       scm_is_pair (s); s = scm_cdr (s))
-    {
-      SCM key = scm_caar (s);
-      SCM val = scm_cdar (s);
-      SCM l = scm_assoc (key, b);
-
-      if (l == SCM_BOOL_F
-         || !ly_is_equal (scm_cdr (l), val))
-
-       return false;
-    }
-  return true;
-}
-
-SCM
-ly_alist_vals (SCM alist)
-{
-  SCM x = SCM_EOL;
-  for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p))
-    x = scm_cons (scm_cdar (p), x);
-  return x;
-}
-
 SCM
 ly_hash2alist (SCM tab)
 {
@@ -750,6 +735,10 @@ procedure_arity (SCM proc)
   return scm_to_int (fixed);
 }
 
+/*
+  C++ interfacing.
+ */
+
 string
 mangle_cxx_identifier (string cxx_id)
 {
@@ -769,3 +758,25 @@ mangle_cxx_identifier (string cxx_id)
   return cxx_id;
 }
 
+
+
+SCM
+ly_string_array_to_scm (vector<string> a)
+{
+  SCM s = SCM_EOL;
+  for (vsize i = a.size (); i ; i--)
+    s = scm_cons (ly_symbol2scm (a[i - 1].c_str ()), s);
+  return s;
+}
+
+/* SYMBOLS is a whitespace separated list.  */
+SCM
+parse_symbol_list (char const *symbols)
+{
+  while (isspace (*symbols))
+    *symbols++;
+  string s = symbols;
+  replace_all (s, '\n', ' ');
+  replace_all (s, '\t', ' ');
+  return ly_string_array_to_scm (string_split (s, ' '));
+}
index 88d303b4e7d80f7952ee4690cf18c245489ab6f7..10b7f2715c0c1674c322fd795056367c489db336 100644 (file)
@@ -258,22 +258,18 @@ Midi_note::get_length () const
 int
 Midi_note::get_fine_tuning () const
 {
-  int ft = audio_->pitch_.quartertone_pitch ();
-  ft -= 2 * audio_->pitch_.semitone_pitch ();
-  ft *= 50; // 1 quarter tone = 50 cents
-  return ft;
+  Rational tune = audio_->pitch_.tone_pitch () * Rational (2);
+  tune -= Rational (get_semitone_pitch ());
+
+  tune *= 100;
+  return (int) double (tune);
 }
 
 int
-Midi_note::get_pitch () const
+Midi_note::get_semitone_pitch () const
 {
-  int p = audio_->pitch_.semitone_pitch () + audio_->transposing_;
-  if (p == INT_MAX)
-    {
-      warning (_ ("silly pitch"));
-      p = 0;
-    }
-  return p;
+  return int (rint (double (audio_->pitch_.tone_pitch () *  Rational (2, 1))))
+    + audio_->transposing_;
 }
 
 string
@@ -301,7 +297,7 @@ Midi_note::to_string () const
     }
 
   str += ::to_string ((char)status_byte);
-  str += ::to_string ((char) (get_pitch () + c0_pitch_));
+  str += ::to_string ((char) (get_semitone_pitch () + c0_pitch_));
   str += ::to_string ((char)dynamic_byte_);
 
   return str;
@@ -326,7 +322,7 @@ Midi_note_off::to_string () const
   Byte status_byte = (char) (0x80 + channel_);
 
   string str = ::to_string ((char)status_byte);
-  str += ::to_string ((char) (get_pitch () + Midi_note::c0_pitch_));
+  str += ::to_string ((char) (get_semitone_pitch () + Midi_note::c0_pitch_));
   str += ::to_string ((char)aftertouch_byte_);
 
   if (get_fine_tuning () != 0)
index 2979c9380ce1127a3d6687180840ca1a70315730..c2aaa085b14d5ee5eab73e2f722524db7f535d2e 100644 (file)
@@ -63,7 +63,7 @@ Midi_walker::do_start_note (Midi_note *note)
   for (vsize i = 0; i < stop_note_queue.size (); i++)
     {
       /* if this pith already in queue */
-      if (stop_note_queue[i].val->get_pitch () == note->get_pitch ())
+      if (stop_note_queue[i].val->get_semitone_pitch () == note->get_semitone_pitch ())
        {
          if (stop_note_queue[i].key < stop_mom)
            {
index 365c3f434474166b64fa6b5df2b9dc03005ecfb5..82f52a5c0055b99af8f41a5dae565fa133f5d4e5 100644 (file)
@@ -191,23 +191,23 @@ LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist",
        {
          Pitch orig (scm_to_int (scm_car (key)),
                      scm_to_int (scm_cdr (key)),
-                     scm_to_int (alter));
+                     ly_scm2rational (alter));
 
          orig = orig.transposed (*p);
 
          SCM key = scm_cons (scm_from_int (orig.get_octave ()),
                              scm_from_int (orig.get_notename ()));
 
-         newlist = scm_cons (scm_cons (key, scm_from_int (orig.get_alteration ())),
+         newlist = scm_cons (scm_cons (key, ly_rational2scm (orig.get_alteration ())),
                              newlist);
        }
       else if (scm_is_number (key))
        {
-         Pitch orig (0, scm_to_int (key), scm_to_int (alter));
+         Pitch orig (0, scm_to_int (key), ly_scm2rational (alter));
          orig = orig.transposed (*p);
 
          key = scm_from_int (orig.get_notename ());
-         alter = scm_from_int (orig.get_alteration ());
+         alter = ly_rational2scm (orig.get_alteration ());
          newlist = scm_cons (scm_cons (key, alter), newlist);
        }
     }
index fb272aae0372af067db72aeef159af97d50271dd..dd53e98643274745dcc1439f889c71e88ddcbfd1 100644 (file)
@@ -202,7 +202,7 @@ transpose_mutable (SCM alist, Pitch delta)
          Pitch transposed = p->transposed (delta);
          scm_set_cdr_x (entry, transposed.smobbed_copy ());
 
-         if (abs (transposed.get_alteration ()) > DOUBLE_SHARP)
+         if (transposed.get_alteration ().abs () > Rational (1,1))
            {
              warning (_f ("transposition by %s makes alteration larger than double",
                           delta.to_string ()));
@@ -217,7 +217,8 @@ transpose_mutable (SCM alist, Pitch delta)
        transpose_music_list (val, delta);
       else if (prop == ly_symbol2scm ("pitch-alist") &&
               scm_is_pair (val))
-       entry = scm_cons (prop, ly_transpose_key_alist (val, delta.smobbed_copy ()));
+       entry = scm_cons (prop,
+                         ly_transpose_key_alist (val, delta.smobbed_copy ()));
       retval = scm_cons (entry, retval);
     }
 
index 8d9dfb44c17c4005d169d54f0cc77435bf2fc709..e5c2ef9e050d83b60b5338d21dbfb5f5aab2addf 100644 (file)
@@ -42,7 +42,7 @@ Note_performer::process_music ()
 
       SCM prop = get_property ("instrumentTransposition");
       if (unsmob_pitch (prop))
-       transposing = unsmob_pitch (prop)->semitone_pitch ();
+       transposing = unsmob_pitch (prop)->rounded_semitone_pitch ();
 
       while (note_evs_.size ())
        {
index 64d6103d44d51dff51dd7900ed4100c4551802c5..ebb322d7731ef9009e247d1df953896b9b71afa5 100644 (file)
@@ -136,7 +136,7 @@ SCM make_music_relative (Pitch start, SCM music, Input loc);
 SCM run_music_function (Lily_parser *, SCM expr);
 SCM get_first_context_id (SCM type, Music *m);
 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
-SCM make_chord_step (int step, int alter);
+SCM make_chord_step (int step, Rational alter);
 SCM make_simple_markup (SCM a);
 bool is_duration (int t);
 bool is_regular_identifier (SCM id);
@@ -1661,7 +1661,7 @@ steno_tonic_pitch:
                $$ = p.smobbed_copy ();
        }
        | TONICNAME_PITCH sub_quotes     {
-               Pitch p =unsmob_pitch ($1);
+               Pitch p = *unsmob_pitch ($1);
 
                p = p.transposed (Pitch (-$2,0,0));
                $$ = p.smobbed_copy ();
@@ -2063,10 +2063,10 @@ step_number:
                $$ = make_chord_step ($1, 0);
         }
        | bare_unsigned '+' {
-               $$ = make_chord_step ($1, SHARP);
+               $$ = make_chord_step ($1, SHARP_ALTERATION);
        }
        | bare_unsigned CHORD_MINUS {
-               $$ = make_chord_step ($1, FLAT);
+               $$ = make_chord_step ($1, FLAT_ALTERATION);
        }
        ;       
 
@@ -2470,10 +2470,10 @@ set_music_properties (Music *p, SCM a)
 
 
 SCM
-make_chord_step (int step, int alter)
+make_chord_step (int step, Rational alter)
 {
        if (step == 7)
-               alter += FLAT;
+               alter += FLAT_ALTERATION;
 
        while (step < 0)
                step += 7;
index 3beb9f43cf94ccffe41a07fcb73f76de6a09524f..16b78e9420348422935fb6cba17ed3a505389de2 100644 (file)
@@ -22,19 +22,21 @@ LY_DEFINE (ly_pitch_transpose, "ly:pitch-transpose",
 
 /* Should add optional args.  */
 LY_DEFINE (ly_make_pitch, "ly:make-pitch",
-          3, 0, 0, (SCM octave, SCM note, SCM alter),
+          2, 1, 0, (SCM octave, SCM note, SCM alter),
           "@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 @var{alter} is zero for a natural, negative for "
-          "flats, or positive for sharps. ")
+          "The @var{alter} is a rational number of whole tones for alteration.")
 {
-  SCM_ASSERT_TYPE (scm_integer_p (octave) == SCM_BOOL_T, octave, SCM_ARG1, __FUNCTION__, "integer");
-  SCM_ASSERT_TYPE (scm_integer_p (note) == SCM_BOOL_T, note, SCM_ARG2, __FUNCTION__, "integer");
-  SCM_ASSERT_TYPE (scm_integer_p (alter) == SCM_BOOL_T, alter, SCM_ARG3, __FUNCTION__, "integer");
-
-  Pitch p (scm_to_int (octave), scm_to_int (note), scm_to_int (alter));
+  SCM_ASSERT_TYPE (scm_is_integer (octave), octave, SCM_ARG1, __FUNCTION__, "integer");
+  SCM_ASSERT_TYPE (scm_is_integer (note), note, SCM_ARG2, __FUNCTION__, "integer");
+  SCM_ASSERT_TYPE (scm_is_rational (alter),
+                  alter, SCM_ARG3, __FUNCTION__, "rational");
+  
+  Pitch p (scm_to_int (octave), scm_to_int (note),
+          ly_scm2rational (alter));
+  
   return p.smobbed_copy ();
 }
 
@@ -63,9 +65,9 @@ LY_DEFINE (ly_pitch_alteration, "ly:pitch-alteration",
 {
   Pitch *p = unsmob_pitch (pp);
   SCM_ASSERT_TYPE (p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
-  int q = p->get_alteration ();
+  Rational q = p->get_alteration ();
 
-  return scm_from_int (q);
+  return ly_rational2scm (q);
 }
 
 LY_DEFINE (pitch_notename, "ly:pitch-notename",
@@ -84,7 +86,7 @@ LY_DEFINE (ly_pitch_quartertones, "ly:pitch-quartertones",
 {
   Pitch *p = unsmob_pitch (pp);
   SCM_ASSERT_TYPE (p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
-  int q = p->quartertone_pitch ();
+  int q = p->rounded_quartertone_pitch ();
   return scm_from_int (q);
 }
 
@@ -94,7 +96,7 @@ LY_DEFINE (ly_pitch_semitones, "ly:pitch-semitones",
 {
   Pitch *p = unsmob_pitch (pp);
   SCM_ASSERT_TYPE (p, pp, SCM_ARG1, __FUNCTION__, "Pitch");
-  int q = p->semitone_pitch ();
+  int q = p->rounded_semitone_pitch ();
   return scm_from_int (q);
 }
 
index 566b729e24fdacd7c1bca1df2ff8aecc6f071357..4d983ab6d5e4e6a729e0440c51d9e6e302426285 100644 (file)
@@ -9,25 +9,26 @@
 #include "pitch.hh"
 
 #include "main.hh"
+#include "scale.hh"
 #include "string-convert.hh"
 #include "warn.hh"
 
 #include "ly-smobs.icc"
 
-Pitch::Pitch (int o, int n, int a)
+
+Pitch::Pitch (int o, int n, Rational a)
 {
   notename_ = n;
   alteration_ = a;
   octave_ = o;
   scale_ = default_global_scale; 
-  normalise ();
+  normalize ();
 }
 
 /* FIXME: why is octave == 0 and default not middleC ? */
 Pitch::Pitch ()
 {
   notename_ = 0;
-  alteration_ = 0;
   scale_ = default_global_scale; 
   octave_ = 0;
 }
@@ -37,7 +38,7 @@ Pitch::compare (Pitch const &m1, Pitch const &m2)
 {
   int o = m1.octave_ - m2.octave_;
   int n = m1.notename_ - m2.notename_;
-  int a = m1.alteration_ - m2.alteration_;
+  Rational a = m1.alteration_ - m2.alteration_;
 
   if (o)
     return o;
@@ -45,76 +46,69 @@ Pitch::compare (Pitch const &m1, Pitch const &m2)
     return n;
   if (a)
     return a;
+  
   return 0;
 }
 
 int
 Pitch::steps () const
 {
-  return notename_ + octave_ * scale_->step_semitones_.size ();
+  return notename_ + octave_ * scale_->step_tones_.size ();
 }
 
-/* Should be settable from input?  */
-// static Byte diatonic_scale_semitones[ ] = { 0, 2, 4, 5, 7, 9, 11 };
-
-
-
-/* Calculate pitch height in 12th octave steps.  Don't assume
-   normalised pitch as this function is used to normalise the pitch.  */
-int
-Pitch::semitone_pitch () const
+Rational
+Pitch::tone_pitch () const
 {
   int o = octave_;
   int n = notename_;
   while (n < 0)
     {
-      n += scale_->step_semitones_.size ();
+      n += scale_->step_tones_.size ();
       o--;
     }
 
-  if (alteration_ % 2)
-    programming_error ("semitone_pitch () called on quarter tone alteration.");
+  Rational tones ((o + n / scale_->step_tones_.size ()) * 6, 1);
+  tones += scale_->step_tones_[n % scale_->step_tones_.size ()];
 
-  return ((o + n / scale_->step_semitones_.size ()) * 12
-         + scale_->step_semitones_[n % scale_->step_semitones_.size ()]
-         + (alteration_ / 2));
+  tones += alteration_;
+  
+  return tones;
 }
 
+/* Calculate pitch height in 12th octave steps.  Don't assume
+   normalized pitch as this function is used to normalize the pitch.  */
 int
-Pitch::quartertone_pitch () const
+Pitch::rounded_semitone_pitch () const
 {
-  int o = octave_;
-  int n = notename_;
-  while (n < 0)
-    {
-      n += scale_->step_semitones_.size ();
-      o--;
-    }
+  return int (double (tone_pitch () * Rational (2)));
+}
 
-  return ((o + n / scale_->step_semitones_.size ()) * 24
-         + 2 * scale_->step_semitones_[n % scale_->step_semitones_.size ()]
-         + alteration_);
+int
+Pitch::rounded_quartertone_pitch () const
+{
+  return int (double (tone_pitch () * Rational (4)));
 }
 
 void
-Pitch::normalise ()
+Pitch::normalize ()
 {
-  int pitch = quartertone_pitch ();
-  while (notename_ >= (int) scale_->step_semitones_.size ())
+  Rational pitch = tone_pitch ();
+  while (notename_ >= (int) scale_->step_tones_.size ())
     {
-      notename_ -= scale_->step_semitones_.size ();
+      notename_ -= scale_->step_tones_.size ();
       octave_++;
-      alteration_ -= quartertone_pitch () - pitch;
+      alteration_ -= tone_pitch () - pitch;
     }
   while (notename_ < 0)
     {
-      notename_ += scale_->step_semitones_.size ();
+      notename_ += scale_->step_tones_.size ();
       octave_--;
-      alteration_ -= quartertone_pitch () - pitch;
+      alteration_ -= tone_pitch () - pitch;
     }
-  while (alteration_ > DOUBLE_SHARP)
+
+  while (alteration_ > Rational (1))
     {
-      if (notename_ == 6)
+      if (notename_ == int (scale_->step_tones_.size ()))
        {
          notename_ = 0;
          octave_++;
@@ -122,47 +116,46 @@ Pitch::normalise ()
       else
        notename_++;
 
-      alteration_ = 0;
-      alteration_ -= quartertone_pitch () - pitch;
+      alteration_ = Rational (0);
+      alteration_ -= tone_pitch () - pitch;
     }
-
-  while (alteration_ < DOUBLE_FLAT)
+  while (alteration_ < Rational(-1))
     {
       if (notename_ == 0)
        {
-         notename_ = 6;
+         notename_ = scale_->step_tones_.size ();
          octave_--;
        }
       else
        notename_--;
 
       alteration_ = 0;
-      alteration_ -= quartertone_pitch () - pitch;
+      alteration_ -= tone_pitch () - pitch;
     }
 }
 
-/* WHugh, wat een intervaas */
 void
 Pitch::transpose (Pitch delta)
 {
-  int new_semi = quartertone_pitch () +delta.quartertone_pitch ();
+  Rational new_alter = tone_pitch () + delta.tone_pitch ();
+
   octave_ += delta.octave_;
   notename_ += delta.notename_;
-  alteration_ += new_semi - quartertone_pitch ();
+  alteration_ += new_alter - tone_pitch ();
 
-  normalise ();
+  normalize ();
 }
 
 Pitch
 pitch_interval (Pitch const &from, Pitch const &to)
 {
-  int sound = to.quartertone_pitch () - from.quartertone_pitch ();
+  Rational sound = to.tone_pitch () - from.tone_pitch ();
   Pitch pt (to.get_octave () - from.get_octave (),
            to.get_notename () - from.get_notename (),
 
            to.get_alteration () - from.get_alteration ());
 
-  return pt.transposed (Pitch (0, 0, sound - pt.quartertone_pitch ()));
+  return pt.transposed (Pitch (0, 0, sound - pt.tone_pitch ()));
 }
 
 /* FIXME
@@ -173,11 +166,12 @@ char const *accname[] = {"eses", "eseh", "es", "eh", "",
 string
 Pitch::to_string () const
 {
-  int n = (notename_ + 2) % scale_->step_semitones_.size ();
+  int n = (notename_ + 2) % scale_->step_tones_.size ();
   string s = ::to_string (char (n + 'a'));
-  if (alteration_)
-    s += string (accname[alteration_ - DOUBLE_FLAT]);
-
+      Rational qtones = alteration_ * Rational (4,1);
+      int qt = int (rint (Real (qtones)));
+      
+      s += string (accname[qt + 4]);
   if (octave_ >= 0)
     {
       int o = octave_ + 1;
@@ -294,7 +288,7 @@ Pitch::get_notename () const
   return notename_;
 }
 
-int
+Rational
 Pitch::get_alteration () const
 {
   return alteration_;
@@ -307,3 +301,6 @@ Pitch::transposed (Pitch d) const
   p.transpose (d);
   return p;
 }
+
+Rational FLAT_ALTERATION (-1, 2);
+Rational SHARP_ALTERATION (1, 2);
index da74dafcdd75453b51b82b0115842ef662775bfc..33bb1a80848fb059576c57c5d89063d4f90e555d 100644 (file)
@@ -83,7 +83,7 @@ Pitched_trill_engraver::make_trill (Stream_event *ev)
 
   SCM handle = scm_assoc (key, keysig);
   bool print_acc
-    = (handle == SCM_BOOL_F) || p->get_alteration () == 0;
+    = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0);
 
   if (trill_head_)
     {
@@ -110,7 +110,7 @@ Pitched_trill_engraver::make_trill (Stream_event *ev)
       trill_accidental_ = make_item ("TrillPitchAccidental", ev->self_scm ());
 
       // fixme: naming -> alterations
-      trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
+      trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->rounded_quartertone_pitch ())));
       Side_position_interface::add_support (trill_accidental_, trill_head_);
       
       trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
index 388e2f2d0fcd31ff1d6b69d8082f6fa560b426e5..cc1efe3d2117c56b34d426a7bf6897981028971f 100644 (file)
@@ -45,5 +45,6 @@ Relative_octave_check::relative_callback (SCM music, SCM last_pitch)
     }
 
   return Pitch (p.get_octave () + delta_oct,
-               p.get_notename (), p.get_alteration ()).smobbed_copy ();
+               p.get_notename (),
+               p.get_alteration ()).smobbed_copy ();
 }
index b71f43fe207106a5d1a2171127642e9c1ddde937..89e8103887b3af3c2d98ace94ecf4e8065137b7c 100644 (file)
@@ -7,35 +7,41 @@
   
 */
 
-#include  "pitch.hh"
+#include "scale.hh"
 
 #include "ly-smobs.icc"
 
+/*
+  todo: put string <-> pitch here too.
+
+*/
 LY_DEFINE (ly_make_scale, "ly:make-scale",
           1, 0, 0, (SCM steps),
           "Create a scale. Takes a vector of ints as argument")
 {
   bool type_ok = scm_is_vector (steps);
 
-  vector<int> semitones; 
+  vector<Rational> semitones; 
   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_integer (step);
+         type_ok = type_ok && scm_is_rational (step);
          if (type_ok)
-           semitones.push_back (scm_to_int (step));
+           {
+             Rational from_c (scm_to_int (scm_numerator (step)),
+                              scm_to_int (scm_denominator (step)));
+             semitones.push_back (from_c);
+           }
        }
     }
-
   
   SCM_ASSERT_TYPE (type_ok, steps, SCM_ARG1, __FUNCTION__, "vector of int");
 
-
   Scale *s = new Scale;
-  s->step_semitones_ = semitones;
+  s->step_tones_ = semitones;
 
   SCM retval =  s->self_scm ();
 
@@ -96,7 +102,7 @@ Scale::Scale ()
 
 Scale::Scale (Scale const &src)
 {
-  step_semitones_ = src.step_semitones_;
+  step_tones_ = src.step_tones_;
   smobify_self ();
 }
 
index a9e655673420ec210e39b3aa818aea85b0653187..4fb33f7199b8ff4698d7d501b060c03baf0802f9 100644 (file)
@@ -113,7 +113,7 @@ Tab_note_heads_engraver::process_music ()
 
       while (!string_found)
        {
-         int fret = unsmob_pitch (scm_pitch)->semitone_pitch ()
+         int fret = unsmob_pitch (scm_pitch)->rounded_semitone_pitch ()
            - scm_to_int (scm_list_ref (string_tunings, scm_from_int (tab_string - 1)));
          if (fret < min_fret)
            tab_string += high_string_one ? 1 : -1;
index f69cc77fbc6b75a7f9aa22783d8abde7239c0952..fc0b867e82754dade0f96effd64658363be008f2 100644 (file)
@@ -554,8 +554,8 @@ AncientRemoveEmptyStaffContext = \context {
   printKeyCancellation = ##t
   keyAlterationOrder = #`(
     (6 . ,FLAT) (2  . ,FLAT) (5 . ,FLAT ) (1  . ,FLAT) (4  . ,FLAT) (0  . ,FLAT) (3  . ,FLAT)
-    (3  . ,SHARP) (0 . ,SHARP) (4 . ,SHARP) (1 . ,SHARP) (5 . ,SHARP) (2 . ,SHARP) (6 . ,SHARP)
-    (6 . ,DOUBLE-FLAT) (2  . ,DOUBLE-FLAT) (5 . ,DOUBLE-FLAT ) (1  . ,DOUBLE-FLAT) (4  . ,DOUBLE-FLAT) (0  . ,DOUBLE-FLAT) (3 . ,DOUBLE-FLAT)
+    (3 . ,SHARP) (0 . ,SHARP) (4 . ,SHARP) (1 . ,SHARP) (5 . ,SHARP) (2 . ,SHARP) (6 . ,SHARP)
+    (6 . ,DOUBLE-FLAT) (2 . ,DOUBLE-FLAT) (5 . ,DOUBLE-FLAT ) (1 . ,DOUBLE-FLAT) (4 . ,DOUBLE-FLAT) (0 . ,DOUBLE-FLAT) (3 . ,DOUBLE-FLAT)
     (3  . ,DOUBLE-SHARP) (0 . ,DOUBLE-SHARP) (4 . ,DOUBLE-SHARP) (2 . ,DOUBLE-SHARP) (5 . ,DOUBLE-SHARP) (2 . ,DOUBLE-SHARP) (6 . ,DOUBLE-SHARP)
   )
 
index cf8ea886f28de2783db191bcb7a768d64092dcb6..1e3a034fd8a91d8b9d47c7665ef62ac1f6100e6d 100644 (file)
@@ -12,6 +12,7 @@ Notes: natural 11 is left from chord if not explicitly specified.
 
 Entry point for the parser.
 "
+  (display modifications)
   (let* ((flat-mods (flatten-list modifications))
         (base-chord (stack-thirds (ly:make-pitch 0 4 0) the-canonical-chord))
         (complete-chord '())
@@ -218,6 +219,7 @@ DURATION, and INVERSION."
   (map (lambda (n)
         (define (nca x)
           (if (= x 7) FLAT 0))
+        
         (if (>= n 8)
             (ly:make-pitch 1 (- n 8) (nca n))
             (ly:make-pitch 0 (- n 1) (nca n))))
index 0d09beae53b5c6f9e994c10cbc5dbe0cd192eb47..cb240332ca0bab1aaf547ba141c6d67229fea44e 100644 (file)
 (define-public DOWN -1)
 (define-public CENTER 0)
 
-(define-safe-public DOUBLE-FLAT -4)
-(define-safe-public THREE-Q-FLAT -3)
-(define-safe-public FLAT -2)
-(define-safe-public SEMI-FLAT -1)
+(define-safe-public DOUBLE-FLAT-QTS -4)
+(define-safe-public THREE-Q-FLAT-QTS -3)
+(define-safe-public FLAT-QTS -2)
+(define-safe-public SEMI-FLAT-QTS -1)
+(define-safe-public NATURAL-QTS 0)
+(define-safe-public SEMI-SHARP-QTS 1)
+(define-safe-public SHARP-QTS 2)
+(define-safe-public THREE-Q-SHARP-QTS 3)
+(define-safe-public DOUBLE-SHARP-QTS 4)
+(define-safe-public SEMI-TONE-QTS 2)
+
+(define-safe-public DOUBLE-FLAT  -1)
+(define-safe-public THREE-Q-FLAT -3/4)
+(define-safe-public FLAT -1/2)
+(define-safe-public SEMI-FLAT -1/4)
 (define-safe-public NATURAL 0)
-(define-safe-public SEMI-SHARP 1)
-(define-safe-public SHARP 2)
-(define-safe-public THREE-Q-SHARP 3)
-(define-safe-public DOUBLE-SHARP 4)
-(define-safe-public SEMI-TONE 2)
+(define-safe-public SEMI-SHARP 1/4)
+(define-safe-public SHARP 1/2)
+(define-safe-public THREE-Q-SHARP 3/4)
+(define-safe-public DOUBLE-SHARP 1)
+(define-safe-public SEMI-TONE 1/2)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; moments
index e71d400859488587b8d86f440064b6237ac3357b..78430f882e0cf4e4d02e9598086f943d93cd5f3d 100644 (file)
@@ -254,7 +254,7 @@ The syntax is the same as `define*-public'."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; init pitch system
 
-(ly:set-default-scale (ly:make-scale #(0 2 4 5 7 9 11)))
+(ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))