]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/accidental-placement.cc (calc_positioning_done): don't
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 21 Sep 2006 00:19:06 +0000 (00:19 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 21 Sep 2006 00:19:06 +0000 (00:19 +0000)
trigger Y-extent calculation too early. Use pure_height instead.

* lily/scale.cc (LY_DEFINE): new file.

ChangeLog
lily/accidental-placement.cc
lily/include/pitch.hh
lily/pitch.cc
lily/scale.cc [new file with mode: 0644]
scm/lily.scm

index 978139cc6d421d0bb86c63ad2fc106508c466165..93a4d4845c5d6289f800a578ee15bd6b3de6990d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-09-21  Han-Wen Nienhuys  <hanwen@lilypond.org>
+
+       * lily/accidental-placement.cc (calc_positioning_done): don't
+       trigger Y-extent calculation too early. Use pure_height instead.
+
+       * lily/scale.cc (LY_DEFINE): new file. 
+
 2006-09-20  Joe Neeman  <joeneeman@gmail.com>
 
        * lily/page-breaking.cc (find_chunks_and_breaks): ignore breaks
index ff68bbdf0ae19b79c079bf2ee0bb2514a2c51ee2..199ff98c93f8b219d34465af2ef75d8401e2bfd7 100644 (file)
@@ -341,14 +341,6 @@ Accidental_placement::calc_positioning_done (SCM smob)
   Accidental_placement_entry *head_ape = new Accidental_placement_entry;
   common[X_AXIS] = common_refpoint_of_array (heads, common[X_AXIS], X_AXIS);
   vector<Skyline_entry> head_skyline (empty_skyline (LEFT));
-
-  vector<Grob *> stems;
-  for (vsize i = 0; i < heads.size  (); i++)
-    if (Grob *s = Rhythmic_head::get_stem (heads[i]))
-      stems.push_back (s);
-  vector_sort (stems, less<Grob*> ());
-  uniq (stems);
-  concat (heads, stems);
   
   vector<Box> head_extents;
   for (vsize i = heads.size (); i--;)
@@ -359,6 +351,25 @@ Accidental_placement::calc_positioning_done (SCM smob)
       insert_extent_into_skyline (&head_skyline, b, Y_AXIS, LEFT);
     }
 
+  vector<Grob *> stems;
+  for (vsize i = 0; i < heads.size  (); i++)
+    {
+      if (Grob *s = Rhythmic_head::get_stem (heads[i]))
+       stems.push_back (s);
+    }
+  
+  vector_sort (stems, less<Grob*> ());
+  uniq (stems);
+  for (vsize i = 0; i < stems.size (); i ++)
+    {
+      int very_large = INT_MAX;
+      
+      Box b (heads[i]->extent (common[X_AXIS], X_AXIS),
+            heads[i]->pure_height (common[Y_AXIS], 0, very_large));
+
+      insert_extent_into_skyline (&head_skyline, b, Y_AXIS, LEFT);
+    }
+  
   head_ape->left_skyline_ = head_skyline;
   head_ape->offset_ = 0.0;
 
index 57cb076b526fdcfa4566a6408b71e3de30fda551..2ebbb71a4179ada0835ba590eb20fbd03583aae8 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,);
+};
+
+
 /** A "tonal" pitch. This is a pitch used in diatonal western music
     (24 quartertones in an octave), as opposed to a frequency in Hz or a
     integer number of semitones.
@@ -34,7 +45,8 @@ private:                              // fixme
   int notename_;
   int alteration_;
   int octave_;
-
+  Scale *scale_;
+  
   void transpose (Pitch);
   void up_to (int);
   void down_to (int);
@@ -84,6 +96,7 @@ 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 */
 
index 80b32e3c69ee97d3fd3e72f484d202dda13dd687..566b729e24fdacd7c1bca1df2ff8aecc6f071357 100644 (file)
@@ -19,6 +19,7 @@ Pitch::Pitch (int o, int n, int a)
   notename_ = n;
   alteration_ = a;
   octave_ = o;
+  scale_ = default_global_scale; 
   normalise ();
 }
 
@@ -27,6 +28,7 @@ Pitch::Pitch ()
 {
   notename_ = 0;
   alteration_ = 0;
+  scale_ = default_global_scale; 
   octave_ = 0;
 }
 
@@ -49,11 +51,13 @@ Pitch::compare (Pitch const &m1, Pitch const &m2)
 int
 Pitch::steps () const
 {
-  return notename_ + octave_ * 7;
+  return notename_ + octave_ * scale_->step_semitones_.size ();
 }
 
 /* Should be settable from input?  */
-static Byte diatonic_scale_semitones[ ] = { 0, 2, 4, 5, 7, 9, 11 };
+// 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.  */
@@ -64,15 +68,15 @@ Pitch::semitone_pitch () const
   int n = notename_;
   while (n < 0)
     {
-      n += 7;
+      n += scale_->step_semitones_.size ();
       o--;
     }
 
   if (alteration_ % 2)
     programming_error ("semitone_pitch () called on quarter tone alteration.");
 
-  return ((o + n / 7) * 12
-         + diatonic_scale_semitones[n % 7]
+  return ((o + n / scale_->step_semitones_.size ()) * 12
+         + scale_->step_semitones_[n % scale_->step_semitones_.size ()]
          + (alteration_ / 2));
 }
 
@@ -83,12 +87,12 @@ Pitch::quartertone_pitch () const
   int n = notename_;
   while (n < 0)
     {
-      n += 7;
+      n += scale_->step_semitones_.size ();
       o--;
     }
 
-  return ((o + n / 7) * 24
-         + 2 * diatonic_scale_semitones[n % 7]
+  return ((o + n / scale_->step_semitones_.size ()) * 24
+         + 2 * scale_->step_semitones_[n % scale_->step_semitones_.size ()]
          + alteration_);
 }
 
@@ -96,15 +100,15 @@ void
 Pitch::normalise ()
 {
   int pitch = quartertone_pitch ();
-  while (notename_ >= 7)
+  while (notename_ >= (int) scale_->step_semitones_.size ())
     {
-      notename_ -= 7;
+      notename_ -= scale_->step_semitones_.size ();
       octave_++;
       alteration_ -= quartertone_pitch () - pitch;
     }
   while (notename_ < 0)
     {
-      notename_ += 7;
+      notename_ += scale_->step_semitones_.size ();
       octave_--;
       alteration_ -= quartertone_pitch () - pitch;
     }
@@ -169,7 +173,7 @@ char const *accname[] = {"eses", "eseh", "es", "eh", "",
 string
 Pitch::to_string () const
 {
-  int n = (notename_ + 2) % 7;
+  int n = (notename_ + 2) % scale_->step_semitones_.size ();
   string s = ::to_string (char (n + 'a'));
   if (alteration_)
     s += string (accname[alteration_ - DOUBLE_FLAT]);
@@ -234,11 +238,11 @@ Pitch::down_to (int notename)
 }
 
 IMPLEMENT_TYPE_P (Pitch, "ly:pitch?");
-
 SCM
-Pitch::mark_smob (SCM)
+Pitch::mark_smob (SCM x)
 {
-  return SCM_EOL;
+  Pitch *p = (Pitch*) SCM_CELL_WORD_1 (x);
+  return p->scale_->self_scm ();
 }
 
 IMPLEMENT_SIMPLE_SMOBS (Pitch);
diff --git a/lily/scale.cc b/lily/scale.cc
new file mode 100644 (file)
index 0000000..b71f43f
--- /dev/null
@@ -0,0 +1,109 @@
+/* 
+  scale.cc -- implement Scale
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
+  
+*/
+
+#include  "pitch.hh"
+
+#include "ly-smobs.icc"
+
+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; 
+  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);
+         if (type_ok)
+           semitones.push_back (scm_to_int (step));
+       }
+    }
+
+  
+  SCM_ASSERT_TYPE (type_ok, steps, SCM_ARG1, __FUNCTION__, "vector of int");
+
+
+  Scale *s = new Scale;
+  s->step_semitones_ = semitones;
+
+  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.")
+{
+  return default_global_scale
+    ? SCM_BOOL_F
+    : default_global_scale->self_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.")
+{
+  Scale *s = Scale::unsmob (scale);
+  SCM_ASSERT_TYPE (s, scale, SCM_ARG1, __FUNCTION__, "scale");
+
+  if (default_global_scale)
+    default_global_scale->unprotect ();
+  default_global_scale = s;
+  s->protect ();
+  
+  return SCM_UNSPECIFIED;
+}
+
+
+int
+Scale::print_smob (SCM x, SCM port, scm_print_state *)
+{
+  (void) x;
+  
+  scm_puts ("#<Scale>", port); 
+  return 1;
+}
+
+
+SCM
+Scale::mark_smob (SCM x)
+{
+  (void) x;
+  return SCM_UNSPECIFIED;
+}
+
+Scale::Scale ()
+{
+  smobify_self ();
+}
+
+Scale::Scale (Scale const &src)
+{
+  step_semitones_ = src.step_semitones_;
+  smobify_self ();
+}
+
+
+Scale::~Scale ()
+{
+}
+
+IMPLEMENT_SMOBS(Scale);
+IMPLEMENT_DEFAULT_EQUAL_P(Scale);
index 495234fb92c6dc9577aa8c7970ffebcd271cee1a..0bb09baffc8ef76f12606c499db5b7c83afbdeec 100644 (file)
@@ -237,7 +237,13 @@ The syntax is the same as `define*-public'."
                                 safe-objects))
        ,safe-symbol)))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; init pitch system
+
+(ly:set-default-scale (ly:make-scale #(0 2 4 5 7 9 11)))
+
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; other files.