Open uliska opened 11 years ago
A good idea indeed. As of the implementation, there is already frescobaldi_app/ly/util.py which has int2text, int2roman and int2letter. The score wizard also uses this functionality. Maybe it is nice to add the conversion routine roman2int there.
Oops. Good that I didn't implement this myself :-) I'm afraid such things will happen more often because of course I don't know the sources intimately ...
For now I'll keep the stuff in my additional module to see where it leads to (and how much it will become). In the end I can incorporate it in an existing file or not.
Have removed int_to_roman and renamed roman_to_int into roman2int.
Unfortunately there are now two parallel structures _roman_numerals
(in util.py) and _roman_letters
(in romannumerals), but I have the impression that merging them would make one of the two algorithms much more complicated.
Also added a few helper routines.
Example snippet (working with the latest commits from romannumerals):
-*- python; selection: yes;
from romannumerals import *
base, index = romansuffix2int(text)
if index >= 0:
text = base + int2roman(index+1)
select a variable name like melodyII
and run the snippet.
Also test with melody
and melodyXD
(invalid numeral).
This isn't a real-world application but an example where this could be going.
I would like to add support for roman numerals because that's a common idiom for indexing variable names without arabic numbers.
I have added a basic module with the conversion routines
int_to_roman()
androman_to_int()
to my fork (https://github.com/uliska/frescobaldi), and invite anybody who is interested in this to pull the romannumerals branch to check it out.Create a new snippet with this text (updated incorporating the later commits):
enter and select a (preferrably small) positive integer in an empty document and run the snippet.
This is only a demonstration to get the idea, there is no error checking etc.
Before continuing I would like to get some feedback if it's interesting and worth the effort. And I'd like to get some ideas/suggestions for functions to be implemented.
As a start here are a few ideas:
Input:
name+int
(e.g.melody6
)Output: music blocks with names
melodyI
upt tomelodyVI
(I need to do this sometimes with transpositions that need enharmonic changes somewhere)
Create a series of variable uses to concatenate a series of indexed variables like