Scripting project

Hello!

I have already had a couple of discussions over the last years with Daniel regarding eventual scripting support and an eventual Lua API. More precisely, I was interested to create an open-source composer’s toolbox that would allow common (and not so common) manipulations, and to “release” that as a Dorico exclusive.

Meanwhile, since complete scripting support is not in 3.5 yet and nowhere near on the roadmap it seems, I decided to start coding this project using the music21 Python library, open-sourced by the MIT (https://web.mit.edu/music21/). I find Lua more fun than Python, but what can you do… Music21 can read/write xml files, so it’s possible to use it by exporting xml music from Dorico to be processed and then importing the resulting xml back. I would much rather be able to do it all inside Dorico, for example by selecting some notes, running a script and outputting the result to a new flow, but meanwhile it’s a working solution.

I am including here some examples of what this will be able to do, to get some community feedback (would you be interested in using that, what functions would you like?), and to show Daniel and developers a very concrete example of what an eventual Lua API could allow us to do. Since Python and Lua are honestly quite close, it will be possible to port things over someday.

I decided to name my own library Arvo, as a hommage to Pärt, but, although you can use it to emulate his style quite easily, you can go well beyond. I feel that there are a million tools out there for twelve-tone composition, but almost nothing for composers interested in applying similar techniques to modal/diatonic worlds so common in, for example, film/game music. So far, I have modules planned for:

  • transformations - transpositions and inversions in scale space, great for transposing “diatonically” within a pentatonic/octatonic/anything scale; also retrogrades with options such as pitch-only or rhythm-only retrogrades, various augmentations, diminutions, etc.


  • minimalism - create various additive or substractive processes, forward/backward, following linear, primes, fibonnacci series, etc.


  • tintinnabuli - create t-voices from m-voices


  • isorhythm - create isorhythmic constructions from pitch/rhythm rows

Here are two examples of recreating some of Part works through scripts, which makes for good testing purposes.

1. Fratres

I entered the basic melody in Dorico:

Then ran the following script, which generates the complete melody by applying a substractive process, substracting from the middle outward, then creating an inversion around the C# axis. The script then creates a tintinnabuli voice in 2nd position downards, and a parallel voice a 10th below.

The output xml as directly imported back to Dorico, the only thing manually added in Dorico being the correct time signatures.

2. Cantus for Benjamin Britten

Here since the basic material is only a descending a minor scale, it was easy to define it directly in the script, apply the additive process, create an isorhythm with the Half/Quarter alternation, and add the tintinnabuli voice in 1st position below:

The result imported into Dorico, again only adding a 6/4 time signature. It goes on until it reaches the middle C:

There! I will continue the development of this in the coming weeks, properly document modules and functions, and share a beta of this here for Dorico users who would be interested to play with it.

Meanwhile, I would be interested to hear where plans are with scripting support! :slight_smile:

Excellent work! I’m a big python fan, and I didn’t know about the music21 library, so that’s great. Is your Arvo library available to download?

Nice work! I’ll bookmark this topic. I also like Python a lot, albeit it’s a long time I don’t use it.

It’s not yet available, I just started development this month, but I’ll make a first beta available in a few weeks. I’m learning how music21 works in order to do things properly.

This is fantastic. I’m also really interested in eventual scripting for Dorico; working with various scales (not necessarily repeating at the octave), using microtonality, just intonation, etc. I’ve messed around with ManuScript (in Sibelius) and OpenMusic, and the possibilities for Dorico are exciting. Thanks for doing this!

I also would like to see some kind of progress in this area (Lua). A lot of compositional tools could be made (win - win situation).
In Sibelius a lot of great plugins exist, strange that in Dorico nobody seems to miss such a feature.

The explanation I have heard is that, as Dorico features are developed and added, many of the “hooks” a scripting language such as Lua would need to link to have not been finalized, so that rather than support outside Lua scripting now and then perhaps pulling the rug out from under third-party scripters later if hooks need changing to better support the Dorico back end, the Development Team has decided not to offer Lua scripting yet.

Doubtless if my recollection is wrong, someone will correct me.

You don’t want plugins. You want functionality.

With Sibelius, once a cottage industry has developed with some very good programmers writing plugins and making them available for free (despite the terrible support for writing them!) there isn’t much incentive for the development team to replace the plugin with an option in the program, so they linger on in every new version of Sibelius.

And eventually, you get plugins which don’t do anything except try to organize the huge collection of plugins, assign short cuts to them, etc … :slight_smile:

Indeed. The same is true for Finale, where almost the entire program is actually a series of plug-ins, each of which must be triggered by the user in sequence, in order to achieve things as mundane as decent beaming, system spacing, etc.

There is a potential alternative to MusicXML import to get those generated examples into Dorico, it is something I have experimented with myself. If you record a macro of manually creating those notes and time signatures and save the macro, you end up with an .lua file that can be executed through the script menu. If you open the .lua file with a text editor, you will see that, although the existing lua functions are very limited, the functions to create things like notes and time signatures can be found by recording a macro doing the task and seeing what Dorico adds to the resulting .lua. Based on what Dorico does, your python project should be able to generate an .lua file with the Dorico functions in the correct order to generate the passage of music and put it into the correct folder in Dorico so that it shows up as a menu item in the Script menu. Then you could simply activate that menu option to “paste” the passage of music in to an existing Dorico project, rather than having to import XML to a new Project and copy and paste.

Nice!

Can Dorico be an option for displaying Music XML from Music 21? Last time I had to find the py script and add it - that was a bit janky and a while ago. I wonder if its changed, or if we can ask the MIT team to add Dorico as an option to the Musecore, Finale, Sibelius that are currently options for displaying things from Music21 without always having to write it to a file and import.

Any additional or alternative apps have to be added to the config file, I believe. I was rather disappointed to find that support for Lilypond has been withdrawn from Music21, and the Noteworthy Composer file I tried to load produced errors.

The what now?

Noteworthy still exists?!

No: which is why I was hoping to use Music21 to translate the files! :laughing:

Haha!

Surprisingly enough, it does! The site’s footer is updated, and although there seems to be no development since 2015 (why mess with perfection), there’s a forum with people still posting. Amazing!

I’m not sure if it will be possible for Music21 to open a music xml file directly in Dorico, I need to read how they do it with MuseScore. But it could be possible by sending a shell command I guess?

On Windows, when I right-click an xml file, I don’t have the option to open it with Dorico. But if I go manually in the “Open With” dialog, browse for Dorico3.5.exe, and select it, it starts the program, and auto imports the xml in a flow in a new project, without any dialog boxes. So if there’s a way from python to output the xml file, then “open it with Dorico”, it should work. I’m not a Python specialist yet however (learning it with this project, from a C#/Lua background) so I don’t know if it can have such shell access to the file system and windows associations.

Yes!

import os
open = 'open -a "Dorico 3.5.app" /Users/LSalgueiro/Desktop/Untitled.xml'
os.system(open)

That won’t run on Windows, of course.

I believe the ‘helper’ apps that music21 uses can be configured in the ~/.music21rc file. When I installed music21, it picked up that I had Finale, to use for XML.

Hello everyone!

Quick update on this, the fall term was quite complicated to manage, and I didn’t have time to pursue the project. But I returned to it since the beginning of the year, and now it’s on github in alpha state if anyone wants to check it:

:slight_smile:

2 Likes

I remember Finale having a counterpoint checker plugin. It was very badly implemented, because it checked for parallel fifths and octaves in different pairs of voices, instead of the same pair of voices (thus giving a lot of false positives). Still, the idea was quite nice, I think. Imagine Dorico giving a warning in real-time whenever one commits a contrapuntal booboo. It can be done, witness the Counterpointer program by Ars Nova.