diff ExplorePresetManager.h @ 6:92850a2b099c

set up preset slots from init file. PD synth has metronome, recieves ticks but doesn't do anything with them.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 17 Oct 2014 14:50:50 +0100
parents
children e25d2b1b185e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ExplorePresetManager.h	Fri Oct 17 14:50:50 2014 +0100
@@ -0,0 +1,98 @@
+//
+//  ExplorePresetManager.h
+//  riftathon
+//
+//  Created by Robert Tubb on 16/10/2014.
+//
+// when people explore and find presets save them
+// record audio
+// can display images and text
+
+// 
+
+#ifndef __riftathon__ExplorePresetManager__
+#define __riftathon__ExplorePresetManager__
+
+#include <iostream>
+#include "presetManager.h"
+
+
+
+class ExplorePresetManager : public PresetManager {
+
+public:
+    void onAppLoad(){
+        // check for already saved stuff
+        startLoadAll();
+        
+        if (thePresets.size() != 16){
+        // if numpresets != 16
+            initPresets();
+        }
+        
+    }
+    void initPresets(){
+
+        presetSlotFilename = ofFilePath::getAbsolutePath(ofToDataPath("presetSlots.json"));
+        
+        // set up 16 preset slots with names and images
+        Json::Value root;
+        Json::Reader reader;
+        
+        
+        ifstream theFile(presetSlotFilename.c_str());
+        stringstream fileText;
+        string line;
+        if(!theFile){
+            cout<<"can't find presetSlot file \n";
+            return;
+        }else{
+            
+            while(theFile){
+                theFile >> line;
+                // cout << line << "\n"; // lots?
+                fileText << line;
+                
+            }
+            
+            theFile.close();
+        }
+        
+        bool parsingSuccessful = reader.parse( fileText.str(), root );
+        
+        if ( !parsingSuccessful )
+        {
+            // report to the user the failure and their locations in the document.
+            std::cout  << "Failed to parse preset slot JSON: \n"
+            << reader.getFormattedErrorMessages();
+            return;
+        }
+        
+        // now put into variables
+        const Json::Value jv = root["presetSlots"];
+        
+        for ( int index = 0; index < jv.size(); ++index ){
+            string name = jv[index]["name"].asString();
+            string imageFileName = jv[index]["imageFileName"].asString();
+            vector<int> empty;
+            generatePresetSlot(name, imageFileName);
+        }
+
+        printAll();
+        
+        filledSlots = 0;
+    }
+    
+//----------------------------------------------------------------------------
+    void presentNextPreset(){
+        
+    }
+protected:
+    int filledSlots;
+    string presetSlotFilename;
+    
+    vector<string> categories;
+    vector<string> names;
+};
+
+#endif /* defined(__riftathon__ExplorePresetManager__) */