Exemplo n.º 1
0
int ParamDialog(tParam *p, tComplex *c){
										//if failure: 0
										//else 1
	DisplayParam(p, c);
	printf("Sollen Parameter geändert werden?\n(j) Ja, bitte.\n(n) Nein, danke.\n(e) Programm beenden!");
	switch (InputChar()){
	case 'j':
		do {
			ChangeParam(p, c);			//Vllt sollte man eine maxAnzahl an Versuchen in Erwähgung ziehen?
		} while(validation(p,c) == 0);	//Schleife wird erst verlassen, wenn Werte Sinn machen.
		return 1;
		break;
	case 'n':
		return 1;
		break;
	case 'e':
		return 0;
		break;
	}
	return 0;
}
Exemplo n.º 2
0
void PARAMETERS_parser(uint8_t* PARAMETERS_buffer, uint8_t nb_PARAMETERS_bytes)
{
	static uint8_t 	index = 0;
	static uint8_t	state = 0;
	static uint8_t	state_number = 0;
	static uint8_t  PARAM_TYPE, PARAM_VALUE;

	uint8_t			PARAMETER_byte;

	uint16_t		PB_wheel;

	// Process message

	while (nb_PARAMETERS_bytes != 0)
	{
		// Read a new byte from the MIDI buffer

		PARAMETER_byte = PARAMETERS_buffer[index];
		// printf("\n\n %c --> %d ",PARAMETER_byte,PARAMETER_byte);
		switch (state)
		{

			// State 0 = Starting point for a new PARAMETER message

			case 0 :
			{
				switch (PARAMETER_byte )
				{

					case '#' :														// Note ON message
					{
						state = 1;													// Next state is 10
						state_number =0;
						// printf ("parameter # event\n");

						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;

						break;
					}

					default :														// Other type of message, move to next byte but stays in state 0
					{
						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;
						state = 0;
						break;
					}
				}


			}break;


			// State 1: ID_NUMBER

			case 1 :
			{
				if (PARAMETER_byte>= '0' && PARAMETER_byte<= '9')												// If the following byte is not a note number
				{
					state = 1;
					TempStr[state_number]= PARAMETER_byte; // Return to state 0 without moving to next byte
					state_number++;
				}else{
					state =0;
				}
				if (index == (PARAMETERS_BUFFER_LENGTH-1))
					index = 0;				// Move to next MIDI byte
				else
					index ++;
				nb_PARAMETERS_bytes--;
				if(state_number == 3)
				{
					TempStr[state_number]= '\0';
					PARAM_TYPE = decdec(TempStr);
					if(PARAM_TYPE == -1)
						state= 0;
					else
						state =2;
				}

			}break;

			case 2 :
			{
				switch (PARAMETER_byte )
				{
					case ':' :														// Note ON message
					{
						state = 3;													// Next state is 10
						state_number =0;
					//	 printf ("parameter : event\n");

						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;

						break;
					}

					default :														// Other type of message, move to next byte but stays in state 0
					{
						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;
						state = 0;
						break;
					}
				}


			}break;
			// State 3: VALUE_NUMBER

			case 3 :
			{
				if (PARAMETER_byte>= '0' && PARAMETER_byte<= '9')												// If the following byte is not a note number
				{
					state = 3;													// Return to state 0 without moving to next byte
					TempStr[state_number]= PARAMETER_byte;
					state_number++;
				}else{
					state =0;
				}
				if (index == (PARAMETERS_BUFFER_LENGTH-1))
					index = 0;				// Move to next MIDI byte
				else
					index ++;
				nb_PARAMETERS_bytes--;
				if(state_number == 3)
				{
					TempStr[state_number]= '\0';
					PARAM_VALUE = decdec(TempStr);
					if(PARAM_VALUE == -1)
						state= 0;
					else
						state =2;
					state =4;
				}

			}break;
			case 4 :
			{
				switch (PARAMETER_byte )
				{
					case ';' :														// Note ON message
					{
						state = 0;
					//	 printf ("parameter ; event\n");
						// printf ("\nCC %d; %d",PARAM_TYPE,PARAM_VALUE);
						 ChangeParam(PARAM_TYPE,PARAM_VALUE);
						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;

						break;
					}

					default :														// Other type of message, move to next byte but stays in state 0
					{
						if (index == (PARAMETERS_BUFFER_LENGTH-1)) index = 0;				// Move to next MIDI byte
						else index ++;
						nb_PARAMETERS_bytes--;
						state = 0;
						break;
					}
				}


			}break;


		}
	}

}