#include "ofApp.h" #include "glew.h" //-------------------------------------------------------------- void ofApp::setup(){ if (dmx.connect("tty.usbserial-ENP6ESY9")){ printf("DMX connected!\n"); //sbx1 - 16chan at 1 //sbx2 - 16chan at 16 //sbx3 - 16chan at 32 //sbx4 - 16chan at 48 //par1 - shutter, intensirty, R, G, B, white at 64 //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)); } else printf("DMX not connected.\n"); midiIn.listPorts(); midiIn.openPort(0); midiIn.addListener(this); dmxIntensity=0; } //-------------------------------------------------------------- void ofApp::update(){ std::stringstream strm; strm << "fps: " << ofGetFrameRate(); ofSetWindowTitle(strm.str()); } void ofApp::updateOutput(ofEventArgs & args){ images.update(); if (dmx.isConnected()){ for (auto m=map.begin();m!=map.end();m++){ m->update(dmxIntensity); } } } //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0,0,0); images.drawGui(); } void ofApp::drawOutput(ofEventArgs & args){ ofBackground(0,0,0); images.drawOutput(); } //-------------------------------------------------------------- void ofApp::exit() { // clean up midiIn.closePort(); midiIn.removeListener(this); } //-------------------------------------------------------------- /* midi - chan 1 bank 1 - program controls faders: cc 81 - 88 pots: cc 1 - 8 top buttons: cc 65 - 72 (0/127) next buttons: cc 73 - 80 (0/127) bank 2 - channel controls fader cc 7 / pot cc 10 channels 1-8 bank1 fader1 - light intensity pot 1 - zoom decay */ void ofApp::newMidiMessage(ofxMidiMessage& msg) { //printf("Midi: %i %i %i\n",msg.channel,msg.control,msg.value); //column 0 for general controls if (msg.channel==1&&msg.control==1){ //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); } if (msg.channel==1&&msg.control==65){ //top button 0 } if (msg.channel==1&&msg.control==73){ //bottom button 0 } if (msg.channel==1&&msg.control==81){ //fader 0 dmxIntensity=msg.value*2; } //column 1 for image set 0 if (msg.channel==1&&msg.control==2){ //pot 1 } if (msg.channel==1&&msg.control==66){ //top button 1 images.additive=(msg.value==127); } if (msg.channel==1&&msg.control==74){ //bottom button 1 } if (msg.channel==1&&msg.control==82){ //fader 1 images.intensity=((float)msg.value)/127.0f; } } //-------------------------------------------------------------- void ofApp::keyPressed(ofKeyEventArgs &keyargs){ images.keyPressed(keyargs); } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ images.mouseDragged(x,y,button); } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ images.mousePressed(x,y,button); } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ images.mouseReleased(x,y,button); } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- 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); } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ std::string filenames; for (auto f = dragInfo.files.begin(); f != dragInfo.files.end(); f++){ if (f!=dragInfo.files.begin()){ filenames=filenames+", "; } filenames=filenames+*f; images.add(*f,dragInfo.position); } }