Forums > MaxMSP

Max find highlight

November 19, 2011 | 5:42 pm

Hi,

I’m working on a tutorial idea and I was wondering if it was possible to use the max object highlight that is used by the find command ? I want to be able to click on an image then see the highlight on a specific object. I hope I’m clear ! Thanks !

Nicolas


November 20, 2011 | 1:09 pm

I looked into something similar. I don’t think there’s a way to leverage the system that the find command uses, however, in javascript you can cycle through all the objects for a certain one and then script a [panel] object into the background and then remove it. You can even animate it to fade in/out or flash should you want to. If this might be helpful let me try to find the example I had and I will post it here.


November 20, 2011 | 2:39 pm

Thanks Luke, I’d definitely like to have a look if you don’t mind.


November 22, 2011 | 1:58 am

Create a [js] object in your patch and then past in the code below. You can send it the "search" message followed by the name of an object (including externals but not abstractions, these are reported the same as [patcher] objects). This will output the number of found matches and highlight the first instance with a [panel] that flashes on and off behind it. You can then send it the "next" message to cycle through all the matches before starting at the beginning.

Let me know if it’s of any use to you. It should even be fairly easy to adjust to suit your purposes, but if you need help just let me know.

var class;
var memory = [];
var panel;
var edge = 3;
var flashes = 6;
var corner = 16;
var count = 0;
var ta = new Task(flash, this);

function search(a) {
	memory = [];
	index = 0;
	count = 0;
	class = a;
	corner = 16;
	this.patcher.apply(iter)
	outlet(0,memory.length);
	next();
}

function iter(obj) {
	if (obj.maxclass == class) {
		memory[index++] = obj;
	}
}

function next() {
	if (panel) {
		this.patcher.remove(panel);
	}
	if (memory.length > 0) {
		obj = memory[count%(memory.length)];
		dim = obj.rect;
		if (obj.maxclass == "message") {
			corner = 20;
		}
		panel = this.patcher.newdefault(0,0,"panel",
		"@patching_position", dim[0]-edge, dim[1]-edge,
		"@patching_rect", dim[0]-edge, dim[1]-edge, dim[2]-dim[0]+2*edge, dim[3]-dim[1]+2*edge,
		"@bgcolor", 1, 0, 0, 0.7,
		"@rounded", corner);
		ta.interval = 300;
		ta.repeat(flashes);
		count++;
	}
}

function flash() {
	i = arguments.callee.task.iterations;
	if (i%2 == 0) {
		panel.message("bgcolor", 1, 0, 0, 0);
	} else {
		panel.message("bgcolor", 1, 0, 0, 0.7);
	}
	if (i == flashes) {
		this.patcher.remove(panel);
	}
}

November 22, 2011 | 10:49 am

Works very well, thank you for this ! Hope to meet at the next London Max meeting, have one on me !

cheers,
Nicolas


Viewing 5 posts - 1 through 5 (of 5 total)