Example #1
0
IoMP3Decoder *IoMP3Decoder_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoMP3Decoder_newTag(state));
	
	IoObject_setDataPointer_(self, calloc(1, sizeof(IoMP3DecoderData)));
	
	//DATA(self)->outSound = 0x0;
	DATA(self)->willProcessMessage = IoMessage_newWithName_label_(state, IOSYMBOL("willProcess"), IOSYMBOL("[MP3Decoder]"));
	DATA(self)->didProcessMessage = IoMessage_newWithName_label_(state, IOSYMBOL("didProcess"), IOSYMBOL("[MP3Decoder]"));
	DATA(self)->inputBuffer  = IoSeq_new(state);
	DATA(self)->outputBuffer = IoSeq_new(state);
	DATA(self)->tmpInputBa = UArray_new();
	
	IoState_registerProtoWithFunc_(state, self, IoMP3Decoder_proto);
	
	{
		IoMethodTable methodTable[] = {
		{"start", IoMP3Decoder_start},
		{"stop",  IoMP3Decoder_stop},
		{"inputBuffer",  IoMP3Decoder_inputBuffer},
		{"outputBuffer",  IoMP3Decoder_outputBuffer},
		
		{NULL, NULL},
		};
		IoObject_addMethodTable_(self, methodTable);
	}
	return self;
}
Example #2
0
IoAudioMixer *IoAudioMixer_rawClone(IoAudioMixer *proto) 
{ 
	IoObject *self = IoObject_rawClonePrimitive(proto);
	self->data = cpalloc(proto->data, sizeof(IoAudioMixerData));
	
	DATA(self)->ioBuffer = IoSeq_new(IOSTATE);
	DATA(self)->buffer = IoSeq_rawUArray(DATA(self)->ioBuffer);
	DATA(proto)->mixBuffer = UArray_new();
	DATA(self)->writeMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("write"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->writeMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->nonBlockingWriteMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("nonBlockingWrite"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->nonBlockingWriteMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->sounds = List_new();
	DATA(self)->soundsToRemove = List_new();
	DATA(self)->events = List_new();
	DATA(self)->activeEvents = List_new();
	DATA(self)->volume = DATA(self)->volume;
	
	DATA(self)->soundTouch = SoundTouch_init();
	SoundTouch_setSampleRate(DATA(self)->soundTouch, 44100);
	SoundTouch_setChannels(DATA(self)->soundTouch, 2);
	DATA(self)->tempo = 1.0;
	IoState_addValue_(IOSTATE, self);
	return self; 
}
Example #3
0
void onXmppAuth(LmConnection *connection, int success, void* data) {
  IoObject *self = data;
  IoMessage *m;

  if(success == 1) {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleAuthenticated"), IOSYMBOL("Loudmouth"));
  } else {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleAuthenticationFailure"), IOSYMBOL("Loudmouth"));
  }

  IoMessage_locals_performOn_(m, self, self);
}
Example #4
0
void IoEvDNSRequest_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
{
	IoEvDNSRequest *self = arg;
	//type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA

	IoObject_setSlot_to_(self, IOSYMBOL("ttl"), IONUMBER(ttl));

	if(result == DNS_ERR_NONE)
	{
		IoList *ioAddresses = IoList_new(IOSTATE);
		IoObject_setSlot_to_(self, IOSYMBOL("addresses"), ioAddresses);
		
		int i;
		for (i = 0; i < count; i ++)
		{
			//addresses needs to be cast according to type
			uint32_t a = ((uint32_t *)addresses)[i];
			struct in_addr addr;
			char *ip;
			addr.s_addr = htonl(get32(rr->rdata));
			ip = (char *)inet_ntoa(addr);
			IoList_rawAppend_(ioAddresses, IOSYMBOL(ip));
		}
	}
	else 
	{
		IoObject_setSlot_to_(self, IOSYMBOL("error"), IOSYMBOL("fail"));
	}

	
	IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleResponse"), IOSYMBOL("IoEvDNSRequest"));
	IoMessage_locals_performOn_(m, self, self);
}
Example #5
0
LmSSLResponse onSslError(LmSSL *ssl, LmSSLStatus status, void* data) {
  IoObject *self = data;

  IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleSslError"), IOSYMBOL("Loudmouth"));
  IoObject *result = IoMessage_locals_performOn_(m, self, self);

  return ISFALSE(result) ? LM_SSL_RESPONSE_STOP : LM_SSL_RESPONSE_CONTINUE;
}
Example #6
0
/***  Loudmouth callbacks ***/
void onXmppConnect(LmConnection *connection, int success, void* data) {
  IoObject *self = data;
  IoMessage *m;
  if(success == 1) {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnect"), IOSYMBOL("Loudmouth"));
    IoMessage_locals_performOn_(m, self, self);

    lm_connection_authenticate(
      connection,
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("username"))),
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("password"))),
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("resource"))),
      onXmppAuth, data, NULL, NULL
    );
  } else {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnectFailure"), IOSYMBOL("Loudmouth"));
    IoMessage_locals_performOn_(m, self, self);
  }
}
Example #7
0
LmHandlerResult onXmppMessage
  (LmMessageHandler *handler, LmConnection *connection, LmMessage *m, void* data)
{
  IoObject *self = data;

  IoList_rawAppend_(
    (IoList *)IoObject_getSlot_(self, IOSYMBOL("_msgsBuffer")),
    IOSYMBOL(lm_message_node_to_string(m->node))
  );

  IoMessage *io_m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("parseMessage"), IOSYMBOL("Loudmouth"));
  IoMessage_locals_performOn_(io_m, self, self);

  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Example #8
0
IoAudioMixer *IoAudioMixer_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoAudioMixer_newTag(state));
	
	self->data = calloc(1, sizeof(IoAudioMixerData));
	DATA(self)->sounds = List_new();
	DATA(self)->soundsToRemove = List_new();
	DATA(self)->events = List_new();
	DATA(self)->activeEvents = List_new();
	DATA(self)->samplesPerBuffer = FRAMES_PER_BUFFER;
	DATA(self)->volume = 1.0;
	
	DATA(self)->ioBuffer = IoSeq_new(IOSTATE);
	DATA(self)->buffer = IoSeq_rawUArray(DATA(self)->ioBuffer);
	DATA(self)->mixBuffer = UArray_new();
	DATA(self)->writeMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("write"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->writeMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->nonBlockingWriteMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("nonBlockingWrite"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->nonBlockingWriteMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->soundTouch = SoundTouch_init();
	SoundTouch_setSampleRate(DATA(self)->soundTouch, 44100);
	SoundTouch_setChannels(DATA(self)->soundTouch, 2);
	DATA(self)->tempo = 1.0;
	
	IoState_registerProtoWithId_(state, self, protoId);
	
	{
		IoMethodTable methodTable[] = {
		{"start", IoAudioMixer_start},
		{"stop", IoAudioMixer_stop},
		{"sounds", IoAudioMixer_sounds},
		{"addSound", IoAudioMixer_addSound_},
		{"addSoundOnSampleOfSound", 
			IoAudioMixer_addSound_onSample_ofSound_},
		{"removeSound", IoAudioMixer_removeSound_},
		{"removeAllSounds", IoAudioMixer_removeAllSounds},
		{"removeSoundOnSampleOfSound", IoAudioMixer_removeSound_onSample_ofSound_},
		{"setSamplesPerBuffer", IoAudioMixer_setSamplesPerBuffer},
		{"setVolume", IoAudioMixer_setVolume},
		{"setTempo", IoAudioMixer_setTempo},
		{"setSampleRate", IoAudioMixer_setSampleRate},
		{"setPitchSemiTones", IoAudioMixer_setPitchSemiTones},
		{"setAudioDevice", IoAudioMixer_setAudioDevice},
		{NULL, NULL},
		};
		IoObject_addMethodTable_(self, methodTable);
	}
	
	DATA(self)->ioAudioDevice = IoObject_rawGetSlot_(self, IOSYMBOL("AudioDevice"));
	{
		IoMessage *m = 0x0;
		IOASSERT(DATA(self)->ioAudioDevice, "unable to find AudioDevice");
	}
	return self;
}
Example #9
0
void onXmppDisconnect(LmConnection *connection, LmDisconnectReason reason, void* data) {
  IoObject *self = data;
  IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleDisconnect"), IOSYMBOL("Loudmouth"));
  IoMessage_locals_performOn_(m, self, self);
}