How to copy event from inside the event

I know this is similar to this topic but the answer there didn’t quite work for me.

I am trying to hack together a kind of livecoding interface using events. I would like to define functions on my event that return a modified copy of the event but I can’t figure out how to access the equivalent of the this keyword from other languages.

When its run, aside from the error. The console should show the value of currentEnvironment to be the outer environment and not the event. How do I access this for an event?

Here is my example:

(~x ={|name, synth|

	var api = (
		synth: synth,
		name: name,
		controlPats: (),
		play: {
			var s =  (type: \set, id:;
			var id =;
			var ps = ~controlPats.collect({
				Pbind(*[type: \set, id: id ]++[key, p.pat, \dur, p.dur])
			Pdef(name, Ppar(
		c: {
			|key, pat, dur(1)|
			var e = ().putAll(currentEnvironment);
			"e is... ".postln;
			e.controlPats[key] = (pat: pat, dur: dur);

~synth !? {; ~synth=nil};
~synth = ~synth??{{
	var env =, \;
	var osc =\, mul: env*\;, \

~x.(\fred, ~synth).c.(\degree, Pseq([1,2,3],inf)).play

hen’t looked through your example carefully but…

when you call a function inside an Event the first argument of the function will be essentially this

e = (a:5, b: {|self| self.a + 1});
e.b; // (notice that you don't have to call `.value` on e.b. b is treated as a method call)

if you want a pseudo-method to return an altered copy of an Event you can do like so

e = (a:5, b: {|self| self.copy.put(\c,9)})

pass in arguments to a pseudo-method like so:

e = (a:5, b: {|self num| self.copy.put(\c,num)})
1 Like

Edit: nevermind! i figured it out. For pseudo-methods you don’t need the extra . for the call. In the example below I should have written a.c(\degree, Pseq([1,23])) and not a.c.(\degree, Pseq([1,23]))
Thank you! That explains so much about what was going on in my example. Can you have arguments other than self in these pseudo-methods? For example:

a = (
  c: {
    |self, key, pat, dur(1)|
a.c.(\degree, Pseq([1,2,3]));

prints out nil for key and pat