[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Custom S-expression export
From: |
Aura Kelloniemi |
Subject: |
Custom S-expression export |
Date: |
Mon, 17 Mar 2025 12:01:18 +0200 |
Hello,
I am developing a tool for processing musical notation in Haskell. I want to
be able to import LilyPond scores and as I don't want to parse LilyPond's
surface syntax and write a Scheme interpreter, I have decided to export
LilyPond scores as S-expressions (which are easy to generate in Guile).
The process works such that my import routine invokes LilyPond with a custom
init file, which runs the S-expression export routine.
The command that my importer uses is:
$ lilypond --init /absolute/path/to/init-file.ly relative/path/to/score-file.ly
The exporter writes output to stdout.
I have a few questions/problems:
1) First of all, is this a good strategy at all or would there be a better way
to make LilyPond run a custom export code and prevent it from generating any
output files itself? I would like my solution to be forwards-compatible from
LilyPond 2.24 onwards to some extent at least..
2) My init code includes "init.ly" with \include in order to also run
LilyPond's normal initialization logic. But this might fail, if somebody has
put a file named init.ly in the same directory where the importer is run (or
where the score file is) (which is very much possible). How could I get the
absolute path of the original LilyPond init file so that I can inlude it
directly?
3) My exporter uses ly:music-mutable-properties to get the list of mutable
properties for ly:music objects. Is there any way to get a list of immutable
properties for a music object? I would like to have one because I wouldn't
want to hardcode property name lists, as property names may change in the
future. I want to export every possible property and then in my import code
decide, what do I need.
4) If some LilyPond score which I try to import, prints something to stdout,
my export routine will fail. Is there any better way to work around this
except to write my exporter's output to a temporary file (which I'd rather
avoid).
5) Would there be any chance to get this functionality to stock LilyPond
(maybe as a separate backend)? This differs from LilyPond's already existing
Scheme printer mostly in that my solution tries to export every possible
detail from the LilyPond source (including source locations).
6) Any other comments?
The code for my custom init file is here:
https://github.com/Merivuokko/scherzo/blob/development/lilypond/ly/sexp-export-init.ly
and the exporter code is here:
https://github.com/Merivuokko/scherzo/blob/development/lilypond/ly/sexp-export.scm
I am not a Guile expert so there may well be things that are broken or work in
unintended ways.
Thank you very much for any help!
--
Aura