Only operate a Teletype when you are fully sober! At least until you are an expert Teletyper.

# > teletype : code exchange

**lloydcole**#580

I’m really rusty!

I need help.

I’m trying to figure out a plan to implement Ableton style follow actions based on where a particular module might be ‘at’ at any given time.

I vaguely recall (I didn’t keep notes) maybe 2 years ago trying something similar and falling back on loading patterns with weighted arrays if values. For example if I wanted 1 to happen most, then 2, and 3 least I’d create a pattern like this 1,1,1,1,1,1,1,1,2,2,2,2, 3 and then randomly access an index. This could work again but I’d be restricted to 4 patterns. Which would probably work for the piece I’m working on, but not more complex pieces.

Lets’ say I have 5 possible bass notes, A, B, C, D and E, each played by their own Kria pattern.

If A is playing, I’d like a script to be able to say - 50% chance of staying on A, 35% chance of playing B, 15% chance of playing E.

Any suggestions?

**xeric**#581

Maybe this is too specific to your given example, but could you abstract the concept a bit? So you take the pitch output of Kria to the Teletype input, and there’s basically a 50% chance of re-harmonizing the pitch, as you described. So 50% of the time it outputs the same as the input, but 35% of the time it transposes up by a whole step, and 15% of the time it transposes up a perfect fifth? And you can just use the PROB op?

**lloydcole**#582

Sorry. I wasn’t clear enough. In my example the Kria bass patterns are single note, so TT knows what KR is doing & it knows what note. What I want to do is change the pattern playing in Kria, using TT, based on preferred probable outcomes for each trigger in (or EVERY) in TT.

**oscillateur**#583

Keeping the idea about using a pattern to store values, you could just have other sets of values starting at a later index and instead of getting a random value in the whole pattern, get a value from the desired start index to that start index + the desired length.

A side effect of that is that you can use the same pattern data (1,1,1,1,1,1,1,1,2,2,2,2, 3 in your example) and get different results depending on your start and end points, basically.

So you would just need to do :

P RRAND [startindex] [endindex]

For your example : P RRAND 0 12

But you could decrease the probability of the “1” value by doing for example P RRAND 3 12

And if your other set of values starts at index 20 then do something like P RRAND 20 32

Disclaimer : I don’t have a Teletype yet so I can’t test that but I don’t see why it wouldn’t work. Just make sure the pattern length is valid.

**lloydcole**#584

Thanks, this is indeed the type of methodology I was using a couple of years ago and after much rumination is starting to look like the only way to weigh the probabilities. My tiny brain will hurt but I’ll try this today. The good news is there are only 6 Kria sequences, and 4 MP scales which need automating. I’ll report back later, thanks!

**scanner_darkly**#585

if i understand correctly… using separate triggers/scripts:

`PROB 20: KR.PAT 1`

etc

using one trigger:

```
PROB 20: KR.PAT 1; BREAK
PROB 50: KR.PAT 2; BREAK
...
KR.PAT 3
```

adjust probability to what you need (in the 2nd example remember that every following probability deals with what’s remaining after the previous one, so in the example above pattern probabilities will be split 20/40/40)

**GoneCaving**#586

The way i’d tackle this is put the cumulative probability in the first column of the patterns, and the next column the Kria pattern to jump to. And then iterate down the rows. So it’s 30% jump to pattern 1, 60% pattern 2, 10% pattern 3. You’d have

30, 1

90, 2

100, 3

Draw X as a random [0,100], and iterate down the first column until the first col value exceeds the random draw, then pick the second col value from the preceding row.

You could then extend this to shift those two cols across one, and have the first column be the current playing Kria pattern, and then have different change probabilities for each currently playing pattern.

Implementation is left as an exercise for the reader

**GoneCaving**#587

Given the original request of 50/35/15, would that translate to

```
PROB 50: KR.PAT 1; BREAK
PROB 70: KR.PAT 2; BREAK
KR.PAT 3
```

And can someone remind me how to format the code blocks? [ETA: Thanks @scanner_darkly!]

**lloydcole**#589

Great. The only thing is - for this piece I need an IF before the PROB and TT wouldn’t let me do that. Maybe I can have a script for each possibility? Then IF x: Script x

**scanner_darkly**#590

you could do that or use `RAND`

and include it in your `IF`

condition:

`IF && your_cond LT RAND 10 5: ...`

since this likely won’t fit on one line you could do this instead:

```
I LT RAND 10 5
IF && I your_cond:
```

**ellips_s**#591

per the request of @misuba, the scene from my post in Latest tracks + videos

it’s a simple scene based on plaits’ chord mode. i don’t own a plaits but the manual kindly tells us what chords are available (i added sus2 at the end). i was externally using kria for root note sequencing (TT in), an attenuated lfo for chord quality (i only used minor triad, and minor 7, 9, 11) (TI.IN 1), and manually choosing voice distribution via PRM

As always, suggestions for refinement or if any glaring errors are present from quickly typing it out here, please let me know!

```
M:
X >> TI.IN 1 10; A PN 0 X
B PN 1 X; C PN 2 X; D PN 3 X
IF < PRM V 2: C A; D B
ELIF < PRM V 6: D B
EVERY 9: CV 1 + V 1 RAND V 2
I:
JF.MODE 1; JF.SHIFT N -2
JF.GOD 1; CV.SLEW 1 800
1:
TR.P 1
DEL 1: Z IN
2:
L 3 6: SCRIPT I
3:
JF.VOX 1 + Z N A V 3
4:
JF.VOX 2 + Z + 10 N B V 4
5:
JF.VOX 3 + Z N C V 4
6:
JF.VOX 4 + Z - N D 10 V 3
tracker:
0 0 12 12
0 0 7 7
0 5 7 12
0 3 7 12
0 3 7 10
0 3 10 14
0 3 10 17
0 4 9 14
0 4 7 14
0 4 7 11
0 4 7 12
0 2 7 12
```

**Pampalini**#592

If I understand you correctly, it sounds like you need a Markov matrix. Unfortunately it’s not straightforward to do in TT (come to think of it, I wonder how come no one has requested this feature yet). What I have done in the past is use the bottom portion of the tracker as a 4 x 4 matrix, where the 4 rows are your states, and the 4 columns are transition probabilities.

Alternatively, you can populate the rows with the next states (instead of their probability) and end up with a finite state machine.

**lloydcole**#593

Well, I’ve managed to get it functioning as I wanted using a whole bunch of these, but it’s not elegant and it ties up 6 scripts. More to follow.

**lloydcole**#594

Thanks! I recall doing something along these lines when I was using TT everyday about 2 years ago but sadly my memory retention seems to be very poor. I need to keep better notes. I will research Markov Matrix.

**Pampalini**#595

Oh, sorry. I should have explained better:

A Markov matrix designates the probabilities of transitioning from the current state to any other state (or possibly staying in the current state). So if you’re in state k, you’ll refer to the k’th row of your matrix to figure out what to do next. The k’th row might be something like [ 0.1, 0.1, 0.2, 0.6] which means jump to state 1 with 10% chance, state 2 with 10%, state 3 with 20% and state 4 with 60%.

Entering the matrix in the tracker is straightforward. From there you’ll need a script that monitors your current state and decides where to go next according to the corresponding row of your matrix.

I hope this helps.

**GoneCaving**#596

I reckon this ought to be possible using the patterns and two scripts. I might have a crack at it over the weekend.

**lloydcole**#597

This makes sense, thanks.

However, wouldn’t multiple PROB ops be needed for each lookup, anyway?

And moving forward… my current piece has 6 patterns in Kria and 3 in MP to move between which is already too much for the tracker to handle with only 3 columns. More complex pieces might be lurking…

**Pampalini**#598

Multiple probabilities is not too complicated. Say you’re in state Z. You can do something like:

```
X RAND 99
IF < X PN 0 Z: Z 0; do whatever else // switch state to 0 and do whatever you want there.
ELIF < X PN 1 Z: Z 1; ... // switch state to 1 ...
ELIF < X PN 2 Z: Z 2; ... // switch state to 2 ...
ELSE: Z 3; ...
```

`PN j Z`

is the transition probability from state Z to state j.

I haven’t tried this, but I think it should work.

For more states, as long as from each state you only transition to 4 other states, you can still apply the above. Instead of a 4 x 4 matrix, you’ll have an N x 4 matrix.

EDIT: I just realized there is a bug in the snippet I wrote above. PM me if you want the details.