示例#1
0
//handle SDL keypresses
void handleKeys(SDL_keysym* keysym, int state)	//key listener
{
	switch(keysym->sym)
	{
		case SDLK_ESCAPE:	endProgram(0);	//if escape is hit
					break;
		//default: cerr << "unrecognized key..."<<endl;
	}
}
示例#2
0
// Process SDL events
void processEvents() {
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_KEYDOWN:	handleKeys(&event.key.keysym, true );	break;
			case SDL_KEYUP  :	handleKeys(&event.key.keysym, false);	break;
			case SDL_QUIT   :	endProgram(0);	break;
		}
	}
}
示例#3
0
文件: main.cpp 项目: jaunas/writeCell
int main()
{
	setlocale(LC_CTYPE, "pl_PL.UTF-8");
	
	screen term("writeCell");
	term.init();

	term.showTitleBar = true;
	term.showStatusBar = true;
	
	menuBar mainMenu;
	menu fileMenu("Plik");
	menuItem newFile("Nowy plik");
	menuItem endProgram("Zakończ program");
	fileMenu.addItem(newFile);
	fileMenu.addItem(endProgram);
	mainMenu.addItem(fileMenu);
	
	term.setMenu(&mainMenu);

	return term.loop();
}
示例#4
0
int argHelp(char** argv, int pos, int argc, void* param)
{
	printf("Usage: %s [parameters]\n\n", argv[0]);
	printf("List of parameters:\n");
	printf("\t-t <int>\tSet tempo [beats per minute] (Default: 60)\n");
	printf("\t-f 0 <float>\tSet frequency of base beat [Hz] (Default: 880.00)\n");
	printf("\t-f 1 <float>\tSet frequency of accented first beat [Hz] (Default: 880.00)\n");
	printf("\t-f 2 <float>\tSet frequency of intermidded beat [Hz] (Default: 880.00)\n");
	printf("\t-p 0 <float>\tSet power of base beat [0..1] (Default: 0.75)\n");
	printf("\t-p 1 <float>\tSet power of accented first beat [0..1] (Default: 0.75)\n");
	printf("\t-p 2 <float>\tSet power of intermidded beat [0..1] (Default: 0.00)\n");
	printf("\t-dp <int>\tHow long to play [s] (Default: 3)\n");
	printf("\t-db <float>\tHow long to play one beat [s] (Default: 0.01)\n");
	printf("\t-m <int>\tSet a measure (Default: 4)\n");
	printf("\t-i <int>\tSet intermediate beats (Default: 0)\n");
	printf("\t-c\t\tEnable counting visually (Default: disabled)\n");
	printf("\t-n <int>\tSet number of tacts to play - disable -dp switch (Default: 0)\n");
	printf("\t-h\t\tPrint this help\n");

	endProgram(0);
	return 1;
}
int main(int argc, char* argv[]) {
/*    int write_buf;
    char read_buf;*/

	// Initialization
    initDevices();
    #ifndef WITHOUT_NETWORK
	initPeerSocket();
	#endif

	usleep(1000000); // delay 3sec
/*
	#ifdef SERVERMODE
	#ifndef WITHOUT_NETWORK
	// Wait for arrival
	waitThreeAxisChange();
	sendStopSignal();
	#endif
	#endif
*/


	// Strart linetracing
	int thr_id[5];
    pthread_t p_threads[5];
/*
	thr_id[0] = pthread_create(&p_threads[0], NULL, detectDistance, (void *)NULL);     
	if (thr_id[0] < 0)     
	{    
		perror("thread1 create error : ");  
		exit(0);    
	}
*/
	thr_id[1] = pthread_create(&p_threads[1], NULL, writeCommand, (void *)NULL);     
	if (thr_id[1] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
/*
	thr_id[2] = pthread_create(&p_threads[2], NULL, findObj, (void *)NULL);     
	if (thr_id[2] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}

	thr_id[3] = pthread_create(&p_threads[3], NULL, backboard, (void *)NULL);     
	if (thr_id[3] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
  	
	thr_id[4] = pthread_create(&p_threads[4], NULL, map_read, (void *)NULL);     
	if (thr_id[4] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
	thr_id[5] = pthread_create(&p_threads[5], NULL, traceLine, (void *)NULL);     
	if (thr_id[5] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
*/
	int status;

	/*
	pthread_join(p_threads[4], (void **)&status);
	pthread_join(p_threads[3], (void **)&status);
	pthread_join(p_threads[0], (void **)&status);
	pthread_join(p_threads[2], (void **)&status);
	pthread_join(p_threads[5], (void **)&status);
	*/
	map_read();
	//pthread_join(p_threads[0], (void **)&status);
	pthread_join(p_threads[1], (void **)&status);
	
	endProgram();

	return 0;
}  
int main(int argc, char* argv[]) {
/*    int write_buf;
    char read_buf;*/

	// Initialization
    initDevices();
    #ifndef WITHOUT_NETWORK
//	initPeerSocket();
	#endif

	usleep(3000000); // delay 3sec

	#ifdef SERVERMODE
	#ifndef WITHOUT_NETWORK
	// Wait for arrival
	
	sendStopSignal();
	#endif
	#endif

	// Strart linetracing
	int thr_id[4];
	pthread_t p_threads[4];

	thr_id[3] = pthread_create(&p_threads[3], NULL, videoFrame, (void *)NULL);     
	if (thr_id[3] < 0)     
	{    
		perror("thread1 create error : ");  
		exit(0);    
	}
	
	confirm_Response();
	
	usleep(1000000);
	
	waitThreeAxisChange();	
	
	thr_id[0] = pthread_create(&p_threads[0], NULL, traceLine, (void *)NULL);     
	if (thr_id[0] < 0)     
	{    
		perror("thread1 create error : ");  
		exit(0);    
	}

	thr_id[1] = pthread_create(&p_threads[1], NULL, writeCommand, (void *)NULL);     
	if (thr_id[1] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
    
	
/*	
	#ifdef CLIENTMODE
	#ifndef WITHOUT_NETWORK
	thr_id[2] = pthread_create(&p_threads[2], NULL, recieveStopSignal, (void *)NULL);     
	if (thr_id[2] < 0) {    
		perror("command thread create error : ");  
		exit(0);    
	}
	
	
	#endif
	#endif
*/  
	int status;
	#ifdef CLIENTMODE
//	pthread_join(p_threads[2], (void **)&status);
	#endif
	pthread_join(p_threads[0], (void **)&status);


	pthread_join(p_threads[1], (void **)&status);
	pthread_join(p_threads[3], (void **)&status);
	
	endProgram();

	return 0;
}  
示例#7
0
int main(int argc, char** argv)
{
	// zak³ada siê, ¿e ramka zawiera próbkê, w której
	// jest d¼wiêk beat-u i cisza do nastêpnego beatu
	// 
	//
	// ramka
	//char *pFrame;
	// licznik
	int i;
//	goc_termInit();
	printf(GOC_STRING_WHITE);

	// Procedury inicjuj±ce
	GOC_DEBUG("Initializing libao");
	ao_initialize();

	GOC_DEBUG("Initializing libao Device");
	aodriverid = ao_default_driver_id();
	if ( aodriverid == -1 )
		return -1;
	openOutputDevice();

	params = allocParameters();

	if ( argc > 1 )
	{
		if ( interpretArgs(argc, argv, params) < 0 )
			endProgram(-1);
	}


	GOC_DEBUG("Allocating buffer");

	generateBeat(params, BEAT_BASE);
	generateBeat(params, BEAT_ACCENT);
	generateBeat(params, BEAT_INTER);
	generateBeat(params, BEAT_QUIET);

//	pFrame = malloc(nFrame);
//	memset(pFrame, 0, nFrame);
	GOC_BINFO("Tempo: %d Rate: %d Channels: %d Bits: %d",
			params->tempo, SAMPLE_RATE, SAMPLE_CHANNELS, SAMPLE_BITS);
//	GOC_BDEBUG("Allocated %d at 0x%X", nFrame, (unsigned int)pFrame);
	if ( params->flags & FLAG_PRINTCOUNT )
	{
		goc_clearscreen();
		goc_gotoxy(1,1);
	}

	printf("Playing ... \n");
	if ( params->pattern )
		printf("Use pattern: %s\n", params->pattern);
	fflush(stdout);
	{
		// to nie do koñca jest liczba ramek - to jest liczba
		// podstawowych beatów jakie maj± zostaæ zagrane - nie
		// s± liczone beat-y po¶rednie
		int nFrames;
		int imeasure = 0;
		int iinter;
		int patternPosition = 0;
		int patternLen = 0;

		char *prevString = goc_stringCopy(NULL, "");
		char playedPattern = '.';

		if ( params->pattern )
		{
			patternLen = strlen(params->pattern);
		}

		if ( params->tacts )
			// na podstawie liczby podanych taktów
			nFrames = params->tacts * params->measure;
		else
			// na podstawie podanego czasu
			nFrames = params->tempo * params->pdur / 60;

		NEXTPATTERN();

		// goc_saveXY();
		for (i=0; i<nFrames; i++)
		{
			if ( imeasure )
			{
				if ( params->flags & FLAG_PRINTCOUNT )
				{
					goc_gotoxy(1, 5);
					printf("%s%s%s%d%s", GOC_STRING_YELLOW, prevString, GOC_STRING_BWHITE, imeasure + 1, GOC_STRING_YELLOW);
					prevString = goc_stringAddInt(prevString, imeasure+1);
					prevString = goc_stringAdd(prevString, " .. ");
					fflush(stdout);
				}
				if ( playedPattern == '.' )
					ao_play(aodev, params->pBeat[BEAT_BASE].pFrame, params->pBeat[BEAT_BASE].nFrame);
				else
					ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame);
				NEXTPATTERN();
			}
			else
			{
				if ( params->flags & FLAG_PRINTCOUNT )
				{
					goc_gotoxy(1, 5);
					printf("%s%s", GOC_STRING_YELLOW, prevString);
					goc_gotoxy(1, 5);
					printf("%s%d%s", GOC_STRING_BWHITE, imeasure + 1, GOC_STRING_YELLOW);
					prevString = goc_stringFree(prevString);
					prevString = goc_stringAddInt(prevString, imeasure+1);
					prevString = goc_stringAdd(prevString, " .. ");

					fflush(stdout);
				}
				if ( playedPattern == '.' )
					ao_play(aodev, params->pBeat[BEAT_ACCENT].pFrame, params->pBeat[BEAT_ACCENT].nFrame);
				else
					ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame);
				NEXTPATTERN();
			}
			if ( (iinter = params->inter) )
			{
				while  ( iinter-- )
				{
					if ( params->flags & FLAG_PRINTCOUNT )
					{
						goc_gotoxy(1, 5);
						printf("%s%s%si%s", GOC_STRING_YELLOW, prevString, GOC_STRING_WHITE, GOC_STRING_YELLOW);
						prevString = goc_stringAdd(prevString, "i .. ");
						fflush(stdout);
					}
					if ( playedPattern == '.' )
						ao_play(aodev, params->pBeat[BEAT_INTER].pFrame, params->pBeat[BEAT_INTER].nFrame);
					else
						ao_play(aodev, params->pBeat[BEAT_QUIET].pFrame, params->pBeat[BEAT_QUIET].nFrame);
					NEXTPATTERN();
				}
			}
			imeasure++;
			imeasure %= params->measure;
		}
		if ( params->flags & FLAG_PRINTCOUNT )
		{
			goc_gotoxy(1, 5);
			printf("%s%s", GOC_STRING_YELLOW, prevString);
		}
		prevString = goc_stringFree(prevString);
	}
	printf("%s\nFinish\n", GOC_STRING_WHITE);

	if ( params->tacts )
	{
		GOC_BINFO("Played %d frames in %d tacts", i, params->tacts);
	}
	else
	{
		GOC_BINFO("Played %d frames in %d seconds", i, params->pdur);
	}

	endProgram(0);
	return 0;
}
示例#8
0
文件: main.c 项目: jds0102/osp3
/*
  This function will parse the input from the trace file and call the proper function
  @param char* line - a line that will be parsed
  @return void 
*/
void parseLine (char * line){
  fprintf(stdout, "%s\n", line);
  char* token = strtok(line, " ");
  if (token == NULL){
    return;
  }

  char * endPtr;
  // Read Command: READ LBA SIZE
  if (strcmp(token, "READ") == 0){
    //Get the lba
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int lba = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse();
    }
    
    //Get the size of the read
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int readSize = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse();
    }
    if (token == NULL){
      errorMsgParse();
    }
    
    //The command should end here
    token = strtok(NULL, " ");
    if (token != NULL){
      errorMsgParse();
    }
    readFromArray(lba,readSize);
  }
  
  // Write command: WRITE LBA SIZE VALUE
  else if (strcmp(token, "WRITE") == 0){
    //Get the lba 
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int lba = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse(14);
    }
    
    //Get the size of the write
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int writeSize = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse();
    }
    
    //Get the value to write
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int value = atoi(token);
    char buff[BLOCK_SIZE];
    int i;
    for(i = 0; i < 256; i++){
      ((int *)buff)[i] = value; 
    }
    
    //The command should end here
    token = strtok(NULL, " ");
    if (token != NULL){
      errorMsgParse();
    }
    writeToArray(lba, writeSize, buff);
  }
  
  //Fail command: FAIL DISK#
  else if (strcmp(token, "FAIL") == 0){
    //Get the disk that failed  
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int disk = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse();
    }
    
    //The command should end here
    token = strtok(NULL, " ");
    if (token != NULL){
      errorMsgParse();
    }
    failDisk(disk);
  }
  
  //Recover command: RECOVER DISK#
  else if (strcmp(token, "RECOVER") == 0){
    //Gert the disk to recover
    token = strtok(NULL, " ");
    if (token == NULL){
      errorMsgParse();
    }
    int disk = strtol(token, &endPtr, 10);
    if (token == endPtr) {
      errorMsgParse();
    }
    
    //The command should end here
    token = strtok(NULL, " ");
    if (token != NULL){
      errorMsgParse();
    }
    recoverDisk(disk);
  }
  
  // End command: END
  else if (strcmp(token, "END") == 0){
    //There should be no other arguments with end
    token = strtok(NULL, " ");
    if (token != NULL){
      errorMsgParse();
    }
    endProgram();
  }
  else if (strcmp(token, "") == 0){
  }
  else{
    errorMsgParse();
  }
}
示例#9
0
void handleKeys(SDL_keysym* keysym, bool state) {
	switch(keysym->sym) {
		case SDLK_ESCAPE:	endProgram(0); break;
		
		case SDLK_UP:
			if(state)
			{
				fov_accel = 150;
			}
			else
			{
				fov_accel = fov;
			}
			break;
		case SDLK_DOWN:	
			if(state)
			{
				fov_accel = 5;
 			}
 			else
 			{
 				fov_accel = fov;
 			}
 			break;	
 		case SDLK_d:
 			if(state)
 			{
 				ang_accel = 0.7f;
 			}
 			else
 			{
 				ang_accel = 0.f;
 			}
 			break;
 		case SDLK_a:
 			if(state)
 			{
 				ang_accel = -0.7f;
 			}
 			else
 			{
 				ang_accel = 0.f;
 			}
 			break;
 			
 			case SDLK_w:
 			if(state)
 			{
 				y_offset_accel = 1.f;
 			}
 			else
 			{
 				y_offset_accel = 0.f;
 			}
 			break;
 			
 			case SDLK_s:
 			if(state)
 			{
 				y_offset_accel = -1.f;
 			}
 			else
 			{
 				y_offset_accel = 0.f;
 			}
 			break;
 			
 			
	}
}