back to list

Ratio manipulation in Python

🔗William S. Annis <wsannis@xxxxxx.xxxx>

10/30/1999 11:42:01 AM

Manipulating piles of ratios quickly gets boring. And my
calculator insists on turning 9/8 into 1 1/8. So, I've written a
short library in Python (a portable language... it should run on any
PC, Mac and most Unix flavors) to help me deal with all of this stuff
without having to spend any more time reducing ratios.

The library and documentation -- with a brief example -- can
be found at http://www.execpc.com/~wsannis/ratio.html . To the best
of my knowledge, everthing it claims to do it does correctly, though I
will certainly respond to any bugs people find.

--
William S. Annis wsannis@execpc.com
Mi parolas Esperanton - La Internacia Lingvo www.esperanto.org

🔗est@xxxxxxxxx.xxx

10/30/1999 12:20:51 PM

William S. Annis discourseth:
>
> The library and documentation -- with a brief example -- can
> be found at http://www.execpc.com/~wsannis/ratio.html .

Extremely neat..I like Python and do a fair amount of audio and MIDI
work with it (e.g., www.hyperreal.org/~est/oolaboola,
www.hyperreal.org/~est/csound/s1).

I'd be better able to use and contribute to your module if you
released it under some defined license. I'm a bit uncomfortable
looking at source code when I don't know my obligations. A copyright
by you in the file along with a declaration of intent (e.g., public
domain, GLPL, GPL, ...) would be most helpful.

Thanks!

Eric

🔗William S. Annis <wsannis@xxxxxx.xxxx>

10/30/1999 2:30:02 PM

>Extremely neat..I like Python and do a fair amount of audio and MIDI
>work with it (e.g., www.hyperreal.org/~est/oolaboola,
>www.hyperreal.org/~est/csound/s1).

Cool. I've written some of my own stuff to make using CSound
easier, particularly in generating score files. So, I've written an
ABC parser. I remap the names to whatever scale I'm interested in,
and sling out the Csound score file, something like this:

--------------------------------------------------
tr = Translation() # This class handles turning ABC into
# pitch streams

# Fill out octaves based on a single octave. If you don't repeat
# at the octave, you have more work to do.
tr.generate_name_to_hz({'C': Ratio(1, 1),
'D': Ratio(9, 8),
'E': Ratio(7, 6), ...})

sco = tr.translate_note_stream(abc("def [da]fg [C2e_1g/2]g"))
cs = CsoundDevice('test.sco')
cs.header()
# The format string is repeatedly passed a hash
cs.stream("i1 %(start)s %(dur) %(dynamic) %(note)s\n", sco)
cs.close()
--------------------------------------------------

A lot of the complexity of the code is because I expect I'll
want to use parts of the framework for MIDI eventually. The most
interesting time saver, as far as I'm concerned, is that I can
arbitrarily map note names to pitches, and then use those names in
strings like "[ceg][dfa]". For now, the "scores" of the pieces I'm
writing to learn about JI are just short Python programs which
interpret strings of notes.

>I'd be better able to use and contribute to your module if you
>released it under some defined license.

Ack! I have templates at work which automatically insert a
copyright notice in new code. I'd forgotten to do that for my home
machine. It's under the Artistic License (a la Perl). I'll add that
notice shortly. Thanks for pointing that out.

--
William S. Annis wsannis@execpc.com
Mi parolas Esperanton - La Internacia Lingvo www.esperanto.org

🔗est@xxxxxxxxx.xxx

10/30/1999 2:47:32 PM

William S. Annis discourseth:
> From: "William S. Annis" <wsannis@execpc.com>
>
> Cool. I've written some of my own stuff to make using CSound
> easier, particularly in generating score files. So, I've written an
> ABC parser. I remap the names to whatever scale I'm interested in,
> and sling out the Csound score file, something like this:
>
> sco = tr.translate_note_stream(abc("def [da]fg [C2e_1g/2]g"))

I don't know this abc() function/class.

> # The format string is repeatedly passed a hash
> cs.stream("i1 %(start)s %(dur) %(dynamic) %(note)s\n", sco)

Oooh..I've never used the %(...)s format..delightful!

> For now, the "scores" of the pieces I'm
> writing to learn about JI are just short Python programs which
> interpret strings of notes.

It's a good score language. :)

Are any of these other tools of yours available??

You might want to join linux-audio-dev (via `subscribe
linux-audio-dev' in the body of a message to
majordomo@ginette.musique.umontreal.ca). There's a lot of nice
csound/python/unix activity there.

Eric

🔗William S. Annis <wsannis@xxxxxx.xxxx>

10/30/1999 3:11:16 PM

>From: est@hyperreal.org
>
>William S. Annis discourseth:
>> sco = tr.translate_note_stream(abc("def [da]fg [C2e_1g/2]g"))
>
>I don't know this abc() function/class.

I should hope not! Then I'd have to find another name for
it. :) It's part of my Csound libraries.

>> For now, the "scores" of the pieces I'm
>> writing to learn about JI are just short Python programs which
>> interpret strings of notes.
>
>It's a good score language. :)

It's doing a fine job so far.

>Are any of these other tools of yours available??

Not yet. I suspect it'll be another month or so before I have
time to document the basics and clean up the code a little more. I've
only really started to use it -- as opposed to my neurotic testing and
debugging -- a few weeks ago, so I'm still working out broken code and
broken design. The ABC parser, for instance, needs to be completely
redone, probably as a class.

Of course, this all brings up a very serious affliction
everyone on this list should be quite familiar with: The Geek-Musician
dilemma, where you become bogged down in the technical bits of music
making and somehow never get around to making actual music. I may
never make music if I try to perfect the software tools I'm writing
before ever using them. :)

I'll post an announcement here and to the CSound list when I
have those python libraries ready for initial release.

--
William S. Annis wsannis@execpc.com
Mi parolas Esperanton - La Internacia Lingvo www.esperanto.org