lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: python-ly, ly.indent


From: Urs Liska
Subject: Re: python-ly, ly.indent
Date: Sat, 17 Aug 2019 21:20:52 +0000

[Including the list again]

17. August 2019 21:16, address@hidden schrieb:

> I currently manage my Lilypond projects with bash scripts that piece
> together all of the files to build the score and parts in different
> editions, page sizes, etc. Here's an example.[1] The automation has
> many advantages, but it's very messy. I'm using files and directory
> structures as a substitute for variables and data structures, and as
> I've hacked on it to accommodate increasingly complex projects it has
> become more unwieldy and less flexible. Right now I'm engraving an
> opera for a client, which has required me to extend the bash scripts to
> handle things like multiple movements with different instrumentations,
> arias transposed to multiple keys, etc., and while it works, I'm not
> happy with how complicated it is.
> 
> To make things easier on myself in the future, I am starting over from
> scratch with Python and hindsight. I just started and haven't gotten far
> yet. I'm taking it slow and trying to make sure I do things "the right
> way" this time. Here's what I have so far, if you're interested.[2]

I can't promise it will eventually pay off in terms of effort, but I' 
definitely encourage you to have a look at Frescobaldi's extension API, which 
has been merged to master and will be available in the next release (whenever 
that will be). It allows you to create and register extensions with a pretty 
simply framework, and with that you (nearly) automatically get

* a Tool panel (see first attached image)
* a Tool menu with actions defined by the extension
* optional integration in various context menus
* a configuration page in the Preferences (second attached image)

Writing an extension has two main advantages: Having the interface for the 
stuff one wants to do within Frescobaldi, and having access to all of 
Frescobaldi's functionality, just like you were adding something to Frescobaldi 
itself. Of course you still have to do the actual programming yourself, but 
it's a very convenient framework to start with. I think one major use case for 
such extensions is creating interfaces for complex projects or repertoires 
where you have to deal with creating LilyPond files, managing content in 
directory structures, validating user input etc. The extension shown in the 
attachments is there to keep track of the progress in a project with 600+ music 
examples where the first and most important task was to provide navigation and 
filtering in that vast amount of individual files.

You may have a look at https://github.com/frescobaldi-extensions where two 
different kinds of example extensions provide a first introduction. The third 
repository with documentation is (as usual) very preliminary, but it may also 
give introductory insights. I'd be glad if someone else would give it a try and 
start using this new feature to give more feedback and different perspectives. 
So far I'd say it's fairly stable but both the conception and testing have been 
pretty much restricted to my own requirements so far.


> 
> By the way, I started using git after reading your blog posts about
> version control, and it has saved my life numerous times. Most recently,
> for the opera I mentioned, I need to add in some ornamentations to some
> arias for the purposes of a recording session, but these ornamentations
> will not be in the final publication. While adding in the
> ornamentations, I caught some errors that would need to be fixed for
> both the version with ornamentations *and* the final publication. Doing
> so was as simple as checking out the master branch, making the changes,
> checking out the ornamentations branch, and merging. Without version
> control I would have had to make these changes to both copies of the
> project in parallel, introducing the risk of discrepancy between the two
> versions due to human error.

Nice to hear that!

I think "saving one's life" is only one part of it. The other may generally be 
even more important: giving you a certain peace of mind. Often when creating 
non-trivial code (LilyPond or programming languages) I really feel much better 
to have a (even WIP) commit to fall back to in case the experiment I just 
started turns out to be a failure. Or if I have to leave some unfinished 
threads in the evening where things don't work and I don't know why - the next 
morning I can ask Git what I have actually done so far (since the last commit), 
and often this gets me on the right track (while simply looking at the 
non-functional total of the file would just make me despair in a non-versioned 
context).

Urs

> 
> Mason
> 
> [1] https://notabug.org/chaosmonk/untouchable-space
> 
> [2] https://notabug.org/chaosmonk/lilypond-project-manager
> 
> On 08/17, Urs Liska wrote:
> 
>> Hi Mason,
>> 
>> great that it really worked how I thought it should :-)
>> 
>> May I ask what you are doing this for?
>> 
>> Best
>> Urs
>> 
>> 17. August 2019 19:25, address@hidden schrieb:
>> 
>> Thanks Urs,
>> 
>> Seeing how the Document and Cursor classes are used there was enough to
>> put me on the right track. I've achieved what I was going for with this:
>> 
>> %%% begin test.py %%%
>> import ly.document
>> import ly.indent
>> 
>> music = '''\\new Staff <<
>> \\relative c' { c4 c c c } |
>> 
>> '''
>> 
>> d = ly.document.Document(music)
>> c = ly.document.Cursor(d)
>> i = ly.indent.Indenter()
>> 
>> c.select_all()
>> i.indent(c)
>> 
>> print (d.plaintext())
>> %%% end test.py %%%
>> 
>> $ python3 test.py
>> \new Staff <<
>> \relative c' { c4 c c c } |
>> 
>> Best,
>> 
>> Mason
>> 
>> On 08/17, Urs Liska wrote:
>> 
>> Just shortly: does
>> 
>> https://github.com/frescobaldi/python-ly/blob/master/ly/cli/main.py
>> 
>> and
>> 
>> https://github.com/frescobaldi/python-ly/blob/master/ly/cli/command.py#L116
>> 
>> help you further? I thought it would be best to look how the ly command line 
>> program does it.
>> 
>> Urs
>> 
>> Am 17. August 2019 03:00:47 MESZ schrieb address@hidden:
>> Hi all,
>> 
>> The command line tools provided by python-ly are very
>> convenient and easy to use, but I'm finding it a little harder to wrap
>> my head around the Python module.
>> 
>> For example, it is easy to automatically indent a file with
>> 
>> $ ly "indent" file.ly
>> 
>> or to indent the output of another command such as
>> 
>> $ cat file.ly | ly "indent"
>> 
>> I'd like to be able to do something similar in Python, using ly.indent
>> to indent files or (preferably) strings. It seems that ly.indent might
>> be what I want, but I'm having trouble figuring out how it works. The
>> Indenter() class, with an indent() function, is defined here,[1] but
>> I'm
>> don't understand what a cursor object is or how to create and pass one.
>> I next tried looking through Frescobaldi's code for example usage and
>> found this,[2] but I think I would need to learn more about how
>> Frescobaldi works in order to follow what's happening, which is deeper
>> than I want to go to indent a string of Lilypond code.
>> 
>> Is there a simple way to use ly.indent similarly to `ly "indent"`, or
>> would I be better off invoking `ly "indent"` externally with
>> os.system()?
>> 
>> Thanks,
>> 
>> Mason
>> 
>> [1]
>> https://github.com/frescobaldi/python-ly/blob/0d91ca2450ba01a8158f53ba05202af3e13bf78d/ly/indent.py
>> 
>> [2]
>> https://github.com/frescobaldi/frescobaldi/blob/09cae764126b505dedf0182beccd78d7934b2de4/frescobaldi
>> app/indent.py
>> 
>> --
>> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
>> 
>> _______________________________________________
>> lilypond-user mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/lilypond-user

Attachment: Bildschirmfoto vom 2019-08-17 22-55-07.png
Description: PNG image

Attachment: Bildschirmfoto vom 2019-08-17 23-00-43.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]