]> git.donarmstrong.com Git - lilypond.git/commitdiff
*** empty log message ***
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 25 May 2004 20:47:11 +0000 (20:47 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 25 May 2004 20:47:11 +0000 (20:47 +0000)
ChangeLog
lily/accidental-engraver.cc
lily/book-paper-def.cc
lily/key-engraver.cc
lily/key-signature-interface.cc
ly/book-paper-defaults.ly
ly/engraver-init.ly
scm/output-tex.scm
scm/paper.scm
scripts/lilypond.py

index 4f0b344a1f199da310c962c3db176a56be5dc794..312fedf22bcb2ed88c0d3680666a7e4693848e14 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,18 @@
 
 2004-05-25  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * scripts/lilypond.py (run_dvips): only add papersize if present.
+
+       * lily/accidental-engraver.cc (update_local_key_signature): new
+       function, fold code from initialize() and process_music().
+       (update_local_key_signature): use deep copy. This fixes one
+       problem from custom-key-signatures.ly.
+       (number_accidentals_from_sig): tighter check for
+       accidental-too-old.
+
+       * ly/engraver-init.ly: remove localKeySignature
+       definition from ChoirStaff, StaffGroup, Score.
+       
        * lily/percent-repeat-engraver.cc (try_music): add moments for
        barlines too. Fixes: skipbars-percent-repeat.ly.
 
index 735e9ff8310baaf356490a56b96787e67965ae3b..4ffd0586b8d249a8980a1f80197047f72625c037 100644 (file)
@@ -41,6 +41,11 @@ Accidental_entry::Accidental_entry ()
 }
 
 struct Accidental_engraver : Engraver {
+
+
+  int get_bar_number ();
+  void update_local_key_signature ();
+
 protected:
   TRANSLATOR_DECLARATIONS (Accidental_engraver);
   virtual void process_music ();
@@ -51,8 +56,8 @@ protected:
   virtual void finalize ();
 public:
 
-  Protected_scm last_keysig_;
-
+  Protected_scm last_keysig_;  // ugh.
+  
   /*
     Urgh. Since the accidentals depend on lots of variables, we have to
     store all information before we can really create the accidentals.
@@ -64,15 +69,22 @@ public:
 
   Array<Accidental_entry> accidentals_;
   Link_array<Spanner> ties_;
-
-  SCM get_bar_num ();
 };
 
 
+/*
+  TODO:
+
+  ugh, it is not clear what properties are mutable and which
+  aren't. eg. localKeySignature is changed at runtime, which means
+  that references in grobs should always store ly_deep_copy ()s of
+  those.
+ */
+
 static void
 set_property_on_children (Context * trans, const char * sym, SCM val)
 {
-  trans->set_property (sym, val);
+  trans->set_property (sym, ly_deep_copy (val));
   for (SCM p = trans->children_contexts (); ly_c_pair_p (p); p = ly_cdr (p))
     {
       Context *trg =  unsmob_context (ly_car (p));
@@ -86,19 +98,30 @@ Accidental_engraver::Accidental_engraver ()
   last_keysig_ = SCM_EOL;
 }
 
+
 void
-Accidental_engraver::initialize ()
+Accidental_engraver::update_local_key_signature ()
 {
   last_keysig_ = get_property ("keySignature");
+  set_property_on_children (context (), "localKeySignature", last_keysig_);
 
-  Context * trans_ = context ();
-  while (trans_)
+  Context * trans = context ()->get_parent_context ();
+
+  /*
+    Huh. Don't understand what this is good for. --hwn.
+   */
+  while (trans && trans->where_defined (ly_symbol2scm ("localKeySignature")))
     {
-      trans_ -> set_property ("localKeySignature",
-                             ly_deep_copy (last_keysig_));
-      trans_ = trans_->get_parent_context ();
+      trans->set_property ("localKeySignature",
+                           ly_deep_copy (last_keysig_));
+      trans = trans->get_parent_context ();
     }
-  set_property_on_children (context (),"localKeySignature", last_keysig_);
+}
+
+void
+Accidental_engraver::initialize ()
+{
+  update_local_key_signature (); 
 }
 
 /*
@@ -111,40 +134,55 @@ Accidental_engraver::initialize ()
 */
 static int
 number_accidentals_from_sig (bool *different,
-                            SCM sig, Pitch *pitch, SCM curbarnum, SCM lazyness, 
+                            SCM sig, Pitch *pitch, int curbarnum, SCM lazyness, 
                             bool ignore_octave)
 {
   int n = pitch->get_notename ();
   int o = pitch->get_octave ();
   int a = pitch->get_alteration ();
-  int curbarnum_i = ly_scm2int (curbarnum);
-  int accbarnum_i = 0;
+  int accbarnum = -1;
 
-  SCM prev;
-  if (ignore_octave)
-    prev = ly_assoc_cdr (scm_int2num (n), sig);
-  else
-    prev = scm_assoc (scm_cons (scm_int2num (o), scm_int2num (n)), sig);
-
-  /* should really be true unless prev == SCM_BOOL_F */
-  if (ly_c_pair_p (prev) && ly_c_pair_p (ly_cdr (prev)))
+  SCM prevs[3];
+  int bar_nums[3] = {-1,-1,-1};
+  int prev_idx = 0;
+  
+  if (!ignore_octave)
     {
-      accbarnum_i = ly_scm2int (ly_cddr (prev));
-      prev = scm_cons (ly_car (prev), ly_cadr (prev));
+      prevs[prev_idx] = scm_assoc (scm_cons (scm_int2num (o), scm_int2num (n)), sig);
+
+      if (ly_c_pair_p (prevs[prev_idx]))
+       prev_idx++;
     }
   
-  /* If an accidental was not found or the accidental was too old */
-  if (prev == SCM_BOOL_F ||
-      (ly_c_number_p (lazyness) && curbarnum_i > accbarnum_i + ly_scm2int (lazyness)))
-    prev = scm_assoc (scm_int2num (n), sig);
-
+  prevs[prev_idx] = scm_assoc (scm_int2num (n), sig);
+  if (ly_c_pair_p (prevs[prev_idx]))
+    prev_idx++;
 
-  SCM prev_acc = (prev == SCM_BOOL_F) ? scm_int2num (0) : ly_cdr (prev);
+  for (int i= 0; i < prev_idx; i++)
+    {
+      if (ly_c_pair_p (prevs[i])
+         && ly_c_pair_p (ly_cdr (prevs[i])))
+       {
+         bar_nums[i]  = ly_scm2int (ly_cddr (prevs[i]));
+         prevs[i] = scm_cons (ly_car (prevs[i]), ly_cadr (prevs[i]));
+       }
+    }
+  
 
-  int p = ly_c_number_p (prev_acc) ? ly_scm2int (prev_acc) : 0;
+  int p = 0; 
+  for (int i= 0; i < prev_idx; i++)
+    {
+      if (accbarnum < 0
+         || (ly_c_number_p (lazyness)
+             && curbarnum > accbarnum + ly_scm2int (lazyness)))
+       {
+         p = ly_scm2int (ly_cdr (prevs[i]));
+         break;
+       }
+    }
 
   int num;
-  if (a == p && ly_c_number_p (prev_acc))
+  if (a == p)
     num = 0;
   else if ( (abs (a)<abs (p) || p*a<0) && a != 0 )
     num = 2;
@@ -158,7 +196,7 @@ number_accidentals_from_sig (bool *different,
 static int
 number_accidentals (bool *different,
                    Pitch *pitch, Context * origin, 
-                   SCM accidentals, SCM curbarnum)
+                   SCM accidentals, int curbarnum)
 {
   int number = 0;
 
@@ -215,18 +253,19 @@ number_accidentals (bool *different,
   return number;
 }
 
-SCM
-Accidental_engraver::get_bar_num ()
+int
+Accidental_engraver::get_bar_number ()
 {
   SCM barnum = get_property ("currentBarNumber");
   SCM smp = get_property ("measurePosition");
-      
+
+  int bn = robust_scm2int (barnum, 0);
+  
   Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
-  if (mp.main_part_ < Rational (0)
-      && ly_c_number_p (barnum))
-    barnum = scm_int2num (ly_scm2int (barnum) - 1);
-      
-  return barnum ;
+  if (mp.main_part_ < Rational (0))
+    bn --;
+  
+  return bn;
 }
 
 void
@@ -236,7 +275,7 @@ Accidental_engraver::process_acknowledged_grobs ()
     {
       SCM accidentals =  get_property ("autoAccidentals");
       SCM cautionaries =  get_property ("autoCautionaries");
-      SCM barnum = get_bar_num ();
+      int barnum = get_bar_number ();
       
       bool extra_natural_b = get_property ("extraNatural") == SCM_BOOL_T;
       for (int i = 0; i  < accidentals_.size (); i++) 
@@ -365,7 +404,7 @@ Accidental_engraver::stop_translation_timestep ()
 
   for (int i = accidentals_.size (); i--;) 
     {
-      SCM barnum = get_bar_num ();
+      int barnum = get_bar_number ();
 
       Music * note = accidentals_[i].melodic_;
       Context * origin = accidentals_[i].origin_;
@@ -379,7 +418,7 @@ Accidental_engraver::stop_translation_timestep ()
       int a = pitch->get_alteration ();
       SCM on_s = scm_cons (scm_int2num (o), scm_int2num (n));
 
-      while (origin)
+      while (origin && origin->where_defined (ly_symbol2scm ("localKeySignature")))
        {
          /*
            huh? we set props all the way to the top? 
@@ -393,7 +432,7 @@ Accidental_engraver::stop_translation_timestep ()
                that of the tied note and of the key signature.
              */
              localsig = ly_assoc_front_x
-               (localsig, on_s, scm_cons (SCM_BOOL_T, barnum));
+               (localsig, on_s, scm_cons (SCM_BOOL_T, scm_int2num (barnum)));
 
              change = true;
            }
@@ -404,13 +443,14 @@ Accidental_engraver::stop_translation_timestep ()
                noteheads with the same notename.
              */
              localsig = ly_assoc_front_x
-               (localsig, on_s, scm_cons (scm_int2num (a), barnum));
+               (localsig, on_s, scm_cons (scm_int2num (a), scm_int2num (barnum)));
 
              change = true;
            }
 
          if (change)
            origin->set_property ("localKeySignature",  localsig);
+         
          origin = origin->get_parent_context ();
        }
     }
@@ -469,15 +509,7 @@ Accidental_engraver::process_music ()
   */
   if (last_keysig_ != sig)
     {
-      Context * trans_ = context ();
-      while (trans_)
-       {
-         trans_ -> set_property ("localKeySignature",  ly_deep_copy (sig));
-         trans_ = trans_->get_parent_context ();
-       }
-      set_property_on_children (context (),"localKeySignature", sig);
-
-      last_keysig_ = sig;
+      update_local_key_signature ();
     }
 }
 
index f67aad213113897ad4b6061ea1d82bbf9f81613f..42d8bd623d13ef88d4b08558ece3aee579c36396 100644 (file)
@@ -214,3 +214,13 @@ Book_paper_def::c_variable (String s) const
 {
   return lookup_variable (ly_symbol2scm (s.to_str0 ()));
 }
+
+
+LY_DEFINE (ly_book_paper_def_scope, "ly:bookpaper-def-scope",
+          1, 0,0, (SCM def),
+          "Get the variable scope inside @var{def}.")
+{
+  Book_paper_def *op = unsmob_book_paper_def (def);
+  SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
+  return op->scope_;
+}
index 2007350427fa9363fd18daf092f013fb63237ad6..f5e4a02d68a9daafb5be57395ba77c22307bb058 100644 (file)
@@ -72,7 +72,6 @@ Key_engraver::create_key (bool def)
       if (to_boolean (get_property ("printKeyCancellation")))
        item_->set_property ("old-accidentals", get_property ("lastKeySignature"));
       item_->set_property ("new-accidentals", get_property ("keySignature"));
-
     }
 
   if (!def)
@@ -135,7 +134,8 @@ Key_engraver::process_music ()
 void
 Key_engraver::stop_translation_timestep ()
 {
-      item_ = 0;
+  item_ = 0;
+  context ()->set_property ("lastKeySignature", get_property ("keySignature"));
 }
 
 
@@ -172,7 +172,6 @@ void
 Key_engraver::start_translation_timestep ()
 {
   key_ev_ = 0;
-  context ()->set_property ("lastKeySignature", get_property ("keySignature"));
 }
 
 
index 4666d4982a749dcdc6ee7fc537f1b13ebcc9c752..7f9a96b1d7d9f37d97ec09968050cc50d131dc85 100644 (file)
@@ -46,9 +46,6 @@ const int NATURAL_TOP_PITCH = 4;
   the thinking to other parties.
 
   - TODO: put this in Scheme
-  
-  - lots of values trivially shared (key doesn't change very
-  often). Compute those once, and use that as cache for the rest.
 
   TODO: can  we do without c0pos? it's partly musical. 
 
@@ -74,6 +71,7 @@ alteration_pos  (SCM what, int alter, int c0p)
     {
       p -= 7; /* Typeset below c_position */
     }
+  
   /* Provide for the four cases in which there's a glitch 
        it's a hack, but probably not worth  
        the effort of finding a nicer solution.
index 42f29ddfefe03357270a1223c31d7958dc05a8f1..198da70b5995c5673040d24253a86ce19dff8825 100644 (file)
@@ -66,4 +66,6 @@
        #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))
 
 
+  papersize = "a4"
+
 }
index 19be19f652b3049e3413b195fde7a4137bee8bf2..fb85ddf42bb7f6ff6d71e2f3756f5862f6746b6c 100644 (file)
@@ -89,7 +89,6 @@
     \name InnerChoirStaff
     \consists "System_start_delimiter_engraver"
     systemStartDelimiter = #'SystemStartBracket
-    localKeySignature = #'()
 
     \accepts "Staff"
     \accepts "DrumStaff"
 \context {
     \type "Engraver_group_engraver"
     \name InnerStaffGroup
-    localKeySignature = #'()
 
     \consists "Span_bar_engraver"
     \consists "Span_arpeggio_engraver"
@@ -390,7 +388,6 @@ AncientRemoveEmptyStaffContext = \context {
 \context {
     \type Score_engraver
     \name Score
-    localKeySignature = #'()
 
     \description "This is the top level notation context.  No
     other context can contain a @code{Score} context.  This context
index 77dd2053b43f457aa10e6c2e57c8383516121771..dbc8a67b6739722d4036beb02689b4b0ca57209d 100644 (file)
    (tex-number-def "lilypondpaper" 'outputscale
                   (number->string (exact->inexact
                                    (ly:bookpaper-outputscale bookpaper))))
-  (apply string-append
-        (map (lambda (x) (font-load-command bookpaper x))
-             (ly:bookpaper-fonts bookpaper)
-             )))
-)
+   (tex-string-def "lilypondpapersize" 'papersize
+                  (eval 'papersize (ly:bookpaper-def-scope bookpaper)))
+   (apply string-append
+         (map (lambda (x) (font-load-command bookpaper x))
+              (ly:bookpaper-fonts bookpaper)
+              )))
+  )
 (define (unknown) 
   "%\n\\unknown\n")
 
index 1cc32532bd0736fa54e1e395e4534cd6ce68c5de..b6ab3761a5c1f828ed68f270c83a98598bd6f741 100644 (file)
@@ -73,8 +73,6 @@
     (module-define! m 'head-sep (* 4 mm))
     (module-define! m 'foot-sep (* 4 mm))))
 
-
-
 (define (internal-set-paper-size module name)
   (let* ((entry (assoc name paper-alist))
         (is-paper? (module-defined? module '$is-paper))
index e9e98492014a3c18a78403dc86726d4a05d6b634..cfe24015c97248943e8c7c03397c0011de5ae548 100644 (file)
@@ -486,7 +486,9 @@ def run_dvips (outbase, extra):
 leaving a PS file in OUTBASE.ps
 '''
        #FIXME: papersize, orientation must come from lilypond-bin
-       opts = ' -t%s' % extra['papersize'][0]
+
+       if extra['papersize']:
+               opts = ' -t%s' % extra['papersize'][0]
        if extra['orientation'] and extra['orientation'][0] == 'landscape':
                opts = opts + ' -tlandscape'