> teletype : code exchange



Once again, something for which a new operator would be perfect as this is just a few lines of C++…
This would actually be a quite useful feature.

With the current TT operators you could implement something like the Fisher-Yates_shuffle but you’d need another script dedicated to that as it won’t fit in one loop line (I could only get it down to 40 characters) :

This is totally untested as I’m nowhere near my Teletype, so probably not working :slight_smile:. And it uses a ton of variables, so not super nice for complex scripts.

[where you want to shuffle the array]

P.N 1; A 4; B 12
L A - B 2: C I; SCRIPT 1

[in script 1]

D RRND C - B 1; 
X P C; P C P D; P D X

The first line initializes things :

  • we work on pattern 1
  • A defines the first index that we want to shuffle and B the last one (in that case from the 4th index to the 12th)

Then we loop over the desired indexes, store the I value in another variable as they are script-dependent and call the desired script (loops working on several lines would make that much less cumbersome). We use script 1 here but it can obviously be any other one.

In the other script, we get a random index in the desired range and then the second line swaps both array elements using a buffer variable (in that case X).

As I said, that’s probably not functional as it’s untested but something like this should basically work.
And an operator for that would be great :slight_smile:.


I’m studying Teletype and as a small exercise, I’ve built a simple euclidean sequencer.
I’m using the tracker to store the values required by ER, as explained here, but instead of using 1 column per trigger output and row 0 for fill, row 1 for length etc, I’m using P0 for fill P1 for length and P2 for rotation. And I’d like to use P3 for the probability.

So, for example on row 0, I have :
4 16 0 100

In a script, I wrote :

Z + 0 A
X PN 2 Z
Y ER PN 0 Z PN 1 Z - T X
Y && Y LT RAND 100 PN 4 Z

I use the variable A as an offset, it gives me the possibility to quickly jump to another euclidean sequence/ another row in the tracker.

The problem is that even if the probability is set to 100 in the tracker, some triggers are not sent, very few of them, but it happens sometimes, so I’m wondering if there’s a better way to write multiple conditions, to combine If and Probability. Is there a problem with the syntax of this script or the order of execution ?



The trouble is this line: Y && Y LT RAND 100 PN 4 Z. Let’s talk through it. we’re saying set Y to be AND of Y (which is 1 or 0) and LT RAND 100 PN 4 Z. But the problem, is that if RAND 100 rolls 100 and PN 4 Z IS 100, the answer to “is RAND 100 less than PN 4 Z?” is no, because 100 is not strictly less than itself. The fix is easy! Replace LT by LTE, which means less-than-or-equal, and has nothing to do with cell phones.


Oh, great ! I understand, and it’s working as exepcted now. Thanks a lot !


What is advancing T?

I’d try this:

B PN 1 A
Y ER PN 0 A B - O PN 2 A

(Assuming “SC.TR.P 0” does nothing, as “TR.P 0” does.)

Or instead of relying on O, which I inevitably want to reference on another line every time I use it,
T WRAP + 1 T 0 B


Thank you.

It’s in script 2


And script 1 only contains the reset, maybe that’s not particularly great.
T 0

I’m not familiar with the syntax yet, it takes me some time to read the script that you’re suggesting, sorry. I think I understand your code and I will try it but at the end there is:
I imagine that SC.TR.P 0 does nothing indeed but I plan to use many similar scripts,multiple euclidean sequences in my scene, SC.TR.P 2, SC.TR.P 3 etc, I should have mentioned that. So I’m not sure I can write the last line like that.


I did kind of write it more for conciseness than readability. I expect PROB PN 3 A: SC.TR.P * Y 3 would work if it fits on a line, your way is clearer as long as you have the lines to spare :slight_smile:

I’ve noticed that depending on Euclidean pattern length, sometimes variables wind up resetting out of sync with the pattern when they hit their maximum or overflow to 0, so I usually wrap them to some multiple of the pattern length. For instance, if the same counter is going to drive a length 8 pattern and a length 12 pattern, I’ll reset it at 24 (or use a separate counter for each pattern).


Ah yes, I get it, yes I think that would work :slight_smile:
thanks !

Edit :

I’ve modified your code and tried :

Z + A 0
Y ER PN 0 Z B - O PN 2 Z
PROB PN 3 Z: SC.TR.P * Y 1

the first line sets variable Z —> row + offset so I can type A 4 in live mode to jump to another “sequence” for example. I’ve also added O 0 in another script (I don’t know if I need to reset the counter). For some reason, it’s not working as expected, I’m testing with a simple 8 16 0 sequence but the beat is not regular. It would be very useful to use this counter / O variable , especially if they can be independent, I didn’t know that. Is it a global variable or is it “one per script” ?


I ended up using the following script, I can have many euclidean seq with probability.


T 0


L 0  7 : $ 3 
T + 1 T


Z + I A; X PN 2 Z
Y ER PN 0 Z PN 1 Z - T X
PROB PN 3 Z: SC.TR.P * Y + I 1

and A is the offset variable for the tracker that I can optionally use to jump to another sequence.


hey, i had a question on your marbles script, specifically clock jitter. if i wanted to isolate just the bit that reads a knob position to determine how much jitter, if any, is applied to the M clock, where would i look? what needs to be modified in the script?

i can use either LV.CV for an arc encoder, or the PARAM knob on teletype itself; i don’t have the TI expander.

i’ve managed to get kria’s clock jittering wildly, but i can’t seem to limit it or affect it with an arc encoder at all. kria never settles back down to its base regular clock at M 220 when the jitter knob is zeroed out.

i’m looking to get a regular kria clock tempo at M 220, no jitter, when the knob is fully CCW. and then at max jitter when the knob is fully clockwise, but only within a small range of possibilities, so jitter shouldn’t vary by more than, say, 40. i don’t want to adjust tempo at all–ideally, the same knob should set it back to 220 when jitter is back to 0.

here’s what i have so far (using variable D; the others are taken):

PROB D: Y RAND - X / X 9
PROB - 100 D: Y 0

LIM LV.CV 1 0 12850
X >> PRM 4; M X

M 220; M.ACT 1


Wanted to check this with you after seeing this post as I have been trying this out, the Kria+JF.vox control. I seem to be getting sync problems, it can run ok for awhile then it would start dropping beats. And when the pattern on Kria changes, it also drops. Does this happen to you?


weird, i have never had any issues like that no. very, very solid. maybe firmware? not sure how to check just friends (prob the most recent) but my TT is 3.0.0 22D6CE8


You’re right, it is most likely the order of my code that is causing that.


I think the KR.POS OP is fast on its way to becoming my favorite.


if you have too much connected to teletype i2c or if just friends is a fair distance away from teletype it could be an i2c related problem. try testing with an empty scene and one i2c op that is easy to validate sonically or visually and use it in metro script, and see if it still skips. if it does you might need to unplug something from i2c or use a powered i2c backpack.


There is only ansible and jf connected to TT. When it’s just some ops, it doesn’t skip. Only started skipping when trying to control jf with ansible. I have moved the order of the code, will check again later when I’m at the modular to see, thanks!


Experimenting with making a swung clock output and came up with a simple solution:



The delay equation is kinda limited because the resolution of the delay time isn’t incredibly fine, but the result allows for “musical” ratios quite easily. Lots of fun to be had tweaking little bits of this, definitely experiment!


This works for swing (with the latest beta):

DEL.R 2 / * M 2 3: TR.P 1


That’s a nice single line solution without tying up another script, thank you! I’m going to experiment more with that tomorrow :+1:


EDIT: tried the turing machine script as mentioned earlier in this thread and on the codex, and not getting the behavior I expect- any chance it is outdated with Teletype 3.0 syntax?