]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/lookup.cc (triangle): new function.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 8 Nov 2002 01:39:37 +0000 (01:39 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 8 Nov 2002 01:39:37 +0000 (01:39 +0000)
* input/regression/measure-grouping.ly (texidoc): new file: show
triangles and brackets for beat groups of 3 and 2.

* lily/include/measure-grouping-spanner.hh (class
Measure_grouping): new file.

* lily/measure-grouping-spanner.cc (brew_molecule): new file

* lily/measure-grouping-engraver.cc (class
Measure_grouping_engraver): new file.

12 files changed:
ChangeLog
input/regression/measure-grouping.ly [new file with mode: 0644]
lily/include/lookup.hh
lily/include/measure-grouping-spanner.hh [new file with mode: 0644]
lily/lookup.cc
lily/measure-grouping-engraver.cc [new file with mode: 0644]
lily/measure-grouping-spanner.cc [new file with mode: 0644]
ps/music-drawing-routines.ps
scm/grob-description.scm
scm/ps.scm
scm/tex.scm
scm/translator-property-description.scm

index 60ad34f2198ac194f3339ade6707b5e73888fefe..35ecb9e217a8bd2fcccfa76de32ea4516016f006 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2002-11-08  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
+
+       * lily/lookup.cc (triangle): new function.
+
+       * input/regression/measure-grouping.ly (texidoc): new file: show
+       triangles and brackets for beat groups of 3 and 2.
+
+       * lily/include/measure-grouping-spanner.hh (class
+       Measure_grouping): new file.
+
+       * lily/measure-grouping-spanner.cc (brew_molecule): new file
+
+       * lily/measure-grouping-engraver.cc (class
+       Measure_grouping_engraver): new file.
+
 2002-11-06  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * Merge from stable:
 
 2002-11-04  Jan Nieuwenhuizen  <janneke@gnu.org>
 
-       * scripts/lilypond-book.py:
-       * scripts/ly2dvi.py: Fix: redirect latex progress/error output to
-       stderr (by default this goes to stdout).  Show lilypond progress,
-       even when not verbose.
+       * scripts/lilypond-book.py: * scripts/ly2dvi.py: Fix: redirect
+       latex progress/error output to stderr (by default this goes to
+       stdout).  Show lilypond progress, even when not verbose.
 
        * python/lilylib.py (system): New optional parameter to control
        showing of progress.
diff --git a/input/regression/measure-grouping.ly b/input/regression/measure-grouping.ly
new file mode 100644 (file)
index 0000000..2eca7d4
--- /dev/null
@@ -0,0 +1,25 @@
+\header
+{
+texidoc = "The Measure_grouping_engraver adds triangles and brackets above beats
+when you set beatGrouping.
+
+(unfinished.)
+"
+}
+\score { \notes
+\context Staff
+        {
+            \time 8/4
+            \property Staff.beatGrouping = #'(3 3) 
+            c4 c c c
+            c4
+            \property Staff.beatGrouping = #'()
+            c c c
+            
+        }
+        \paper  {
+            \translator { \StaffContext
+                          \consists "Measure_grouping_engraver"
+                          }
+            }
+        }
index b81c610f315283498716c1eac80f2c0176a36d42..e4ffb541b76bb812a1362358f651c8dd1fc188b1 100644 (file)
@@ -31,6 +31,7 @@ struct Lookup
   static Molecule roundfilledbox (Box b, Real blotdiameter);
   static Molecule repeat_slash (Real w, Real slope, Real th);
   static Molecule line (Real th, Offset from, Offset to);
+  static Molecule triangle (Interval, Real, Real);
 };
 
 #endif // LOOKUP_HH
diff --git a/lily/include/measure-grouping-spanner.hh b/lily/include/measure-grouping-spanner.hh
new file mode 100644 (file)
index 0000000..afba2bf
--- /dev/null
@@ -0,0 +1,25 @@
+/*   
+measure-grouping-spanner.hh -- declare 
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#ifndef MEASURE_GROUPING_SPANNER_HH
+#define MEASURE_GROUPING_SPANNER_HH
+
+#include "grob.hh"
+
+class Measure_grouping
+{
+public:
+  DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM ));
+  static bool has_interface (Grob*);
+};
+
+
+#endif /* MEASURE_GROUPING_SPANNER_HH */
+
index e12dd064ff8f00ff5e38ad54a379eae090f36fa4..67022a606e218502ce3169ec2f7ed8fa0e0a7669 100644 (file)
@@ -551,15 +551,31 @@ Lookup::bracket (Axis a, Interval iv, Real thick, Real protude)
   return m;
 }
 
+Molecule
+Lookup::triangle (Interval iv, Real thick, Real protude)
+{
+  Box b ;
+  b[X_AXIS] =iv;
+  b[Y_AXIS] = Interval (0, protude);
+
+  SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
+                     gh_double2scm (thick),
+                     gh_double2scm (iv.length()), 
+                     gh_double2scm (protude), SCM_UNDEFINED);
+
+  return Molecule (b, s);
+}
+
+
 /*
   TODO: use rounded boxes.
  */
 LY_DEFINE(ly_bracket ,"ly:bracket",
          4, 0, 0,
          (SCM a, SCM iv, SCM t, SCM p),
-         "Make a bracket in direction @var{a}. The extent of the bracket is
-given by @var{iv}. The wings protude by an amount of @var{p}, which
-may be negative. The thickness is given by @var{t}.")
+         "Make a bracket in direction @var{a}. The extent of the bracket is " 
+         "given by @var{iv}. The wings protude by an amount of @var{p}, which "
+         "may be negative. The thickness is given by @var{t}.")
 {
   SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
   SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
diff --git a/lily/measure-grouping-engraver.cc b/lily/measure-grouping-engraver.cc
new file mode 100644 (file)
index 0000000..bbeab81
--- /dev/null
@@ -0,0 +1,119 @@
+/*   
+  measure-grouping-engraver.cc --  implement Measure_grouping_engraver
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ */
+
+#include "score-engraver.hh"
+#include "spanner.hh"
+#include "warn.hh"
+#include "side-position-interface.hh"
+
+class Measure_grouping_engraver : public Engraver
+{
+public:
+  TRANSLATOR_DECLARATIONS(Measure_grouping_engraver);
+
+protected:
+  Spanner * grouping_;
+  Rational stop_grouping_mom_;
+
+  virtual void start_translation_timestep ();
+  virtual void finalize ();
+  virtual void acknowledge_grob (Grob_info);
+};
+
+void
+Measure_grouping_engraver::finalize()
+{
+  if (grouping_)
+    {
+      grouping_->set_bound (RIGHT,
+                           unsmob_grob (get_property ("currentCommandColumn")));
+      typeset_grob (grouping_);
+      grouping_= 0;
+    }
+}
+
+
+void
+Measure_grouping_engraver::acknowledge_grob (Grob_info gi)
+{
+  if (grouping_)
+    {
+      Side_position_interface::add_support (grouping_, gi.grob_);
+    }
+}
+
+void
+Measure_grouping_engraver::start_translation_timestep ()
+{
+  Moment now = now_mom();
+  if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
+    {
+      Side_position_interface::add_staff_support (grouping_);
+      grouping_->set_bound (RIGHT,
+                           unsmob_grob (get_property ("currentMusicalColumn")));
+      typeset_grob (grouping_);
+      grouping_ = 0;
+    }
+  
+  if (now.grace_part_)
+    return; 
+  
+  SCM grouping = get_property ("beatGrouping");
+  if (gh_pair_p (grouping))
+    {
+      Moment *measpos = unsmob_moment (get_property ("measurePosition"));
+      Rational mp = measpos->main_part_;
+      
+      Moment * beatlen = unsmob_moment (get_property ("beatLength"));
+      Rational bl = beatlen->main_part_;
+       
+      Rational where (0);
+      for (SCM s = grouping; gh_pair_p (s);
+          where += Rational (gh_scm2int (gh_car (s))) * bl,
+          s = gh_cdr (s)
+          )
+       {
+         int grouplen = gh_scm2int (gh_car(s));
+         if (where == mp)
+           {
+             if (grouping_)
+               {
+                 programming_error ("Huh, last grouping not finished yet.");
+                 continue;
+               }
+             
+             grouping_ = new Spanner (get_property ("MeasureGrouping"));
+             grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
+             announce_grob (grouping_, SCM_EOL);
+
+
+             stop_grouping_mom_ = now.main_part_ + Rational(grouplen - 1) * bl ;
+             top_engraver ()->add_moment_to_process (Moment (stop_grouping_mom_));
+
+             if (grouplen == 3)
+               grouping_->set_grob_property ("type", ly_symbol2scm ("triangle"));
+             else
+               grouping_->set_grob_property ("type", ly_symbol2scm ("bracket"));
+             
+             break ; 
+           }
+       }
+    }
+}
+Measure_grouping_engraver::Measure_grouping_engraver()
+{
+  grouping_ = 0;
+}
+
+ENTER_DESCRIPTION(Measure_grouping_engraver,
+/* descr */       "Creates Measure_grouping objects using beatGrouping property",
+/* creats*/       "MeasureGrouping",
+/* accepts */     "",
+/* acks  */      "note-column-interface",
+/* reads */       "beatGrouping beatLength measurePosition currentMusicalColumn",
+/* write */       "");
diff --git a/lily/measure-grouping-spanner.cc b/lily/measure-grouping-spanner.cc
new file mode 100644 (file)
index 0000000..55c76ae
--- /dev/null
@@ -0,0 +1,53 @@
+/*   
+measure-grouping-spanner.cc --  implement Measure_grouping
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+#include "paper-def.hh"
+#include "spanner.hh"
+#include "measure-grouping-spanner.hh"
+#include "lookup.hh" 
+#include "item.hh"
+
+MAKE_SCHEME_CALLBACK (Measure_grouping, brew_molecule, 1);
+SCM 
+Measure_grouping::brew_molecule (SCM grob)
+{
+  Spanner * me = dynamic_cast<Spanner*> (unsmob_grob (grob));
+
+  /*
+    TODO: robustify.
+   */
+  SCM which = me->get_grob_property ("type");
+  SCM thick = me->get_grob_property ("thickness");
+  SCM height = me->get_grob_property ("height");
+
+  Real t = me->get_paper ()->get_var ("linethickness") *   gh_scm2double (thick); 
+  Grob *common = me->get_bound(LEFT)->common_refpoint (me->get_bound (RIGHT),
+                                                      X_AXIS);
+  Real w = me->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
+    - me->get_bound (RIGHT)->relative_coordinate (common, X_AXIS);
+
+  Interval iv (0,w);
+
+  Molecule m; 
+  if (which == ly_symbol2scm ("bracket"))
+    {
+      m = Lookup::bracket (X_AXIS, iv,t, gh_scm2double (height));
+    }
+  else if (which == ly_symbol2scm ("triangle"))
+    {
+      m = Lookup::triangle (iv, t, gh_scm2double (height));
+    }
+
+  return m.smobbed_copy();
+}
+
+ADD_INTERFACE (Measure_grouping,"measure-grouping-interface",
+              "indicate groups of beats. Valid choices for 'type are 'bracket and 'triangle.",
+              "thickness height");
+
+  
index 114669bbb6386f92309baba809df526dfd66116b..338272affd653db3c52d803a70e251fb9db9d8c4 100644 (file)
        } ifelse
 } bind def
 
+
+/draw_symmetric_x_triangle %  th w h
+{
+    setlinewidth
+    0 0 moveto
+    dup
+    0 rlineto
+    2 div
+    exch rlineto
+    0 0 lineto
+    stroke
+} bind def
+
 /draw_round_box % breapth width depth height blot
 {
        /blot exch def
index 3302ffba541e2e2eeb1548d9b52e97d690e0b5b5..2b5e39b0f46a2c07cbbff3a5db292d84a727509b 100644 (file)
        (padding . 0.8)
        (meta . ((interfaces . (text-interface side-position-interface font-interface mark-interface self-alignment-interface item-interface ))))
        ))
-
+    
+    (MeasureGrouping
+     . (
+       (Y-offset-callbacks . (,Side_position_interface::aligned_side))
+       (molecule-callback . ,Measure_grouping::brew_molecule)
+       (meta . ((interfaces . (spanner-interface measure-grouping-interface))))
+       (padding . 2)
+       (direction . 1)
+       (thickness . 1)
+       (height . 2.0)
+       ))
     (MultiMeasureRest
      . (
        (spacing-procedure . ,Multi_measure_rest::set_spacing_rods)
index f6f20fe81400d3203d3f383962ffb883bb0dd470..3d1e99034f88280a226412db3287e0dbd5195781 100644 (file)
     (list arch_angle arch_width arch_height height arch_thick thick))
    " draw_bracket"))
 
+(define (symmetric-x-triangle thick w h)
+  (string-append
+   (numbers->string (list thick w h ))
+   " draw_symmetric_x_triangle"))
+
+
 (define (char i)
   (string-append 
    "(\\" (inexact->string i 8) ") show " ))
 
+
 (define (comment s)
   (string-append "% " s "\n"))
 
+
 (define (dashed-line thick on off dx dy)
   (string-append 
    (ly:number->string dx)
index 4026ec1789c13b94e388ec52b9f6efd86409abb8..41b43d2d68c30abbde7ac1868e016e46f08d9398 100644 (file)
@@ -99,6 +99,9 @@
 (define (zigzag-line centre? zzw zzh thick dx dy)
   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
 
+(define (symmetric-x-triangle t w h)
+  (embedded-ps (list 'symmetric-x-triangle t w h)))
+
 (define (font-load-command name-mag command)
   (string-append
    "\\font\\" command "="
index 3d9982067c027d32309b72142e62e61230e159dd..a560876d724adf3e6f2fc344281991e12162a7fa 100644 (file)
@@ -132,6 +132,8 @@ using barchecks in polyphonic music.")
 (translator-property-description 'barNumberVisibility procedure? "Procedure that takes an int and returns whether the corresponding bar number should be printed")
 (translator-property-description 'beamMelismaBusy boolean? "Signal if a beam is set when automaticMelismata is set")
 (translator-property-description 'beatLength ly:moment? "The length of one beat in this time signature.")
+(translator-property-description 'beatGrouping list?
+                                "List of beatgroups. Eg. in 5/8 time #(list 2 3).")
 (translator-property-description 'breakAlignOrder list? "Defines the order in which
 prefatory matter (clefs, key signatures) appears, eg. this puts the
 key signatures after the bar lines: