SCErr meth_s_get(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
{
	sc_msg_iter msg(inSize, inData);

	Graph *graph = Msg_GetGraph(inWorld, msg);
	if (!graph) return kSCErr_NodeNotFound;

	int numheads = msg.tags ? strlen(msg.tags) - 1 : msg.remain() >> 2;

	big_scpacket packet;
	packet.adds("/n_set");
	packet.maketags(numheads * 2 + 2);
	packet.addtag(',');
	packet.addtag('i');
	packet.addi(graph->mNode.mID);

	while (msg.remain() >= 4) {
		if (msg.nextTag('i') == 's') {
			int32* name = msg.gets4();
			int32 hash = Hash(name);
			float32 value = 0.f;
			Graph_GetControl(graph, hash, name, 0, value);
			packet.addtag('s');
			packet.addtag('f');
			packet.adds((char*)name);
			packet.addf(value);
		} else {
			int32 index = msg.geti();
			float32 value = 0.f;
			Graph_GetControl(graph, index, value);
			packet.addtag('i');
			packet.addtag('f');
			packet.addi(index);
			packet.addf(value);
		}
	}

	if (packet.size()) {
		CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
	}

	return kSCErr_None;
}
Esempio n. 2
0
SCErr meth_s_getn(World *inWorld, int inSize, char *inData, ReplyAddress* inReply)
{
	sc_msg_iter msg(inSize, inData);

	Graph *graph = Msg_GetGraph(inWorld, msg);
	if (!graph) return kSCErr_NodeNotFound;

	// figure out how many tags to allocate
	int numcontrols = 0;
	int numheads = msg.tags ? strlen(msg.tags) - 1 >> 1 : msg.remain() >> 3;

	while (msg.remain()) {
		msg.geti(); // skip start
		int32 n = msg.geti();
		numcontrols += n;
	}

	big_scpacket packet;
	packet.adds("/n_setn");
	packet.maketags(numheads * 2 + numcontrols + 2);
	packet.addtag(',');

	// start over at beginning of message
	msg.init(inSize, inData);
	msg.geti(); // skip buf index

	packet.addtag('i');
	packet.addi(graph->mNode.mID);

	while (msg.remain()) {
		if (msg.nextTag('i') == 's') {
			int32* name = msg.gets4();
			int32 hash = Hash(name);
			int32 n = msg.geti();
			packet.addtag('s');
			packet.addtag('i');
			packet.adds((char*)name);
			packet.addi(n);
			for (int i=0; i<n; ++i) {
				float32 value = 0.f;
				Graph_GetControl(graph, hash, name, i, value);
				packet.addtag('f');
				packet.addf(value);
			}
		} else {
			int32 index = msg.geti();
			int32 n = msg.geti();
			packet.addtag('i');
			packet.addtag('i');
			packet.addi(index);
			packet.addi(n);
			for (int i=0; i<n; ++i) {
				float32 value = 0.f;
				Graph_GetControl(graph, index+i, value);
				packet.addtag('f');
				packet.addf(value);
			}
		}
	}

	if (packet.size()) {
		CallSequencedCommand(SendReplyCmd, inWorld, packet.size(), packet.data(), inReply);
	}

	return kSCErr_None;
}