Beispiel #1
0
static void callback_send_a_buffer_create(void *user, VNodeID node_id, VBufferID buffer_id, const char *name,
        VNABlockType type, real64 frequency)
{
    VSNodeAudio *node;
    unsigned int i, j, count;

    if(frequency < 0.0)
        return;
    node = (VSNodeAudio *)vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL)
        return;

    for(i = 0; i < node->buffer_count; i++)
    {
        if(buffer_id != i)
        {
            for(j = 0; name[j] == node->buffers[i].name[j] && name[j] != 0; j++);
            if(name[j] == node->buffers[i].name[j])
                return;
        }
    }

    if(buffer_id < node->buffer_count && node->buffers[buffer_id].name[0] != 0 && type != node->buffers[buffer_id].type)
    {
        free(node->buffers[buffer_id].data);
        vs_destroy_subscription_list(node->buffers[buffer_id].subscribers);
        node->buffers[buffer_id].name[0] = 0;
    }

    if(buffer_id >= node->buffer_count || node->buffers[buffer_id].name[0] == 0)
    {
        for(buffer_id = 0; buffer_id < node->buffer_count && node->buffers[buffer_id].name[0] != 0; buffer_id++);
        if(buffer_id == node->buffer_count)
        {
            buffer_id = node->buffer_count;
            node->buffer_count += 16;
            node->buffers = realloc(node->buffers, (sizeof *node->buffers) * node->buffer_count);
            for(i = buffer_id; i < node->buffer_count; i++)
                node->buffers[i].name[0] = 0;
        }
        node->buffers[buffer_id].subscribers = vs_create_subscription_list();
        node->buffers[buffer_id].type = type;
        node->buffers[buffer_id].frequency = frequency;
        node->buffers[buffer_id].length = 64;
        node->buffers[buffer_id].data = malloc(sizeof(*node->buffers[buffer_id].data) * node->buffers[buffer_id].length);
        for(i = 0; i < node->buffers[buffer_id].length; i++)
            node->buffers[buffer_id].data[i] = NULL;
    }
    for(i = 0; name[i] != 0 && i < 15; i++)
        node->buffers[buffer_id].name[i] = name[i];
    node->buffers[buffer_id].name[i] = 0;

    count =	vs_get_subscript_count(node->head.subscribers);
    for(i = 0; i < count; i++)
    {
        vs_set_subscript_session(node->head.subscribers, i);
        verse_send_a_buffer_create(node_id, buffer_id, name, type, frequency);
    }
    vs_reset_subscript_session();
}
Beispiel #2
0
static void callback_send_a_block_clear(void *user, VNodeID node_id, VLayerID buffer_id, uint32 id)
{
    VSNodeAudio *node;
    unsigned int i, count;
    node = (VSNodeAudio *)vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL)
        return;
    if(node->buffer_count <= buffer_id)
        return;
    if(node->buffers[buffer_id].name[0] == 0)
        return;
    if(id >= node->buffers[buffer_id].length)
        return;
    if(node->buffers[buffer_id].data[id] == NULL)
        return;
    free(node->buffers[buffer_id].data[id]);
    node->buffers[buffer_id].data[id] = NULL;
    count =	vs_get_subscript_count(node->buffers[buffer_id].subscribers);
    for(i = 0; i < count; i++)
    {
        vs_set_subscript_session(node->buffers[buffer_id].subscribers, i);
        verse_send_a_block_clear(node_id, buffer_id, id);
    }
    vs_reset_subscript_session();
}
Beispiel #3
0
VNodeID vs_node_create(VNodeID owner_id, unsigned int type)
{
	unsigned int count, i;
	VSNodeHead *node;
	VNodeID node_id;

	printf("vs_node_create(%u, %u)\n", owner_id, type);
	switch(type)
	{
		case V_NT_OBJECT :
			node = vs_o_create_node(owner_id);
		break;
		case V_NT_GEOMETRY :
			node = vs_g_create_node(owner_id);
		break;
		case V_NT_MATERIAL :
			node = vs_m_create_node(owner_id);
		break;
		case V_NT_BITMAP :
			node = vs_b_create_node(owner_id);
		break;
		case V_NT_TEXT :
			node = vs_t_create_node(owner_id);
		break;
		case V_NT_CURVE :
			node = vs_c_create_node(owner_id);
		break;
		case V_NT_AUDIO :
			node = vs_a_create_node(owner_id);
		break;
		default:
			fprintf(stderr, "Can't create node of unknown type %u\n", type);
			return 0U;
	}
	node_id = node->id;

	count =	vs_get_subscript_count(VSNodeStorage.list[type]);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(VSNodeStorage.list[type], i);
		if(owner_id != verse_session_get_avatar())
			verse_send_node_create(node_id, type, VN_OWNER_OTHER);
		else
			verse_send_node_create(node_id, type, VN_OWNER_MINE);
	}
	if(count != 0)
		vs_reset_subscript_session();
	return node_id;
}
Beispiel #4
0
static void callback_send_a_block_set(void *user, VNodeID node_id, VLayerID buffer_id, uint32 block_index,
                                      VNABlockType type, const VNABlock *data)
{
    static const size_t	blocksize[] = {
        VN_A_BLOCK_SIZE_INT8   * sizeof (int8),
        VN_A_BLOCK_SIZE_INT16  * sizeof (int16),
        VN_A_BLOCK_SIZE_INT24  * 3 * sizeof (int8),
        VN_A_BLOCK_SIZE_INT32  * sizeof (int32),
        VN_A_BLOCK_SIZE_REAL32 * sizeof (real32),
        VN_A_BLOCK_SIZE_REAL64 * sizeof (real64)
    };
    VSNodeAudio *node;
    unsigned int i, count;

    if(type > VN_A_BLOCK_REAL64)	/* Protect blocksize array. */
        return;

    node = (VSNodeAudio *)vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL)
        return;
    if(node->buffers[buffer_id].name[0] == 0)
        return;
    if(type != node->buffers[buffer_id].type)		/* Disregard attempts to set data of wrong type. */
        return;
    if(block_index > node->buffers[buffer_id].length)
    {
        node->buffers[buffer_id].data = realloc(node->buffers[buffer_id].data,
                                                (sizeof *node->buffers[buffer_id].data) * (block_index + 64));
        for(i = node->buffers[buffer_id].length; i < block_index + 64; i++)
            node->buffers[buffer_id].data[i] = NULL;
        node->buffers[buffer_id].length = block_index + 64;
    }

    if(node->buffers[buffer_id].data[block_index] == NULL)
        node->buffers[buffer_id].data[block_index] = malloc(blocksize[type]);
    if(node->buffers[buffer_id].data[block_index] != NULL)
    {
        memcpy(node->buffers[buffer_id].data[block_index], data, blocksize[type]);
        count =	vs_get_subscript_count(node->buffers[buffer_id].subscribers);
        for(i = 0; i < count; i++)
        {
            vs_set_subscript_session(node->buffers[buffer_id].subscribers, i);
            verse_send_a_block_set(node_id, buffer_id, block_index, type, data);
        }
        vs_reset_subscript_session();
    }
}
Beispiel #5
0
void callback_send_node_destroy(void *user_data, VNodeID node_id)
{
	unsigned int count, i;
	VSNodeHead *node;
	VNodeType type;
	node = vs_get_node_head(node_id);
	if(node == NULL)
		return;
	VSNodeStorage.nodes[node_id] = NULL;
	type = node->type;
	switch(type)
	{
		case V_NT_OBJECT :
			vs_o_destroy_node(node);
		break;
		case V_NT_GEOMETRY :
			vs_g_destroy_node(node);
		break;
		case V_NT_MATERIAL :
			vs_m_destroy_node(node);
		break;
		case V_NT_BITMAP :
			vs_b_destroy_node(node);
		break;
		case V_NT_TEXT :
			vs_t_destroy_node(node);
		break;
		case V_NT_CURVE :
			vs_c_destroy_node(node);
		break;
		case V_NT_AUDIO :
			vs_c_destroy_node(node);
		break;
		default:
			fprintf(stderr, __FILE__ " Can't handle node_destroy for type %d--not implemented", type);
		return;
	}
	count =	vs_get_subscript_count(VSNodeStorage.list[type]);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(VSNodeStorage.list[type], i);
		verse_send_node_destroy(node_id);
	}
	vs_reset_subscript_session();
}
Beispiel #6
0
static void callback_send_a_stream_destroy(void *user, VNodeID node_id, VLayerID stream_id)
{
    VSNodeAudio *node;
    unsigned int i, count;

    node = (VSNodeAudio *)vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL || stream_id >= node->stream_count || node->streams[stream_id].name[0] == 0)
        return;
    vs_remove_subscriptor(node->streams[stream_id].subscribers);
    node->streams[stream_id].name[0] = 0;
    count =	vs_get_subscript_count(node->head.subscribers);
    for(i = 0; i < count; i++)
    {
        vs_set_subscript_session(node->head.subscribers, i);
        verse_send_a_stream_destroy(node_id, stream_id);
    }
    vs_reset_subscript_session();
}
Beispiel #7
0
static void callback_send_c_key_destroy(void *user, VNodeID node_id, VLayerID curve_id, uint32 key_id)
{
	VSNodeCurve *node;
	unsigned int i, count;
	node = (VSNodeCurve *)vs_get_node(node_id, V_NT_CURVE);
	if(node == NULL || node->curve_count <= curve_id || node->curves[curve_id].name[0] == 0)
		return;
	if(node->curves[curve_id].length <= key_id || node->curves[curve_id].keys[key_id].pos == V_REAL64_MAX)
		return;
	node->curves[curve_id].keys[key_id].pos = V_REAL64_MAX;
	count =	vs_get_subscript_count(node->curves[curve_id].subscribers);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(node->curves[curve_id].subscribers, i);
		verse_send_c_key_destroy(node_id, curve_id, key_id);
	}
	vs_reset_subscript_session();
}
Beispiel #8
0
static void callback_send_c_curve_destroy(void *user, VNodeID node_id, VLayerID curve_id)
{
	VSNodeCurve *node;
	unsigned int i, count;
	node = (VSNodeCurve *)vs_get_node(node_id, V_NT_CURVE);
	if(node == NULL || node->curve_count >= curve_id || node->curves[curve_id].name[0] == 0)
		return;
	vs_remove_subscriptor(node->curves[curve_id].subscribers);
	node->curves[curve_id].name[0] = 0;
	free(node->curves[curve_id].keys);
	count =	vs_get_subscript_count(node->head.subscribers);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(node->head.subscribers, i);
		verse_send_c_curve_destroy(node_id, curve_id);
	}
	vs_reset_subscript_session();
}
Beispiel #9
0
static void callback_send_a_stream_create(void *user, VNodeID node_id, VLayerID stream_id, const char *name)
{
    VSNodeAudio *node;
    unsigned int i, j, count;

    node = (VSNodeAudio *) vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL)
        return;

    for(i = 0; i < node->stream_count; i++)
    {
        if(stream_id != i)
        {
            for(j = 0; name[j] == node->streams[i].name[j] && name[j] != 0; j++);
            if(name[j] == node->streams[i].name[j])
                return;
        }
    }
    if(stream_id >= node->stream_count || node->streams[stream_id].name[0] == 0)
    {
        for(stream_id = 0; stream_id < node->stream_count && node->streams[stream_id].name[0] != 0; stream_id++);
        if(stream_id == node->stream_count)
        {
            stream_id = node->stream_count;
            node->stream_count += 16;
            node->streams = realloc(node->streams, (sizeof *node->streams) * node->stream_count);
            for(i = stream_id; i < node->stream_count; i++)
                node->streams[i].name[0] = 0;
        }
        node->streams[stream_id].subscribers = vs_create_subscription_list();
    }
    for(i = 0; name[i] != 0 && i < 15; i++)
        node->streams[stream_id].name[i] = name[i];
    node->streams[stream_id].name[i] = 0;
    count =	vs_get_subscript_count(node->head.subscribers);
    for(i = 0; i < count; i++)
    {
        vs_set_subscript_session(node->head.subscribers, i);
        verse_send_a_stream_create(node_id, stream_id, name);
    }
    vs_reset_subscript_session();
}
Beispiel #10
0
static void callback_send_c_key_set(void *user, VNodeID node_id, VLayerID curve_id, uint32 key_id, uint8 dimensions, real64 *pre_value, uint32 *pre_pos, real64 *value, real64 pos, real64 *post_value, uint32 *post_pos)
{
	VSNodeCurve *node;
	unsigned int i, count;
	node = (VSNodeCurve *)vs_get_node(node_id, V_NT_CURVE);
	if(node == NULL)
		return;
	if(node->curve_count <= curve_id)
		return;
	if(node->curves[curve_id].name[0] == 0)
		return;
	if(node == NULL || node->curve_count <= curve_id || node->curves[curve_id].name[0] == 0 || node->curves[curve_id].dimensions != dimensions)
		return;
	if(node->curves[curve_id].length <= key_id || node->curves[curve_id].keys[key_id].pos == V_REAL64_MAX)
	{
		for(key_id = 0; key_id < node->curves[curve_id].length && node->curves[curve_id].keys[key_id].pos != V_REAL64_MAX; key_id++);
		if(key_id == node->curves[curve_id].length)
			for(i = 0; i < 64; i++)
				node->curves[curve_id].keys[node->curves[curve_id].length++].pos = V_REAL64_MAX;
	}
	for(i = 0; i < dimensions; i++)
		node->curves[curve_id].keys[key_id].pre_value[i] = pre_value[i];
	for(i = 0; i < dimensions; i++)
		node->curves[curve_id].keys[key_id].pre_pos[i] = pre_pos[i];
	for(i = 0; i < dimensions; i++)
		node->curves[curve_id].keys[key_id].value[i] = value[i];
		node->curves[curve_id].keys[key_id].pos = pos;
	for(i = 0; i < dimensions; i++)
		node->curves[curve_id].keys[key_id].post_value[i] = post_value[i];
	for(i = 0; i < dimensions; i++)
		node->curves[curve_id].keys[key_id].post_pos[i] = post_pos[i];
	count =	vs_get_subscript_count(node->curves[curve_id].subscribers);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(node->curves[curve_id].subscribers, i);
		verse_send_c_key_set(node_id, curve_id, key_id, dimensions, pre_value, pre_pos, value, pos, post_value, post_pos);
	}
	vs_reset_subscript_session();
}
Beispiel #11
0
static void callback_send_a_stream(void *user, VNodeID node_id, VLayerID stream_id, uint32 time_s, uint32 time_f,
                                   VNABlockType type, real64 frequency, const VNABlock *data)
{
    VSNodeAudio *node;
    unsigned int i, count;

    if(frequency < 0)
        return;
    node = (VSNodeAudio *)vs_get_node(node_id, V_NT_AUDIO);
    if(node == NULL)
        return;
    if(node->stream_count <= stream_id)
        return;
    if(node->streams[stream_id].name[0] == 0)
        return;
    count =	vs_get_subscript_count(node->streams[stream_id].subscribers);
    for(i = 0; i < count; i++)
    {
        vs_set_subscript_session(node->streams[stream_id].subscribers, i);
        verse_send_a_stream(node_id, stream_id, time_s, time_f, type, frequency, data);
    }
    vs_reset_subscript_session();
}
Beispiel #12
0
static void callback_send_c_curve_create(void *user, VNodeID node_id, VLayerID curve_id, const char *name, uint8 dimensions)
{
	VSNodeCurve *node;
	unsigned int i, j, count;
	node = (VSNodeCurve *)vs_get_node(node_id, V_NT_CURVE);
	if(node == NULL)
		return;

	for(i = 0; i < node->curve_count; i++)
	{
		if(curve_id != i)
		{
			for(j = 0; name[j] == node->curves[i].name[j] && name[j] != 0; j++);
			if(name[j] == node->curves[i].name[j])
				return;
		}
	}
	if(curve_id >= node->curve_count || node->curves[curve_id].name[0] == 0)
	{
		for(curve_id = 0; curve_id < node->curve_count && node->curves[curve_id].name[0] != 0; curve_id++);
		if(curve_id == node->curve_count)
		{
			curve_id = node->curve_count;
			node->curve_count += 16;
			node->curves = realloc(node->curves, (sizeof *node->curves) * node->curve_count);
			for(i = curve_id; i < node->curve_count; i++)
				node->curves[i].name[0] = 0;		
		}
		node->curves[curve_id].subscribers = vs_create_subscription_list();
		node->curves[curve_id].length = 64;
		node->curves[curve_id].keys = malloc((sizeof *node->curves[curve_id].keys) * 64);
		for(i = 0; i < 64; i++)
			node->curves[curve_id].keys[i].pos = V_REAL64_MAX;			

	}else if(node->curves[curve_id].dimensions != dimensions)
	{
		for(i = 0; i < node->curves[curve_id].length; i++)
		{
			if(node->curves[curve_id].keys[i].pos != V_REAL64_MAX)
			{
				for(j = node->curves[curve_id].dimensions; j < dimensions; j++)
				{
					node->curves[curve_id].keys[i].pre_value[j] = node->curves[curve_id].keys[i].pre_value[0];
					node->curves[curve_id].keys[i].pre_pos[j] = node->curves[curve_id].keys[i].pre_pos[0];
					node->curves[curve_id].keys[i].value[j] = node->curves[curve_id].keys[i].value[0];
					node->curves[curve_id].keys[i].post_value[j] = node->curves[curve_id].keys[i].post_value[0];
					node->curves[curve_id].keys[i].post_pos[j] = node->curves[curve_id].keys[i].post_pos[0];
				}
			}
		}
		vs_destroy_subscription_list(node->curves[curve_id].subscribers);
		node->curves[curve_id].subscribers = vs_create_subscription_list();
	}
	for(i = 0; name[i] != 0 && i < 15; i++)
		node->curves[curve_id].name[i] = name[i];
	node->curves[curve_id].name[i] = 0;
	node->curves[curve_id].dimensions = dimensions;
	count =	vs_get_subscript_count(node->head.subscribers);
	for(i = 0; i < count; i++)
	{
		vs_set_subscript_session(node->head.subscribers, i);
		verse_send_c_curve_create(node_id, curve_id, name, dimensions);
	}
	vs_reset_subscript_session();
}