mouseX scrolling through array

hey,
im struggling to use mouse x to scroll through an array of envelopes and post.ln
any guidance would be superhelpful, thanks

//////////////////////////

~envelopes = Array.new;
~envelopes =  ~envelopes.add("Env.adsr(0,1,0,1,4+(~vel*4.8),0)");
~envelopes =  ~envelopes.add("Env([5,4,7,3,8,3.5],[1,6,3,7,9,2])");


~ctrl = { 
		var a0 = MouseX.kr(0, 1, 0, 0.2);
		
			SendReply.kr(Changed.kr(a0), '/ctrl', [a0]);
		}.play;

~mouse1 = 0;

	OSCdef(\listenmouse, {
			arg msg;
	var selection;
			
			~mouse1 = msg[3..];
	
	~envelopes.item.do({ arg item; 
		
		[item].postln;
	});

		["mouse:" ++ ~mouse1].postln;
}, '/ctrl');

///////////////////////////

im struggling to use mouse x to scroll through an array of envelopes and post.ln

maybe this isn’t what you’re searching for, but do you know that you can hold down the ‘alt’ key and click+drag to post values?

(
[
	Env.adsr(0,1,0,1,4+(1*4.8),0),
	Env([5,4,7,3,8,3.5],[1,6,3,7,9,2])
].plot;
)

//will post this kind of info...
[ 99, [ 4.4330825805664 ] ]
[ 100, [ 4.3889722824097 ] ]
[ 101, [ 4.3448619842529 ] ]
[ 103, [ 4.2566413879395 ] ]
[ 106, [ 4.1243109703064 ] ]

#|
fredrikolofsson.com musicalfieldsforever.com

not quite what im after but cool

I can’t guess what is the purpose of calling item here. It isn’t a standard library method. I suspect this is a mistake.

hjh

yeah item is definitely a mistake, i thought perhaps related to scrolling through arrays

Rereading, I think maybe you just want the normal at method. Arrays have no concept of “scrolling through” hence nothing special to do with the array for that. You can get an index number from the mouse and ~envelopes[index].

hjh

ah ok, my secong guess was SelectX

This seems very useful… can you post the working solution?

If you’re accessing array items within the server, then you’d use Select or SelectX.

If you’re accessing them within the client, then you’d use at or similar.

The code examples retrieve the mouse values into the client – the OSC responder is client side, not running in the server – so SelectX wouldn’t have been appropriate.

Also the array contains strings, which the server doesn’t understand. So it pretty much has to be the client.

Client-vs-server is a sticking point for a lot of users, because it’s not immediately clear where the boundaries are. It takes some time to learn.

hjh

ok, yeah im definatley still feeling out client vs server architecture.
is ArrayBuffer.at helpful client side?

i tried to proliferate this a bit to no prevail a few different ways and either get ‘put’ errors or ‘basic at’ integer errors
this was my latest iteration using selection

~envelopes = Array.new;
~envelopenames = Array.new;
~envelopenames =  ~envelopenames.add("1");
~envelopes =  ~envelopes.add("Env.adsr(0,1,0,1,4+(~vel*4.8),0)");
~envelopenames =  ~envelopenames.add("2");
~envelopes =  ~envelopes.add("Env([5,4,7,3,8,3.5],[1,6,3,7,9,2])");



~ctrl = { 
		var a0 = MouseX.kr(0, 1, 0, 0.2);
		
			SendReply.kr(Changed.kr(a0), '/ctrl', [a0]);
		}.play;

~mouse1 = 0;

	OSCdef(\listenmouse, {
			arg msg;
	var selection;
	
	~mouse1[selection] = ~envelopes;
	~mouse1 = msg[3..] + ~envelopenames;
	
	
		
	

		["mouse:" ++ ~mouse1].postln;
}, '/ctrl');

Three questions in programming:

  1. What information do you have? Here the answer is an array (OSC message) consisting of ['/ctrl', a node ID, a message ID, a mouse value] and only the last is relevant. Also you have an array of envelope strings.

  2. What information do you need? Presumably this is just the envelope string in the array at the index.

  3. What operations will get from 1 to 2? I think here it may be as simple as ~envelopes[msg[3]].

First line means ~mouse.put(selection, ~envelopes) – a/ put is meaningful for arrays but ~mouse starts off as a number so that’s not going to get very far; b/ selection is nil and you can’t put into an array at an index of nil; c/ even supposing you address those, I’ve no idea how it helps you get from 1 to 2 above by saving a reference to your complete array into another array.

Second line erases the first result and replaces it with [index] + ["1", "2"] … again, I’m not sure of the relevance of this operation.

Does the following get you closer to where you want to go?

OSCdef(\listenmouse, { arg msg;
	("mouse: " ++ ~envelopes[msg[3]]).postln;
}, '/ctrl');

EDIT: One other refinement – var a0 = MouseX.kr(0, 1.999, 0, 0.2).floor; – this will make the behavior of Changed more meaningful in this context.

hjh

2 Likes

thank u hjh! this is infact very very helpful! i may have one more related question but i will explore this first