summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/addons.make3
-rw-r--r--gui/src/chainImage.cpp76
-rw-r--r--gui/src/chainImage.h13
-rw-r--r--gui/src/main.cpp18
-rw-r--r--gui/src/ofApp.cpp152
-rw-r--r--gui/src/ofApp.h89
6 files changed, 277 insertions, 74 deletions
diff --git a/gui/addons.make b/gui/addons.make
index 22f4cad..eff8aaa 100644
--- a/gui/addons.make
+++ b/gui/addons.make
@@ -1,3 +1,4 @@
ofxJSON
ofxDMX
-OfxMidi \ No newline at end of file
+ofxMidi
+ofxArtnet \ No newline at end of file
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp
index 275b107..6fdca96 100644
--- a/gui/src/chainImage.cpp
+++ b/gui/src/chainImage.cpp
@@ -14,13 +14,17 @@ void chainImage::init(ofPoint _linkPos,float _linkScale,float _linkRot){
setAnchorPercent(0.5,0.5);
}
-void chainImage::start(){
- transition=0.0f;
+void chainImage::start(bool reverse=false){
+ transition=reverse?1.0f:0.0f;
time=ofGetElapsedTimef();
setUseTexture(true);
- scale=linkScale;
+ scale=reverse?linkScale*link->linkScale:linkScale;
- //where there is rotation of the link, the path needs to be rotated?
+}
+
+int chainImage::update(float decayRatio){
+
+ //where there is rotation of the link, the path needs to be rotated
path.clear();
@@ -41,10 +45,7 @@ void chainImage::start(){
destination.x,destination.y);
//totalframes=log(1.0f/256)/log(decayRatio);
- //framecount=0;
-}
-bool chainImage::update(float decayRatio){
scale*=decayRatio;
@@ -62,12 +63,16 @@ bool chainImage::update(float decayRatio){
//transition=min(1.0f,((float)framecount)/totalframes);
-
- if (scale>linkScale*link->linkScale) return false;
- else {
- transition = 1.0f;
- return true;
+ if (scale>linkScale){
+ transition = 0.0f;
+ return SWITCH_REVERSE;
+ }
+ if (scale>linkScale*link->linkScale){
+ return SWITCH_NONE;
}
+ transition = 1.0f;
+ return SWITCH_FORWARD;
+
}
ofVec3f chainImage::getTransform(){
@@ -188,7 +193,7 @@ void chainImageSet::drawOutput(){
float camera_throw= (float)outputSize.y/(float)outputSize.x; //the ratio of z distance to x width
- camera_throw*=0.9; //fudge factor to allow tweening
+ camera_throw*=fitFactor; //fudge factor to allow tweening
if (images.size()){
@@ -216,15 +221,15 @@ void chainImageSet::drawOutput(){
}
-void chainImageSet::drawGui(){
-
- ofBackground(0,0,0);
+void chainImageSet::drawGui(int x,int y){
float t_xoffs=0.0;
float borderwidth=THUMB_SIZE*0.1; //ofGetWindowHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
glPushMatrix();
+
+
/*
float relscale=((float)ofGetWindowHeight())/THUMB_SIZE;
glScalef(relscale,relscale,relscale);
@@ -241,7 +246,9 @@ void chainImageSet::drawGui(){
float thumby=ii->thumbnail.getHeight()/2;
float thumbscale=ii->thumbnail.getWidth()/ii->getWidth();
+ glPushMatrix();
+ glTranslatef(x,y,0);
//why do I have to set this every time??
ii->thumbnail.setAnchorPercent(0.5,0.5);
@@ -252,8 +259,9 @@ void chainImageSet::drawGui(){
ii->thumbnail.getHeight()
);
+ ofSetColor(255,255,255);
if (ii==selected) ofSetColor(255,0,0);
- else ofSetColor(255,255,255);
+ if (&(*ii)==currentImage) ofSetColor(0,255,0);
ofDrawLine(t_xoffs+borderwidth,borderwidth,
t_xoffs+borderwidth+ii->thumbnail.getWidth(),borderwidth);
@@ -332,7 +340,7 @@ void chainImageSet::drawGui(){
t_xoffs+=ii->thumbnail.getWidth()+(borderwidth*2);
- //glPopMatrix();
+ glPopMatrix();
}
}
@@ -561,13 +569,31 @@ bool chainImageSet::loadJson(std::string _filename){
void chainImageSet::update(){
- if (images.size()){
- if (currentImage->update(decayFactor)){ //if returns true, switch images
- currentImage=currentImage->link;
- currentImage->start();
- ofLogNotice() << "Switched images";
- currentImage->update(decayFactor);
- }
+ if (images.size()){
+ int switchResponse=currentImage->update(decayFactor);
+ switch(switchResponse){
+ case SWITCH_FORWARD:{
+ currentImage=currentImage->link;
+ currentImage->start();
+ ofLogNotice() << "Switched images forward";
+ currentImage->update(decayFactor);
+ break;
+ }
+ case SWITCH_NONE:
+ break;
+ case SWITCH_REVERSE:{
+ for (auto ii=images.begin();ii!=images.end();++ii){
+ if (ii->link->filename==currentImage->filename){
+ currentImage=&(*ii);
+ currentImage->start(true);
+ ofLogNotice() << "Switched images reverse";
+ currentImage->update(decayFactor);
+ break;
+ }
+ }
+ break;
+ }
+ }
}
}
diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h
index 891afdd..a4f4367 100644
--- a/gui/src/chainImage.h
+++ b/gui/src/chainImage.h
@@ -9,6 +9,10 @@
#define BEZIER_OUT 0.2
#define BEZIER_IN 0.5
+#define SWITCH_NONE 0
+#define SWITCH_FORWARD 1
+#define SWITCH_REVERSE 2
+
class chainImage : public ofImage{
//todo: threaded image loader
@@ -19,7 +23,7 @@ class chainImage : public ofImage{
}
void init(ofPoint _linkPos,float _linkScale,float _linkRot);
- void start();
+ void start(bool reverse);
bool load(std::string _filename){
filename=_filename;
if (ofImage::load(filename)){
@@ -34,7 +38,7 @@ class chainImage : public ofImage{
return false;
}
- bool update(float decayRatio);
+ int update(float decayRatio);
ofVec3f getTransform();
float getScale();
float getRotation();
@@ -75,8 +79,9 @@ class chainImageSet{
decayFactor=.999;
additive=false;
intensity=1.0f;
+ fitFactor=0.9f;
}
- void drawGui();
+ void drawGui(int x,int y);
void drawOutput();
void update();
bool add(std::string filename,glm::vec2 pos);
@@ -91,6 +96,7 @@ class chainImageSet{
ofPoint outputSize;
std::list <chainImage> images;
+ std::list <chainImage> images2;
float currentDefaultImageRatio;
std::list<chainImage>::iterator selected;
@@ -98,6 +104,7 @@ class chainImageSet{
ofPoint dragPoint;
float dragScale;
float dragRotate;
+ float fitFactor;
std::string filename;
diff --git a/gui/src/main.cpp b/gui/src/main.cpp
index 52f9d48..521be02 100644
--- a/gui/src/main.cpp
+++ b/gui/src/main.cpp
@@ -25,12 +25,21 @@ int main(int argc, char *argv[]){
settings.resizable = true;
shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
+ // uncomment next line to share main's OpenGL resources with gui
+ settings.shareContextWith = mainWindow;
+
+ settings.width = 800;
+ settings.height = 450;
+ settings.setPosition(ofVec2f(1400,0));
+ settings.resizable = true;
+ shared_ptr<ofAppBaseWindow> previewWindow = ofCreateWindow(settings);
+ previewWindow->setVerticalSync(false);
+
settings.width = 1600;
- settings.height = 200;
+ settings.height = 400;
settings.setPosition(ofVec2f(0,700));
settings.resizable = true;
- // uncomment next line to share main's OpenGL resources with gui
- settings.shareContextWith = mainWindow;
+
shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);
guiWindow->setVerticalSync(false);
@@ -40,7 +49,10 @@ int main(int argc, char *argv[]){
ofAddListener(mainWindow->events().update,mainApp.get(),&ofApp::updateOutput);
ofAddListener(mainWindow->events().draw,mainApp.get(),&ofApp::drawOutput);
ofAddListener(mainWindow->events().windowResized,mainApp.get(),&ofApp::outputWindowResized);
+ ofAddListener(mainWindow->events().keyPressed,mainApp.get(),&ofApp::outputKeyPressed);
+ ofAddListener(previewWindow->events().draw,mainApp.get(),&ofApp::drawOutput);
+
ofRunApp(guiWindow, mainApp);
ofRunMainLoop();
}
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index d99300c..797f729 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -4,7 +4,7 @@
//--------------------------------------------------------------
void ofApp::setup(){
- if (dmx.connect("tty.usbserial-ENP6ESY9")){
+ if (dmx.connect("tty.usbserial-ENP6ESY9",120)){
printf("DMX connected!\n");
//sbx1 - 16chan at 1
@@ -15,17 +15,25 @@ void ofApp::setup(){
//par2 - shutter, intensirty, R, G, B, white at 70
//par3 - shutter, intensirty, R, G, B, white at 76
- map.push_back(dmxMap(&dmx,66,67,68,65,0.1,0.1));
- map.push_back(dmxMap(&dmx,72,73,74,71,0.5,0.1));
- map.push_back(dmxMap(&dmx,78,79,80,77,0.9,0.1));
+ // R, G, B, white, dimmer, shutter
+
+ map.push_back(USBdmxMap(&dmx,80,0.1,0.1));
+ map.push_back(USBdmxMap(&dmx,90,0.5,0.1));
+ map.push_back(USBdmxMap(&dmx,100,0.9,0.1));
+ map.push_back(USBdmxMap(&dmx,110,0.5,0.5));
}
- else printf("DMX not connected.\n");
+ else printf("USB DMX not connected.\n");
+
+ //artnet.setup("10.7.186.17");
+ //memset(dmx_data,0,512);
midiIn.listPorts();
midiIn.openPort(0);
midiIn.addListener(this);
- dmxIntensity=0;
+ dmxIntensity=255;
+
+ next_update=ofGetElapsedTimef()+5.0f;
}
//--------------------------------------------------------------
@@ -41,12 +49,8 @@ void ofApp::update(){
void ofApp::updateOutput(ofEventArgs & args){
images.update();
+ images2.update();
- if (dmx.isConnected()){
- for (auto m=map.begin();m!=map.end();m++){
- m->update(dmxIntensity);
- }
- }
}
@@ -54,13 +58,27 @@ void ofApp::updateOutput(ofEventArgs & args){
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0,0,0);
- images.drawGui();
+ images.drawGui(0,0);
+ images2.drawGui(0,200);
}
void ofApp::drawOutput(ofEventArgs & args){
ofBackground(0,0,0);
images.drawOutput();
+ images2.drawOutput();
+
+ if (dmx.isConnected()&&ofGetElapsedTimef()>next_update){
+ //if (dmx.isConnected()&&()){
+ for (auto m=map.begin();m!=map.end();m++){
+ m->update(dmxIntensity);
+
+ }
+ //artnet.sendDmx("10.7.175.170", dmx_data, 512);
+
+ next_update=ofGetElapsedTimef()+0.2f;
+ }
+
}
@@ -105,48 +123,109 @@ void ofApp::newMidiMessage(ofxMidiMessage& msg) {
//column 0 for general controls
- if (msg.channel==1&&msg.control==1){
+ int offet=0;
+
+ if (msg.channel==1&&msg.control==1+offet){
//pot 0
//from .9 to 1.1 but reaching numbers very near 1
-
- images.decayFactor=1.0 - (pow(2.0f,((float)msg.value-64)/8)/pow(2,8));
-
- //printf("Val %i, decay: %f \n",msg.value,sf);
+ float signed_value=(float)msg.value-64;
+ if (signed_value<0){
+ images.decayFactor=1.0 + (pow(4.0f,abs(signed_value)/8)/pow(4,8));
+ }
+ else {
+ images.decayFactor=1.0 - (pow(4.0f,(signed_value)/8)/pow(4,8));
+ }
+ images2.decayFactor=images.decayFactor;
+
+ printf("Val %i, decay: %f \n",msg.value,images.decayFactor);
}
- if (msg.channel==1&&msg.control==65){
+ if (msg.channel==1&&msg.control==65+offet){
//top button 0
}
- if (msg.channel==1&&msg.control==73){
+ if (msg.channel==1&&msg.control==73+offet){
//bottom button 0
}
- if (msg.channel==1&&msg.control==81){
+ if (msg.channel==1&&msg.control==81+offet){
//fader 0
dmxIntensity=msg.value*2;
+ printf("Val %i, dmx intensity: %i \n",msg.value,dmxIntensity);
}
-//column 1 for image set 0
+//column 5 for image set 0
+
+ offet=4;
- if (msg.channel==1&&msg.control==2){
+ if (msg.channel==1&&msg.control==1+offet){
//pot 1
}
- if (msg.channel==1&&msg.control==66){
+ if (msg.channel==1&&msg.control==65+offet){
//top button 1
images.additive=(msg.value==127);
}
- if (msg.channel==1&&msg.control==74){
+ if (msg.channel==1&&msg.control==73+offet){
//bottom button 1
}
- if (msg.channel==1&&msg.control==82){
+ if (msg.channel==1&&msg.control==81+offet){
//fader 1
images.intensity=((float)msg.value)/127.0f;
}
+//column 6 for image set 1
+
+ offet=5;
+
+ if (msg.channel==1&&msg.control==1+offet){
+ //pot 1
+ }
+ if (msg.channel==1&&msg.control==65+offet){
+ //top button 1
+ images.additive=(msg.value==127);
+ }
+ if (msg.channel==1&&msg.control==73+offet){
+ //bottom button 1
+ }
+ if (msg.channel==1&&msg.control==81+offet){
+ //fader 1
+ images2.intensity=((float)msg.value)/127.0f;
+ }
+
+//column 1 for more controls
+ offet=1;
+
+ if (msg.channel==1&&msg.control==1+offet){
+ //pot 1
+ images.fitFactor=1.0f+(((float)msg.value-64)/64.0f);
+ images2.fitFactor=1.0f+(((float)msg.value-64)/64.0f);
+
+ printf("Val %i, fitfactor: %f \n",msg.value,images.fitFactor);
+ }
+ if (msg.channel==1&&msg.control==65+offet){
+ //top button 1
+
+ }
+ if (msg.channel==1&&msg.control==73+offet){
+ //bottom button 1
+ }
+ if (msg.channel==1&&msg.control==81+offet){
+ //fader 1
+
+ }
+
}
//--------------------------------------------------------------
void ofApp::keyPressed(ofKeyEventArgs &keyargs){
images.keyPressed(keyargs);
+
+
+}
+
+void ofApp::outputKeyPressed(ofKeyEventArgs &args){
+ if(args.key == ' '){
+ outputFS=!outputFS;
+ ofSetFullscreen(outputFS);
+ }
}
//--------------------------------------------------------------
@@ -161,17 +240,26 @@ void ofApp::mouseMoved(int x, int y ){
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
- images.mouseDragged(x,y,button);
+ if (y<ofGetHeight()/2){
+ images.mouseDragged(x,y,button);
+ }
+ else images2.mouseDragged(x,y,button);
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
- images.mousePressed(x,y,button);
+ if (y<ofGetHeight()/2){
+ images.mousePressed(x,y,button);
+ }
+ else images2.mousePressed(x,y,button);
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
- images.mouseReleased(x,y,button);
+ if (y<ofGetHeight()/2){
+ images.mouseReleased(x,y,button);
+ }
+ else images2.mouseReleased(x,y,button);
}
//--------------------------------------------------------------
@@ -192,6 +280,7 @@ void ofApp::windowResized(int w, int h){
void ofApp::outputWindowResized(ofResizeEventArgs &resizeargs){
//printf("Output window: %i,%i \n",resizeargs.width,resizeargs.height);
images.outputSize=ofPoint(resizeargs.width,resizeargs.height);
+ images2.outputSize=ofPoint(resizeargs.width,resizeargs.height);
}
//--------------------------------------------------------------
@@ -209,7 +298,12 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
}
filenames=filenames+*f;
- images.add(*f,dragInfo.position);
+ if (dragInfo.position.y<200){
+ images.add(*f,dragInfo.position);
+ }
+ else images2.add(*f,dragInfo.position);
+
+
}
}
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
index 20116a1..181c4c7 100644
--- a/gui/src/ofApp.h
+++ b/gui/src/ofApp.h
@@ -2,22 +2,34 @@
#include "ofMain.h"
#include "ofxDmx.h"
+//#include "ofxArtnet.h"
#include "ofxMidi.h"
#include "chainImage.h"
-class dmxMap{
+class USBdmxMap{
//resolution independent DMX colour tracker
public:
- dmxMap(){
+ USBdmxMap(){
}
- dmxMap(ofxDmx *_dmx,int _chan_R,int _chan_G,int _chan_B,int _chan_intensity,float _x,float _y){
+ USBdmxMap(ofxDmx *_dmx,int chan_base,float _x,float _y){
dmx=_dmx;
- chan_R=_chan_R;
- chan_G=_chan_G;
- chan_B=_chan_B;
- chan_intensity=_chan_intensity;
+
+ // R, G, B, white, dimmer, shutter
+
+ // dimmer, shutter, R, G, B, white
+
+
+ chan_intensity=chan_base;
+ chan_shutter=chan_base+1;
+ chan_R=chan_base+2;
+ chan_G=chan_base+3;
+ chan_B=chan_base+4;
+ chan_white=chan_base+5;
+
+ //dmx->setLevel(chan_shutter,15,0);
+ //dmx->update();
x=_x;
y=_y;
}
@@ -25,17 +37,57 @@ class dmxMap{
unsigned char color[3];
glReadPixels(x*ofGetWidth() , ofGetHeight() - (y*ofGetHeight()) , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , color);
//printf("dmxMap %i,%i: colour %i %i %i\n",x,y,color[0],color[1],color[2]);
- dmx->setLevel(chan_R, color[0]);
- dmx->setLevel(chan_G, color[1]);
- dmx->setLevel(chan_B, color[2]);
- dmx->setLevel(chan_intensity, intensity);
+
+ dmx->setLevel(chan_R,color[0]); //,0);
+ dmx->setLevel(chan_G,color[1]); //,0);
+ dmx->setLevel(chan_B,color[2]); //,0);
+ dmx->setLevel(chan_white,0); //,0);
+ dmx->setLevel(chan_intensity,intensity); //,0);
+ dmx->setLevel(chan_shutter,255); //,0);
dmx->update();
+
+ printf("Dmx: %i,%i,%i @ %i \n",color[0],color[1],color[2],intensity);
}
- int chan_R, chan_G, chan_B, chan_intensity;
+ int chan_R, chan_G, chan_B, chan_intensity, chan_shutter, chan_white;
float x,y;
ofxDmx *dmx;
};
+class ArtnetDmxMap{
+ //resolution independent DMX colour tracker
+ public:
+ ArtnetDmxMap(){
+ }
+ ArtnetDmxMap(unsigned char *_dmx_data,int chan_base,float _x,float _y){
+ dmx_data=_dmx_data;
+ chan_shutter=chan_base;
+ chan_intensity=chan_base+1;
+ chan_R=chan_base+2;
+ chan_G=chan_base+3;
+ chan_B=chan_base+4;
+
+ //dmx->setLevel(chan_shutter,15,0);
+ //dmx->update();
+ x=_x;
+ y=_y;
+ }
+ void update(int intensity){
+ unsigned char color[3];
+ glReadPixels(x*ofGetWidth() , ofGetHeight() - (y*ofGetHeight()) , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , color);
+ //printf("dmxMap %i,%i: colour %i %i %i\n",x,y,color[0],color[1],color[2]);
+ dmx_data[chan_shutter]=255;
+ dmx_data[chan_intensity]=intensity;
+ dmx_data[chan_R]=color[0];
+ dmx_data[chan_G]=color[1];
+ dmx_data[chan_B]=color[2];
+
+ //printf("Dmx: %i,%i,%i @ %i \n",color[0],color[1],color[2],intensity);
+ }
+ int chan_R, chan_G, chan_B, chan_intensity, chan_shutter;
+ float x,y;
+ unsigned char *dmx_data;
+};
+
class ofApp : public ofBaseApp, public ofxMidiListener{
public:
@@ -46,6 +98,8 @@ class ofApp : public ofBaseApp, public ofxMidiListener{
void drawOutput(ofEventArgs & args);
void exit();
+ void outputKeyPressed(ofKeyEventArgs & args);
+
void keyPressed(ofKeyEventArgs &keyargs);
void keyReleased(int key);
void mouseMoved(int x, int y );
@@ -62,9 +116,14 @@ class ofApp : public ofBaseApp, public ofxMidiListener{
vector<string> arguments;
chainImageSet images;
+ chainImageSet images2;
ofxDmx dmx;
- vector<dmxMap> map;
+ //ofxArtnet artnet;
+
+ //unsigned char dmx_data[512];
+
+ vector<USBdmxMap> map;
void newMidiMessage(ofxMidiMessage& eventArgs);
ofxMidiIn midiIn;
@@ -72,4 +131,8 @@ class ofApp : public ofBaseApp, public ofxMidiListener{
int dmxIntensity;
+ bool outputFS;
+
+ float next_update;
+
};