From 16e2473835d6829f9f4074a13bb1e91cf7124e88 Mon Sep 17 00:00:00 2001
From: Krisjanis Rijnieks <krisjanis.rijnieks@gmail.com>
Date: Sat, 8 Oct 2016 22:56:49 +0200
Subject: [PATCH] Add Application::setNextPreset on <n> keypress

---
 src/Application/Application.cpp | 18 ++++++++++++++++++
 src/Application/Application.h   |  1 +
 2 files changed, 19 insertions(+)

diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp
index e099fe1..e811d2f 100644
--- a/src/Application/Application.cpp
+++ b/src/Application/Application.cpp
@@ -136,6 +136,10 @@ void Application::onKeyPressed(ofKeyEventArgs & args){
 	 case 'z':
 		 _cmdManager.undo();
 		 break;
+		 
+	 case 'n':
+		 setNextPreset();
+		 break;
 
 	 default:
 		 // All the other keypresses are handled by the application state onKeyPressed
@@ -230,6 +234,20 @@ void Application::setActivePreset(unsigned int i){
 	_cmdManager.exec(new SetActivePresetCmd(this, i));
 }
 
+void Application::setNextPreset(){
+	unsigned int numPresets = _surfaceManager.getNumPresets();
+	if(numPresets <= 1){
+		return;
+	}
+	int activePreset = _surfaceManager.getActivePresetIndex();
+	if(activePreset >= numPresets - 1){
+		activePreset = 0;
+	}else{
+		activePreset += 1;
+	}
+	setActivePreset(activePreset);
+}
+
 bool Application::loadXmlSettings(string fileName){
 	if(!ofFile::doesFileExist(fileName)){
 		ofLogError("Application::loadXmlSettings()") << fileName << " does not exist";
diff --git a/src/Application/Application.h b/src/Application/Application.h
index e9099dc..f65d646 100644
--- a/src/Application/Application.h
+++ b/src/Application/Application.h
@@ -71,6 +71,7 @@ class Application : public KeyListener {
 	
 		// Command executors
 		void setActivePreset(unsigned int i);
+		void setNextPreset();
 	
 	protected:
 		void setState(ApplicationBaseMode * st);