comparison 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
comparison
equal deleted inserted replaced
5:213df0baed47 6:92850a2b099c
1 //
2 // ExplorePresetManager.h
3 // riftathon
4 //
5 // Created by Robert Tubb on 16/10/2014.
6 //
7 // when people explore and find presets save them
8 // record audio
9 // can display images and text
10
11 //
12
13 #ifndef __riftathon__ExplorePresetManager__
14 #define __riftathon__ExplorePresetManager__
15
16 #include <iostream>
17 #include "presetManager.h"
18
19
20
21 class ExplorePresetManager : public PresetManager {
22
23 public:
24 void onAppLoad(){
25 // check for already saved stuff
26 startLoadAll();
27
28 if (thePresets.size() != 16){
29 // if numpresets != 16
30 initPresets();
31 }
32
33 }
34 void initPresets(){
35
36 presetSlotFilename = ofFilePath::getAbsolutePath(ofToDataPath("presetSlots.json"));
37
38 // set up 16 preset slots with names and images
39 Json::Value root;
40 Json::Reader reader;
41
42
43 ifstream theFile(presetSlotFilename.c_str());
44 stringstream fileText;
45 string line;
46 if(!theFile){
47 cout<<"can't find presetSlot file \n";
48 return;
49 }else{
50
51 while(theFile){
52 theFile >> line;
53 // cout << line << "\n"; // lots?
54 fileText << line;
55
56 }
57
58 theFile.close();
59 }
60
61 bool parsingSuccessful = reader.parse( fileText.str(), root );
62
63 if ( !parsingSuccessful )
64 {
65 // report to the user the failure and their locations in the document.
66 std::cout << "Failed to parse preset slot JSON: \n"
67 << reader.getFormattedErrorMessages();
68 return;
69 }
70
71 // now put into variables
72 const Json::Value jv = root["presetSlots"];
73
74 for ( int index = 0; index < jv.size(); ++index ){
75 string name = jv[index]["name"].asString();
76 string imageFileName = jv[index]["imageFileName"].asString();
77 vector<int> empty;
78 generatePresetSlot(name, imageFileName);
79 }
80
81 printAll();
82
83 filledSlots = 0;
84 }
85
86 //----------------------------------------------------------------------------
87 void presentNextPreset(){
88
89 }
90 protected:
91 int filledSlots;
92 string presetSlotFilename;
93
94 vector<string> categories;
95 vector<string> names;
96 };
97
98 #endif /* defined(__riftathon__ExplorePresetManager__) */