Dirty flag in cplusplus

hi. i have a c++ custom op (chop) which has a lots of other ops (chop)(Satelits) connected on its inputs. the satelits are generating different arrays of data (pattern, s-curve … ) which goes into the main c++ op. inside ive a lot of loops.

im now looking for an efficient way to only iterate throug parts of the code, if the satelit has changes in its parameter values. ( a classical dirty flag)

if (dirty == true) do_loop;

what would be a good solution for that?

thx

You can’t specifically detect parameter changes, but you can tell if an input has cooked since you last saw it using its totalCooks member (OP_CHOPInput::totalCooks for a CHOP) - if the OP itself is unchanged (the opId) and the number of cooks is the same, then the output of that input has not changed.

1 Like

ah - ok - i will give that a try. :slight_smile:

maybe the python class inside the c++ custom chops also will allow to read out a dirty flag of an connected node?

“dirty” state only makes sense from the point of view of your OP - if another OP is connected to the same node but cooked several times before yours cooks once, the node will no longer be dirty from its point of view - but still dirty for yours. You will have to track state like I suggest - here’s one way to do it:

In the header, add to your CHOP class:

class YourCPlusPlusCHOP : public CHOP_CPlusPlusBase
{
public:
	// etc...
private:
	struct ChangeCheck {
		bool check(const OP_CHOPInput *input)
		{
			uint32_t inputOpId = input ? input->opId : 0;
			int64_t inputTotalCooks = input ? input->totalCooks : 0;
			bool changed = inputOpId != opId || inputTotalCooks != totalCooks;
			opId = inputOpId;
			totalCooks = inputTotalCooks;
			return changed;
		}
	private:
		uint32_t opId = 0;
		int64_t totalCooks = -1;
	};
	std::vector<ChangeCheck> myInputState;
	// your other member variables...
};

And then in your execute() method:

for (int i = 0; i < inputs->getNumInputs(); i++)
{
	const OP_CHOPInput *cinput = inputs->getInputCHOP(i);
	if (myInputState[i].check(cinput))
	{
		// The input has changed, do something with it
		// (cinput might be nullptr if no input is connected)
	}
}
1 Like

thank you a lot :slight_smile:

1 Like