Piano Rolls

Hi all -

I was wondering if anyone knows of a standard extension/Quark for a piano roll implementation.

I’m only aware of this one: https://github.com/defaultxr/PianoRoll, which is no longer under active development.

Thanks!

Made an attempt to mock-up a quick one, but I seem to be misunderstanding something about evaluating a function - I don’t seem to be getting a value, as expected.

I was thinking this task could return an array for each column - this example is still just trying to procure the array from the first column, though. Any pointers would be great. Thanks.

(
var win, off=20;
win = Window("", Rect(10, 10, 500, 500)).front;
~m = Array.fill(10, {|x|
	Array.fill(10, {|y|
		Button(win, Rect(off+(40*x), off+(40*y), 40, 40))
		.states_([
			[" ", Color.white, Color.grey],
			["X", Color.yellow, Color.white]])})});
~n = Task({
	inf.do({|x|
	~o = (~m[0].collect{|y|
	{y.value}.defer;
		});
		~o.postln;
		0.5.wait;
	});
});
)
~n.play;

Because of the .defer requirement to access GUI objects’ state, it turns out not to be a good idea to use GUI objects to store data. (Patching environments, especially Max, encourage this design pattern [I’m looking at you, pattrstorage], but it’s really an anti-pattern.)

Instead, keep the data in its own array, and use the GUI to reflect the data.

(
var win, off=20;
win = Window("", Rect(10, 10, 500, 500)).front;
~m = Array.fill(10, { |x|
	Array.fill(10, { |y|
		0
	})
});

~buttons = Array.fill(10, { |x|
	Array.fill(10, { |y|
		Button()  // deleted coordinates, because see G below
		.states_([
			[" ", Color.white, Color.grey],
			["X", Color.yellow, Color.white]
		])  // please close brackets on the same level where they were opened
		.action_({ |view|
			~m[x][y] = view.value;
		});
	})
});

// G: Qt can make the grid for you
win.layout = GridLayout.columns( * ~buttons);
)

(
~n = Task({
	inf.do({ |x|
		~o = ~m.wrapAt(x);  // now no collect needed
		~o.postln;
		0.5.wait;
	});
});
)

~n.play;

~n.stop;

hjh

1 Like