Re: include music-function

2012-01-09 Thread Jan-Peter Voigt

Hello again,

Am 07.01.2012 09:42, schrieb David Kastrup:

Actually, this is quite too complicated...

(ly:parser-include-string parser
   (format #f \\include ~S file))

should likely be all that is needed here.

Sorry for thinking too complicated.


so its just:
--snip--
#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location
; condition when to include
 (if (or (string=? outname locname) (string-suffix? outname 
locname))
 (ly:parser-include-string parser (format \\include 
\~A\\n file)))

 (make-music 'SequentialMusic 'void #t
--snip--

So another solution to issue 1096, Carl mentioned, could be:
--snip--
#(define-public includeIf (define-music-function (parser location pred 
file)(procedure? string?)

 (if (pred parser location)
 (ly:parser-include-string parser (format \\include 
\~A\\n file)))

 (make-music 'SequentialMusic 'void #t)))

\includeIf #(lambda (parser location) (not (defined? 'defs))) defs.ly
--snip--
where in defs.ly somewhere defs is defined. Or the given lambda looks 
into a singleton containing all filenames already included or ...

Of course one could use just
--snip--
#(define-public includeIfNotDef (define-music-function (parser location 
sym file)(symbol? string?)

 (if (not (defined? sym))
 (ly:parser-include-string parser (format \\include 
\~A\\n file)))

 (make-music 'SequentialMusic 'void #t)))

\includeIfNotDef #'defs defs.ly
--snip--
Conclusion: To write a different include music-function, use 
(ly:parser-include-string parser (format \\include \~A\\n file)) so 
that this can be done in global context.


The other function I implemented is also only changing the 
parser-include-string and removes ly:gulp-file.
This is working for me and I am sharing it here, but I don't want to 
bother anyone to look thru this code. The only thing I'd like to know 
is: In %load-path the scheme search-path is stored ... where is the 
lilypond-search-path stored? I propably just didn't saw in the docs?


To explain the other include function a little bit (see below): The 
directory containing the file named in location is reference point for 
the directory search. Because ly:find-file doesn't find directories, I 
cannot refer to that. (It would be nice, but I'd call it a special thing 
and not an issue ;) ). One could use a reference file and include all 
siblings matching the pattern or ... or ...

This fits for me:
If I have a collection of files to include part-nn.ly in a directory 
called parts I can place a file parts.ly in the upper directory 
containing

--snip--
\includePattern parts part-[0-9][0-9].ly
--snip--
Parameters:
1 - string? directory to search
2 - string? regular expression to match filenames

The include order is not predictable, so the include files should 
contain variable definitions and not typeset by themself. Of course one 
could first collect all filenames in a list, sort it and then do the 
inclusion with for-each over that list.

But there might be many other ideas, how to search and include part-files.

Cheers,
Jan-Peter

--snip--
#(use-modules (ice-9 regex))
#(define-public includePattern (define-music-function (parser location 
idir pattern)(string? string?)

(let* ((normalize-list (lambda (path)
 (let ((ret '()))
  (for-each (lambda (e)
(set! ret (cond ((equal? e 
..)(if ( (length ret) 1) (cdr ret) '()))
((equal? e 
.) ret)
(else `(,e 
,@ret) path)

  (reverse ret
   (normalize-path (lambda (s) (string-join (normalize-list 
(string-split s #\/)) / 'infix)))

   (extract-path (lambda (location)
 (let* ((loc (car (ly:input-file-line-char-column 
location)))

(dirmatch (string-match (.*/).* loc))
(dirname (if (regexp-match? dirmatch) 
(normalize-path (match:substring dirmatch 1)) ./)))

   dirname
   )))

   (dirname (string-append (extract-path location) idir)))

  (if (not (eq? #\. (string-ref dirname 0))) (set! dirname 
(normalize-path dirname)))

  (if (or (= (string-length dirname) 0)
  (not (eq? #\/ (string-ref dirname (- (string-length 
dirname) 1)

  (set! dirname (string-append dirname /)))
  (if (or (not (file-exists? dirname)) (not (eq? 'directory 
(stat:type (stat dirname)

  (set! dirname #f))

  (if dirname (let* ((dir (opendir dirname))
   (entry (readdir dir)))
  (while (not (eof-object? entry

Re: include music-function

2012-01-07 Thread Jan-Peter Voigt
Hello Carl, Hello David,
thanks for your replies!
I will read through those threads next week. This might help me understand what 
is happening under the hood.

The basic include is working as expected. But I think it would be a nice 
feature if one could search for files to include using scheme.

Cheers,
Jan-Peter

Am 06.01.2012 um 21:40 schrieb Carl Sorensen c_soren...@byu.edu:

 On 1/6/12 7:28 AM, David Kastrup d...@gnu.org wrote:
 
 
 Now I don't want to repeat old mistakes, but I don't really have the
 time for an extended investigation.  So if somebody gives me all the
 data in a manner that does not require all too much thinking on my side,
 I might try putting that kind of functionality back.
 
 Here is a thread that discusses this problem.  You were not interested in
 eliminating
 parser-parse-file at this point, but it appears that it got eliminated
 anyway.
 
 http://thread.gmane.org/gmane.comp.gnu.lilypond.devel/29392/focus=29404
 
 
 These patches came in response to issue 1096,
 
 http://code.google.com/p/lilypond/issues/detail?id=1096
 
 
 where a segfault happened with parser-parse-string due to infinite
 recursion, IIUC.  Also see issue 1119:
 
 http://code.google.com/p/lilypond/issues/detail?id=1119
 
 
 
 A related thread (indexed in issue 1096) is:
 
 http://lists.gnu.org/archive/html/lilypond-devel/2010-02/msg00106.html
 
 
 HTH,
 
 Carl
 
 
 

___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-07 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 Am 06.01.2012 10:17, schrieb Jan-Peter Voigt:
 Am 06.01.2012 09:35, schrieb Jan-Peter Voigt:
 Hello David,

 the \sourcefilename hint is helpful! Thank you!
 If I use this in my function and do a ly:parser-clone, the location
 is up to date:
 ...
 Now I will look, if this is working also with
 ly:parser-include-string while resetting filename and fileline at
 the end, so that definitions in the included file get into the
 current parser.


 ... yes it does:

 --snip--
 #(define-public includeLocal (define-music-function (parser location
 file)(string?)
 (let ((outname (format ~A.ly (ly:parser-output-name parser)))
   (locname (car (ly:input-file-line-char-column location)))
   (locpos (cadr (ly:input-file-line-char-column location
  (if (or (string=? outname locname)(string-suffix? outname
 locname))
  (begin
(ly:parser-include-string parser (format
 \\sourcefilename \~A\ \\sourcefileline 0\n (ly:find-file file)))
(ly:parser-include-string parser (ly:gulp-file file))
(ly:parser-include-string parser (format 
 \\sourcefilename \~A\ \\sourcefileline ~A\n locname locpos
  (make-music 'SequentialMusic 'void #t
 --snip--

 ... but if I include a file in an included file, it will not
 parse. I will investigate that for more info.
 OK, now I had lunch and saw my own mistakes ...

 Here are the two functions I implemented ... still a bit clumsy, but
 it works for now ... if you are interested *how* and *why* to use
 them, don't hesitate to mail me!

Actually, this is quite too complicated...

(ly:parser-include-string parser
  (format #f \\include ~S file))

should likely be all that is needed here.

Sorry for thinking too complicated.

-- 
David Kastrup


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-07 Thread Jan-Peter Voigt
Ah, yes ... I will rewrite this, when I'm in my machine again 

Cheers, Jan-Peter


Am 07.01.2012 um 09:42 schrieb David Kastrup d...@gnu.org:

 Jan-Peter Voigt jp.vo...@gmx.de writes:
 
 Am 06.01.2012 10:17, schrieb Jan-Peter Voigt:
 Am 06.01.2012 09:35, schrieb Jan-Peter Voigt:
 Hello David,
 
 the \sourcefilename hint is helpful! Thank you!
 If I use this in my function and do a ly:parser-clone, the location
 is up to date:
 ...
 Now I will look, if this is working also with
 ly:parser-include-string while resetting filename and fileline at
 the end, so that definitions in the included file get into the
 current parser.
 
 
 ... yes it does:
 
 --snip--
 #(define-public includeLocal (define-music-function (parser location
 file)(string?)
(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location)))
  (locpos (cadr (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname
 locname))
 (begin
   (ly:parser-include-string parser (format
 \\sourcefilename \~A\ \\sourcefileline 0\n (ly:find-file file)))
   (ly:parser-include-string parser (ly:gulp-file file))
   (ly:parser-include-string parser (format 
 \\sourcefilename \~A\ \\sourcefileline ~A\n locname locpos
 (make-music 'SequentialMusic 'void #t
 --snip--
 
 ... but if I include a file in an included file, it will not
 parse. I will investigate that for more info.
 OK, now I had lunch and saw my own mistakes ...
 
 Here are the two functions I implemented ... still a bit clumsy, but
 it works for now ... if you are interested *how* and *why* to use
 them, don't hesitate to mail me!
 
 Actually, this is quite too complicated...
 
 (ly:parser-include-string parser
  (format #f \\include ~S file))
 
 should likely be all that is needed here.
 
 Sorry for thinking too complicated.
 
 -- 
 David Kastrup
 
 
 ___
 lilypond-devel mailing list
 lilypond-devel@gnu.org
 https://lists.gnu.org/mailman/listinfo/lilypond-devel

___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-06 Thread Jan-Peter Voigt

Hello David,

the \sourcefilename hint is helpful! Thank you!
If I use this in my function and do a ly:parser-clone, the location is 
up to date:


--snip--
#(define-public showloc (define-music-function (parser location)()
(format #t  ~A\n (ly:input-file-line-char-column location))
(make-music 'SequentialMusic 'void #t)))

#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 (ly:parser-parse-string (ly:parser-clone parser)
   (format \\sourcefilename \~A\\n\\sourcefileline 
~A\n~A file 0 (ly:gulp-file file

 (make-music 'SequentialMusic 'void #t
--snip--

Now I will look, if this is working also with ly:parser-include-string 
while resetting filename and fileline at the end, so that definitions in 
the included file get into the current parser.


Cheers,
Jan-Peter

Am 05.01.2012 17:14, schrieb David Kastrup:

Jan-Peter Voigtjp.vo...@gmx.de  writes:


#(define-public includeLocal (define-music-function (parser location
file)(string?)
 (let ((outname (format ~A.ly (ly:parser-output-name parser)))
   (locname (car (ly:input-file-line-char-column location
  (if (or (string=? outname locname)(string-suffix? outname
locname))
  (let ((content (ly:gulp-file file)))
   (ly:parser-include-string parser content)))
  (make-music 'SequentialMusic 'void #t

\includeLocal test.ly
--snip--
This function first compares the outname with the location name and
only includes the file if they match. (This should not work, if you
have set some output-suffix!)

This is a usable solution to me. But I would like to have the correct
location info available, while parsing the included file.
Is it possible to create an arbitrary include-music-function? This
would make it possible, to (for example) include all files in a
directory or matching a specific pattern.

You can start your string with \sourcefilename and \sourcefileline.
ly:parser-parse-expression has optional arguments for that purpose.  If
you would consider this helpful, I might try fudging this into
parser-include-string as well.

I have not followed the reasons why we would not have
parser-include-file.




___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-06 Thread Jan-Peter Voigt

Am 06.01.2012 09:35, schrieb Jan-Peter Voigt:

Hello David,

the \sourcefilename hint is helpful! Thank you!
If I use this in my function and do a ly:parser-clone, the location is 
up to date:

...
Now I will look, if this is working also with ly:parser-include-string 
while resetting filename and fileline at the end, so that definitions 
in the included file get into the current parser.




... yes it does:

--snip--
#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location)))
  (locpos (cadr (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 (begin
   (ly:parser-include-string parser (format 
\\sourcefilename \~A\ \\sourcefileline 0\n (ly:find-file file)))

   (ly:parser-include-string parser (ly:gulp-file file))
   (ly:parser-include-string parser (format  
\\sourcefilename \~A\ \\sourcefileline ~A\n locname locpos

 (make-music 'SequentialMusic 'void #t
--snip--

... but if I include a file in an included file, it will not parse. I 
will investigate that for more info.


Cheers,
Jan-Peter


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-06 Thread Jan-Peter Voigt

Am 06.01.2012 10:17, schrieb Jan-Peter Voigt:

Am 06.01.2012 09:35, schrieb Jan-Peter Voigt:

Hello David,

the \sourcefilename hint is helpful! Thank you!
If I use this in my function and do a ly:parser-clone, the location 
is up to date:

...
Now I will look, if this is working also with 
ly:parser-include-string while resetting filename and fileline at the 
end, so that definitions in the included file get into the current 
parser.




... yes it does:

--snip--
#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location)))
  (locpos (cadr (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 (begin
   (ly:parser-include-string parser (format 
\\sourcefilename \~A\ \\sourcefileline 0\n (ly:find-file file)))

   (ly:parser-include-string parser (ly:gulp-file file))
   (ly:parser-include-string parser (format  
\\sourcefilename \~A\ \\sourcefileline ~A\n locname locpos

 (make-music 'SequentialMusic 'void #t
--snip--

... but if I include a file in an included file, it will not parse. I 
will investigate that for more info.

OK, now I had lunch and saw my own mistakes ...

Here are the two functions I implemented ... still a bit clumsy, but it 
works for now ... if you are interested *how* and *why* to use them, 
don't hesitate to mail me!


--snip--
\version 2.15.21

#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location)))
  (file (ly:find-file file)))
 (if (or (string=? outname locname) (string-suffix? outname 
locname))

 (begin
   ;(ly:input-message location include ~A file)
   (ly:parser-include-string parser (format 
\\sourcefilename \~A\ \\sourcefileline 0\n~A

   file (ly:gulp-file file
 )
 (make-music 'SequentialMusic 'void #t

% EXAMPLE
% include file from lilypond search path (like \include)
\includeLocal test-local.ily

#(use-modules (ice-9 regex))
#(define-public includePattern (define-music-function (parser location 
idir pattern)(string? string?)

(let* ((normalize-list (lambda (path)
 (let ((ret '()))
  (for-each (lambda (e)
(set! ret (cond ((equal? e 
..)(if ( (length ret) 1) (cdr ret) '()))
((equal? e 
.) ret)
(else `(,e 
,@ret) path)

  (reverse ret
   (normalize-path (lambda (s) (string-join (normalize-list 
(string-split s #\/)) / 'infix)))

   (extract-path (lambda (location)
 (let* ((loc (car (ly:input-file-line-char-column 
location)))

(dirmatch (string-match (.*/).* loc))
(dirname (if (regexp-match? dirmatch) 
(normalize-path (match:substring dirmatch 1)) ./)))

   dirname
   )))

   (dirname (string-append (extract-path location) idir)))

  (if (not (eq? #\. (string-ref dirname 0))) (set! dirname 
(normalize-path dirname)))

  (if (or (= (string-length dirname) 0)
  (not (eq? #\/ (string-ref dirname (- (string-length 
dirname) 1)

  (set! dirname (string-append dirname /)))
  (if (or (not (file-exists? dirname)) (not (eq? 'directory 
(stat:type (stat dirname)

  (set! dirname #f))

  (if dirname (let* ((dir (opendir dirname))
   (entry (readdir dir)))
  (while (not (eof-object? entry))
 (if (regexp-match? (string-match pattern entry))
 (let ((file (string-append dirname entry)))
  ;(ly:input-message location include 
~A file)

  (ly:parser-include-string parser
(format \\sourcefilename \~A\ 
\\sourcefileline 0\n~A file (ly:gulp-file file)

 (set! entry (readdir dir))
  )
  (closedir dir)
  ))
)
(make-music 'SequentialMusic 'void #t)))

% EXAMPLE
% param 1: file path of containing directory, relative to the including 
file!

% param 2: regular expression to match filenames
\includePattern ../test/scheme ^.*\.ily$
--snip--

Cheers,
Jan-Peter


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-06 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 Here are the two functions I implemented ... still a bit clumsy, but
 it works for now ... if you are interested *how* and *why* to use
 them, don't hesitate to mail me!

If anybody is game for digging up the old discussion: I don't think it
makes sense to require a user to rebuild ly:parser-include-file or
whatever it was called previously manually.

I mean, builds character and all (actually, lots of characters), but all
in all, it should be core functionality.

Now I don't want to repeat old mistakes, but I don't really have the
time for an extended investigation.  So if somebody gives me all the
data in a manner that does not require all too much thinking on my side,
I might try putting that kind of functionality back.

-- 
David Kastrup

___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-06 Thread Carl Sorensen
On 1/6/12 7:28 AM, David Kastrup d...@gnu.org wrote:


Now I don't want to repeat old mistakes, but I don't really have the
time for an extended investigation.  So if somebody gives me all the
data in a manner that does not require all too much thinking on my side,
I might try putting that kind of functionality back.

Here is a thread that discusses this problem.  You were not interested in
eliminating
parser-parse-file at this point, but it appears that it got eliminated
anyway.

http://thread.gmane.org/gmane.comp.gnu.lilypond.devel/29392/focus=29404


These patches came in response to issue 1096,

http://code.google.com/p/lilypond/issues/detail?id=1096


where a segfault happened with parser-parse-string due to infinite
recursion, IIUC.  Also see issue 1119:

http://code.google.com/p/lilypond/issues/detail?id=1119



A related thread (indexed in issue 1096) is:

http://lists.gnu.org/archive/html/lilypond-devel/2010-02/msg00106.html


HTH,

Carl




___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


include music-function

2012-01-05 Thread Jan-Peter Voigt

Dear lily-list-members,

first of all: A happy new year!

In my projects I often combine several files, each containing one piece, 
to a book.
In fact, I store the music in a scheme-based structure to instantiate it 
later.
The included files shall intentionally not create a PDF, so that 
instantiation can be organized in bookparts as needed.
But when I work on a specific piece I want to debug it without compiling 
the whole book.
One solution would be to use frescobaldi and a comment %%master: 
../main.ly at the end of the file. But then I have to create a 
master-file for each part.
So I created a music-function to include a testfile wich contains 
instructions to instantiate the music stored in my structures only if I 
am compiling this file directly:

--snip--
#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 (let ((content (ly:gulp-file file)))
  (ly:parser-include-string parser content)))
 (make-music 'SequentialMusic 'void #t

\includeLocal test.ly
--snip--
This function first compares the outname with the location name and only 
includes the file if they match. (This should not work, if you have set 
some output-suffix!)


This is a usable solution to me. But I would like to have the correct 
location info available, while parsing the included file.
Is it possible to create an arbitrary include-music-function? This 
would make it possible, to (for example) include all files in a 
directory or matching a specific pattern.


Cheers,
Jan-Peter


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 I am compiling this file directly:
 --snip--
 #(define-public includeLocal (define-music-function (parser location
 file)(string?)
 (let ((outname (format ~A.ly (ly:parser-output-name parser)))
   (locname (car (ly:input-file-line-char-column location
  (if (or (string=? outname locname)(string-suffix? outname
 locname))
  (let ((content (ly:gulp-file file)))
   (ly:parser-include-string parser content)))
  (make-music 'SequentialMusic 'void #t

 \includeLocal test.ly
 --snip--
 This function first compares the outname with the location name and
 only includes the file if they match. (This should not work, if you
 have set some output-suffix!)

 This is a usable solution to me. But I would like to have the correct
 location info available, while parsing the included file.
 Is it possible to create an arbitrary include-music-function? This
 would make it possible, to (for example) include all files in a
 directory or matching a specific pattern.

Any reason you don't just do #{ \include #file #} here?

-- 
David Kastrup


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread Jan-Peter Voigt

Hello David,

Any reason you don't just do #{ \include #file #} here?


yes there is:
--snip--
\version 2.15.21

#(define-public includeLocal (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 #{ \include $file #}
 (make-music 'SequentialMusic 'void #t)

\includeLocal test.ily
--snip--
this places the include in some context, generated by #{ #}.
So if I have:
--snip-- (test.ily)
\version 2.15.21

mus = \relative c' {
  c4 e g c
}

{ \mus }
--snip--
it will fail, because I try to assign mus here in a contained context.

Cheers,
Jan-Peter


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 Hello David,
 Any reason you don't just do #{ \include #file #} here?

 yes there is:
 --snip--
 \version 2.15.21

 #(define-public includeLocal (define-music-function (parser location
 file)(string?)
 (let ((outname (format ~A.ly (ly:parser-output-name parser)))
   (locname (car (ly:input-file-line-char-column location
  (if (or (string=? outname locname)(string-suffix? outname
 locname))
  #{ \include $file #}
  (make-music 'SequentialMusic 'void #t)

 \includeLocal test.ily
 --snip--
 this places the include in some context, generated by #{ #}.

Ah yes.  ly:parse-file does not help either?

-- 
David Kastrup


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread Jan-Peter Voigt

Hello David,

Am 05.01.2012 13:50, schrieb David Kastrup:


Ah yes.  ly:parse-file does not help either?


yes it does, thanks ... but ...

--snip--
#(define-public includeLoc (define-music-function (parser location 
file)(string?)

(let ((outname (format ~A.ly (ly:parser-output-name parser)))
  (locname (car (ly:input-file-line-char-column location
 (if (or (string=? outname locname)(string-suffix? outname 
locname))

 (ly:parse-file file))
 (make-music 'SequentialMusic 'void #t
--snip--

I nowadays store the music in a scheme structure saved as a singleton in 
a self-made module. If the included file refers to this singleton, the 
music will appear ... great!


Before this, I created variables
--snip--
music = \relative c' { c4 e g c }
\includeLocal test-music.ly
--snip--
and used a file
--snip-- (test-music.ly)
{ \music }
--snip--

This does not work ... the var music is not known in the file included 
with ly:parse-file.
There has been a function ly:parser-parse-file in 2.12 - and if my 
memory doesn't trick me, there has been discussion on devel why and how 
to remove it.

This might or might not have been useful in this context.
So a question remains: How could I carry defined variables between 
inside-outside ly:parse-file ?


Cheers,
Jan-Peter


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 This does not work ... the var music is not known in the file
 included with ly:parse-file.
 There has been a function ly:parser-parse-file in 2.12 - and if my
 memory doesn't trick me, there has been discussion on devel why and
 how to remove it.
 This might or might not have been useful in this context.

Maybe.  At that time, I was not acquainted with the code.

 So a question remains: How could I carry defined variables between
 inside-outside ly:parse-file ?

With the current tools, I don't have much of an idea.

-- 
David Kastrup


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: include music-function

2012-01-05 Thread David Kastrup
Jan-Peter Voigt jp.vo...@gmx.de writes:

 #(define-public includeLocal (define-music-function (parser location
 file)(string?)
 (let ((outname (format ~A.ly (ly:parser-output-name parser)))
   (locname (car (ly:input-file-line-char-column location
  (if (or (string=? outname locname)(string-suffix? outname
 locname))
  (let ((content (ly:gulp-file file)))
   (ly:parser-include-string parser content)))
  (make-music 'SequentialMusic 'void #t

 \includeLocal test.ly
 --snip--
 This function first compares the outname with the location name and
 only includes the file if they match. (This should not work, if you
 have set some output-suffix!)

 This is a usable solution to me. But I would like to have the correct
 location info available, while parsing the included file.
 Is it possible to create an arbitrary include-music-function? This
 would make it possible, to (for example) include all files in a
 directory or matching a specific pattern.

You can start your string with \sourcefilename and \sourcefileline.
ly:parser-parse-expression has optional arguments for that purpose.  If
you would consider this helpful, I might try fudging this into
parser-include-string as well.

I have not followed the reasons why we would not have
parser-include-file.

-- 
David Kastrup


___
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel