Lilypond svg output to stdout?

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

Lilypond svg output to stdout?

Marcel Aartsen
Hi,

As the subject says, I would like to have Lilypond output svg to stdout.
Can it be done? How do I do that?

Some background: I am developing an online course in Open edX [1], and
for that course I am writing an XBlock [2]. This means that the user on
the front end triggers a request that is processed by some server-side
Python code that, in my case, in turn calls Lilypond. Lilypond's output
is ultimately on the front end to be displayed in html, so I figured
that svg output would be best. And I reckon that it will be
unnecessarily cumbersome and slow to let Lilypond write to file and then
let the Python code read that file back from disk.

Any ideas to output Lilypond's svg to stdout? Or better alternatives?

Thanks!
Marcel


[1] Open edX https://open.edx.org/ is an open source learning platform
(like e.g. Moodle) developed by MIT and Harvard

[2] XBlocks
https://edx.readthedocs.io/projects/xblock/en/latest/introduction.html
are Python libraries used to provide custom course units for learners
and instructors on the Open edX platform.


0xFAE136BF78A26731.asc (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Lilypond svg output to stdout?

David Wright
On Thu 30 Apr 2020 at 21:58:28 (+0200), Marcel Aartsen wrote:
> As the subject says, I would like to have Lilypond output svg to stdout.
> Can it be done? How do I do that?

I don't think you can use stdout itself, as LP already uses it.
However, you can use a pipe:

$ mkfifo foo.svg
$ lilypond -dbackend=svg -o foo music.ly

which will block until you, say,

$ cat foo.svg | some-consumer-of-svg

I haven't tested whether LP *insists* on adding an .svg extension.

> Some background: I am developing an online course in Open edX [1], and
> for that course I am writing an XBlock [2]. This means that the user on
> the front end triggers a request that is processed by some server-side
> Python code that, in my case, in turn calls Lilypond. Lilypond's output
> is ultimately on the front end to be displayed in html, so I figured
> that svg output would be best. And I reckon that it will be
> unnecessarily cumbersome and slow to let Lilypond write to file and then
> let the Python code read that file back from disk.
>
> Any ideas to output Lilypond's svg to stdout? Or better alternatives?

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: Lilypond svg output to stdout?

Valentin Villenave-3
On 4/30/20, David Wright <[hidden email]> wrote:
> On Thu 30 Apr 2020 at 21:58:28 (+0200), Marcel Aartsen wrote:
> I don't think you can use stdout itself, as LP already uses it.

Well, there *used* to be some work towards something like that; see
the framework-socket.scm file in LilyPond’s source code…

> I haven't tested whether LP *insists* on adding an .svg extension.

It does, but that can be overriden:
https://lists.gnu.org/archive/html/lilypond-user/2019-12/msg00414.html

Cheers,
-- V.

Reply | Threaded
Open this post in threaded view
|

Re: Lilypond svg output to stdout?

David Wright
On Sun 03 May 2020 at 12:22:31 (+0200), Valentin Villenave wrote:

> On 4/30/20, David Wright <[hidden email]> wrote:
> > On Thu 30 Apr 2020 at 21:58:28 (+0200), Marcel Aartsen wrote:
> > I don't think you can use stdout itself, as LP already uses it.
>
> Well, there *used* to be some work towards something like that; see
> the framework-socket.scm file in LilyPond’s source code…
>
> > I haven't tested whether LP *insists* on adding an .svg extension.
>
> It does, but that can be overriden:
> https://lists.gnu.org/archive/html/lilypond-user/2019-12/msg00414.html

Probably hardly worth the effort in this case (and when using files,
it's easy enough to rename them).

BTW I tested my example just by catting the pipe (to let LP run to
completion) and piping the output into less as the consumer (to save
it spewing onto the terminal).

I ought to make it clear that it was intended for the SVG-consumer
to normally be a program, like inkscape. So summarising:

  $ mkfifo foo.svg
  $ lilypond -dbackend=svg -o foo music.ly

  $ inkscape foo.svg

on two terminals, or

  $ mkfifo foo.svg
  $ lilypond -dbackend=svg -o foo music.ly &
  $ inkscape foo.svg

on one.

Sometime, perhaps, I'll try it on two machines, using a socket.

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: Lilypond svg output to stdout?

csmcd
A way to output to stdout directly (on Linux):

    $ ln -s /dev/stdout foo.svg
    $ lilypond -dbackend=svg -o foo music.ly

Regards,
Curt

On 5/5/2020 2:42 PM, David Wright wrote:

> On Sun 03 May 2020 at 12:22:31 (+0200), Valentin Villenave wrote:
>> On 4/30/20, David Wright <[hidden email]> wrote:
>>> On Thu 30 Apr 2020 at 21:58:28 (+0200), Marcel Aartsen wrote:
>>> I don't think you can use stdout itself, as LP already uses it.
>> Well, there *used* to be some work towards something like that; see
>> the framework-socket.scm file in LilyPond’s source code…
>>
>>> I haven't tested whether LP *insists* on adding an .svg extension.
>> It does, but that can be overriden:
>> https://lists.gnu.org/archive/html/lilypond-user/2019-12/msg00414.html
> Probably hardly worth the effort in this case (and when using files,
> it's easy enough to rename them).
>
> BTW I tested my example just by catting the pipe (to let LP run to
> completion) and piping the output into less as the consumer (to save
> it spewing onto the terminal).
>
> I ought to make it clear that it was intended for the SVG-consumer
> to normally be a program, like inkscape. So summarising:
>
>    $ mkfifo foo.svg
>    $ lilypond -dbackend=svg -o foo music.ly
>
>    $ inkscape foo.svg
>
> on two terminals, or
>
>    $ mkfifo foo.svg
>    $ lilypond -dbackend=svg -o foo music.ly &
>    $ inkscape foo.svg
>
> on one.
>
> Sometime, perhaps, I'll try it on two machines, using a socket.
>
> Cheers,
> David.
>