I guess you’re interested in what individual monome button within the GRButton’s bounds triggered the change of GRButton value to true and thus starts playing the pattern? You can use the lastPressed() method GRButton inherits from GRView for that.
~drone = GRButton(a, 0@4, 4, 3);
~drone.action = {|view, value|
if(value,
{
var pressedButton;
pressedButton = view.lastPressed;
pressedButton.postln; // a Point representing x, y
pressedButton.x.postln; // x position, an Integer
pressedButton.y.postln; // y position, an Integer
Pbindef(\gran, \sndBuf, b[\cuts][rrand(0, ~ssize)], \bpWet, 0.1).play;
},
{Pbindef(\gran).stop}
);
};
Note that above x, y is only posted when the GRButton is changed from unlit to lit since the postln calls are in the GRButton action function and the first if clause. A GRButton is handled as a whole so pressing two monome buttons within a GRButton bounds after each other without releasing in between will not trigger the GRButton action twice. This is by design.
Triggering something every time a monome button of a GRButton is pressed regardless of whether it changes the value (leds) is also possible but then you need to use another action. Let me know if I should elaborate on that.
That’s exactly what I wanted, thanks! I’m using this to build something to improvise with soundscapes and dancers on Tuesday. If you’re interested I can post the code and samples so you or others can see what all these questions were about.
I believe there are several ways of doing this but the one that comes to my mind is to listen to updates from the EventStreamPlayer that is spawned on pattern-play. Simple example code using a coupled GRButton:
(
a = Pbind(*[
degree: Pseq([0, 3, 2, 5], 4),
dur: 0.1
]);
b = GRScreenGrid.new;
c = GRButton.new(b, 0@0);
c.action = { |button, value|
if (value) {
d = a.play;
d.addDependant { |what, state|
if (state == \stopped) { c.value = false }
};
} {
d.stop;
d.releaseDependants;
}
};
)
I have never used Pbindef so I’m not sure how it works but I guess this is applicable for Pbindef too.