diff options
| -rw-r--r-- | gui/src/lineSegmenter.cpp | 2 | ||||
| -rw-r--r-- | oscReceiveExample/Makefile | 13 | ||||
| -rw-r--r-- | oscReceiveExample/addons.make | 2 | ||||
| -rw-r--r-- | oscReceiveExample/config.make | 142 | ||||
| -rw-r--r-- | oscReceiveExample/mame/vector.cpp | 264 | ||||
| -rw-r--r-- | oscReceiveExample/mame/vector.h | 71 | ||||
| -rw-r--r-- | oscReceiveExample/src/main.cpp | 14 | ||||
| -rw-r--r-- | oscReceiveExample/src/ofApp.cpp | 282 | ||||
| -rw-r--r-- | oscReceiveExample/src/ofApp.h | 50 |
9 files changed, 839 insertions, 1 deletions
diff --git a/gui/src/lineSegmenter.cpp b/gui/src/lineSegmenter.cpp index 495190d..3f434b1 100644 --- a/gui/src/lineSegmenter.cpp +++ b/gui/src/lineSegmenter.cpp @@ -84,7 +84,7 @@ const vector <colourPolyline> & colourLineSegmenter::getSegments(int num,float c segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex)); } else { - segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex)); + segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex) ); } segments.push_back(segment); } diff --git a/oscReceiveExample/Makefile b/oscReceiveExample/Makefile new file mode 100644 index 0000000..177e172 --- /dev/null +++ b/oscReceiveExample/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=$(realpath ../../..) +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/oscReceiveExample/addons.make b/oscReceiveExample/addons.make new file mode 100644 index 0000000..1b8f1d2 --- /dev/null +++ b/oscReceiveExample/addons.make @@ -0,0 +1,2 @@ +ofxOsc +ofxHelios diff --git a/oscReceiveExample/config.make b/oscReceiveExample/config.make new file mode 100644 index 0000000..a2f4f86 --- /dev/null +++ b/oscReceiveExample/config.make @@ -0,0 +1,142 @@ +################################################################################ +# CONFIGURE PROJECT MAKEFILE (optional) +# This file is where we make project specific configurations. +################################################################################ + +################################################################################ +# OF ROOT +# The location of your root openFrameworks installation +# (default) OF_ROOT = ../../.. +################################################################################ +OF_ROOT = ../../openFrameworks + +################################################################################ +# PROJECT ROOT +# The location of the project - a starting place for searching for files +# (default) PROJECT_ROOT = . (this directory) +# +################################################################################ +# PROJECT_ROOT = . + +################################################################################ +# PROJECT SPECIFIC CHECKS +# This is a project defined section to create internal makefile flags to +# conditionally enable or disable the addition of various features within +# this makefile. For instance, if you want to make changes based on whether +# GTK is installed, one might test that here and create a variable to check. +################################################################################ +# None + +################################################################################ +# PROJECT EXTERNAL SOURCE PATHS +# These are fully qualified paths that are not within the PROJECT_ROOT folder. +# Like source folders in the PROJECT_ROOT, these paths are subject to +# exlclusion via the PROJECT_EXLCUSIONS list. +# +# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXTERNAL_SOURCE_PATHS = + +################################################################################ +# PROJECT EXCLUSIONS +# These makefiles assume that all folders in your current project directory +# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations +# to look for source code. The any folders or files that match any of the +# items in the PROJECT_EXCLUSIONS list below will be ignored. +# +# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete +# string unless teh user adds a wildcard (%) operator to match subdirectories. +# GNU make only allows one wildcard for matching. The second wildcard (%) is +# treated literally. +# +# (default) PROJECT_EXCLUSIONS = (blank) +# +# Will automatically exclude the following: +# +# $(PROJECT_ROOT)/bin% +# $(PROJECT_ROOT)/obj% +# $(PROJECT_ROOT)/%.xcodeproj +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXCLUSIONS = + +################################################################################ +# PROJECT LINKER FLAGS +# These flags will be sent to the linker when compiling the executable. +# +# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ + +# Currently, shared libraries that are needed are copied to the +# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to +# add a runtime path to search for those shared libraries, since they aren't +# incorporated directly into the final executable application binary. +# TODO: should this be a default setting? +# PROJECT_LDFLAGS=-Wl,-rpath=./libs + +################################################################################ +# PROJECT DEFINES +# Create a space-delimited list of DEFINES. The list will be converted into +# CFLAGS with the "-D" flag later in the makefile. +# +# (default) PROJECT_DEFINES = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_DEFINES = + +################################################################################ +# PROJECT CFLAGS +# This is a list of fully qualified CFLAGS required when compiling for this +# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS +# defined in your platform specific core configuration files. These flags are +# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. +# +# (default) PROJECT_CFLAGS = (blank) +# +# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in +# your platform specific configuration file will be applied by default and +# further flags here may not be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CFLAGS = + +################################################################################ +# PROJECT OPTIMIZATION CFLAGS +# These are lists of CFLAGS that are target-specific. While any flags could +# be conditionally added, they are usually limited to optimization flags. +# These flags are added BEFORE the PROJECT_CFLAGS. +# +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) +# +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) +# +# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the +# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration +# file will be applied by default and further optimization flags here may not +# be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE = +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG = + +################################################################################ +# PROJECT COMPILERS +# Custom compilers can be set for CC and CXX +# (default) PROJECT_CXX = (blank) +# (default) PROJECT_CC = (blank) +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CXX = +# PROJECT_CC = diff --git a/oscReceiveExample/mame/vector.cpp b/oscReceiveExample/mame/vector.cpp new file mode 100644 index 0000000..89c27c2 --- /dev/null +++ b/oscReceiveExample/mame/vector.cpp @@ -0,0 +1,264 @@ +// license:BSD-3-Clause +// copyright-holders:Brad Oliver,Aaron Giles,Bernd Wiebelt,Allard van der Bas +/****************************************************************************** + * + * vector.c + * + * anti-alias code by Andrew Caldwell + * (still more to add) + * + * 040227 Fixed miny clip scaling which was breaking in mhavoc. AREK + * 010903 added support for direct RGB modes MLR + * 980611 use translucent vectors. Thanks to Peter Hirschberg + * and Neil Bradley for the inspiration. BW + * 980307 added cleverer dirty handling. BW, ASG + * fixed antialias table .ac + * 980221 rewrote anti-alias line draw routine + * added inline assembly multiply fuction for 8086 based machines + * beam diameter added to draw routine + * beam diameter is accurate in anti-alias line draw (Tcosin) + * flicker added .ac + * 980203 moved LBO's routines for drawing into a buffer of vertices + * from avgdvg.c to this location. Scaling is now initialized + * by calling vector_init(...). BW + * 980202 moved out of msdos.c ASG + * 980124 added anti-alias line draw routine + * modified avgdvg.c and sega.c to support new line draw routine + * added two new tables Tinten and Tmerge (for 256 color support) + * added find_color routine to build above tables .ac + * + * Vector Team + * + * Brad Oliver + * Aaron Giles + * Bernd Wiebelt + * Allard van der Bas + * Al Kossow (VECSIM) + * Hedley Rainnie (VECSIM) + * Eric Smith (VECSIM) + * Neil Bradley (technical advice) + * Andrew Caldwell (anti-aliasing) + * + **************************************************************************** */ + +#include "emu.h" +#include "emuopts.h" +#include "rendutil.h" +#include "vector.h" + +//make SUBTARGET=arcade + +//#include "libheliosdac/HeliosDacAPI.h" +#include "osc/OscOutboundPacketStream.h" + +#include "ip/IpEndpointName.h" + +#define ADDRESS "127.0.0.1" +#define PORT 7070 + +#define VECTOR_WIDTH_DENOM 512 + +#define MAX_POINTS 10000 + +float vector_options::s_flicker = 0.0f; +float vector_options::s_beam_width_min = 0.0f; +float vector_options::s_beam_width_max = 0.0f; +float vector_options::s_beam_intensity_weight = 0.0f; + +void vector_options::init(emu_options& options) +{ + s_beam_width_min = options.beam_width_min(); + s_beam_width_max = options.beam_width_max(); + s_beam_intensity_weight = options.beam_intensity_weight(); + s_flicker = options.flicker(); +} + +// device type definition +DEFINE_DEVICE_TYPE(VECTOR, vector_device, "vector_device", "VECTOR") + +vector_device::vector_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, VECTOR, tag, owner, clock), + device_video_interface(mconfig, *this), + m_vector_list(nullptr), + m_min_intensity(255), + m_max_intensity(0), + transmitSocket(IpEndpointName( ADDRESS, PORT )) +{ +} + +void vector_device::device_start() +{ + vector_options::init(machine().options()); + + m_vector_index = 0; + + /* allocate memory for tables */ + m_vector_list = make_unique_clear<point[]>(MAX_POINTS); +} + +/* + * www.dinodini.wordpress.com/2010/04/05/normalized-tunable-sigmoid-functions/ + */ +float vector_device::normalized_sigmoid(float n, float k) +{ + // valid for n and k in range of -1.0 and 1.0 + return (n - n * k) / (k - fabs(n) * 2.0f * k + 1.0f); +} + + +/* + * Adds a line end point to the vertices list. The vector processor emulation + * needs to call this. + */ +void vector_device::add_point(int x, int y, rgb_t color, int intensity) +{ + point *newpoint; + + intensity = std::max(0, std::min(255, intensity)); + + m_min_intensity = intensity > 0 ? std::min(m_min_intensity, intensity) : m_min_intensity; + m_max_intensity = intensity > 0 ? std::max(m_max_intensity, intensity) : m_max_intensity; + + if (vector_options::s_flicker && (intensity > 0)) + { + float random = (float)(machine().rand() & 255) / 255.0f; // random value between 0.0 and 1.0 + + intensity -= (int)(intensity * random * vector_options::s_flicker); + + intensity = std::max(0, std::min(255, intensity)); + } + + newpoint = &m_vector_list[m_vector_index]; + newpoint->x = x; + newpoint->y = y; + newpoint->col = color; + newpoint->intensity = intensity; + + m_vector_index++; + if (m_vector_index >= MAX_POINTS) + { + m_vector_index--; + logerror("*** Warning! Vector list overflow!\n"); + } +} + + +/* + * The vector CPU creates a new display list. We save the old display list, + * but only once per refresh. + */ +void vector_device::clear_list(void) +{ + m_vector_index = 0; +} + +#define OSC_BUFFER_SIZE 65535 +#define OSC_PACKET_LENGTH 5 + +uint32_t vector_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) +{ + uint32_t flags = PRIMFLAG_ANTIALIAS(1) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD) | PRIMFLAG_VECTOR(1); + const rectangle &visarea = screen.visible_area(); + float xscale = 1.0f / (65536 * visarea.width()); + float yscale = 1.0f / (65536 * visarea.height()); + float xoffs = (float)visarea.min_x; + float yoffs = (float)visarea.min_y; + + point *curpoint; + int lastx = 0; + int lasty = 0; + + curpoint = m_vector_list.get(); + + screen.container().empty(); + screen.container().add_rect(0.0f, 0.0f, 1.0f, 1.0f, rgb_t(0xff,0x00,0x00,0x00), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_VECTORBUF(1)); + + float m1,m2,m3,m4; + m1=m2=m3=m4=0.0f; + + char buffer[OSC_BUFFER_SIZE]; + osc::OutboundPacketStream p( buffer, OSC_BUFFER_SIZE ); + + + int MAX_PACKETS=OSC_BUFFER_SIZE/(OSC_PACKET_LENGTH*sizeof(float)); + + //theres a limit of ~54000 bytes for a udp packet this way + //hmm, this is failing with far less, like 14k + + int recorded=0; + + float oscdata[m_vector_index*5]; + int osccounter=0; + + for (int i = 0; i < m_vector_index; i++) + { + render_bounds coords; + + float intensity = (float)curpoint->intensity / 255.0f; + float intensity_weight = normalized_sigmoid(intensity, vector_options::s_beam_intensity_weight); + + // check for static intensity + float beam_width = m_min_intensity == m_max_intensity + ? vector_options::s_beam_width_min + : vector_options::s_beam_width_min + intensity_weight * (vector_options::s_beam_width_max - vector_options::s_beam_width_min); + + // normalize width + beam_width *= 1.0f / (float)VECTOR_WIDTH_DENOM; + + coords.x0 = ((float)lastx - xoffs) * xscale; + coords.y0 = ((float)lasty - yoffs) * yscale; + coords.x1 = ((float)curpoint->x - xoffs) * xscale; + coords.y1 = ((float)curpoint->y - yoffs) * yscale; + + if (coords.x0<m1) m1=coords.x0; + if (coords.y0<m2) m2=coords.y0; + if (coords.x0>m3) m3=coords.x0; + if (coords.y0>m4) m4=coords.y0; + + if ((recorded<MAX_PACKETS)&&((coords.x0!=coords.x1)||(coords.y0!=coords.y1))){ + oscdata[osccounter]=(coords.x0); + oscdata[++osccounter]=(coords.y0); + oscdata[++osccounter]=(beam_width); + *((uint32_t*)(&oscdata[++osccounter]))=(osc::int32)((curpoint->intensity << 24) | (curpoint->col & 0xffffff)); + osccounter++; + //p << coords.x1 << coords.y1 << beam_width; + //p << 1.0f; //(osc::int32)((curpoint->intensity << 24) | (curpoint->col & 0xffffff)); + recorded++; + } + + if (curpoint->intensity != 0) + { + screen.container().add_line( + coords.x0, coords.y0, coords.x1, coords.y1, + beam_width, + (curpoint->intensity << 24) | (curpoint->col & 0xffffff), + flags); + } + + lastx = curpoint->x; + lasty = curpoint->y; + + curpoint++; + + //std::cout << std::hex << (osc::int32)((curpoint->intensity << 24) | (curpoint->col & 0xffffff)) << std::endl; + } + + //(osc::int32)((curpoint->intensity << 24) | (curpoint->col & 0xffffff) + + /* + Tims-MacBook-Pro:mame tim$ sudo sysctl -w net.inet.udp.maxdgram=65535 + Password: + net.inet.udp.maxdgram: 9216 -> 65535 + */ + osc::Blob points=osc::Blob(oscdata,recorded*sizeof(float)*4); + + p << osc::BeginBundleImmediate << osc::BeginMessage( "/points" ) << recorded << points << osc::EndMessage << osc::EndBundle; + + transmitSocket.Send( p.Data(), p.Size() ); + + //if (recorded<m_vector_index){ + //std::cout << "Capacity: "<< p.Capacity() << " Sending " << p.Size() << " bytes, " << recorded << " packets of " << m_vector_index << std::endl; + //} + + return 0; +} diff --git a/oscReceiveExample/mame/vector.h b/oscReceiveExample/mame/vector.h new file mode 100644 index 0000000..658789e --- /dev/null +++ b/oscReceiveExample/mame/vector.h @@ -0,0 +1,71 @@ +// license:BSD-3-Clause +// copyright-holders:Brad Oliver,Aaron Giles,Bernd Wiebelt,Allard van der Bas +#ifndef MAME_VIDEO_VECTOR_H +#define MAME_VIDEO_VECTOR_H + +#pragma once + +#include "ip/UdpSocket.h" + +class vector_device; + +class vector_options +{ +public: + friend class vector_device; + + static float s_flicker; + static float s_beam_width_min; + static float s_beam_width_max; + static float s_beam_intensity_weight; + +protected: + static void init(emu_options& options); +}; + +class vector_device : public device_t, public device_video_interface +{ +public: + template <typename T> static constexpr rgb_t color111(T c) { return rgb_t(pal1bit(c >> 2), pal1bit(c >> 1), pal1bit(c >> 0)); } + template <typename T> static constexpr rgb_t color222(T c) { return rgb_t(pal2bit(c >> 4), pal2bit(c >> 2), pal2bit(c >> 0)); } + template <typename T> static constexpr rgb_t color444(T c) { return rgb_t(pal4bit(c >> 8), pal4bit(c >> 4), pal4bit(c >> 0)); } + + // construction/destruction + vector_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); + void clear_list(); + + void add_point(int x, int y, rgb_t color, int intensity); + + // device-level overrides + virtual void device_start() override; + +private: + /* The vertices are buffered here */ + struct point + { + point() : x(0), y(0), col(0), intensity(0) { } + + int x; int y; + rgb_t col; + int intensity; + }; + + std::unique_ptr<point[]> m_vector_list; + int m_vector_index; + int m_min_intensity; + int m_max_intensity; + + float normalized_sigmoid(float n, float k); + + UdpTransmitSocket transmitSocket; +}; + +// device type definition +DECLARE_DEVICE_TYPE(VECTOR, vector_device) + +#define MCFG_VECTOR_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, VECTOR, 0) + +#endif // MAME_VIDEO_VECTOR_H diff --git a/oscReceiveExample/src/main.cpp b/oscReceiveExample/src/main.cpp new file mode 100644 index 0000000..b156efd --- /dev/null +++ b/oscReceiveExample/src/main.cpp @@ -0,0 +1,14 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main( ){ + + ofSetupOpenGL(640,480, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new ofApp()); + +} diff --git a/oscReceiveExample/src/ofApp.cpp b/oscReceiveExample/src/ofApp.cpp new file mode 100644 index 0000000..b7dbc8f --- /dev/null +++ b/oscReceiveExample/src/ofApp.cpp @@ -0,0 +1,282 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + // listen on the given port + cout << "listening for osc messages on port " << PORT << "\n"; + receiver.setup(PORT); + +/* + ofxUDPSettings settings; + settings.receiveOn(PORT); + settings.blocking = false; + + udpConnection.Setup(settings); +*/ + current_msg_string = 0; + mouseX = 0; + mouseY = 0; + mouseButtonState = ""; + + ofSetWindowTitle("osc receiver"); + + poly.clear(); + + //ofSetFrameRate(50); + + copy_polys=1000; + create_polys=0; + + ofSetFrameRate(60); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + + // hide old messages + for(int i = 0; i < NUM_MSG_STRINGS; i++){ + if(timers[i] < ofGetElapsedTimef()){ + msg_strings[i] = ""; + } + } + + int received_frames=0; + int dumped_frames=0; + + int numpoints=0; + ofBuffer buf; + + // check for waiting messages + while(receiver.hasWaitingMessages()){ + + // get the next message + ofxOscMessage m; + receiver.getNextMessage(m); + + //cout << "got a message " << m.getAddress() << " args: "<< m.getNumArgs() << std::endl;; + + if(m.getAddress() == "/points"){ + // both the arguments are float's + + + + //for (int i=0;i<m.getNumArgs();i+=4){ + // poly.addVertex( + // m.getArgAsFloat(i)*ofGetScreenWidth(), + // m.getArgAsFloat(i+1)*ofGetScreenWidth(), + // ofColor(m.getArgAsInt32(i+3))); + //} + + numpoints=m.getArgAsInt(0); + + buf=m.getArgAsBlob(1); + + received_frames++; + + //cout << "got a message: " << numpoints << " points, " << buf.size() << " bytes" << std::endl;; + + + } + + // check for mouse moved message + else if(m.getAddress() == "/mouse/position"){ + // both the arguments are float's + mouseXf = m.getArgAsFloat(0); + mouseYf = m.getArgAsFloat(1); + } + // check for mouse button message + else if(m.getAddress() == "/mouse/button"){ + // first argument is int32, second is a string + mouseButtonInt = m.getArgAsInt32(0); + mouseButtonState = m.getArgAsString(1); + } + // check for an image being sent (note: the size of the image depends greatly on your network buffer sizes - if an image is too big the message won't come through ) + else if(m.getAddress() == "/image" ){ + ofBuffer buffer = m.getArgAsBlob(0); + receivedImage.load(buffer); + } + else{ + dumped_frames++; + // unrecognized message: display on the bottom of the screen + string msg_string; + msg_string = m.getAddress(); + msg_string += ":"; + for(int i = 0; i < m.getNumArgs(); i++){ + // get the argument type + msg_string += " "; + msg_string += m.getArgTypeName(i); + msg_string += ":"; + // display the argument - make sure we get the right type + if(m.getArgType(i) == OFXOSC_TYPE_INT32){ + msg_string += ofToString(m.getArgAsInt32(i)); + } + else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){ + msg_string += ofToString(m.getArgAsFloat(i)); + } + else if(m.getArgType(i) == OFXOSC_TYPE_STRING){ + msg_string += m.getArgAsString(i); + } + else{ + msg_string += "unknown"; + } + } + // add to the list of strings to display + msg_strings[current_msg_string] = msg_string; + timers[current_msg_string] = ofGetElapsedTimef() + 5.0f; + current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS; + // clear the next line + msg_strings[current_msg_string] = ""; + } + + } + + //cout << "got " << received_frames << " vector frames "; + //if (received_frames){ + // cout << poly[0] <<" "<<poly.getColourAt(0); + //} + //cout << std::endl; + + if (numpoints){ + poly.clear(); + + ofPolyline p; + + char* data=buf.getData(); + + int bufpoints=buf.size()/(sizeof(float)*4); + + float* floats=(float*) data; //new float[buf.size()/sizeof(float)]; + //memcpy(floats,data,buf.size()); + + uint32_t* ints=(uint32_t*)(floats); + + //for some reason this maxes out at ~600 points per second??? + //in the laser show we routinely copy 1000 per frame, at leat 25k? + + for (int i=0;i<min(copy_polys,numpoints);i++){ + uint8_t* pixel=(uint8_t*)(&ints[i*4+3]); + poly.addVertex( //why does this get shite performance? ridiculous + floats[i*4]*ofGetWidth(), + floats[i*4+1]*ofGetHeight(), + ofColor(pixel[2],pixel[1],pixel[0],pixel[3])); + + //cout << floats[i*4] << "," << floats[i*4+1] << " " << std::hex << ofColor(pixel[0],pixel[1],pixel[2],pixel[3]) << std::endl;; + + } + + //delete[] floats; + + stats_message=ofToString(received_frames)+": "+ofToString(poly.size()); //+" dumped: "+ofToString(dumped_frames); + + unsigned long points_to_dump=0; + + for (int i=0;i<min(points_to_dump,poly.size());i++){ + std::cout << poly[i].x << "," << poly[i].y << " " << ofToString(poly.getColourAt(i)) << std::endl; + } + } + +/* + char udpMessage[100000]; + if (udpConnection.Receive(udpMessage,100000)){ + cout << "got a packet "<< std::endl;; + + } +*/ + + +} + + +//-------------------------------------------------------------- +void ofApp::draw(){ + + colourPolyline testpoly; + + for (int i=0;i<create_polys;i++) testpoly.addVertex(ofRandom(ofGetWidth()),ofRandom(ofGetHeight())); + + std::stringstream strm; + strm << "fps: " << ofGetFrameRate(); + ofSetWindowTitle(strm.str()); + + ofBackground(0,0,0); + + ofSetColor(255,255,255); + + if(poly.size()) poly.drawDebug(SHOWBLACK); + + ofSetColor(255,255,255); + + ofDrawBitmapString(stats_message,10,ofGetHeight()-20); + + ofDrawBitmapString(ofToString(create_polys),10,ofGetHeight()-40); + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + + switch(key){ + case ',': + copy_polys=max(0,copy_polys-10); + break; + case '.': + copy_polys+=10; + break; + case '<': + create_polys=max(0,create_polys-10); + break; + case '>': + create_polys+=10; + break; + } + +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/oscReceiveExample/src/ofApp.h b/oscReceiveExample/src/ofApp.h new file mode 100644 index 0000000..bc91852 --- /dev/null +++ b/oscReceiveExample/src/ofApp.h @@ -0,0 +1,50 @@ +#pragma once + +#include "ofMain.h" +#include "ofxOsc.h" +#include "colourPolyline.h" + +#define PORT 7070 +#define NUM_MSG_STRINGS 20 + +class ofApp : public ofBaseApp { + public: + + void setup(); + void update(); + void draw(); + ~ofApp(){ + receiver.stop(); + } + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + ofTrueTypeFont font; + ofxOscReceiver receiver; + + int current_msg_string; + string msg_strings[NUM_MSG_STRINGS]; + float timers[NUM_MSG_STRINGS]; + + float mouseXf, mouseYf; + int mouseButtonInt; + string mouseButtonState; + + ofImage receivedImage; + colourPolyline poly; + + string stats_message; + + int copy_polys; + int create_polys; +}; |
