Skip to content

Commit 29e7108

Browse files
first version of directory watching code and increase buffers to 10
1 parent 9a7bebd commit 29e7108

File tree

8 files changed

+376
-15
lines changed

8 files changed

+376
-15
lines changed

bin/data/.gitkeep

Whitespace-only changes.

bin/data/code/1.cy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//rotate
2+
move
3+
rotate
4+
color red
5+
box
6+
move
7+
rotate

bin/data/sprites/1.png

46.7 KB
Loading

cyril.xcodeproj/project.pbxproj

Lines changed: 303 additions & 0 deletions
Large diffs are not rendered by default.

src/cyrilApp.cpp

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ void cyrilApp::setup(){
77

88
ofSoundStreamSetup(0, 1, this, 44100, beat.getBufferSize(), 4);
99

10+
// Switch back to external data folder
11+
ofSetDataPathRoot("../../../data/");
12+
// Directory watcher for data folder
13+
codeWatcher.registerAllEvents(this);
14+
std::string folderToWatch = ofToDataPath("code", true);
15+
codeWatcher.addPath(folderToWatch, true, &fileFilter);
16+
1017
ofBackground(0);
1118
pauseProg = false;
1219
lightsOn = true;
@@ -21,6 +28,7 @@ void cyrilApp::setup(){
2128
running[6] = false;
2229
running[7] = false;
2330
running[8] = false;
31+
running[9] = false;
2432
error[0] = false;
2533
error[1] = false;
2634
error[2] = false;
@@ -30,6 +38,7 @@ void cyrilApp::setup(){
3038
error[6] = false;
3139
error[7] = false;
3240
error[8] = false;
41+
error[9] = false;
3342

3443
#ifdef FULL_DEBUG
3544
ofSetLogLevel("ofxGLEditor", OF_LOG_VERBOSE);
@@ -174,7 +183,7 @@ void cyrilApp::draw(){
174183
float Y_SCALE = (*_state.sym)[REG_Y_SCALE];
175184
float Z_SCALE = (*_state.sym)[REG_Z_SCALE];
176185

177-
for (int i = 0; i < 9; ++i) {
186+
for (int i = 0; i < 10; ++i) {
178187
if (running[i]) {
179188
if (prog[i]->valid) {
180189
ofPushMatrix();
@@ -208,7 +217,7 @@ void cyrilApp::draw(){
208217
ofPushMatrix();
209218
ofPushStyle();
210219
ofTranslate(X_MID - 45, 10);
211-
for (int i = 0; i < 9; ++i) {
220+
for (int i = 0; i < 10; ++i) {
212221
if (error[i]) {
213222
ofSetColor(255,0,0);
214223
}
@@ -265,17 +274,13 @@ void cyrilApp::toggleLights(void * _o) {
265274
((cyrilApp *)_o)->_state.light->setAttenuation(1.f,0.f,0.f);
266275
}
267276
void cyrilApp::loadFile(void * _o) {
268-
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
269-
ofSetDataPathRoot("../../../");
270-
((cyrilApp *)_o)->editor.loadFile(ofToString(whichEditor)+".txt", whichEditor);
271-
ofSetDataPathRoot("../Resources/data");
272-
((cyrilApp *)_o)->editor.update();
277+
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
278+
//((cyrilApp *)_o)->editor.loadFile(ofToString(whichEditor)+".txt", whichEditor);
279+
//((cyrilApp *)_o)->editor.update();
273280
}
274281
void cyrilApp::saveFile(void * _o) {
275-
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
276-
ofSetDataPathRoot("../../../");
277-
((cyrilApp *)_o)->editor.saveFile(ofToString(whichEditor)+".txt", whichEditor);
278-
ofSetDataPathRoot("../Resources/data");
282+
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
283+
//((cyrilApp *)_o)->editor.saveFile(ofToString(whichEditor)+".txt", whichEditor);
279284
}
280285
void cyrilApp::resetTimers(void * _o) {
281286
((cyrilApp *)_o)->doResetTimers = true;
@@ -308,6 +313,37 @@ void cyrilApp::runScript(void * _o) {
308313
}
309314

310315

316+
void cyrilApp::onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt) {
317+
ofFile file = ofFile(evt.item.path());
318+
if (file.getExtension() == "cy") {
319+
cout << "Load: " << file.getFileName() << endl;
320+
int whichEditor = editor.currentBuffer;
321+
editor.loadFile(evt.item.path(), whichEditor);
322+
editor.update();
323+
}
324+
}
325+
void cyrilApp::onDirectoryWatcherItemRemoved(const DirectoryWatcherManager::DirectoryEvent& evt) {
326+
cout << "Unload: " << evt.item.path() << endl;
327+
}
328+
void cyrilApp::onDirectoryWatcherItemModified(const DirectoryWatcherManager::DirectoryEvent& evt) {
329+
ofFile file = ofFile(evt.item.path());
330+
if (file.getExtension() == "cy") {
331+
cout << "Reload: " << evt.item.path() << endl;
332+
int whichEditor = editor.currentBuffer;
333+
editor.loadFile(evt.item.path(), whichEditor);
334+
//editor.update();
335+
runScript(this);
336+
}
337+
}
338+
void cyrilApp::onDirectoryWatcherItemMovedFrom(const DirectoryWatcherManager::DirectoryEvent& evt) {
339+
340+
}
341+
void cyrilApp::onDirectoryWatcherItemMovedTo(const DirectoryWatcherManager::DirectoryEvent& evt) {
342+
343+
}
344+
void cyrilApp::onDirectoryWatcherError(const Poco::Exception& exc) {
345+
346+
}
311347

312348

313349
//--------------------------------------------------------------

src/cyrilApp.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "ofxEditor.h"
1010
#include "ofxBeat.h"
1111

12+
#include "ofxIO.h"
13+
using namespace ofx::IO;
14+
1215
class cyrilApp : public ofBaseApp{
1316

1417
ofxEditor editor;
@@ -17,9 +20,9 @@ class cyrilApp : public ofBaseApp{
1720
//ofxXmlSettings settings;
1821
string fileName;
1922

20-
Cyril *prog[9];
21-
bool running[9];
22-
bool error[9];
23+
Cyril *prog[10];
24+
bool running[10];
25+
bool error[10];
2326

2427
CyrilState _state;
2528
vector<string> progFiles;
@@ -41,9 +44,12 @@ class cyrilApp : public ofBaseApp{
4144

4245
int lastSignalReport;
4346

47+
DirectoryWatcherManager codeWatcher;
48+
HiddenFileFilter fileFilter;
49+
4450
public:
4551

46-
cyrilApp(): editor(9, "DroidSansMono.ttf") {}
52+
cyrilApp(): editor(10, "../Resources/DroidSansMono.ttf") {}
4753

4854
void setup();
4955
void update();
@@ -75,5 +81,13 @@ class cyrilApp : public ofBaseApp{
7581
static void pauseProgram(void *);
7682
static void runScript(void *);
7783

84+
// Directory watcher callbacks
85+
void onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt);
86+
void onDirectoryWatcherItemRemoved(const DirectoryWatcherManager::DirectoryEvent& evt);
87+
void onDirectoryWatcherItemModified(const DirectoryWatcherManager::DirectoryEvent& evt);
88+
void onDirectoryWatcherItemMovedFrom(const DirectoryWatcherManager::DirectoryEvent& evt);
89+
void onDirectoryWatcherItemMovedTo(const DirectoryWatcherManager::DirectoryEvent& evt);
90+
void onDirectoryWatcherError(const Poco::Exception& exc);
91+
7892
};
7993

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
map < string, ofColor > colorNameMap;
88

99
int main( ){
10+
// Set this temporarily to load font from packaged Resources
1011
ofSetDataPathRoot("../Resources/data");
1112
ofSetEscapeQuitsApp(false);
1213

0 commit comments

Comments
 (0)