Example #1
0
//--------------------------------------------------------------
void ofApp::update(){
    while(receiver.hasWaitingMessages()) {
        ofxOscMessage m;
        receiver.getNextMessage(&m);
        if(m.getAddress()=="/param"){
            param0 = m.getArgAsFloat(0);
        }
        if(m.getAddress()=="/Velocity1"){
            int param1 = m.getArgAsInt32(0);
            if(param1>0) {
                flag0 = true;
            }
        }
        if(m.getAddress()=="/state1"){
            state1 = m.getArgAsFloat(0);
            if(state1>0) {
                //flag1 = true;
            }
        }
        if(m.getAddress()=="/state2"){
            state2 = m.getArgAsFloat(0);
            if(state2>0) {
                //flag2 = true;
            }
        }
        dumpOSC(m);
    }
    if(state1>0) {
        for(int i=0; i<points.size(); i++) {
            points[i].x = points[i].x + ofRandom(10)-5;
            points[i].y = points[i].y + ofRandom(10)-5;
        }
        //flag1 = false;
    }
}
Example #2
0
SC_DLLEXPORT_C bool World_SendPacketWithContext(World *inWorld, int inSize, char *inData, ReplyFunc inFunc, void *inContext)
{
	bool result = false;
	if (inSize > 0) {
		if (inWorld->mDumpOSC) dumpOSC(inWorld->mDumpOSC, inSize, inData);

		OSC_Packet* packet = (OSC_Packet*)malloc(sizeof(OSC_Packet));
		char *data = (char*)malloc(inSize);
		packet->mReplyAddr.mSockAddr.sin_addr.s_addr = 0;
		packet->mReplyAddr.mSockAddr.sin_port = 0;
		packet->mReplyAddr.mReplyFunc = inFunc;
		packet->mReplyAddr.mReplyData = inContext;
		packet->mSize = inSize;
		packet->mData = data;
		packet->mReplyAddr.mSocket = 0;
		memcpy(data, inData, inSize);

		result = ProcessOSCPacket(inWorld, packet);
	}
	return result;
}
Example #3
0
void testApp::update(){
    //現在順番待ちのOSCメッセージがあるか確認
    while(receiver.hasWaitingMessages()){
        //次のメッセージを取得
        ofxOscMessage m;
        oscString = m.getAddress();
        receiver.getNextMessage(&m);
        
        //マウスの位置を取得
        if(m.getAddress() == "/mouse/position"){
            remoteMouse.x = m.getArgAsInt32(0);
            remoteMouse.y = m.getArgAsInt32(1);
            
        }
        //マウスボタンの状態を取得
        else if (m.getAddress() == "/mouse/button") {
            mouseButtonState = m.getArgAsString(0) ;
        }
        
        //OSCメッセージをそのままコンソールに出力
        dumpOSC(m);
    }
    
    //マウスアップされたら、新規にRingを追加
    if(mouseButtonState == "up"){
        rings.push_back(new Ring(ofPoint(remoteMouse.x, remoteMouse.y)));
        mouseButtonState = "";
    }
    
    //Ring更新
    for(vector <Ring *>::iterator it = rings.begin(); it != rings.end();){
        (*it)->update();
        if ((*it)->dead) {
            delete (*it);
            it = rings.erase(it);
        } else {
            ++it;
        }
    }
}
void* SC_UdpInPort::Run()
{
	OSC_Packet *packet = 0;
	while (true) {
		if (!packet) {
			// preallocate packet before we need it.
			packet = (OSC_Packet*)malloc(sizeof(OSC_Packet));
		}

		packet->mReplyAddr.mSockAddrLen = sizeof(sockaddr_in);
#ifdef _WIN32
		int size = recvfrom(mSocket, (char *)mReadBuf, kMaxUDPSize , 0,
#else
		int size = recvfrom(mSocket, mReadBuf, kMaxUDPSize , 0,
#endif
								(struct sockaddr *) &packet->mReplyAddr.mSockAddr, (socklen_t*)&packet->mReplyAddr.mSockAddrLen);

		if (size > 0) {
			char *data = (char*)malloc(size);
			memcpy(data, mReadBuf, size);
			if (mWorld->mDumpOSC) dumpOSC(mWorld->mDumpOSC, size, data);

			packet->mReplyAddr.mReplyFunc = udp_reply_func;
			packet->mReplyAddr.mReplyData = 0;
			packet->mSize = size;
			packet->mData = data;
			packet->mReplyAddr.mSocket = mSocket;

			if (!ProcessOSCPacket(mWorld, packet))
			{
				scprintf("command FIFO full\n");
				free(data);
				free(packet);
			}
			packet = 0;
			data = 0;
		}
	}
	return 0;
}
void ofMultiTaction::update(bool isDumpOSC)
{
    while (d->receiver.hasWaitingMessages()) {
        ofxOscMessage m;
        d->receiver.getNextMessage(&m);
        
        if (m.getAddress() == "/fingerDown") {
            Finger finger = makeFingerFromOSC(m);
            appendFinger(finger);
        }
        else if(m.getAddress() == "/fingerMove") {
            Finger finger = makeFingerFromOSC(m);
            appendFinger(finger);
        }
        else if(m.getAddress() == "/fingerUp") {
            Finger finger = makeFingerFromOSC(m);
            removeFinger(finger);
        }
        
        else if(m.getAddress() == "/markerDown") {
            Marker marker = makeMarkerFromOSC(m);
            appendMarker(marker);
        }
        else if(m.getAddress() == "/markerMove") {
            Marker marker = makeMarkerFromOSC(m);
            appendMarker(marker);
        }
        else if(m.getAddress() == "/markerUp") {
            Marker marker = makeMarkerFromOSC(m);
            removeMarker(marker);
        }
        
        if (isDumpOSC) {
            dumpOSC(m);
        }
    }
    
}
CFDataRef SC_MachMessagePort::messagePortCallBack(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info)
{
    // CFShow(data);
    SC_MachMessagePort *port = (SC_MachMessagePort *) info;
    OSC_Packet* packet = (OSC_Packet *) malloc(sizeof(OSC_Packet));
    bzero(&packet->mReplyAddr, sizeof(ReplyAddress));
    packet->mReplyAddr.mReplyFunc = port->mReplyPort ? mach_reply_func : null_reply_func;
	packet->mReplyAddr.mReplyData = 0;
    packet->mReplyAddr.mSocket = (int)(int64)port->mReplyPort;
    packet->mSize = CFDataGetLength(data);
    packet->mData = (char*) memcpy(malloc(packet->mSize), CFDataGetBytePtr(data), packet->mSize);

    World *world = port->mWorld;
    if (world->mDumpOSC) dumpOSC(world->mDumpOSC, packet->mSize, packet->mData);

    if (!ProcessOSCPacket(world, packet)) {
        scprintf("command FIFO full\n");
        free(packet->mData);
        free(packet);
    }

    // how can we send a reply? we could block here until the message is processed...
    return NULL;
}
void* SC_TcpConnectionPort::Run()
{
	const int kMaxPasswordLen = 32;
	char buf[kMaxPasswordLen];
	OSC_Packet *packet = 0;
	// wait for login message
	int32 size;
	int32 msglen;

	// first message must be the password. 4 tries.
	bool validated = mWorld->hw->mPassword[0] == 0;
	for (int i=0; !validated && i<4; ++i) {
		size = recvall(mSocket, &msglen, sizeof(int32) );
		if (size < 0) goto leave;

		msglen = ntohl(msglen);
		if (msglen > kMaxPasswordLen) break;

		size = recvall(mSocket, buf, msglen);
		if (size < 0) goto leave;

		validated = strcmp(buf, mWorld->hw->mPassword) == 0;
#ifdef _WIN32
		if (!validated) Sleep(i+1);	// thwart cracking.
#else
		if (!validated) sleep(i+1);	// thwart cracking.
#endif
	}

	if (validated) {
		while (true) {
			if (!packet) {
				packet = (OSC_Packet*)malloc(sizeof(OSC_Packet));
			}
			size = recvall(mSocket, &msglen, sizeof(int32));
			if (size != sizeof(int32)) goto leave;

			// sk: msglen is in network byte order
			msglen = ntohl(msglen);

			char *data = (char*)malloc(msglen);
			size = recvall(mSocket, data, msglen);
			if (size < msglen) goto leave;

			if (mWorld->mDumpOSC) dumpOSC(mWorld->mDumpOSC, size, data);

			packet->mReplyAddr.mReplyFunc = tcp_reply_func;
			packet->mReplyAddr.mReplyData = 0;
			packet->mSize = msglen;
			packet->mData = data;
			packet->mReplyAddr.mSocket = mSocket;
			if (!ProcessOSCPacket(mWorld, packet)) {
				scprintf("command FIFO full\n");
				free(data);
				free(packet);
			}
			packet = 0;
		}
	}
leave:
    delete this; // ohh this could cause a crash if a reply tries to access it..
    return 0;
}