# > teletype : code exchange

#599

OK, that was easier, and simpler than I thought. One script. Here I’m setting A in lieu of KR.PAT for testing purposes. Col 0 in the patterns is the current state, col 1 is the cumulative probabilty of state transition, and col 2 the state you transition to. I’m using Y only to shorten the line length. This approach could easily be extended to have a second block of data to manage a second matrix.

``````#I
A 0

#1
X 0; Y A
Z RRAND 0 100
W < PN 0 X Y: X + X 1
W < PN 1 X Z: X + X 1
A PN 2 X

#P
8	8	6	0
1	1	1	1
0	0	0	0
63	63	63	63

0	30	1	0
0	60	2	0
0	100	3	0
1	50	1	0
1	100	2	0
2	100	3	0
3	60	0	0
3	100	1	0
``````

#600

I came up with a variation on your quantizer with a pattern note list, which handles octaves.

``````Y DIV V 1 4             // for a 4-note "scale"/chord
A DIV ADD VV 12 IN V 1  // A is the octave; a small offset added to make sure the shift is in the right place
Z MOD IN V 1            // look at the value within this specific octave
X DIV QT Z Y Y          // find pattern index
CV 1 ADD V A N PN 0 X   // look up note and add octave
``````

The offset on line 2 might need to be adjusted depending on the scale or CV source; I determined it experimentally so it might vary.

I kind of want to try a “find the nearest pitch in the table” method, so if I set it for a blues scale and play a blues scale on a keyboard, I get what I expect instead of having notes shift out from under me. My first try was unsuccessful, but then I had only been playing with Teletype for about 2 hours at that point

#601

…and then it occurred to me on the way to work, I can use the same method but always have a scale length of 11, and just let the pattern do the mapping work. So that blues scale would be 0, 0, 3, 3, 5, 6, 7, 7, 10, 10, 12 (I think).

#603

didn’t want to pile up on TT-talk in the tracks thread, but I think individual ‘metronomes’ in the non-txo teletype setup can be done with recursive delays, right?

script 1:
`TR.P 1`
`DEL 300: \$ 1`

script 2:
`TR.P 2`
`DEL 310: \$ 2`

and in live, to kick it off:
`\$ 1; \$ 2`

#604

True! Didn’t think of that.

#605

I did something similar: i inserted a DEL 200: SCRIPT 1 and DEL 190: SCRIPT 2 at the end of script 1 and 2. Then i start them in sync by pressing f1 and f2 together (I don’t know why but it fucks the script pretty bad if i press f1 or f2 again when they’re looping, they start missing steps in the patterns and loosing the rythm).
Still i can’t insert differences smaller than 10ms between the two scripts so the phasing is still pretty fast!

#606

I just finished something based on the M.U. Marbles. Suggestions of useful missing features are welcome :

tt13s.txt (1.7 KB)

In short:
PRM = clock speed
TI.PRM1 is a clock JITTER probability
TI.PRM2 fully CCW it creates random notes (with a V range defined by TI.PRM4). Turning the knob a bit CW will lock the notes and gradualy morph from random notes from the sequence to the locked one (once fully CW).
TI.PRM3 is the pattern Lenght (from 1 to 16 steps).
TI.PRM5 is the coin toss probability used to create TR 3 and 4 rhythms (with associated cv values linked to CV 1), be aware that the random/lock thing is global ( for TR 1 3 4 and CV 1 3 4).
Little add: once the sequence is locked you can play with the coin toss probability

``````GAME OF MARBLES
PRM: CLOCK FROM 0 TO 1000MS
TI.PRM 1: JITTER
TI.PRM 2: FCCW WRITE FCW READ
TI.PRM 3: P LENGHT 1 TO 16
TI.PRM 4: V RANGE
TI.PRM 5: COIN TOSS PROB

#1
I RSH TI.PRM 1 7
PROB I: Y RAND - X / X 9
PROB - 100 I: Y 0
DEL Y: SCRIPT 2
IF GT PN.I 0 A: PN.I 0 0

#2
Z RAND TI.PRM 4;
IF EZ D: CV 1 VV Z
TR.P 1; PN.NEXT 0;
IF EZ D: PN.HERE 0 Z
IF NZ D: SCRIPT 3
SCRIPT 4

#3
I 1
PROB - 100 / D 10: I 0
IF EQ I 0: PN.I 0 RAND A
T PN.HERE 0
CV 1 VV T;

#4
B 3; PN.NEXT 2;
PROB TI.PRM 5: B 4
IF EZ D: PN.HERE 2 B
IF EZ D: CV B CV 1
IF EZ D: TR.P B
IF NZ D: SCRIPT 5

#5
IF EQ PN.HERE 2 3: SCRIPT 6
ELSE: SCRIPT 7

#6
I 1
PROB - 100 / D 10: I 0
IF NZ I: TR.P PN.HERE 2
ELSE: TR.P B
CV 3 CV 1

#7
I 1
PROB - 100 / D 10: I 0
IF NZ I: TR.P PN.HERE 2
ELSE: TR.P B
CV 4 CV 1

#8

#M
IF EZ PN.I 2: TR.P 2
TI.PRM.MAP 1 0 12850
A >> TI.PRM 3 10
L 0 3: PN.END I A
X >> PRM 4; M X; D TI.PRM 2;
SCRIPT 1

#I
TI.PRM.MAP 4 0 800
TI.PRM.MAP 2 0 1000
TI.PRM.MAP 5 0 100
L 1 4: TR.TIME I 20
M 200; M.ACT 1
L 0 3: PN.I I 0

#P
64	64	64	64
1	1	1	1
0	0	0	0
15	15	15	15

197	0	3	0
1	0	3	0
72	0	3	0
378	0	3	0
365	0	3	0
158	0	3	0
170	0	3	0
328	0	4	0
347	0	3	0
166	0	3	0
207	0	4	0
46	0	3	0
232	0	3	0
212	0	4	0
43	0	4	0
159	0	4	0
67	0	3	0
158	0	3	0
265	0	3	0
204	0	3	0
317	0	3	0
26	0	3	0
62	0	3	0
2	0	3	0
58	0	3	0
66	0	3	0
314	0	3	0
240	0	3	0
156	0	3	0
28	0	3	0
285	0	3	0
162	0	3	0
100	0	3	0
284	0	3	0
169	0	3	0
137	0	3	0
271	0	3	0
233	0	3	0
300	0	3	0
276	0	3	0
141	0	3	0
111	0	3	0
246	0	3	0
27	0	3	0
309	0	3	0
258	0	3	0
243	0	3	0
300	0	3	0
242	0	3	0
42	0	3	0
264	0	3	0
258	0	3	0
229	0	3	0
251	0	3	0
164	0	3	0
214	0	3	0
458	0	3	0
46	0	3	0
341	0	3	0
295	0	3	0
334	0	3	0
501	0	3	0
317	0	3	0
336	0	3	0
``````

Cheers

Mutable Instruments Marbles
#607

whoa whoa… sorry, but what does the dollar sign do?

#608

it’s an alias for `SCRIPT`

#609

Hopefully I will start adding to this thread again, but right now I have another cry for help -
I want to manually trigger some scripts, using the keyboard, or a manually generated gate, and I want to quantize them to a clock, which will be connected to a trigger input of TT. Like using a Data flip flop (from the Plog manual - The D Flip-flop output latches to whatever logic level the input is but only when the CLK signal transitions from low to high.)
Maybe I should put a Plog next to TT, but that would restrict me to quantizing just one input. If I needed more then a TT solution would be needed.

#610

So you want the gate to only rise and fall on the beat?
I’m away from Teletype right now, but it sounds like all you need is to check the `STATE` of your gate input each time metro fires, and update the corresponding output:

``````M
L 1 4 : TR I STATE I
``````

This would quantize inputs 1-4 to gate outputs 1-4

#611

I want the action that I want to trigger to happen on the beat.
I should have mentioned I’m using an external clock, so 16s (or whatever is chosen to quantize to) will be going to one of the trigger inputs.

#612

Sure, so just use input 8 for tempo, and have your metro synced there:

``````8
T TIME
TIME 0
M T
``````

As described in https://monome.org/docs/modular/teletype/studies-4/

#613

Thanks so much. It’s a little scary how little of that I had retained in my memory. I studied all of the studies as they were being produced…

#614

Can be shortened to:

``````8:
M LAST 8
``````

Although I think what lloydcole was wanting is more like this, no self-patching required:

``````1:
S: TR 1 ER 3 8 O // or whatever you want to happen on the beat after input 1 is triggered

2:
S: \$ 5 // or whatever you want to happen on the beat after input 2 is triggered... etc.

8:
S.ALL``````

#615

That works well for quantizing the trigger start, and obviously supporting more complex events, but if you want gates to end on the beat as well I don’t think that will work. I always forget about the stack op – there’s definitely some interesting things you could make with the scene you described, I’m going to play with that later

no self-patching required:

For what it’s worth I don’t think my code should require any self patching – just takes external gate inputs and quantizes them out the outputs.

#616

This sounds good.
I’ve never used stacking before.
So on each clock the script looks to see if there’s anything in the stack and if there is it executes and clears the stack, preventing any repetition, which was my worry with the previous suggestion.
I’ll try this and report back.
Thanks!

#617

Well… if you trigger 1, it will push commands onto the stack multiple times, so it’ll happen multiple times when script 8 fires.

To guarantee a max of one per beat, you could reserve a variable to set flags for each input. It’s a litlte less elegant programming-wise I suppose, but whatever works:

``````1:
BSET Z 1

2:
BSET Z 2

8:
IF NZ BGET Z 1:  // do script 1 stuff here
IF NZ BGET Z 2:  // do script 2 stuff here, etc.
Z 0
``````

Yet another way to do this would be using delays, but again, if you trigger 1 twice within the same beat you’d double up on delayed commands.

``````1:
DEL SUB Z LAST 8: // do script 1 stuff here

2:
DEL SUB Z LAST 8: // do script 2 stuff here, etc.

8:
Z LAST 8``````

#618

But I won’t do that I’ll either trigger the script with a manually generated gate, or function key.

#619

I’ve been using variations of this:

``````// script 1, the command(s) you want executed to a quantized beat
TR.PULSE

// script 2, adds command to the stack, stack holds a max of 8 commands
S: SCRIPT 1

// script 3, feed your clock into this
S.POP``````