From: Han-Wen Nienhuys Date: Sat, 21 Sep 2002 13:30:18 +0000 (+0000) Subject: * lily/identifier-smob.cc (unpack_identifier): new file. X-Git-Tag: release/1.7.0~3 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c82da428296a290d2728eac6e36de3b3b80d14d1;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 2a6dead7f0..71cf1f201c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2002-09-21 Han-Wen Nienhuys + * 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 7030ee0f1f..c6381820b6 100644 --- 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 index 0000000000..76710822ef --- /dev/null +++ b/input/test/scheme-interactions.ly @@ -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 index 0000000000..2d380454d8 --- /dev/null +++ b/lily/identifier-smob.cc @@ -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 + +*/ +#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 ("#", 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 index 0000000000..3063def1f2 --- /dev/null +++ b/lily/include/identifier-smob.hh @@ -0,0 +1,21 @@ +/* +identifier-smob.hh -- declare identifier smob. + +source file of the GNU LilyPond music typesetter + +(c) 2002 Han-Wen Nienhuys + + */ + +#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 */ + diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 06449288ed..7910035d3a 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -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; }; diff --git a/lily/lexer.ll b/lily/lexer.ll index 48d8c35640..c058cbc7e3 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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; } { @@ -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)) { diff --git a/scm/beam.scm b/scm/beam.scm index 0b615e9fa8..91a0414173 100644 --- a/scm/beam.scm +++ b/scm/beam.scm @@ -38,10 +38,10 @@ (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)) @@ -50,10 +50,10 @@ )) -(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))) diff --git a/scm/chord-name.scm b/scm/chord-name.scm index 337235adf9..7aba797718 100644 --- a/scm/chord-name.scm +++ b/scm/chord-name.scm @@ -440,7 +440,7 @@ ;; 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 @@ -488,7 +488,7 @@ ;; 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)) @@ -519,7 +519,7 @@ ;; ;; 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' diff --git a/scm/grob-description.scm b/scm/grob-description.scm index 5f942e35fa..985b8f7ef1 100644 --- a/scm/grob-description.scm +++ b/scm/grob-description.scm @@ -437,6 +437,7 @@ (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)))) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 60fe590d09..cb2aa8e8c7 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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. diff --git a/scm/output-lib.scm b/scm/output-lib.scm index fe67ac1120..00c827595b 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -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))