.invert() function converting ints to floats

for example, if I have

s = P[0,1,1,0]

and I call


this produces

s => [1.0,0.0,0.0,1.0]

I’ve tried casting but that doesn’t work. Is there a way I can represent the pattern in this format?

s-prime => [0,1,1,0]
s-invert =>[1,0,0,1]

EDIT ---------------

seems like this works for printing:

Print(Pattern([round(i) for i in s.invert()]))

Is there a better work around?

Hi Thallein!

I guess the most “FoxDot” way to do it would be:

P[0, 1, 1, 0].invert().transform(int)

The transform method just calls the function on every item in the pattern, or transforms it again if it’s a nested pattern. Maybe I could add a few short-hand transformations like:

P[0, 1, 1, 0].invert().int()

Can I ask why you need it to be an integer value btw? If you are playing notes, they should be treated the same, no?

It’s purely cosmetic. I needed to show the relationship between a binary sequence and it’s inversion and wanted to make the output look as clear as possible. I started an Algorave Club on my campus and it’s made up of a lot of people who either a) know music but don’t know how to code or b) know how to code but don’t know music theory. So I’m working on a jupyter notebook project that functions as both a music theory and programming lesson using the FoxDot library.

Ah I see. The problem is that Python 3 will automatically convert values to float after a division (which occurs in in the .invert() method) so it will always return floating point values. Even something like print(1 / 1) will return 1.0. I think I will add some methods like .int(), .str() etc that will convert all of the values.