Пример #1
0
END_TEST

START_TEST (test_World_does_not_have_a_cell_at_specified_location_when_cell_is_in_different_world)
{
	World *world = World_New();
	World_Add_Cell(World_New(), Cell_New(0, 0)); /* cell in another world */

	fail_if(World_Has_Cell_At(world, Coordinates_New(0, 0)), "Excepted cell (x=%d, y=%d) to be not present in the world, but was", 0, 0);
	World_Destroy(world);
}
Пример #2
0
END_TEST

START_TEST (test_World_if_it_has_a_cell_at_specified_location)
{
	World *world = World_New();
	World_Add_Cell(world, Cell_New(0, 0));

	fail_unless(World_Has_Cell_At(world, Coordinates_New(0, 0)), "Excepted cell (x=%d, y=%d) to be present in the world, but wasn't", 0, 0);
	fail_if(World_Has_Cell_At(world, Coordinates_New(1, 0)), "Excepted cell (x=%d, y=%d) to be not present in the world, but was", 1, 0);
	World_Destroy(world);
}
Пример #3
0
END_TEST

START_TEST (test_World_does_not_add_cell_if_cell_already_exists_in_the_world)
{
	World *world = World_New();
	World_Add_Cell(world, Cell_New(5, 4));
	World_Add_Cell(world, Cell_New(5, 4));

	long cell_count = World_Cell_Count(world);
	fail_unless(World_Cell_Count(world) == 1, "Expected world to contain %ld cells, but contained %ld", 1, cell_count);
	World_Destroy(world);
}
Пример #4
0
END_TEST

START_TEST (test_World_knows_the_generation_for_a_non_existing_cell_is_zero)
{
	World *world = World_New();
	Cell cell1 = Cell_New(0, 0); cell1.generation = 10; World_Add_Cell(world, cell1);
	Cell cell2 = Cell_New(1, 0); cell2.generation = 11; World_Add_Cell(world, cell2);

	long int gen = World_Generation_For(world, Coordinates_New(0, 1));
	fail_unless(gen == 0, "Excepted cell (x=%d, y=%d) to have generation %ld, but was %ld", 0, 0, 0, gen);
	World_Destroy(world);
}
Пример #5
0
END_TEST

START_TEST (test_World_knows_the_generation_for_a_cell_specified_by_its_coordinates_is_the_actual_cell_generation)
{
	World *world = World_New();
	Cell cell1 = Cell_New(0, 0); cell1.generation = 10; World_Add_Cell(world, cell1);
	Cell cell2 = Cell_New(1, 0); cell2.generation = 11; World_Add_Cell(world, cell2);

	long int gen = World_Generation_For(world, Coordinates_New(0, 0));
	fail_unless(gen == 10, "Excepted cell (x=%d, y=%d) to have generation %ld, but was %ld", 0, 0, 10, gen);
	World_Destroy(world);
}
Пример #6
0
END_TEST

START_TEST (test_World_knows_its_cell_count)
{
	World *world = World_New();
	World_Add_Cell(world, Cell_New(0, 0));
	World_Add_Cell(world, Cell_New(1, 4));
	World_Add_Cell(world, Cell_New(2, 4));

	long int cell_count = World_Cell_Count(world);
	fail_unless(cell_count == 3, "Expected cell count to be %ld, but was %ld", 3, cell_count);
	World_Destroy(world);
}
Пример #7
0
END_TEST

START_TEST (test_World_visits_accept_custom_data)
{
	World *world = World_New();
	World_Add_Cell(world, Cell_New(0, -1));

	long int *expected_trace = (long int*)(malloc( sizeof(long int) ));
	*expected_trace = 100;

	World_At_Each_Cell(world, w_add_up_cell_values, expected_trace);

	fail_unless(w_trace == 100, "Expected trace %ld, but was %ld", *expected_trace, w_trace);
	free(expected_trace);
	World_Destroy(world);
}
Пример #8
0
END_TEST

START_TEST (test_World_knows_count_of_neighbours_around_locations)
{
	World *world = World_New();
	Cell cell = Cell_New(0, 0);
	World_Add_Cell(world, cell);
	Coordinates locations[2];
	locations[0] = Coordinates_New(0, 1);
	locations[1] = Coordinates_New(3, 0);

	World_Add_Cell(world, Cell_New(0, 1)); /* neighbour */
	World_Add_Cell(world, Cell_New(3, 0)); /* neighbour */

	long int count = World_Cell_Count_Around(world, Coordinates_New(0, 0), locations, 2);
	fail_unless(count == 2, "Expected neighbour count to be %ld, but was %ld", 1, count);
	World_Destroy(world);
}
Пример #9
0
END_TEST

START_TEST (test_World_knows_does_not_count_cell_not_present_in_pool)
{
	World *world = World_New();
	Cell cell = Cell_New(0, 0);
	World_Add_Cell(world, cell);
	Coordinates locations[2];
	locations[0] = Coordinates_New(0, 1);
	locations[1] = Coordinates_New(3, 0);

	World_Add_Cell(world, Cell_New( 0,  2)); World_Add_Cell(world, Cell_New( 2,  2));
	World_Add_Cell(world, Cell_New( 2,  0)); World_Add_Cell(world, Cell_New( 2, -2));
	World_Add_Cell(world, Cell_New( 0, -2)); World_Add_Cell(world, Cell_New(-2, -2));
	World_Add_Cell(world, Cell_New(-2,  0)); World_Add_Cell(world, Cell_New(-2,  2));

	long int count = World_Cell_Count_Around(world, Coordinates_New(0, 0), locations, 2);
	fail_unless(count == 0, "Expected neighbour count to be %ld, but was %ld", 0, count);
	World_Destroy(world);
}
Пример #10
0
END_TEST

START_TEST (test_World_knows_all_cell_locations_near_a_set)
{
	World *world = World_New();
	World_Add_Cell(world, Cell_New(0, 0));
	World_Add_Cell(world, Cell_New(1, 1));
	Coordinates locations[4];
	locations[0] = Coordinates_New(0, 1);
	locations[1] = Coordinates_New(1, 1);

	World *zone = World_All_Neighbours_For_Set(world, locations, 2);
	long int cell_count = World_Cell_Count(zone);
	fail_unless(cell_count == 4, "Expected cell count to be %ld, but was %ld", 4, cell_count);

	fail_unless(World_Has_Cell_At(zone, Coordinates_New( 1,  2)), "Expected cell (x=%d,y=%d) to be present, but wasn't",  1,  2);
	fail_unless(World_Has_Cell_At(zone, Coordinates_New( 2,  2)), "Expected cell (x=%d,y=%d) to be present, but wasn't",  2,  2);
	fail_unless(World_Has_Cell_At(zone, Coordinates_New( 1,  1)), "Expected cell (x=%d,y=%d) to be present, but wasn't",  1,  1);
	fail_unless(World_Has_Cell_At(zone, Coordinates_New( 0,  1)), "Expected cell (x=%d,y=%d) to be present, but wasn't",  0,  1);
	World_Destroy(world);
}
Пример #11
0
void SCProcess::startUp(WorldOptions options, CFStringRef pluginsPath,  CFStringRef synthdefsPath,  int preferredPort) {

    pthread_t scThread;
    char stringBuffer[PATH_MAX] ;
    OSCMessages messages;

    CFStringGetCString(pluginsPath, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
    setenv("SC_PLUGIN_PATH", stringBuffer, 1);
    CFStringGetCString(synthdefsPath, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
    setenv("SC_SYNTHDEF_PATH", stringBuffer, 1);
    this->portNum = findNextFreeUdpPort(preferredPort);
    world = World_New(&options);
    //world->mDumpOSC=2;
    if (world) {
        if (this->portNum >= 0) World_OpenUDP(world, this->portNum);
        pthread_create (&scThread, NULL, scThreadFunc, (void*)world);
    }
    if (world->mRunning) {
        small_scpacket packet = messages.initTreeMessage();
        World_SendPacket(world, 16, (char*)packet.buf, null_reply_func);
    }
}
Пример #12
0
int main(int argc, char* argv[])
{
    setlinebuf(stdout);

#ifdef _WIN32
#ifdef SC_WIN32_STATIC_PTHREADS
    // initialize statically linked pthreads library
    pthread_win32_process_attach_np();
#endif

    // initialize winsock
    WSAData wsaData;
	int nCode;
    if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) {
		scprintf( "WSAStartup() failed with error code %d.\n", nCode );
        return 1;
    }
#endif

	int udpPortNum = -1;
	int tcpPortNum = -1;

	WorldOptions options = kDefaultWorldOptions;

	for (int i=1; i<argc;) {
		if (argv[i][0] != '-' || argv[i][1] == 0 || strchr("utaioczblndpmwZrNSDIOMHvRUhPL", argv[i][1]) == 0) {
			scprintf("ERROR: Invalid option %s\n", argv[i]);
			Usage();
		}
		int j = i;
		switch (argv[j][1]) {
			case 'u' :
				checkNumArgs(2);
				udpPortNum = atoi(argv[j+1]);
				break;
			case 't' :
				checkNumArgs(2);
				tcpPortNum = atoi(argv[j+1]);
				break;
			case 'a' :
				checkNumArgs(2);
				options.mNumAudioBusChannels = atoi(argv[j+1]);
				break;
			case 'i' :
				checkNumArgs(2);
				options.mNumInputBusChannels = atoi(argv[j+1]);
				break;
			case 'o' :
				checkNumArgs(2);
				options.mNumOutputBusChannels = atoi(argv[j+1]);
				break;
			case 'c' :
				checkNumArgs(2);
				options.mNumControlBusChannels = atoi(argv[j+1]);
				break;
			case 'z' :
				checkNumArgs(2);
				options.mBufLength = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'Z' :
				checkNumArgs(2);
				options.mPreferredHardwareBufferFrameSize = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'b' :
				checkNumArgs(2);
				options.mNumBuffers = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'l' :
				checkNumArgs(2);
				options.mMaxLogins = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'n' :
				checkNumArgs(2);
				options.mMaxNodes = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'd' :
				checkNumArgs(2);
				options.mMaxGraphDefs = NEXTPOWEROFTWO(atoi(argv[j+1]));
				break;
			case 'p' :
				checkNumArgs(2);
				options.mPassword = argv[j+1];
				break;
			case 'm' :
				checkNumArgs(2);
				options.mRealTimeMemorySize = atoi(argv[j+1]);
				break;
			case 'w' :
				checkNumArgs(2);
				options.mMaxWireBufs = atoi(argv[j+1]);
				break;
			case 'r' :
				checkNumArgs(2);
				options.mNumRGens = atoi(argv[j+1]);
				break;
			case 'S' :
				checkNumArgs(2);
				options.mPreferredSampleRate = (uint32)atof(argv[j+1]);
				break;
			case 'D' :
				checkNumArgs(2);
				options.mLoadGraphDefs = atoi(argv[j+1]);
				break;
			case 'N' :
#ifdef NO_LIBSNDFILE
				scprintf("NRT mode not supported: scsynth compiled without libsndfile\n");
				exit(0);
#endif
// -N cmd-filename input-filename output-filename sample-rate header-format sample-format
				checkNumArgs(7);
				options.mRealTime = false;
				options.mNonRealTimeCmdFilename    = strcmp(argv[j+1], "_") ? argv[j+1] : 0;
				options.mNonRealTimeInputFilename  = strcmp(argv[j+2], "_") ? argv[j+2] : 0;
				options.mNonRealTimeOutputFilename = argv[j+3];
				options.mPreferredSampleRate = (uint32)atof(argv[j+4]);
				options.mNonRealTimeOutputHeaderFormat = argv[j+5];
				options.mNonRealTimeOutputSampleFormat = argv[j+6];
				break;
#ifdef __APPLE__
			case 'I' :
				checkNumArgs(2);
				options.mInputStreamsEnabled = argv[j+1];
				break;
			case 'O' :
				checkNumArgs(2);
				options.mOutputStreamsEnabled = argv[j+1];
				break;
            case 'M':
#endif
			case 'H' :
				checkNumArgs(2);
				options.mInDeviceName = argv[j+1];
#ifdef __APPLE__
				if (i+1>argc || argv[j+2][0]=='-')
				{
					options.mOutDeviceName = options.mInDeviceName;
				}
				else
				{
					// If there's a second argument then the user wants separate I/O devices
					options.mOutDeviceName = argv[j+2];
					++i;
				}
#else
				options.mOutDeviceName = options.mInDeviceName; // Non-Mac platforms always use same device
#endif
				break;
			case 'L' :
				checkNumArgs(1);
#if (_POSIX_MEMLOCK - 0) >=  200112L
				options.mMemoryLocking = true;
#else
				options.mMemoryLocking = false;
#endif
				break;
			case 'v' :
				checkNumArgs(2);
				options.mVerbosity = atoi(argv[j+1]);
				break;
			case 'R' :
				checkNumArgs(2);
				options.mRendezvous = atoi(argv[j+1]) > 0;
				break;
			case 'U' :
				checkNumArgs(2);
				options.mUGensPluginPath = argv[j+1];
				break;
			case 'P' :
				checkNumArgs(2);
				options.mRestrictedPath = argv[j+1];
				break;
			case 'h':
			default: Usage();
		}
	}
	if (udpPortNum == -1 && tcpPortNum == -1 && options.mRealTime) {
		scprintf("ERROR: There must be a -u and/or a -t options, or -N for nonrealtime.\n");
		Usage();
	}
	if (options.mNumInputBusChannels + options.mNumOutputBusChannels > options.mNumAudioBusChannels) {
		scprintf("ERROR: number of audio bus channels < inputs + outputs.\n");
		Usage();
	}

	struct World *world = World_New(&options);
	if (!world) return 1;

	if (!options.mRealTime) {
#ifdef NO_LIBSNDFILE
		return 1;
#else
		int exitCode = 0;
		try {
			World_NonRealTimeSynthesis(world, &options);
		} catch (std::exception& exc) {
			scprintf("%s\n", exc.what());
			exitCode = 1;
		}
		return exitCode;
#endif
	}

	if (udpPortNum >= 0) {
		if (!World_OpenUDP(world, udpPortNum)) {
			World_Cleanup(world);
			return 1;
		}
	}
	if (tcpPortNum >= 0) {
		if (!World_OpenTCP(world, tcpPortNum, options.mMaxLogins, 8)) {
			World_Cleanup(world);
			return 1;
		}
	}

	if(options.mVerbosity >=0){
#ifdef NDEBUG
		scprintf("SuperCollider 3 server ready.\n");
#else
		scprintf("SuperCollider 3 server ready (debug build).\n");
#endif
	}
	fflush(stdout);

	World_WaitForQuit(world);


#ifdef _WIN32
    // clean up winsock
    WSACleanup();

#ifdef SC_WIN32_STATIC_PTHREADS
    // clean up statically linked pthreads
    pthread_win32_process_detach_np();
#endif // SC_WIN32_STATIC_PTHREADS
#endif // _WIN32

	return 0;
}
extern "C" int scsynth_android_start(JNIEnv* env, jobject obj, 
						jint srate, jint hwBufSize, jint numInChans, jint numOutChans, jint shortsPerSample,
						jstring pluginsPath, jstring synthDefsPath){

	jboolean isCopy;
	bufflen = shortsPerSample*numOutChans*hwBufSize;
	buff = (short*) calloc(bufflen,sizeof(short));
	const char* pluginsPath_c   = env->GetStringUTFChars(pluginsPath,   &isCopy);
	const char* synthDefsPath_c = env->GetStringUTFChars(synthDefsPath, &isCopy);
	__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "scsynth_android_start(%i, %i, %i, %i, %i, %s, %s)",
		(int)srate, (int)hwBufSize, (int)numInChans, (int)numOutChans, (int)shortsPerSample, pluginsPath_c, synthDefsPath_c);
    setenv("SC_PLUGIN_PATH",   pluginsPath_c,   1);
    setenv("SC_SYNTHDEF_PATH", synthDefsPath_c, 1);
    
    // DEBUG: Check that we can read the path
	DIR *dip;
	struct dirent *dit;
	if ((dip = opendir(pluginsPath_c)) == NULL){
		__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Could not opendir(%s)\n", pluginsPath_c);
	}else{
		__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "OK, listing opendir(%s)\n", pluginsPath_c);
		while ((dit = readdir(dip)) != NULL){
			__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Entry: %s\n", dit->d_name);
		}
		if (closedir(dip) == -1)
			__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Could not closedir(%s)\n", pluginsPath_c);
	}

	env->ReleaseStringUTFChars(pluginsPath,   pluginsPath_c);
	env->ReleaseStringUTFChars(synthDefsPath, synthDefsPath_c);



	WorldOptions options = kDefaultWorldOptions;
	options.mPreferredSampleRate = srate;
	options.mPreferredHardwareBufferFrameSize = hwBufSize;
	options.mNumInputBusChannels  = numInChans;
	options.mNumOutputBusChannels = numOutChans;
	
	// Reduce things down a bit for lower-spec - these are all open for review
	options.mNumBuffers  = 512;
	options.mMaxGraphDefs = 512;
	options.mMaxWireBufs = 512;
	options.mNumAudioBusChannels = 32;
	options.mRealTimeMemorySize = 512;
	options.mNumRGens = 16;
	options.mLoadGraphDefs = 1;
	options.mVerbosity = 2; // TODO: reduce this back to zero for non-debug builds once dev't is stable
	options.mBufLength = 64; // was hwBufSize / numOutChans;
	
	
	// Similar to SCProcess:startup :
	pthread_t scThread;
	OSCMessages messages;
	
    world = World_New(&options);
    //world->mDumpOSC=2;
    if (world) {
        pthread_create (&scThread, NULL, scThreadFunc, (void*)world);
    }
    if (world->mRunning){
        small_scpacket packet = messages.initTreeMessage();
        World_SendPacket(world, 16, (char*)packet.buf, null_reply_func);
        return 0;
    }else{
    	return 1;
    }
}
Пример #14
0
int prBootInProcessServer(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp;

	if (!gInternalSynthServer.mWorld) {
		SetPrintFunc(&vpost);
		WorldOptions options = kDefaultWorldOptions;

		PyrObject *optionsObj = a->uo;
		PyrSlot *optionsSlots = optionsObj->slots;

		static char mInputStreamsEnabled[512], mOutputStreamsEnabled[512], mDeviceName[512];
		int err;

		err = slotIntVal(optionsSlots + 0, (int*)&options.mNumAudioBusChannels);
		if (err) return err;

		err = slotIntVal(optionsSlots + 1, (int*)&options.mNumControlBusChannels);
		if (err) return err;

		err = slotIntVal(optionsSlots + 2, (int*)&options.mNumInputBusChannels);
		if (err) return err;

		err = slotIntVal(optionsSlots + 3, (int*)&options.mNumOutputBusChannels);
		if (err) return err;

		err = slotIntVal(optionsSlots + 4, (int*)&options.mNumBuffers);
		if (err) return err;

		err = slotIntVal(optionsSlots + 5, (int*)&options.mMaxNodes);
		if (err) return err;

		err = slotIntVal(optionsSlots + 6, (int*)&options.mMaxGraphDefs);
		if (err) return err;

		err = slotIntVal(optionsSlots + 8, (int*)&options.mBufLength);
		if (err) return err;

		if (NotNil(optionsSlots + 9)) {
			err = slotIntVal(optionsSlots + 9, (int*)&options.mPreferredHardwareBufferFrameSize);
			if (err) return err;
		}

		err = slotIntVal(optionsSlots + 10, (int*)&options.mRealTimeMemorySize);
		if (err) return err;

		err = slotIntVal(optionsSlots + 11, (int*)&options.mNumRGens);
		if (err) return err;

		err = slotIntVal(optionsSlots + 12, (int*)&options.mMaxWireBufs);
		if (err) return err;

		if (NotNil(optionsSlots + 13)) {
			err = slotIntVal(optionsSlots + 13, (int*)&options.mPreferredSampleRate);
			if (err) return err;
		}

		options.mLoadGraphDefs = IsTrue(optionsSlots + 14) ? 1 : 0;

		#ifdef SC_DARWIN
		err = slotStrVal(optionsSlots+15, mInputStreamsEnabled, 512);
		if(err) options.mInputStreamsEnabled = NULL;
		else options.mInputStreamsEnabled = mInputStreamsEnabled;

		err = slotStrVal(optionsSlots+16, mOutputStreamsEnabled, 512);
		if(err) options.mOutputStreamsEnabled = NULL;
		else options.mOutputStreamsEnabled = mOutputStreamsEnabled;
		#endif

		err = slotStrVal(optionsSlots+17, mDeviceName, 512);
		if(err) options.mInDeviceName = options.mOutDeviceName = NULL;
		else options.mInDeviceName = options.mOutDeviceName = mDeviceName;

		options.mNumSharedControls = gInternalSynthServer.mNumSharedControls;
		options.mSharedControls = gInternalSynthServer.mSharedControls;

		gInternalSynthServer.mWorld = World_New(&options);
	}

	return errNone;
}