implicitly running a lilypond script through a python script before compilation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

implicitly running a lilypond script through a python script before compilation

Joseph Chrestien
Hi all,

I know this is going to sound strange: is it possible (or even imaginable) to run a Python code snippet from "within" Lilypond code at compile time?

This is my situation: I am currently using a custom extension of the "Column markup" Frescobaldi snippet, to print verses below a staff. So far, so good (just discovered these snippets - very nice indeed!), but I am compiling quite a large library I am afraid I might want to change some details in the snippet as time goes by. Currently, that would mean highlight-clicking every single ly file.

I am interested if anybody has a clue in how I can tweak Lily configs (if possible) so that my input script (A) would be automatically submitted to (say) a Python script called `verse-markup` located in the right folder and would be *implicitly* transformed into script (B). [See below]

I had a vague idea I could change the Frescobaldi execute path so that the script (invisibly) first goes to Python before being submitted to Lilypond in the "script B" form - does that seem any good? Has anyone already done it, who could give me a tip?

Thanks!
Joseph


PS. or maybe a magic "\include pysnippets.ly" command ? that would be absolute dream :)

------------------------------------------
Script A: what I want in my script window
------------------------------------------
\score { \relative c'' { c2 g4 e c1 } }

%!%!%!snippet:verse-markup%!%!%!
This is my first verse
La la la la la

This is my second verse
Lo lo lo lo lo
%!%!%!end-snippet%!%!%!

------------------------------------------
Script B: what I want Lilypond to read at compile time and change to PDF
------------------------------------------
\score { \relative c'' { c2 g4 e c1 } }

\markup{
    \line { This is my first verse }
    \line { La la la la la }
    \line { This is my second verse }
    \line { Lo lo lo lo lo }
    % I know this markup doesn't work but it made it simple ;-)
}

------------------------------------------
Snippet: something like this should be saved in a nearby folder
------------------------------------------
text = '\n'.join(r'\line { %s }' % l for l in text.splitlines())
if state[-1] != 'markup':
    text = '\\markup {\n%s\n}' % text


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: implicitly running a lilypond script through a python script before compilation

Thomas Morley-2
2016-05-01 22:48 GMT+02:00 Joseph Chrestien <[hidden email]>:
> Hi all,
>
> I know this is going to sound strange: is it possible (or even imaginable) to run a Python code snippet from "within" Lilypond code at compile time?


Yes, see this thread in the german forum
http://www.lilypondforum.de/index.php?topic=2087.0
discussed are different possibilities:

(1) python from within a lilyfile.ly:

Example:

The file hello-world.py contains:

print "Hello World!"

In a .ly-file:

pyMx =
#(define-void-function (parser location)()
    (system "python hello-world.py")
    ;; or:
    ;(system* "python" "hello-world.py")
  )

\pyMx

(2) use make
(3) use abjad
Example here:
http://abjad.mbrsi.org/for_beginners/abjad_hello_world_in_a_file.html


HTH,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: implicitly running a lilypond script through a python script before compilation

Joseph Chrestien
> Yes, see this thread in the german forum
> http://www.lilypondforum.de/index.php?topic=2087.0
discussed are different possibilities:

> (1) python from within a lilyfile.ly:

Yay, it works! I have "Hello world" in the log, which is already great.

However, I can't find yet whether I have some chance of recursively modifying the Lilypond input through python before compilation goes any further... the German forum conversation does not mention that and I suspect it will not be very easy... However, I should be able to read from it and (over)write an external lilyfile, then have that one included in the original score. Looking good to me.

I'll keep you updated with that. Thanks for the tip (I'm desperate with Guile :S)
Joseph

PS
> (2) use make
> (3) use abjad
As I'm working with others (some of them the non geek type), the lesser the better, but thks anyway.

---------------------------------------------------------------------------------------
From: Thomas Morley <[hidden email]>
Sent: Sunday, May 1, 2016 6:21 PM
To: Joseph Chrestien
Cc: [hidden email]
Subject: Re: implicitly running a lilypond script through a python script before compilation

2016-05-01 22:48 GMT+02:00 Joseph Chrestien <[hidden email]>:
> Hi all,
>
> I know this is going to sound strange: is it possible (or even imaginable) to run a Python code snippet from "within" Lilypond code at compile time?


Yes, see this thread in the german forum
http://www.lilypondforum.de/index.php?topic=2087.0
discussed are different possibilities:

(1) python from within a lilyfile.ly:

Example:

The file hello-world.py contains:

print "Hello World!"

In a .ly-file:

pyMx =
#(define-void-function (parser location)()
    (system "python hello-world.py")
    ;; or:
    ;(system* "python" "hello-world.py")
  )

\pyMx

(2) use make
(3) use abjad
Example here:
http://abjad.mbrsi.org/for_beginners/abjad_hello_world_in_a_file.html


HTH,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: implicitly running a lilypond script through a python script before compilation

David Wright
On Sun 01 May 2016 at 23:04:05 (+0000), Joseph Chrestien wrote:

> > Yes, see this thread in the german forum
> > http://www.lilypondforum.de/index.php?topic=2087.0
> discussed are different possibilities:
>
> > (1) python from within a lilyfile.ly:
>
> Yay, it works! I have "Hello world" in the log, which is already great.
>
> However, I can't find yet whether I have some chance of recursively modifying the Lilypond input through python before compilation goes any further... the German forum conversation does not mention that and I suspect it will not be very easy... However, I should be able to read from it and (over)write an external lilyfile, then have that one included in the original score. Looking good to me.
>
> I'll keep you updated with that. Thanks for the tip (I'm desperate with Guile :S)
It works for me on linux. I've also attached the file that gets
written on the fly. Whether make-cake.py can read yummy.ly while
LP is also processing it may depend on your OS.

Cheers,
David.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

make-cake.py (67 bytes) Download Attachment
yummy.ly (127 bytes) Download Attachment
yummy.pdf (25K) Download Attachment
eat-me.ly (9 bytes) Download Attachment