Automatically generating "tonal" canons with music21 and scamp

Hi, maybe you can get some music21 help on the music21 mailing list?

While I can technically modify the code to generate more sophisticated canons, I’m afraid it will not be possible for me to spend time on actually doing it. In the short term I have concerts upcoming (in fact: tomorrow is one) and generally am working on very different things nowadays. I suspect this is not the answer you were hoping for, but I hope you understand.

I understand! I can surely wait some time before getting a table canon maker. I’m sure they’ll be able to find what’s wrong.

I just don’t manage to properly use music21. The import really appears to work fine, but once in pyscripter, it says “no module found” :smiling_face_with_tear:. I’ve been asking for help on the music21 forum but it wasn’t of any help yet.

I’ve downloaded the canon generator the 29/11/2020 but still didn’t manage to make it work since then… Python is not something I seem to be good at yet.
I’m seriously considering just giving you chords and asking you to give me the mscz file at this point… :sob:.

Maybe you can give me something where I can contact you beside here too if you got any idea of what to do?

If you can do the import if you start python on the command line, then it should be possible to also run the canon generator from the command line instead of inside pyscripter?

It could be that e.g. pyscripter by default is set up to use a different python executable than the one you use on the command line (another version of python perhaps, for which music21 is not installed), but such things are not really easy to diagnose “by email”.

Thanks, that’s a great idea! Where will the canon be generated though? For the email thing, I can send videos on discord or by email.

Something really strange happened when I copy pasted the code in the terminal. Seems like it has some problem with the #. Should I just remove all passages with it in the code?

Actually it seems like it tries to launch each lines individually by itself as soon as I copy paste it. And it can’t do it for many of them, not just the #.

you shouldn’t copy paste anything into the terminal

if you have the code of the canon generator in a file c:\fullpath\to\canon_generator.py (change the file path as needed for your system), then on the command prompt, run python with the name of the python code file as argument, e.g.

python c:\fullpath\to\canon_generator.py


I can’t believe it.
My jaw’s dropping.
Music21 doesn’t have the cream of the cream of the scales??
They have quarter tones but not the enigmatic scale???


I tried with C D Em F G Am B in major scale and got all those errors.

I installed the two other modules, python rtmidi and pynput but it gives me this? What else could there be that doesn’t work?

I suspect something has changed in music21 itself since I made it, so the code would have to be revised and updated for the new music21 version.

Will you do that soon? I’d like so much to test your canon generator!!
Also, what is path to musescore? Where I should put the path to where I want the created file to end up? What happens if I put nothing?

If you look closely to the screenshot, you will see that the error originates from canon-gen.py line 148 in the function “transform”. There you see direction=chosen_step. From the screenshot it appears that chosen_step has been assigned a string ‘descending’. However, according to the music21 documentation, music21.scale.intervalNetwork — music21 Documentation direction should now be an enum instead of a string, so you will need to change the code in the canon-generator a bit not to use strings, but to use an enum instead (see the music21 documentation I linked to).

In other words, instead of strings like ‘ascending’ and ‘descending’, newer versions music21 now expect something like scale.Direction.ASCENDING or scale.Direction.DESCENDING.

path_to_musescore is the path to where the musescore executable can be found.

So I shouldn’t put anything? The executable is the part of the musescore files with the logo that lauches the program I believe? Why is there a path to it when the generator generates?

So I shouldn’t put anything? The executable is the part of the musescore files with the logo that lauches the program I believe? Why is there a path to it when the generator generates?

To be honest I forgot the details, but I guess it had to do with displaying a score. I’d start by trying not to set anything.

I see. By the way, I asked help for it on the music21 group so maybe I’ll finally be able to do it?

Your generator will allow me to do impossible things like making many voices canons with the locrian and the enigmatic scale! I actually found great progressions using music theory. Also, any way you plan to make a crab canon generator? Here’s a progression I made that kinda goes from Gb major tonality to F locrian for someone who asked how they could do that in their pieces:


It still didn’t work. Reposting now since I’m not sure if you saw my previous messages? By the way, enigmatic progression:

Even enigmatic music!