Ejemplo n.º 1
0
void testMultipleDeathListeners()
{
	TEST_SETUP();

	song_iterator_add_death_listener(
			it,
			it,
			(void (*)(void *, void*))DeathListenerCallback);

	song_iterator_add_death_listener(
			it,
			it,
			(void (*)(void *, void*))DeathListenerCallback);

	for (i=0; i < SONG_CMD_COUNT; i++)
	{
		message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	}

	TESTEQUAL(SI_FINISHED, message);

	TEST_TEARDOWN();

	TESTEQUAL(2, calledDeathListenerCallback);
}
Ejemplo n.º 2
0
TeeSongIterator::TeeSongIterator(SongIterator *left, SongIterator *right) {
	int i;
	int firstfree = 1; /* First free channel */
	int incomplete_map = 0;

	_readyToMorph = false;
	_status = TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE;

	_children[TEE_LEFT].it = left;
	_children[TEE_RIGHT].it = right;

	// By default, don't remap
	for (i = 0; i < 16; i++) {
		_children[TEE_LEFT].channel_remap[i] = i;
		_children[TEE_RIGHT].channel_remap[i] = i;
	}

	/* Default to lhs channels */
	channel_mask = left->channel_mask;
	for (i = 0; i < 16; i++)
		if (channel_mask & (1 << i) & right->channel_mask
		        && (i != MIDI_RHYTHM_CHANNEL) /* Share rhythm */) { /*conflict*/
			while ((firstfree == MIDI_RHYTHM_CHANNEL)
			        /* Either if it's the rhythm channel or if it's taken */
			        || (firstfree < MIDI_CHANNELS
			            && ((1 << firstfree) & channel_mask)))
				++firstfree;

			if (firstfree == MIDI_CHANNELS) {
				incomplete_map = 1;
				warning("[songit-tee <%08lx,%08lx>] Could not remap right channel #%d: Out of channels",
				        left->ID, right->ID, i);
			} else {
				_children[TEE_RIGHT].channel_remap[i] = firstfree;

				channel_mask |= (1 << firstfree);
			}
		}
#ifdef DEBUG_TEE_ITERATOR
	if (incomplete_map) {
		int c;
		fprintf(stderr, "[songit-tee <%08lx,%08lx>] Channels:"
		        " %04x <- %04x | %04x\n",
		        left->ID, right->ID,
		        channel_mask,
		        left->channel_mask, right->channel_mask);
		for (c = 0 ; c < 2; c++)
			for (i = 0 ; i < 16; i++)
				fprintf(stderr, "  map [%d][%d] -> %d\n",
				        c, i, _children[c].channel_remap[i]);
	}
#endif


	song_iterator_add_death_listener(left, this);
	song_iterator_add_death_listener(right, this);
}
Ejemplo n.º 3
0
static void song_iterator_transfer_death_listeners(SongIterator *it, SongIterator *it_from) {
	for (int i = 0; i < SONGIT_MAX_LISTENERS; ++i) {
		if (it_from->_deathListeners[i])
			song_iterator_add_death_listener(it, it_from->_deathListeners[i]);
		it_from->_deathListeners[i] = 0;
	}
}