Example #1
0
	void handleMotionEvent(AInputEvent* input)
	{
		int32_t action = AMotionEvent_getAction(input);
		int actionMasked = action & AMOTION_EVENT_ACTION_MASK;
		int actionPointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;

// 		LOG(0, ".. motion: %d %d\n", actionMasked, actionPointerIndex);
		size_t numPointers = AMotionEvent_getPointerCount(input);

		float scale = 1.0f / _inputScale;

		for (size_t i=0; i<numPointers; ++i)
		{
			int sysIndex = i;
			Touch* touch = NULL;
			bool on = false;

			switch (actionMasked)
			{
			case AMOTION_EVENT_ACTION_DOWN:
			case AMOTION_EVENT_ACTION_POINTER_DOWN:
				touch = assignTouch(sysIndex);
				on = true;
				break;

			case AMOTION_EVENT_ACTION_MOVE:
				touch = getTouch(sysIndex);
				on = true;
				break;

			case AMOTION_EVENT_ACTION_POINTER_UP:
			case AMOTION_EVENT_ACTION_UP:
				touch = getTouch(sysIndex);
				on = sysIndex != actionPointerIndex;
				break;
			}

			if (touch == NULL) continue;

			float x = AMotionEvent_getX(input, sysIndex);
			float y = AMotionEvent_getY(input, sysIndex);
			Vector3 pos(x, y, 0);
			pos *= scale;
// 			LOG(0, ".. pointer %d %f %f\n", sysIndex, pos.x, pos.y);

			touch->pointer->move(on, pos);
		}

		if (actionMasked == AMOTION_EVENT_ACTION_POINTER_UP || actionMasked == AMOTION_EVENT_ACTION_UP)
			releaseTouch(actionPointerIndex);
	}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    soundTouchDestory
 * Signature: ()V
 */
void Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchDestory(
		JNIEnv *env, jobject obj) {

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);

	delete soundTouch;
}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    setPitchSemiTones
 * Signature: (D)V
 */
void Java_com_example_soundtouchdemo_NativeSoundTouch_setPitchSemiTones(
		JNIEnv *env, jobject obj, jfloat jpitch) {

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);

	float pitch = jpitch;
	soundTouch->setPitchSemiTones(pitch);
}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    soundTouchFlushLastSamples
 * Signature: ()V
 */
void Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchFlushLastSamples(
		JNIEnv *env, jobject obj) {

	LOGD("SoundTouch flush");

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);
	soundTouch->flush();
}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    setTempoChange
 * Signature: (F)V
 */
void Java_com_example_soundtouchdemo_NativeSoundTouch_setTempoChange(
		JNIEnv *env, jobject obj, jfloat jtempo) {

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);

	float tempo = jtempo;
	soundTouch->setTempoChange(tempo);

}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    soundTouchgethVersion
 * Signature: ()Ljava/lang/String;
 */
jstring Java_com_example_soundtouchdemo_NativeSoundTouch_soundTouchgethVersion(
		JNIEnv *env, jobject obj) {

	const char *verStr;

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);
	verStr = soundTouch->getVersionString();

	// return version as string
	return env->NewStringUTF(verStr);
}
void GameplayLayer::_handleActionDiceDragMoved(EventCustom* event) {
  auto data = (ActionDiceDragData*) event->getUserData();
  auto sprite = data->getSprite();
  auto touch = data->getTouch();
  auto dice = sprite->getDice();
  
  auto touchLocation = this->convertTouchToNodeSpace(touch);
  sprite->setPosition(touchLocation);
  
  auto handler = DiceDragHandlerFactory::getHandler(dice);
  handler->dragMoved(data, this, this->_getDockableContainer());
}
Example #8
0
	Touch* assignTouch(int sysIndex)
	{
		Touch* touch = getTouch(sysIndex);
		if (touch) return touch;

		for (uint i=0; i<COUNT_OF(_touch); ++i)
		{
			touch = &_touch[i];
			if (touch->sysIndex == -1)
			{
				touch->sysIndex = sysIndex;
				return touch;
			}
		}

		return NULL;
	}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    shiftingPitch
 * Signature: ([BII)V
 */
void Java_com_example_soundtouchdemo_NativeSoundTouch_shiftingPitch(JNIEnv *env,
		jobject obj, jbyteArray jarray, jint offset, jint length) {

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);

	jbyte *data;

	data = env->GetByteArrayElements(jarray, JNI_FALSE);

	//soundtouch::SAMPLETYPE sampleBuffer[length];
	//memcpy(&sampleBuffer, data, length);

	//(16*1)/8=2bytes,length/2=x;x¸ösample

	soundTouch->putSamples((soundtouch::SAMPLETYPE*) data, length / (16 / 8));

	env->ReleaseByteArrayElements(jarray, data, 0);

}
/*
 * Class:     com_example_soundtouchdemo_NativeSoundTouch
 * Method:    receiveSamples
 * Signature: ([BI)I
 */
jint Java_com_example_soundtouchdemo_NativeSoundTouch_receiveSamples(
		JNIEnv *env, jobject obj, jbyteArray jarray, jint jLenght) {

	int receiveSamples = 0;
	int maxReceiveSamples = jLenght / (16 / 8);

	soundtouch::SoundTouch* soundTouch = getTouch(env, obj);

	jbyte *data;

	data = env->GetByteArrayElements(jarray, JNI_FALSE);

	receiveSamples = soundTouch->receiveSamples((soundtouch::SAMPLETYPE*) data,
			maxReceiveSamples);

	//memcpy(data, sampleBuffer, receiveSize);

	env->ReleaseByteArrayElements(jarray, data, 0);

	return receiveSamples;
}
Example #11
0
bool showStepByStep( T_Cell cell, T_Cell grid[][GRID_SIZE] ) {
	bool retval; // La valeur de retour, vrai si l'utilisateur a choisi de revenir en arriere
	int currentChoice = 1; // Chaque choix dans le menu a un numero
	int userChoice; // Le choix de l'uilisateur
	bool outOf=false; // booleen permet de sortir de la boucle
	do {
		printf("\n");
		//printf("\033[u");
		clearConsole();
		//system("clear"); // Initialiser le terminal
		retval = false; // Valeur faux par default
		printGrid(&cell, grid); // Afficher la grille
		
		if (currentChoice==1) // Si le choix courant egale au numero de menu 
			printf("\033[36m[*] CONTINUER\033[0m\n"); // afficher le menu coloré
		else
			printf("[ ] Continuer\n"); // sinon affichage normal
		if (currentChoice==2)
			printf("\033[36m[*] SAUVGARDER LA GRILLE DANS UN FICHIER\033[0m\n");
		else 
			printf("[ ] Sauvgarder la grille dans un fichier\n");
		if (currentChoice==3)
			printf("\033[36m[*] REVENIRE A L'ETAPE PRECEDENTE\033[0m\n");
		else 
			printf("[ ] Revenir a l'etape precedente\n");
		if (currentChoice==4)
			printf("\033[36m[*] APPLIQUER UNE REGLE\033[0m\n");
		else
			printf("[ ] Appliquer une regle\n");
		if (currentChoice==5)
			printf("\033[36m[#] QUITTER\033[0m \n");
		else
			printf("[ ] Quiter\n");
		
		
		userChoice=getTouch(); // prend le numero de la touche qui l'utilisateur a choisi
		switch (userChoice) { //faire un switch pour le code de la touche
			case 300: { // 300 si la valeur renvoyer par la fonction getTouch() ou cas ou l'utilisateur choisi la fleche haut
				if (currentChoice>1) 
					currentChoice--;
				else
					currentChoice=5;
				break;
			}
			case 301: {
				if (currentChoice<5) 
					currentChoice++;
				else 
					currentChoice=1;
				break;
			}
			default: {
				if (userChoice=='\n' || userChoice=='\r') { // si l'utilisateur a choisi un choix
					switch (currentChoice) {
						case 1: { outOf=true; break;} // continuer
						case 2: { exportCurrentGrid(grid); break; }; // exporter la grille courante
						case 3: {outOf=true; retval=true; break;} // revenir en arriere
						case 4: { // le choix d'application une regle
							bool secondOutOf=false; // booleen permet de sortir de la boucle suivante
							printf("\n  [ Entrer le numero de la regle] : ");
							do {
								int ruleNumber; // le numero de la regle
								ruleNumber=getch(); 
								switch (ruleNumber) {
									case '1': { // regle 1
										secondOutOf = true; // sortire de boucle apres l'application de la regle
										firstRule(grid); // appliquer la regle 2
										printf("\nregle 1 applique avec succes!\ntaper une touche pour continuer... ");
										getTouch(); // attender un signal pour continue
										break;
									} // end of case '1'
									case '2': { // regle 2
										secondOutOf = true;
										secondRule(grid, false);
										printf("\nregle 2 applique avec succes!\ntaper une touche pour continuer... ");
										getTouch();
										break;
									} // end of case '2'
									case '3': { // regle 3
										secondOutOf = true;
										thirdRule(grid, false);
										printf("\nregle 3 applique avec succes!\ntaper une touche pour continuer... ");
										getTouch();
										break;
									} // end of case '3'
									case '4': { // regle 4
										secondOutOf = true;
										forthRule(grid);
										printf("\nregle 4 applique avec succes!\ntaper une touche pour continuer... ");
										getTouch();
										break;
									} // end of case '4'
									default: break;
								} // end of switch ruleNumber
							}while (!secondOutOf);
							break;} // end of case 4
						case 5: {
							printf("\n");
							exit(EXIT_SUCCESS);
						} // end of case 5
						default: break;
					} // end of currentChoice
				} // end of default
			}
		} // end of switchuserchoice
		
	} while (!outOf);
	return  retval;
}
Example #12
0
void scanGridValues(T_Cell grid[][GRID_SIZE], bool importFromFile) {
	bool outOf=false;
	int line, column;
	line = 0; column=0;
	int userChoise;
	if (!importFromFile) {
		//printf("\nSaisie les %d valeurs de la grille: ",GRID_SIZE*GRID_SIZE);
		do 
		{
			//system("clear"); // initialiser le terminal
			//printf("\033[u");
			clearConsole();
			printGrid(&grid[line][column], grid); // Afficher la grille
			printf("Entrer la valeur de la case [%d][%d]: ",line,column);
			userChoise = getTouch(); // scan la valeur
			switch (userChoise) { // pour deplacer entre les case de la grille
				case 300: { // touche UP
					if (line>0)
						line--;
					break;
				}
				case 301: { // Touche DOWN
					if (line<GRID_SIZE-1)
						line++;
					break;
				}
				case 302: { // touche RIGHT
					if (column<GRID_SIZE-1)
						column++;
					break;
				}
				case 303: { // touche LEFT
					if (column>0) 
						column--;
					break;
				}
				case '0': { // Effacer la valeur de la case acctuelle
					grid[line][column].value = userChoise-48;
					break;
				}
				default: { // les 9 valeurs possible de la case
					if (userChoise>'0' && userChoise<='9') {
						if (addPossible(userChoise-48, grid[line][column], grid))
							grid[line][column].value = userChoise-48;
						break;
					}
					else if (userChoise=='\n' || userChoise=='\r') { // resoudre la grille
						outOf = true;
						break;
					}
					else {
						outOf=false;
						break;
					}
				}
			}
		} while (!outOf);
	} // end of if no importFromFile
	else importGrid(grid);
	firstRule(grid); // Appliquer la regle 1
}
Example #13
0
void DisplayClass::processButtons()
{
	getTouch();

#ifdef SKIP
	Serial.print("processButtonIndex = "); Serial.print(myTouchButton);
	Serial.println();
#endif
	switch (TouchedButtonIndex){
	default:
	case END_BUT:
#ifdef SKIP
		Serial.print("Error processButtonIndex = "); Serial.print(myTouchButton);
		Serial.println();
#endif
		break;
		// Process the Temperature UP/DOWN Buttons Here
	case COOL_UP:
		(p_tb1+COOL_UP)->DisplayButton(GRAY1, BRIGHT_RED, "+");
		tempControl.incrementHighTemp();  // Added for Test 10/7/15
		break;
	case COOL_DN:
		(p_tb1 + COOL_DN)->DisplayButton(GRAY1, 0x071f, "-");
		tempControl.decrementHighTemp();  // Added for Test 10/7/15
		break;
	case HEAT_UP:
		(p_tb1 + HEAT_UP)->DisplayButton(GRAY1, BRIGHT_RED, "+");
		tempControl.incrementLowTemp();
		break;
	case HEAT_DN:
		(p_tb1 + HEAT_DN)->DisplayButton(GRAY1, 0x071f, "-");
		tempControl.decrementLowTemp();
		break;

	// Process the Mode Control Buttons Here
	case HEAT:
		//(p_tb1 + HEAT)->DisplayButton(YELLOW, 0x071f, "Ht");// BRIGHT_BLUE
		tempControl.setSysMode(SYS_HEAT);
		break;
	case AUTO:
		//(p_tb1 + AUTO)->DisplayButton(YELLOW, 0x071f, "Au");// BRIGHT_BLUE
		tempControl.setSysMode(SYS_AUTO);
		break;
	case COOL:
		//(p_tb1 + COOL)->DisplayButton(YELLOW, 0x071f, "Co");// BRIGHT_BLUE
		tempControl.setSysMode(SYS_COOL);
		break;
	case OFF:
		//	(p_tb1 + OFF)->DisplayButton(YELLOW, 0x071f, "Of");// BRIGHT_BLUE
		tempControl.setSysMode(SYS_OFF);
		break;
	case FAN:
		//(p_tb1 + 8)->DisplayButton(YELLOW, 0x071f, "Fa");// BRIGHT_BLUE
		tempControl.toggleSysFan();
		break;
	case EM_HEAT:
		//(p_tb1 + EM_HEAT)->DisplayButton(YELLOW, 0x071f, "EH");// BRIGHT_BLUE
		tempControl.setSysMode(SYS_EMR_HEAT);
		break;
	}

	if (TouchedButtonIndex == END_BUT) {
	//	??? Need this?
	}

	switch (HeldButtonIndex){
	default:
		break;
	// Process the Repeating Buttons for Temperatre UP/DOWN Here
	case COOL_UP:
		(p_tb1)->DisplayButton(GRAY2, BRIGHT_RED, "+");
		tempControl.incrementHighTemp();
		break;
	case COOL_DN:
		(p_tb1 + COOL_DN)->DisplayButton(GRAY2, 0x071f, "-");// BRIGHT_BLUE
		tempControl.decrementHighTemp();
		break;
	case HEAT_UP:
		(p_tb1 + HEAT_UP)->DisplayButton(GRAY2, BRIGHT_RED, "+");
		tempControl.incrementLowTemp();
		break;
	case HEAT_DN:
		(p_tb1 + HEAT_DN)->DisplayButton(GRAY2, 0x071f, "-");// BRIGHT_BLUE
		tempControl.decrementLowTemp();
		break;
	//case HEAT:
	//	//(p_tb1 + HEAT)->DisplayButton(YELLOW, 0x071f, "Ht");// BRIGHT_BLUE
	//	tempControl.setSysMode(SYS_HEAT);
	//	break;
	//case AUTO:
	//	//(p_tb1 + AUTO)->DisplayButton(YELLOW, 0x071f, "Au");// BRIGHT_BLUE
	//	tempControl.setSysMode(SYS_AUTO);
	//	break;
	//case COOL:
	//	//(p_tb1 + COOL)->DisplayButton(YELLOW, 0x071f, "Co");// BRIGHT_BLUE
	//	tempControl.setSysMode(SYS_COOL);
	//	break;
	//case OFF:
	////	(p_tb1 + OFF)->DisplayButton(YELLOW, 0x071f, "Of");// BRIGHT_BLUE
	//	tempControl.setSysMode(SYS_OFF);
	//	break;
	////case FAN:
	////	//(p_tb1 + FAN)->DisplayButton(YELLOW, 0x071f, "Fa");// BRIGHT_BLUE
	////	tempControl.toggleSysFan();
	////	break;
	//case EM_HEAT:
	//	//(p_tb1 + EM_HEAT)->DisplayButton(YELLOW, 0x071f, "EH");// BRIGHT_BLUE
	//	tempControl.setSysMode(SYS_EMR_HEAT);
	//	break;

	}

	switch (ReleaseButtonIndex){
	case END_BUT:
	default:
		ReleaseButtonIndex = END_BUT;
		break;
	case COOL_UP:
		(p_tb1+COOL_UP)->DisplayButton(WHITE, RED, "+");
		break;
	case COOL_DN:
		(p_tb1 + COOL_DN)->DisplayButton(WHITE, BLUE, "-");
		break;

	case HEAT_UP:
		(p_tb1 + HEAT_UP)->DisplayButton(WHITE, RED, "+");
		break;
	case HEAT_DN:
		(p_tb1 + HEAT_DN)->DisplayButton(WHITE, BLUE, "-");
		break;

	}
	if (ReleaseButtonIndex == END_BUT) {
// ??? is this needed
	}
}
Example #14
0
void CIwGameInput::Update()
{
	// Update the pointer if it is available
	if (PointerAvailable)
		s3ePointerUpdate();

	// Update key system if it is available
	s3eKeyboardUpdate();

	Tapped = false;

	int num_touches = getTouchCount();
	DragDelta.x = 0;
	DragDelta.y = 0;

	if (num_touches == 0)
		Dragging = false;
	else
		Dragging = true;

	// User has just pressed screen so start timer
	if (PreviousNumTouches == 0 && num_touches == 1)
	{
		TapTimer.setDuration(TAP_TIME_MS);
		TouchedPos.x = getTouch(0)->x;
		TouchedPos.y = getTouch(0)->y;
	}

	// User has stopped pressing screen so check to see if press was a short press (a tap)
	if (PreviousNumTouches == 1 && num_touches == 0)
	{
		// Only check if touch hasnt moved much
		int dx = getTouch(0)->x - TouchedPos.x;
		int dy = getTouch(0)->y - TouchedPos.y;
		int d = dx * dx + dy * dy;
		DragDelta.x = dx;
		DragDelta.y = dy;

		if (d <= TAP_SENSITIVITY)
		{
			if (TapTimer.HasTimedOut())
			{
				TapTimer.Stop();
				Tapped = true;
			}
		}
		else
		{
			TapTimer.Stop();
		}
	}

	PreviousNumTouches = num_touches;

	// Update buttons
	BackPressed = false;
	bool back_released = (s3eKeyboardGetState(s3eKeyBack) & S3E_KEY_STATE_RELEASED) == S3E_KEY_STATE_RELEASED || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_RELEASED) == S3E_KEY_STATE_RELEASED;
	if (back_released)
		BackPressed = true;

	MenuPressed = false;
	bool menu_released = (s3eKeyboardGetState(s3eKeyMenu) & S3E_KEY_STATE_RELEASED) == S3E_KEY_STATE_RELEASED || (s3eKeyboardGetState(s3eKeyAbsASK) & S3E_KEY_STATE_RELEASED) == S3E_KEY_STATE_RELEASED;
	if (menu_released)
		MenuPressed = true;

	// Update accelerometer
	if (AccelerometerActive)
	{
		AccelerometerPosition.x = s3eAccelerometerGetX();
		AccelerometerPosition.y = s3eAccelerometerGetY();
		AccelerometerPosition.z = s3eAccelerometerGetZ();
	}

	// Update compass
	if (CompassActive)
	{
		CompassDirection = s3eCompassGet();
		s3eCompassHeading heading = { 0, 0, 0 };
		if (s3eCompassGetHeading(&heading) != S3E_RESULT_SUCCESS)
		{
			CompassHeading.x = heading.m_X;
			CompassHeading.y = heading.m_Y;
			CompassHeading.z = heading.m_Z;
		}
	}

}
Example #15
0
static portTASK_FUNCTION( vLcdTask, pvParameters )
{
	unsigned int pressure;
	unsigned int xPos;
	unsigned int yPos;
	//portTickType xLastWakeTime;
	
	int step_width = 320/sequence_steps;
	int step_height = 240/numNotes;
	int left, bottom = 0;
	int right = step_width;
	int top = step_height;
	
	int i, n, x;
	int waiting = 0;
	
	int newlySelectedSequence = 0;
	
	int prevMode = 0;
	int prevSeq = 0;

	/* Just to stop compiler warnings. */
	( void ) pvParameters;

	/* Initialise LCD display */
	/* NOTE: We needed to delay calling lcd_init() until here because it uses
	 * xTaskDelay to implement a delay and, as a result, can only be called from
	 * a task */
	lcd_init();
	
	lcd_fillScreen(LIGHT_GRAY);
	
	/* Initial LCD display */
	setupScreen(step_width,left, bottom,right,top);

	/* Infinite loop blocks waiting for a touch screen interrupt event from
	 * the queue. */
	 
	while(1)
	{
		/* Clear TS interrupts (EINT3) */
		/* Reset and (re-)enable TS interrupts on EINT3 */
		EXTINT = 8;						/* Reset EINT3 */

		/* Enable TS interrupt vector (VIC) (vector 17) */
		VICIntEnable = 1 << 17;			/* Enable interrupts on vector 17 */

		/* Block on a queue waiting for an event from the TS interrupt handler */
		xSemaphoreTake(xLcdSemphr, portMAX_DELAY);
				
		/* Disable TS interrupt vector (VIC) (vector 17) */
		VICIntEnClr = 1 << 17;

		/* Measure next sleep interval from this point */
		//xLastWakeTime = xTaskGetTickCount();
		
		// When switching sequences in edit mode.
		if(mode == 2){
			setupScreen(step_width,0, 0,step_width,step_height);
			mode = 0;
		}
		// Switching from playback mode to edit mode, screen must be setup.
		if((prevMode == 1) && (mode == 0)){
			setupScreen(step_width,0, 0,step_width,step_height);
		}
		// Switching from edit mode to playback mode.
		else if((prevMode == 0) && (mode == 1)) {
			setupPlaybackMode();
		}
		
		prevMode = mode;
		
		/*** EDIT MODE ***/
		/*****************/
		if(mode != 1) {
			/* Start polling the touchscreen pressure and position ( getTouch(...) ) */
			/* Keep polling until pressure == 0 */
			getTouch(&xPos, &yPos, &pressure);
			while (pressure > 0)
			{
				// Button debounce on screen touch.
				waiting = 0;
				while(waiting<100000) {
					waiting++;
				}
				// Iterating through each row.
				for(i=0; i<numNotes; i++) {
					if((xPos < top) && (xPos > bottom)) {
						// If touch within bounds of row i, check for the corresponding column.
						for(n=0; n<sequence_steps; n++) {
							if((yPos < right) && (yPos > left)){
								// Render column cells to clear previously selected cell and set up newly selected or change previously selected note time.
								for(x=0; x<numNotes;x++){
									lcd_fillRect((x*step_height), (n*step_width), (x*step_height)+step_height, ((n*step_width)+step_width), LIGHT_GRAY);
									lcd_drawRect((x*step_height), (n*step_width), (x*step_height)+step_height, ((n*step_width)+step_width), DARK_GRAY);
									if(x != i){
										// Majority of cells will have no note.
										timing[x][n] = 0;
									}
								}
								if(timing[i][n]==0 || timing[i][n]==1){
									timing[i][n]++;
								}
								else {
									timing[i][n] = timing[i][n] + 2;
								}
								if (timing[i][n] > 4){
									timing[i][n] = 0;
								}
								final_timing[n] = timing[i][n];
							  
								if(timing[i][n] == 1){
									// Full note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, MAROON);
								}
								else if(timing[i][n] == 2){
									// Half note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, OLIVE);
								}
								else if(timing[i][n] == 4){
									// Quarter note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, PURPLE);
								}
								sequence[n] = i;
							}
							left = left + step_width;
							right = right + step_width;
						}	
					}
					left = 0;
					right = step_width;
					top = top + step_height;
					bottom = bottom + step_height;
				}
				step_width = 320/sequence_steps;
				bottom = 0;
				left = 0;
				right = step_width;
				top = step_height;
				
				getTouch(&xPos, &yPos, &pressure);
			}
		}
		/*** PLAYBACK MODE ***/
		/*********************/
		else {
			/* Start polling the touchscreen pressure and position ( getTouch(...) ) */
			/* Keep polling until pressure == 0 */
			getTouch(&xPos, &yPos, &pressure);
			while (pressure > 0)
			{
				// Bound touch area for more efficiency.
				if((xPos < 235) && (xPos > 185)){
					// Select current sequence.
					for(i=0; i<9; i++) {
						if(((xPos < 235) && (xPos > 185)) && ((yPos < (35*i) + 35) && (yPos > (35*i) + 5))){
							// If a new sequence selected, must save the one that's currently in use to the listOfSequences[][] and listOfTimingSequences[][]
							// and then reinitialise the current sequence[] to the relative one in listOfSequences[][] and listOfTimingSequences[][].
							newlySelectedSequence = i;
							if(newlySelectedSequence != currentlySelectedSequence) {
								lcd_fillRect(185, (35*currentlySelectedSequence) + 5, 235, (35*currentlySelectedSequence) + 35, LIGHT_GRAY);
								lcd_fillRect(185, (35*newlySelectedSequence) + 5, 235, (35*newlySelectedSequence) + 35, MAGENTA);
								for(n=0;n<sequence_steps;n++){
									listOfSequences[currentlySelectedSequence][n] = sequence[n];
									listOfTimingSequences[currentlySelectedSequence][n] = final_timing[n];
								}
								currentlySelectedSequence = newlySelectedSequence;
								for(n=0;n<sequence_steps;n++){
									sequence[n] = listOfSequences[currentlySelectedSequence][n];
									final_timing[n] = listOfTimingSequences[currentlySelectedSequence][n];
								}
							}
						}
					}
				}
				getTouch(&xPos, &yPos, &pressure);
			}
			// Prevent flicker.
			if(prevSeq != currentlySelectedSequence){
				// Only fill part of screen to reduce flicker.
				lcd_fillRect(0, 0, 175, 320, LIGHT_GRAY);
				// Setup note bars for current sequence[] and final_timing[].
				for(i=0; i<sequence_steps; i++) {
					if(sequence[i] != numNotes) {
						if(final_timing[i]==1){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, MAROON);
						}
						else if(final_timing[i]==2){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, OLIVE);
						}
						else if(final_timing[i]==4){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, PURPLE);
						}
					}
				}
				// Setup BPM visual display.
				updateBPMVisuals();
				// Setup octave visual display.
				updateOctaveVisuals();
			}
			prevSeq = currentlySelectedSequence;
		}
	}
}