]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/identifier-smob.cc (unpack_identifier): new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 21 Sep 2002 13:30:18 +0000 (13:30 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 21 Sep 2002 13:30:18 +0000 (13:30 +0000)
* lily/lexer.ll (identifier_type): new function.  use ly-id to
pass off scheme expressions as music identifiers.

12 files changed:
ChangeLog
NEWS
input/test/scheme-interactions.ly [new file with mode: 0644]
lily/identifier-smob.cc [new file with mode: 0644]
lily/include/identifier-smob.hh [new file with mode: 0644]
lily/include/my-lily-lexer.hh
lily/lexer.ll
scm/beam.scm
scm/chord-name.scm
scm/grob-description.scm
scm/music-functions.scm
scm/output-lib.scm

index 2a6dead7f0a6a67dac0144b49e724737c6eecf94..71cf1f201c8aa3829d500fc3532945c1a0fb3fef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2002-09-21  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * lily/identifier-smob.cc (unpack_identifier): new file.
+
+       * lily/lexer.ll (identifier_type): new function.  use ly-id to
+       pass off scheme expressions as music identifiers.
+
        * scm/lily.scm: reorganisation, cleanups.
 
        * lily/main.cc: small cleanups.
diff --git a/NEWS b/NEWS
index 7030ee0f1f3dbb8ef33aef375272f474b8e7f5a2..c6381820b609f925678d245dd028be9e9b1d24eb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,40 +1,6 @@
 
-New features in 1.6 since 1.4
-
-* Support for figured bass and tablature.
-
-* Completely rewritten beam formatting: provides much better output
-now.
-
-* Completely revised and improved music font.
-
-* Completely rewritten MIDI import support.
-
-* Completely rewritten grace note support. Practically speaking this
-means that grace notes can be slurred to normal normal notes.
-
-* Improved accidental handling and formatting: styles for producing
-cautionaries may vary, and complex collisions between accidentals of a
-chord are handled much better.
-
-* Better spacing: both globally and locally. This includes subtle
-details like optical stem spacing.
-
-* More support for ancient notation: mensural ligatures, ambitus
-(pitch range) of voices, more shapes, etc.
-
-* More support for piano notation: bracket pedals, directed arpeggios,
-arpeggio brackets.
-
-* Easier music polyphonic music entry.
-
-* More extensibility, many speedups and bugfixes
-
-* The manual has been thoroughly revised.
-
-* Development is now hosted at http://savannah.gnu.org, and sources
-can be downloaded through anonymous CVS.
-
-* Support for windows: LilyPond is part of the cygwin distribution,
-which comes with a user-friendly installer.
+New features in 1.7 since 1.6
 
+* Deeper integration of the input language and Scheme. You can now use
+LilyPond identifiers in Scheme, and use Scheme expressions instead of
+LilyPond identifiers.
diff --git a/input/test/scheme-interactions.ly b/input/test/scheme-interactions.ly
new file mode 100644 (file)
index 0000000..7671082
--- /dev/null
@@ -0,0 +1,24 @@
+
+\header {
+
+    texidoc = "With @code{ly-id}, you can pass of the result of
+Scheme expressions as lilypond input. Within a Scheme expression, you
+can use, define or change lilypond variables. "
+
+}
+
+
+foo = \notes \transpose c' { d''4-. }
+bra = \notes \transpose c' { e'4-. }
+
+\score { 
+  \context Voice \notes\relative c' {
+      c4
+      #(ly-id (make-sequential-music (list foo foo foo )))
+      #(begin (define baz (make-simultaneous-music (list foo bra)))
+       (empty-music))
+      c4
+      \baz
+      c4
+  }
+}
diff --git a/lily/identifier-smob.cc b/lily/identifier-smob.cc
new file mode 100644 (file)
index 0000000..2d38045
--- /dev/null
@@ -0,0 +1,61 @@
+/*   
+identifier-smob.cc -- implement glue to pass Scheme expressions off as
+identifiers.
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+*/
+#include "identifier-smob.hh"
+/*
+  C&P from example/box.c
+ */
+
+scm_t_bits package_tag;
+
+/* Print a textual represenation of the smob to a given port.  */
+static int
+print_box (SCM b, SCM port, scm_print_state *pstate)
+{
+  SCM value = SCM_CELL_OBJECT_1 (b);
+
+  scm_puts ("#<packaged object ", port);
+  scm_write (value, port);
+  scm_puts (">", port);
+
+  /* Non-zero means success.  */
+  return 1;
+}
+
+
+/* This defines the primitve `make-box', which returns a new smob of
+   type `box', initialized to `#f'.  */
+LY_DEFINE(package_identifier, "ly-id", 1,0,0, (SCM arg),
+         "Package a Scheme object, so it is treated as an identifier.")
+{
+  /* This macro creates the new objects, stores the value `#f' into it
+     and returns it to the caller.  */
+  SCM_RETURN_NEWSMOB (package_tag, arg);
+}
+
+
+/* This is the primitive `box-ref' which returns the object stored in
+   the box.  */
+SCM
+unpack_identifier(SCM box)
+{
+  if (SCM_IMP(box) || SCM_CELL_TYPE(box) != package_tag)
+    return SCM_UNDEFINED;
+  
+  return SCM_CELL_OBJECT_1 (box);
+}
+
+static void
+init_box_type (void)
+{
+  package_tag = scm_make_smob_type ("box", 0);
+  scm_set_smob_mark (package_tag, scm_markcdr);
+  scm_set_smob_print (package_tag, print_box);
+}
+ADD_SCM_INIT_FUNC(package, init_box_type); 
diff --git a/lily/include/identifier-smob.hh b/lily/include/identifier-smob.hh
new file mode 100644 (file)
index 0000000..3063def
--- /dev/null
@@ -0,0 +1,21 @@
+/*   
+identifier-smob.hh -- declare identifier smob.
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#ifndef IDENTIFIER_SMOB_HH
+#define IDENTIFIER_SMOB_HH
+
+#include "lily-guile.hh"
+
+
+SCM package_identifier (SCM);
+bool identifier_smob_p (SCM);
+SCM unpack_identifier (SCM);
+
+#endif /* IDENTIFIER_SMOB_HH */
+
index 06449288ed14a011ce7747375f7d8fb68357fe84..7910035d3a6bd3f3025b1d8fc1933d085097b99b 100644 (file)
@@ -69,7 +69,7 @@ private:
   int lookup_keyword (String);
   int scan_bare_word (String);
   int scan_escaped_word (String);
-
+  int identifier_type (SCM);
   char escaped_char (char) const;
 };
 
index 48d8c3564048cdac9e594947b7161ebfac8c5bd8..c058cbc7e3c2c392915c8f4d047f37dea6f85105 100644 (file)
@@ -45,6 +45,7 @@
 #include "lilypond-input-version.hh"
 #include "translator-def.hh"
 #include "music-output-def.hh"
+#include "identifier-smob.hh"
 
 /*
 RH 7 fix (?)
@@ -262,14 +263,21 @@ HYPHEN            --
                yylval.scm =  SCM_EOL;
                return SCM_T;
        }
-       yylval.scm = ly_parse_scm (s, &n, here_input());
-       
+       SCM sval = ly_parse_scm (s, &n, here_input());
+
        for (int i=0; i < n; i++)
        {
                yyinput ();
        }
        char_count_stack_.top () += n;
 
+       if (unpack_identifier (sval) != SCM_UNDEFINED)
+       {
+               yylval.scm = unpack_identifier(sval);
+               return identifier_type (yylval.scm);
+       }
+               
+       yylval.scm = sval;
        return SCM_T;
 }
 <figures>{
@@ -524,17 +532,8 @@ My_lily_lexer::pop_state ()
 }
 
 int
-My_lily_lexer::scan_escaped_word (String str)
+My_lily_lexer::identifier_type(SCM sid)
 {
-       // use more SCM for this.
-
-       SCM sym = ly_symbol2scm (str.to_str0 ());
-
-       int l = lookup_keyword (str);
-       if (l != -1) {
-               return l;
-       }
-       SCM sid = lookup_identifier (str);
        if (gh_string_p (sid)) {
                yylval.scm = sid; 
                return STRING_IDENTIFIER;
@@ -558,10 +557,26 @@ My_lily_lexer::scan_escaped_word (String str)
                yylval.scm = sid;
                return MUSIC_OUTPUT_DEF_IDENTIFIER;
        }
+       return SCM_IDENTIFIER;
+}
+
+
+int
+My_lily_lexer::scan_escaped_word (String str)
+{
+       // use more SCM for this.
 
-       if (sid != SCM_UNDEFINED) {
+       SCM sym = ly_symbol2scm (str.to_str0 ());
+
+       int l = lookup_keyword (str);
+       if (l != -1) {
+               return l;
+       }
+       SCM sid = lookup_identifier (str);
+       if (sid != SCM_UNDEFINED)
+       {
                yylval.scm = sid;
-               return SCM_IDENTIFIER;
+               return identifier_type (sid);
        }
 
        if ((YYSTATE != notes) && (YYSTATE != chords)) {
index 0b615e9fa8a738947a26f58cdabb25b95a87d581..91a041417356c76074aff62db1b1fc7c0b8ab710 100644 (file)
   (sign (- up down)))
 
 ;; arguments are in the form (up . down)
-(define (beam-dir-majority count total)
+(define-public (beam-dir-majority count total)
   (dir-compare (car count) (cdr count)))
 
-(define (beam-dir-majority-median count total)
+(define-public (beam-dir-majority-median count total)
   "First try majority. If that doesn't work, try median."
   (let ((maj (dir-compare (car count) (cdr count))))
     (if (not (= maj 0))
     ))
 
 
-(define (beam-dir-mean count total)
+(define-public (beam-dir-mean count total)
   (dir-compare (car total) (cdr total)))
 
-(define (beam-dir-median count total)
+(define-public (beam-dir-median count total)
   (if (and (> (car count) 0)
           (> (cdr count) 0))
       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
index 337235adf95dc26e49a3ffee24d3987ecdd4f892..7aba79771854a8aff0e3e1d708185c9b88aa1a23 100644 (file)
 
 ;; DONT use non-ascii characters, even if ``it works'' in Windows
 
-(define chord::names-alist-american '())
+(define-public chord::names-alist-american '())
 
 (set! chord::names-alist-american
       (append 
 
 ;; American style chordnames use no "no",
 ;; but otherwise very similar to banter for now
-(define (chord::name-american tonic exception-part unmatched-steps
+(define-public (chord::name-american tonic exception-part unmatched-steps
                              bass-and-inversion steps)
   (let ((additions (chord::additions unmatched-steps))
        (subtractions #f))
 ;;
 ;; DONT use non-ascii characters, even if ``it works'' in Windows
 
-(define chord::names-alist-jazz '())
+(define-public chord::names-alist-jazz '())
 (set! chord::names-alist-jazz
       (append 
       '(
@@ -815,7 +815,7 @@ If we encounter a chromatically altered step, turn on list-step
 ;; If you set subtract #f, the chord::inner-name-jazz does not see any
 ;; subtractions, ever, so they don't turn up in the chord name.
 ;;
-(define (chord::name-jazz tonic exception-part unmatched-steps
+(define-public (chord::name-jazz tonic exception-part unmatched-steps
                          bass-and-inversion steps)
   (let ((additions (chord::additions unmatched-steps))
        ;; get no 'omit' or 'no'
index 5f942e35fa857215db0884b9cff10870d95bd5a8..985b8f7ef13a76f76a88991b47ae20e3b7f80942 100644 (file)
        (stem-attachment-function . ,note-head-style->attachment-coordinates)
        (font-family . ancient)
        (style . mensural)
+       (glyph-name-procedure . ,find-notehead-symbol)
        (meta . ((interfaces . (ligature-head-interface rhythmic-head-interface
                                                        font-interface
                                                        note-head-interface staff-symbol-referencer-interface))))
index 60fe590d09d16cce75a1c50b7615ff95e4411354..cb2aa8e8c7b1b034aacbaf8e8b0e4cbc84e47816 100644 (file)
@@ -325,6 +325,9 @@ this is not an override
      m
      ))
 
+(define-public (empty-music)
+  (ly-id (ly-make-music "Music"))
+  )
 ;;;
 
 ; Make a function that checks score element for being of a specific type. 
index fe67ac11203b8c1050dad7e25f569cc0a30f340d..00c827595bf80082133e6bfe812293127a4274a5 100644 (file)
@@ -222,7 +222,7 @@ centered, X==1 is at the right, X == -1 is at the left."
          (string-encode-integer (quotient i 26))))))
 
 
-(define ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
+(define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
 
 (define-public (default-bar-number-visibility barnum) (> barnum 1))