]> git.donarmstrong.com Git - lilypond.git/commitdiff
Move `easy notation' print callback to scheme.
authorNeil Puttock <n.puttock@gmail.com>
Wed, 19 Aug 2009 18:50:44 +0000 (19:50 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Wed, 19 Aug 2009 18:50:44 +0000 (19:50 +0100)
* remove easy-notation.cc

* add exported function ly:staff-symbol-staff-space to make accessing
  'staff-space more convenient

* add scheme implementation of ly:note-head::brew-ez-stencil to
  output-lib.scm

* add convert-rule

lily/easy-notation.cc [deleted file]
lily/staff-symbol-referencer-scheme.cc
ly/property-init.ly
python/convertrules.py
scm/output-lib.scm
scm/safe-lily.scm

diff --git a/lily/easy-notation.cc b/lily/easy-notation.cc
deleted file mode 100644 (file)
index 8838efe..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
-  easy-notation.cc --  implement easy notation heads
-
-  source file of the GNU LilyPond music typesetter
-
-  (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
-*/
-
-#include "note-head.hh"
-
-#include <cctype>
-using namespace std;
-
-#include "font-interface.hh"
-#include "grob.hh"
-#include "music.hh"
-#include "output-def.hh"
-#include "staff-symbol-referencer.hh"
-#include "stem.hh"
-#include "stream-event.hh"
-#include "text-interface.hh"
-#include "rhythmic-head.hh"
-
-/*
-
-TODO: move to scheme
-
-*/
-MAKE_SCHEME_CALLBACK (Note_head, brew_ez_stencil, 1);
-SCM
-Note_head::brew_ez_stencil (SCM smob)
-{
-  Grob *me = unsmob_grob (smob);
-  int log = Rhythmic_head::duration_log (me);
-
-  SCM cause = me->get_property ("cause");
-  SCM spitch = unsmob_stream_event (cause)->get_property ("pitch");
-  Pitch *pit = unsmob_pitch (spitch);
-
-  SCM idx = scm_from_int (pit->get_notename ());
-  SCM names = me->get_property ("note-names");
-  SCM charstr = SCM_EOL;
-  if (scm_is_vector (names))
-    charstr = scm_vector_ref (names, idx);
-  else
-    {
-      char s[2] = "a";
-      s[0] = char ((pit->get_notename () + 2) % 7 + 'a');
-      s[0] = char (toupper (s[0]));
-      charstr = scm_from_locale_string (s);
-    }
-
-  SCM letter
-    = Text_interface::interpret_string (me->layout ()->self_scm (),
-                                       Font_interface::text_font_alist_chain (me),
-                                       charstr);
-
-  Stencil l (*unsmob_stencil (letter));
-  l.align_to (X_AXIS, CENTER);
-  l.align_to (Y_AXIS, CENTER);
-
-  l = Stencil (Box (), l.expr ());
-  Real ss = Staff_symbol_referencer::staff_space (me);
-  Real lt = Staff_symbol_referencer::line_thickness (me);
-
-  Real radius = (ss + lt) / 2.0;
-  Real stem_thick = 1.3 * lt;
-  if (Grob *stem = unsmob_grob (me->get_object ("stem")))
-    stem_thick = Stem::thickness (stem);
-
-  int black = (log >= 2);
-
-  Stencil head;
-  Box extent (Interval (-radius, radius),
-             Interval (-radius, radius));
-
-  Stencil black_head (extent,
-                     scm_list_4 (ly_symbol2scm ("circle"),
-                                 scm_from_double (radius),
-                                 scm_from_double (0.0),
-                                 SCM_BOOL_T));
-  Stencil white_head;
-  if (black)
-    l = l.in_color (1, 1, 1);
-  else
-    {
-      white_head = Stencil (extent,
-                           scm_list_4 (ly_symbol2scm ("circle"),
-                                       scm_from_double (radius - stem_thick),
-                                       scm_from_double (0.0),
-                                       SCM_BOOL_T));
-
-      white_head = white_head.in_color (1, 1, 1);
-    }
-
-  Stencil total;
-  total.add_stencil (l);
-  total.add_stencil (white_head);
-  total.add_stencil (black_head);
-  total.translate_axis (radius, X_AXIS);
-
-  return total.smobbed_copy ();
-}
-
index ebf268677781f1bf56b23f5c96f1258356951d37..74dd8c2e3a97671ce06eb9882ecbef37e5c4a081 100644 (file)
@@ -7,13 +7,13 @@
 */
 
 #include "grob.hh"
-#include "staff-symbol-referencer.hh"
-#include "staff-symbol.hh"
 #include "libc-extension.hh"
+#include "staff-symbol.hh"
+#include "staff-symbol-referencer.hh"
 
 LY_DEFINE (ly_grob_staff_position, "ly:grob-staff-position",
-          1, 0, 0, (SCM sg),
-          "Return the Y-position of @var{sg} relative to the staff.")
+           1, 0, 0, (SCM sg),
+           "Return the Y-position of @var{sg} relative to the staff.")
 {
   LY_ASSERT_SMOB (Grob, sg, 1);
   Grob *g = unsmob_grob (sg);
@@ -27,7 +27,8 @@ LY_DEFINE (ly_grob_staff_position, "ly:grob-staff-position",
 
 LY_DEFINE (ly_position_on_line_p, "ly:position-on-line?",
            2, 0, 0, (SCM sg, SCM spos),
-           "Return whether @var{pos} is on a line of the staff associated with the the grob @var{sg} (even on an extender line).")
+           "Return whether @var{spos} is on a line of the staff associated"
+           " with the the grob @var{sg} (even on an extender line).")
 {
   LY_ASSERT_SMOB (Grob, sg, 1);
   LY_ASSERT_TYPE (scm_is_number, spos, 2);
@@ -40,10 +41,22 @@ LY_DEFINE (ly_position_on_line_p, "ly:position-on-line?",
 
 LY_DEFINE (ly_staff_symbol_line_thickness, "ly:staff-symbol-line-thickness",
            1, 0, 0, (SCM grob),
-           "Returns the line-thickness of the staff associated with @var{grob}.")
+           "Returns the @code{line-thickness} of the staff associated"
+           " with @var{grob}.")
 {
   LY_ASSERT_SMOB (Grob, grob, 1);
   Grob *g = unsmob_grob (grob);
   Real thickness = Staff_symbol_referencer::line_thickness (g);
   return scm_from_double (thickness);
 }
+
+LY_DEFINE (ly_staff_symbol_staff_space, "ly:staff-symbol-staff-space",
+           1, 0, 0, (SCM grob),
+           "Returns the @code{staff-space} of the staff associated"
+           " with @var{grob}.")
+{
+  LY_ASSERT_SMOB (Grob, grob, 1);
+  Grob *g = unsmob_grob (grob);
+  Real staff_space = Staff_symbol_referencer::staff_space (g);
+  return scm_from_double (staff_space);
+}
index 3063f39807abf3551f37d774250cac5bf5c2d188..49ff7dc560b0e46d7a4c650dcaa871f3241b83e0 100644 (file)
@@ -117,8 +117,8 @@ tieSolid = {
 }
 
 easyHeadsOn = {
-  \override NoteHead #'stencil = #ly:note-head::brew-ez-stencil
-  \override NoteHead #'font-size = #-7
+  \override NoteHead #'stencil = #note-head::brew-ez-stencil
+  \override NoteHead #'font-size = #-8
   \override NoteHead #'font-family = #'sans
   \override NoteHead #'font-series = #'bold
 }
index 71298e2698713427c696aec7f790b30e177bd600..e0d118f11a7826ce0b8400938728311c1e0ce3e7 100644 (file)
@@ -2913,7 +2913,8 @@ revert-auto-beam-setting have been eliminated.  \\overrideBeamSettings has been\
 added.  BeatGrouping has been eliminated.\n\
 Different settings for vertical layout.\n\
 ly:system-start-text::print -> system-start-text::print\n\
-Beam #'thickness -> Beam #'beam-thickness"))
+Beam #'thickness -> Beam #'beam-thickness\n\
+ly:note-head::brew-ez-stencil -> note-head::brew-ez-stencil"))
 def conv(str):
     if re.search("override-auto-beam-setting", str):
         stderr_write ("\n")
@@ -2936,7 +2937,8 @@ def conv(str):
         stderr_write(NOT_SMART % _("alignment-offsets has been changed to alignment-distances: \
 you must now specify the distances between staves rather than the offset of staves.\n"))
         stderr_write(UPDATE_MANUALLY)
-    str = re.sub ('ly:system-start-text::print', 'system-start-text::print', str)
+    str = re.sub ('ly:(system-start-text::print|note-head::brew-ez-stencil)',
+                  '\\1', str)
     str = re.sub ('(\\bBeam\\s+#\')(?=thickness\\b)', '\\1beam-', str)
     return str
 
index 152f35c7cfe9e31131302ec5affd563e83229f05..142a2d0341df1807e223061333a7493af7d0d8df 100644 (file)
           (string-append (number->string (max 0 log))
                          (symbol->string style)))))))
 
+(define-public (note-head::brew-ez-stencil grob)
+  (let* ((log (ly:grob-property grob 'duration-log))
+        (pitch (ly:event-property (event-cause grob) 'pitch))
+        (pitch-index (ly:pitch-notename pitch))
+        (note-names (ly:grob-property grob 'note-names))
+        (pitch-string (if (vector? note-names)
+                          (vector-ref note-names pitch-index)
+                          (string
+                           (integer->char
+                            (+ (modulo (+ pitch-index 2) 7)
+                               (char->integer #\A))))))
+        (staff-space (ly:staff-symbol-staff-space grob))
+        (line-thickness (ly:staff-symbol-line-thickness grob))
+        (stem (ly:grob-object grob 'stem))
+        (stem-thickness (* (if (ly:grob? stem)
+                               (ly:grob-property stem 'thickness)
+                               1.3)
+                           line-thickness))
+        (radius (/ (+ staff-space line-thickness) 2))
+        (letter (markup #:center-align #:vcenter pitch-string))
+        (filled-circle (markup #:draw-circle radius 0 #t)))
+
+    (grob-interpret-markup
+     grob
+     (if (>= log 2)
+        (make-combine-markup
+         filled-circle
+         (make-with-color-markup white letter))
+        (make-combine-markup
+         (make-combine-markup
+          filled-circle
+          (make-with-color-markup white (make-draw-circle-markup
+                                         (- radius stem-thickness) 0 #t)))
+         letter)))))
+
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; bar numbers
 (define-public ((every-nth-bar-number-visible n) barnum)
   (= 0 (modulo barnum n)))
 
-(define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
+(define-public ((modulo-bar-number-visible n m) barnum)
+  (and (> barnum 1) (= m (modulo barnum n))))
 
 (define-public ((set-bar-number-visibility n) tr)
   (let ((bn (ly:context-property tr 'currentBarNumber)))
index a4625c1e926aac6c0bf9169b66ddeb2ac051db41..1793003de29f8dfb50eb7a015814910e765fd829 100644 (file)
    ly:multi-measure-rest::print
    ly:multi-measure-rest::set-spacing-rods
    ly:note-head::print
-;;   ly:note-head::brew-ez-stencil
    ly:ottava-bracket::print
    ly:paper-column::print
    ly:percent-repeat-item-interface::beat-slash