Integrating a Scheme function into Lilypond

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

Integrating a Scheme function into Lilypond

Joseph Wakeling
Hello all,

As discussed on the lilypond-devel mailing list,
http://lists.gnu.org/archive/html/lilypond-devel/2010-07/msg00141.html

... I'm working on developing true chromatic transposition as built-in
functionality for Lilypond.

The current fruit of this work is contained in the attached file
naturalizeMusicModern.ly which defines a flexible Scheme function that
can be used to naturalize pitches according to various different rules.

As a first step to building this into core Lilypond, the obvious thing
to do seems to be to move the Scheme functions into a .scm file in the
scm/ directory of the Lilypond source code.  This I've done (see the
attached file naturalize.scm) and I've written another Lilypond demo to
make use of this (naturalizeMusicIntegrated.ly).

Lilypond appears to 'recognize' the existence of the new .scm file since
issuing a 'make' command rebuilds various stuff after that file is
edited.  However, when running the newly-built Lilypond on
naturalizeMusicIntegrated.ly I get an error,

    GNU LilyPond 2.13.28
    Processing `naturalizeMusicIntegrated.ly'
    Parsing...naturalizeMusicIntegrated.ly:5:4: In expression
    (ly:naturalize m (ly:naturalize-limit >= 1) ...):
    naturalizeMusicIntegrated.ly:5:4: Unbound variable: ly:naturalize

(... note that my native installed Lilypond is the 2.12.x version that
comes built in with Ubuntu, so it's not simply that I'm running the
wrong Lilypond.)

So, it looks like the functions in my new .scm file are not visible to
the Lilypond interpreter.  How do I make them so? :-)

Thanks & best wishes,

    -- Joe

naturalizeMusicModern.ly (5K) Download Attachment
naturalize.scm (1K) Download Attachment
naturalizeMusicIntegrated.ly (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Integrating a Scheme function into Lilypond

Neil Puttock
On 21 July 2010 20:50, Joseph Wakeling <[hidden email]> wrote:

> So, it looks like the functions in my new .scm file are not visible to
> the Lilypond interpreter.  How do I make them so? :-)

The .scm file has to be loaded into the `lily' module; see the
definition of `init-scheme-files', which lists all the files to be
loaded.

Cheers,
Neil

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Integrating a Scheme function into Lilypond

Joseph Wakeling
On 07/21/2010 10:04 PM, Neil Puttock wrote:
> The .scm file has to be loaded into the `lily' module; see the
> definition of `init-scheme-files', which lists all the files to be
> loaded.

Great, thanks -- all working now.

Style query -- is the naming of the functions as ly:naturalize etc.
appropriate?  Or should I kill the ly: prefix?

I have a few technical queries too, but I'm going to try and figure them
out myself first (they're Scheme-y rather than Lilypond-y...).

Thanks again & best wishes,

    -- Joe


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Integrating a Scheme function into Lilypond

Neil Puttock
On 21 July 2010 22:00, Joseph Wakeling <[hidden email]> wrote:
> On 07/21/2010 10:04 PM, Neil Puttock wrote:
>> The .scm file has to be loaded into the `lily' module; see the
>> definition of `init-scheme-files', which lists all the files to be
>> loaded.
>
> Great, thanks -- all working now.
>
> Style query -- is the naming of the functions as ly:naturalize etc.
> appropriate?  Or should I kill the ly: prefix?

Kill.  It should only be used for functions exported from C++.

> I have a few technical queries too, but I'm going to try and figure them
> out myself first (they're Scheme-y rather than Lilypond-y...).

I've just had a quick glance at naturalize.scm, and one thing jumps out:

(/ 1 2)

is more conveniently written as a rational,

1/2

though it's probably easier to see what's going on in the file if you
use the predefined constants for alterations:

SHARP

Cheers,
Neil

---
----
Join the Frogs!