From 285afa80427ca7c750bbf0a605914196769e1774 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 18 Nov 2002 00:09:28 +0000 Subject: [PATCH] * lily/text-item.cc (text_to_molecule): new function * scm/new-markup.scm (lambda): new file * lily/function-documentation.cc (ly_add_function_documentation): add proc property as well --- lily/chord-name-engraver.cc | 4 +-- lily/clef-engraver.cc | 4 --- lily/custos.cc | 14 +------- lily/dots.cc | 6 ++-- lily/duration.cc | 26 +++++++------- lily/font-interface.cc | 15 ++++++++ lily/font-metric.cc | 11 +++--- lily/function-documentation.cc | 8 ++++- lily/include/font-interface.hh | 1 + lily/include/lily-guile.hh | 4 +-- lily/include/ly-smobs.icc | 4 +-- lily/include/my-lily-lexer.hh | 1 + lily/include/text-item.hh | 5 ++- lily/lexer.ll | 4 +++ lily/my-lily-lexer.cc | 18 ++++++++++ lily/parser.yy | 30 ++++++++++++++++ lily/text-item.cc | 13 ++++++- ly/spanners-init.ly | 1 + scm/lily.scm | 1 + scm/new-markup.scm | 65 ++++++++++++++++++++++++++++++++++ 20 files changed, 185 insertions(+), 50 deletions(-) create mode 100644 scm/new-markup.scm diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc index 44e3fb8424..2c6d0e4faa 100644 --- a/lily/chord-name-engraver.cc +++ b/lily/chord-name-engraver.cc @@ -107,8 +107,8 @@ Chord_name_engraver::stop_translation_timestep () } ENTER_DESCRIPTION(Chord_name_engraver, -/* descr */ "Catch note-events, Tonic_reqs, Inversion_reqs, Bass_req -and generate the appropriate chordname.", +/* descr */ "Catch note-events, Tonic_reqs, Inversion_reqs, Bass_req " +"and generate the appropriate chordname.", /* creats*/ "ChordName", /* accepts */ "note-event busy-playing-event", /* acks */ "", diff --git a/lily/clef-engraver.cc b/lily/clef-engraver.cc index c2e671216b..bcdd8f3e36 100644 --- a/lily/clef-engraver.cc +++ b/lily/clef-engraver.cc @@ -11,16 +11,13 @@ #include #include "translator-group.hh" - #include "bar-line.hh" #include "staff-symbol-referencer.hh" - #include "engraver.hh" #include "direction.hh" #include "side-position-interface.hh" #include "item.hh" - class Clef_engraver : public Engraver { public: @@ -82,7 +79,6 @@ Clef_engraver::acknowledge_grob (Grob_info info) if (Bar_line::has_interface (info.grob_) && gh_string_p (get_property ("clefGlyph"))) create_clef (); - } } diff --git a/lily/custos.cc b/lily/custos.cc index 3b6d91cc38..c14597e20c 100644 --- a/lily/custos.cc +++ b/lily/custos.cc @@ -109,17 +109,5 @@ Custos::brew_molecule (SCM smob) } ADD_INTERFACE (Custos, "custos-interface", - "A custos is a staff context symbol that appears at the end of a - staff line with monophonic musical contents (i.e. with a single - voice). It anticipates the pitch of the first note of the following - line and thus helps the player or singer to manage line breaks - during performance, thus enhancing readability of a score. - - Custodes were frequently used in music notation until the 16th - century. There were different appearences for different notation - styles. Nowadays, they have survived only in special forms of - musical notation such as via the editio vaticana dating back to the - beginning of the 20th century. - -[TODO: add to glossary]", + "Engrave custodes", "style adjust-if-on-staffline neutral-direction neutral-position"); diff --git a/lily/dots.cc b/lily/dots.cc index 1af6f64c4e..c048131e6a 100644 --- a/lily/dots.cc +++ b/lily/dots.cc @@ -76,9 +76,9 @@ Dots::brew_molecule (SCM d) ADD_INTERFACE (Dots, "dots-interface", - "The dots to go with a notehead/rest. A separate interface, since they -are a party in collision resolution. -#'direction is the Direction to handle staff-line collisions in.", + "The dots to go with a notehead/rest. A separate interface, since they " +" are a party in collision resolution. " +" #'direction is the Direction to handle staff-line collisions in.", "direction dot-count"); diff --git a/lily/duration.cc b/lily/duration.cc index bfee07eba4..c8e6040527 100644 --- a/lily/duration.cc +++ b/lily/duration.cc @@ -137,19 +137,19 @@ Duration::less_p (SCM p1, SCM p2) LY_DEFINE(make_duration, "ly:make-duration", 2, 2, 0, (SCM length, SCM dotcount, SCM num, SCM den), - " -@var{length} is the negative logarithm (base 2) of the duration: -1 is a half note, 2 is a quarter note, 3 is an eighth -note, etc. The number of dots after the note is given by -@var{dotcount}. - -The duration factor is optionally given by @var{num} and @var{den}. - -A duration is a musical duration, i.e. a length of time described by a -power of two (whole, half, quarter, etc.) and a number of augmentation -dots. - -") +" \n" +"@var{length} is the negative logarithm (base 2) of the duration:\n" +"1 is a half note, 2 is a quarter note, 3 is an eighth\n" +"note, etc. The number of dots after the note is given by\n" +"@var{dotcount}.\n" +"\n" +"The duration factor is optionally given by @var{num} and @var{den}.\n" +"\n" +"A duration is a musical duration, i.e. a length of time described by a\n" +"power of two (whole, half, quarter, etc.) and a number of augmentation\n" +"dots. \n" +"\n" +"") { SCM_ASSERT_TYPE(gh_number_p (length), length, SCM_ARG1, __FUNCTION__, "integer"); SCM_ASSERT_TYPE(gh_number_p (dotcount), dotcount, SCM_ARG2, __FUNCTION__, "integer"); diff --git a/lily/font-interface.cc b/lily/font-interface.cc index eb1c518a4a..f8fbf0dfaf 100644 --- a/lily/font-interface.cc +++ b/lily/font-interface.cc @@ -44,6 +44,21 @@ Font_interface::font_alist_chain (Grob *me) return ch; } + +MAKE_SCHEME_CALLBACK(Font_interface, get_property_alist_chain, 1); +SCM +Font_interface::get_property_alist_chain (SCM grob) +{ + + Grob * g = unsmob_grob (grob); + SCM_ASSERT_TYPE(g, grob, SCM_ARG1, __FUNCTION__, "grob"); + return font_alist_chain (g); + +} + + + + /* todo: split up this func, reuse in text_item? */ diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 20776e444a..c3374a4b02 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -146,8 +146,8 @@ Font_metric::find_by_name (String) const LY_DEFINE(ly_find_glyph_by_name, "ly:find-glyph-by-name", 2 , 0, 0, (SCM font, SCM name), - "This function retrieves a Molecule for the glyph named @var{name} in -@var{font}. The font must be available as an AFM file.") + "This function retrieves a Molecule for the glyph named @var{name} in " +"@var{font}. The font must be available as an AFM file.") { Font_metric *fm = unsmob_metrics (font); SCM_ASSERT_TYPE(fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); @@ -159,9 +159,9 @@ LY_DEFINE(ly_find_glyph_by_name, "ly:find-glyph-by-name", 2 , 0, 0, LY_DEFINE(ly_text_dimension,"ly:text-dimension", 2 , 0, 0, (SCM font, SCM text), - "Given the font metric in @var{font} and the string @var{text}, compute -the extents of that text in that font. The return value is a pair of -number-pairs.") + "Given the font metric in @var{font} and the string @var{text}, compute " +"the extents of that text in that font. The return value is a pair of " +"number-pairs.") { Box b; Font_metric *fm = unsmob_metrics (font); @@ -180,7 +180,6 @@ number-pairs.") Molecule Font_metric::get_char_molecule (int code) const { - Molecule m ; SCM at = scm_list_n (ly_symbol2scm ("char"), gh_int2scm (code), SCM_UNDEFINED); at = fontify_atom (this, at); diff --git a/lily/function-documentation.cc b/lily/function-documentation.cc index 73cba4aac2..46dbbfe572 100644 --- a/lily/function-documentation.cc +++ b/lily/function-documentation.cc @@ -1,16 +1,22 @@ #include "lily-guile.hh" #include "protected-scm.hh" +#include "string.hh" static Protected_scm doc_hash_table ; -void ly_add_function_documentation (char const * fname, +void ly_add_function_documentation (SCM func, + char const * fname, char const * varlist, char const * doc) { if (!gh_vector_p (doc_hash_table )) doc_hash_table = scm_make_vector (gh_int2scm (59), SCM_EOL); + String s = String (" - ") + "LilyPond procedure: " + fname + " " + varlist + + "\n" + doc ; + scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"), + scm_makfrom0str (s.to_str0 ())); SCM entry = gh_cons (scm_makfrom0str (varlist), scm_makfrom0str (doc)); scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname), entry); } diff --git a/lily/include/font-interface.hh b/lily/include/font-interface.hh index 176e4c3210..ada4660ce9 100644 --- a/lily/include/font-interface.hh +++ b/lily/include/font-interface.hh @@ -21,6 +21,7 @@ struct Font_interface static SCM add_style (Grob*, SCM style, SCM alist_chain); static bool wild_compare (SCM field_val, SCM val); DECLARE_SCHEME_CALLBACK (properties_to_font_name, (SCM,SCM)); + DECLARE_SCHEME_CALLBACK (get_property_alist_chain, (SCM)); static bool has_interface (Grob*); }; diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index c0aed3729c..cf1fe9dfed 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -265,7 +265,7 @@ TYPE ## _ ## FUNC ## _init_functions () \ ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions); \ -void ly_add_function_documentation (char const * fname, +void ly_add_function_documentation (SCM proc, char const * fname, char const * varlist, char const * doc); @@ -286,7 +286,7 @@ INITPREFIX ## init ()\ {\ FNAME ## _proc \ = scm_c_define_gsubr (PRIMNAME,REQ, OPT, VAR, (Scheme_function_unknown) FNAME);\ - ly_add_function_documentation (PRIMNAME, #ARGLIST, DOCSTRING);\ + ly_add_function_documentation ( FNAME ## _proc ,PRIMNAME, #ARGLIST, DOCSTRING);\ scm_c_export (PRIMNAME,NULL);\ }\ ADD_SCM_INIT_FUNC (INITPREFIX ## init_unique_prefix, INITPREFIX ## init);\ diff --git a/lily/include/ly-smobs.icc b/lily/include/ly-smobs.icc index 7140218fef..24c746b6ae 100644 --- a/lily/include/ly-smobs.icc +++ b/lily/include/ly-smobs.icc @@ -15,8 +15,8 @@ #define IMPLEMENT_TYPE_P(CL, FUNCNAME)\ void init_type_ ## CL ()\ {\ - scm_c_define_gsubr (FUNCNAME, 1, 0, 0, (Scheme_function_unknown) CL::smob_p);\ - ly_add_function_documentation (FUNCNAME, "(SCM x)", "Check if @var{x} is a " #CL " object");\ + SCM subr = scm_c_define_gsubr (FUNCNAME, 1, 0, 0, (Scheme_function_unknown) CL::smob_p);\ + ly_add_function_documentation (subr, FUNCNAME, "(SCM x)", "Check if @var{x} is a " #CL " object");\ scm_c_export (FUNCNAME, NULL);\ }\ ADD_SCM_INIT_FUNC (init_type_ ## CL, init_type_ ## CL) diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 3cc210b958..e52d22573b 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -72,6 +72,7 @@ public: private: int lookup_keyword (String); int scan_bare_word (String); + SCM scan_markup_word (String); int scan_escaped_word (String); int identifier_type (SCM); char escaped_char (char) const; diff --git a/lily/include/text-item.hh b/lily/include/text-item.hh index e8479e9d74..70a7609d21 100644 --- a/lily/include/text-item.hh +++ b/lily/include/text-item.hh @@ -19,13 +19,12 @@ class Text_item { public: DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM)); + DECLARE_SCHEME_CALLBACK (text_to_molecule, (SCM,SCM, SCM)); static Molecule text2molecule (Grob *me, SCM text, SCM properties); static Molecule string2molecule (Grob *me, SCM text, SCM properties); static Molecule markup_text2molecule (Grob *me, SCM markup_text, SCM properties); - static bool has_interface (Grob*); - - + private: static Molecule lookup_character (Grob *me, Font_metric*, SCM char_name); static Molecule lookup_text (Grob *me, Font_metric*, SCM text); diff --git a/lily/lexer.ll b/lily/lexer.ll index c6e6b7a920..de7da49658 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -296,6 +296,7 @@ HYPHEN -- return FIGURE_OPEN; } } + { {ALPHAWORD} { return scan_bare_word (YYText ()); @@ -427,6 +428,9 @@ HYPHEN -- } } + + + <> { diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index cc3e5df351..55519c2176 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -224,3 +224,21 @@ My_lily_lexer::prepare_for_next_token () { last_input_ = here_input(); } + +#if 0 +SCM +My_lily_lexer::scan_markup_word (String s) +{ + /* + TODO: better implementation: + + - make a table of markup functions, for quicker lookup + + - error handling. + + */ + SCM s = scm_c_eval_str ((s + "-markup").to_str0()); + yylval.scm = s; + return MARKUP_HEAD; +} +#endif diff --git a/lily/parser.yy b/lily/parser.yy index bb919029b6..204426ae8a 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -2215,3 +2215,33 @@ My_lily_lexer::try_special_identifiers (SCM * destination, SCM sid) } return -1; } +#if 0 + +markup: + STRING { + $$ = scm_list_n (scm_c_eval_string ("simple-markup"), $1, SCM_UNDEFINED); + } + | MARKUP_HEAD0 markup + | MARKUP_HEAD1 SCM_T markup + | MARKUP_HEAD2 markup + | MARKUP_LIST_HEAD + | MARKUP_LIST_HEAD + | markup_list { + $$ = $1 + ; + +markup_list: + '<' markup_list_body '>' { $$ = scm_reverse_x ($1, SCM_EOL); } + ; + +markup_line: + '{' markup_list_body '}' { $$ = .. scm_reverse_x ($1, SCM_EOL); } + + ; +markup_list_body: + /**/ { $$ = SCM_EOL; } + markup_list_body markup { + $$ = gh_cons ($2, $1) ; + } + ; +#endif diff --git a/lily/text-item.cc b/lily/text-item.cc index c84ee7e7f0..47a7426c27 100644 --- a/lily/text-item.cc +++ b/lily/text-item.cc @@ -59,7 +59,18 @@ Text_item::text2molecule (Grob *me, SCM text, SCM alist_chain) } return Molecule (); } - + + +MAKE_SCHEME_CALLBACK(Text_item,text_to_molecule,3); +SCM +Text_item::text_to_molecule (SCM grob, SCM props, SCM markup) +{ + Grob *me = unsmob_grob (grob); + + return Text_item::text2molecule (me, markup, props).smobbed_copy(); +} + + Molecule Text_item::string2molecule (Grob *me, SCM text, SCM alist_chain) { diff --git a/ly/spanners-init.ly b/ly/spanners-init.ly index 78d81ad999..60ad14adee 100644 --- a/ly/spanners-init.ly +++ b/ly/spanners-init.ly @@ -3,6 +3,7 @@ startCluster = #(make-span-event 'ClusterEvent START) stopCluster = #(make-span-event 'ClusterEvent STOP) + groupOpen = #(make-span-event 'NoteGroupingEvent START) groupClose = #(make-span-event 'NoteGroupingEvent STOP) diff --git a/scm/lily.scm b/scm/lily.scm index 9980da2c38..51a2dd819b 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -238,5 +238,6 @@ is the first to satisfy CRIT "script.scm" "drums.scm" "midi.scm" + "new-markup.scm" )) diff --git a/scm/new-markup.scm b/scm/new-markup.scm new file mode 100644 index 0000000000..78cbb7779a --- /dev/null +++ b/scm/new-markup.scm @@ -0,0 +1,65 @@ + + + +(define-public (simple-markup grob props . rest) + (Text_item::text_to_molecule grob props (car rest)) + ) + +(define-public (line-markup grob props . rest) + (stack-molecules + X 1 1.0 + (map (lambda (x) (interpret_markup grob props x)) (car rest))) + ) + +(define (combine-molecule-list lst) + (if (null? (cdr lst)) (car lst) + (ly:add-molecule (car lst) (combine-molecule-list (cdr lst))) + )) + +(define-public (combine-markup grob props . rest) + (combine-molecule-list (map (lambda (x) (interpret_markup grob props x)) (car rest)))) + +(define-public (bold-markup grob props . rest) + (interpret_markup grob (cons '((font-series . bold)) props) (car rest)) + ) + +(define-public (column-markup grob props . rest) + (stack-molecules + Y -1 0.0 + (map (lambda (x) (interpret_markup grob props x)) (car rest))) + ) + +;; todo. Use macro? +(map + (lambda (x) + + (set-object-property! + (eval (string->symbol (string-append (symbol->string x) "-markup")) (current-module)) + 'markup-function? #t)) + + '(simple column bold combine line ) + ) + +(define-public (brew-new-markup-molecule grob) + (interpret_markup grob + (Font_interface::get_property_alist_chain grob) + (ly:get-grob-property grob 'text) + ) + ) + +(define (interpret_markup grob props markup) + (let* + ( + (func (car markup)) + (args (cdr markup)) + ) + + (apply func (cons grob (cons props args)) ) + )) + +(define (new-markup? x) + (markup-function? (car x)) +) + +(define (markup-function? x) + (object-property 'markup-function? x)) -- 2.39.2