Пример #1
0
    std::vector<ActorUId> Scene::shutdown()
    {
        
        Controller::get()->eventManager()->removeListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneUpdate), SceneUpdateEvent::TYPE );
        Controller::get()->eventManager()->removeListener( fastdelegate::MakeDelegate(this, &Scene::handleReturnActorCreate), ReturnActorCreatedEvent::TYPE );
        Controller::get()->eventManager()->removeListener( fastdelegate::MakeDelegate(this, &Scene::handleScenePreDraw), ScenePreDrawEvent::TYPE );
        Controller::get()->eventManager()->removeListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneDraw), SceneDrawEvent::TYPE );
        Controller::get()->eventManager()->removeListener( fastdelegate::MakeDelegate(this, &Scene::handleShutDown), ShutDownEvent::TYPE );
        Controller::get()->eventManager()->removeListener(fastdelegate::MakeDelegate(this, &Scene::handleInitGUI), InitGUIEvent::TYPE);
        
        CI_LOG_V("shutting down scene...");
        std::vector<ActorUId> persistent_actors;
        std::vector<ActorUId> uninit_gui;
        for( auto & a : mActors)
        {
            uninit_gui.push_back(a.first);
            
            if( auto actor = a.second.lock() )
            {
                if(actor->isPersistent())
                    persistent_actors.push_back(a.first);
                else
                    ec::Controller::get()->eventManager()->triggerEvent(DestoryActorEvent::create(a.first));

            }
        }
        
        Controller::get()->eventManager()->triggerEvent(UninitGUIEvent::create(uninit_gui));
        
        CI_LOG_V("returning "+std::to_string(persistent_actors.size())+" persistent actors");
        mActors.clear();
        mSceneManager->clear();
        return persistent_actors;
    }
Пример #2
0
 void Scene::handleReturnActorCreate( EventDataRef event )
 {
     auto e = std::dynamic_pointer_cast<ReturnActorCreatedEvent>(event);
     auto actorWeak = e->getActorWeakRef();
     if ( auto actorStrong = actorWeak.lock() ) {
         CI_LOG_V("receieved actor create info: "+ actorStrong->getName());
         mActors.insert( std::make_pair(actorStrong->getUId(), actorWeak) );
     }else{
         CI_LOG_V("receieved actor create info: FAILED TO CREATE ACTOR");
     }
 }
Пример #3
0
Context::Context( const std::string &name ):mName(name),mState( State::create(this) ){
    
    std::string packagePath = "package.path = \'";
    
    std::string stream;
    stream = "Cinder-Luabind adding lua 'require' paths \n";
    
    for( auto & path : ci::app::getAssetDirectories() ){
        stream += path.string() + "\n";
        packagePath += path.string()+"/?;";
        packagePath += path.string()+"/?.lua;";
    }
    
    ///need to add this one, how to get the name??
    //    std::string appResourcePath = ci::app::getAppPath().string() + "/Script.app/Contents/Resources/";
    //    auto p1 = appResourcePath + "?;";
    //    auto p2 = appResourcePath + "?.lua;";
    
    packagePath += "\' .. package.path";
    
    runLuaScript(packagePath);
    
    CI_LOG_V( stream );

}
	void VDFbo::setFragmentShader(unsigned int aShaderIndex, string aFragmentShaderString, string aName) {
		try {
			mFboTextureShader = gl::GlslProg::create(mVDSettings->getDefaultVextexShaderString(), aFragmentShaderString);
			mFboTextureFragmentShaderString = aFragmentShaderString; // set only if compiles successfully
			// 20161209 problem on Mac mFboTextureShader->setLabel(aName);
			mFboName = aName;
			mShaderIndex = aShaderIndex;
		}
		catch (gl::GlslProgCompileExc &exc) {
			mError = string(exc.what());
			CI_LOG_V("unable to load/compile fragment shader:" + string(exc.what()));
		}
		catch (const std::exception &e) {
			mError = string(e.what());
			CI_LOG_V("unable to load fragment shader:" + string(e.what()));
		}
	}
Пример #5
0
JsonManagerRef JsonManager::create( const std::string &fileName )
{
	auto contents = getFileContents( fileName );
	sJsonManager = JsonManagerRef( new JsonManager( fileName, contents ) );
	sJsonManagerInitialized = true;
	CI_LOG_V("Created JsonManager");
	return JsonManager::get();
}
	bool VDFbo::fromXml(const XmlTree &xml) {
		mId = xml.getAttributeValue<string>("id", "");
		string mGlslPath = xml.getAttributeValue<string>("shadername", "0.frag");
		mWidth = xml.getAttributeValue<int>("width", mVDSettings->mFboWidth);
		mHeight = xml.getAttributeValue<int>("height", mVDSettings->mFboHeight);
		mInputTextureIndex = xml.getAttributeValue<int>("inputtextureindex", 0);
		CI_LOG_V("fbo id " + mId + "fbo shadername " + mGlslPath);
		mShaderName = mGlslPath;
		// 20161209 problem on Mac mFboTextureShader->setLabel(mShaderName);
		return true;
	}
void ReymentaServerApp::cleanup()
{
	// save warp settings
	Warp::writeSettings(mWarps, writeFile(mSettings));
	CI_LOG_V("shutdown");

	// save warp settings
	//mBatchass->getWarpsRef()->save();
	// save params
	mParameterBag->save();
	ui::Shutdown();
}
	VDFbo::VDFbo(VDSettingsRef aVDSettings, VDAnimationRef aVDAnimation)
		: mFilePathOrText("")
		, mFboName("fbo")
	{
		CI_LOG_V("VDFbo constructor");
		mVDSettings = aVDSettings;
		mVDAnimation = aVDAnimation;
		mType = UNKNOWN;

		mInputTextureIndex = 0; 


		mPosX = mPosY = 0.0f;
		mZoom = 1.0f;
		isReady = false;
		mFlipV = mFlipH = false;

		// init the fbo whatever happens next
		fboFmt.setColorTextureFormat(fmt);
		mFbo = gl::Fbo::create(mVDSettings->mFboWidth, mVDSettings->mFboHeight, fboFmt);
		mError = "";
		// init with passthru shader
		mShaderName = "0";

		// load feedback fragment shader
		try {
			mFboTextureShader = gl::GlslProg::create(mVDSettings->getDefaultVextexShaderString(), mVDSettings->getDefaultFragmentShaderString());
			CI_LOG_V("fbo default vtx-frag compiled");
		}
		catch (gl::GlslProgCompileExc &exc) {
			mError = string(exc.what());
			CI_LOG_V("fbo unable to load/compile vtx-frag shader:" + string(exc.what()));
		}
		catch (const std::exception &e) {
			mError = string(e.what());
			CI_LOG_V("fbo unable to load vtx-frag shader:" + string(e.what()));
		}
		mFboName = "default";
		if (mError.length() > 0) mVDSettings->mMsg = mError;
	}
std::vector<Polygon> PolygonApproximator::approximatePolygonsFromContours( std::vector<Contour> const & contours )
{
	std::vector<int> contourCoords;
	std::vector<int> approximatedPolygonCoords;

	contourCoords.reserve(100);
	approximatedPolygonCoords.reserve(40);

	std::vector<Polygon> approximatedPolygons;

	for ( auto & contour : contours )
	{
		contourCoords.clear();
		approximatedPolygonCoords.clear();

		for ( auto & pos : contour.mCoords )
		{
			contourCoords.push_back( pos.x );
			contourCoords.push_back( pos.y );
		}

		std::vector<int>::const_iterator begin = contourCoords.begin();
		std::vector<int>::const_iterator end = contourCoords.end();

		// In original implementation, Epsilon was:
		// cvContourPerimeter(mInnerContours)*0.02
		// Essentially the length of the contour * 0.02
		CI_LOG_V("Contour to approximate to polygon with: " << contourCoords.size() << " num coords" );
		psimpl::simplify_douglas_peucker<2>( begin, end, contour.calcPerimeter() * 0.02, std::back_inserter( approximatedPolygonCoords ) );
		CI_LOG_V( "Approximated polygon with: " << approximatedPolygonCoords.size() << " num coords" );

		approximatedPolygons.emplace_back( Polygon( approximatedPolygonCoords ));
	}

	return std::move( approximatedPolygons );
}
//! from json
void WarpPerspectiveBilinear::fromJson(const JsonTree &json)
{
	Warp::fromJson(json);
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// get corners
		JsonTree corners(warp.getChild("corners"));
		for (size_t i = 0; i < corners.getNumChildren(); i++) {
			JsonTree child = corners.getChild(i);
			float x = (child.hasChild("x")) ? child.getValueForKey<float>("x") : 0.0f;
			float y = (child.hasChild("y")) ? child.getValueForKey<float>("y") : 0.0f;
			mWarp->setControlPoint(i, vec2(x, y));
			CI_LOG_V("corner:" + toString(x) + " " + toString(y));
		}
	}
}
Пример #11
0
// static
void VM::readFileCallback(const uint8_t** data, intptr_t* fileLength, void* stream )
{
	CI_LOG_V( "bang" );
	if (!stream) {
		*data = 0;
		*fileLength = 0;
	} else {
		FILE* file = reinterpret_cast<FILE*>(stream);

		// Get the file size.
		fseek(file, 0, SEEK_END);
		*fileLength = ftell(file);
		rewind(file);

		// Allocate data buffer.
		*data = new uint8_t[*fileLength];
		*fileLength = fread(const_cast<uint8_t*>(*data), 1, *fileLength, file);
	}
}
Пример #12
0
// static
bool VM::interruptIsolateCallback()
{
	CI_LOG_V( "continuing.." );
	return true;
}
void PolygonApproximator::testSimplification()
{
	mTestPoly1.push_back( ci::vec2( 20, 20 ) );
	mTestPoly1.push_back( ci::vec2( 30, 40 ) );
	mTestPoly1.push_back( ci::vec2( 70, 140 ) );
	mTestPoly1.push_back( ci::vec2( 10, 99 ) );

	for ( float x = 30; x < 500; ++x )
	{
		mTestPoly1.push_back( ci::vec2( x, 200 + 200 * sin( x / 100 ) ) );
		CI_LOG_V( "pos " << ci::vec2( x, 200 + 200 * sin( x / 100 ) ) );
	}

	std::list<float> aList;

	for ( auto const & temp : mTestPoly1 )
	{
		aList.push_back( temp.x );
		aList.push_back( temp.y );
		CI_LOG_V( "this a coord?" << temp );
	}

	auto begin = aList.begin();
	auto end = aList.end();

	std::vector<float> aVec;

	psimpl::simplify_douglas_peucker<2>( begin, end, 100, std::back_inserter( aVec ) );

	for ( int vecIndex = 0; vecIndex < aVec.size(); )
	{
		mTestPoly1Reduced.push_back( ci::vec2( aVec[vecIndex], aVec[vecIndex + 1] ) );

		vecIndex += 2;
	}


	mTestPoly2.push_back( ci::vec2( 20, 20 ) );
	mTestPoly2.push_back( ci::vec2( 25, 15 ) );
	mTestPoly2.push_back( ci::vec2( 30, 10 ) );

	mTestPoly2.push_back( ci::vec2( 300, 10 ) );
	mTestPoly2.push_back( ci::vec2( 305, 15 ) );
	mTestPoly2.push_back( ci::vec2( 310, 20 ) );

	mTestPoly2.push_back( ci::vec2( 310, 320 ) );
	mTestPoly2.push_back( ci::vec2( 305, 325 ) );
	mTestPoly2.push_back( ci::vec2( 300, 330 ) );

	mTestPoly2.push_back( ci::vec2( 30, 330 ) );
	mTestPoly2.push_back( ci::vec2( 25, 325 ) );
	mTestPoly2.push_back( ci::vec2( 20, 320 ) );

	mTestPoly2.push_back( ci::vec2( 20, 20 ) );


	std::list<float> aList2;

	for ( auto const & temp : mTestPoly2 )
	{
		aList2.push_back( temp.x );
		aList2.push_back( temp.y );
	}

	auto begin2 = aList2.begin();
	auto end2 = aList2.end();

	std::vector<float> aVec2;

	psimpl::simplify_douglas_peucker<2>( begin2, end2, 50, std::back_inserter( aVec2 ) );

	for ( int vecIndex = 0; vecIndex < aVec2.size(); )
	{
		mTestPoly2Reduced.push_back( ci::vec2( aVec2[vecIndex], aVec2[vecIndex + 1] ) );

		vecIndex += 2;
	}

}
void ReymentaServerApp::fileDrop(FileDropEvent event)
{
	int index;
	string ext = "";
	// use the last of the dropped files
	const fs::path &mPath = event.getFile(event.getNumFiles() - 1);
	string mFile = mPath.string();
	int dotIndex = mFile.find_last_of(".");
	int slashIndex = mFile.find_last_of("\\");

	if (dotIndex != std::string::npos && dotIndex > slashIndex) ext = mFile.substr(mFile.find_last_of(".") + 1);
	index = (int)(event.getX() / (margin + mParameterBag->mPreviewFboWidth + inBetween));// +1;
	//mBatchass->log(mFile + " dropped, currentSelectedIndex:" + toString(mParameterBag->currentSelectedIndex) + " x: " + toString(event.getX()) + " PreviewFboWidth: " + toString(mParameterBag->mPreviewFboWidth));

	if (ext == "wav" || ext == "mp3")
	{
		//mAudio->loadWaveFile(mFile);
	}
	else if (ext == "png" || ext == "jpg")
	{
		if (index < 1) index = 1;
		if (index > 3) index = 3;
		//mTextures->loadImageFile(mParameterBag->currentSelectedIndex, mFile);
		mBatchass->getTexturesRef()->loadImageFile(index, mFile);
	}
	else if (ext == "glsl")
	{
		if (index < 4) index = 4;
		int rtn = mBatchass->getShadersRef()->loadPixelFragmentShaderAtIndex(mFile, index);
		if (rtn > -1 && rtn < mBatchass->getShadersRef()->getCount())
		{
			mParameterBag->controlValues[22] = 1.0f;
			// TODO  send content via websockets
			/*fs::path fr = mFile;
			string name = "unknown";
			if (mFile.find_last_of("\\") != std::string::npos) name = mFile.substr(mFile.find_last_of("\\") + 1);
			if (fs::exists(fr))
			{

			std::string fs = loadString(loadFile(mFile));
			if (mParameterBag->mOSCEnabled) mOSC->sendOSCStringMessage("/fs", 0, fs, name);
			}*/
			// save thumb
			//timeline().apply(&mTimer, 1.0f, 1.0f).finishFn([&]{ saveThumb(); });
		}
	}
	else if (ext == "mov" || ext == "mp4")
	{
		/*
		if (index < 1) index = 1;
		if (index > 3) index = 3;
		mBatchass->getTexturesRef()->loadMovieFile(index, mFile);*/
	}
	else if (ext == "fs")
	{
		//mShaders->incrementPreviewIndex();
		mBatchass->getShadersRef()->loadFragmentShader(mPath);
	}
	else if (ext == "xml")
	{
		mBatchass->getWarpsRef()->loadWarps(mFile);
	}
	else if (ext == "patchjson")
	{
		// try loading patch
		try
		{
			JsonTree patchjson;
			try
			{
				patchjson = JsonTree(loadFile(mFile));
				mParameterBag->mCurrentFilePath = mFile;
			}
			catch (cinder::JsonTree::Exception exception)
			{
				CI_LOG_V("patchjsonparser exception " + mFile + ": " + exception.what());

			}
			//Assets
			int i = 1; // 0 is audio
			JsonTree jsons = patchjson.getChild("assets");
			for (JsonTree::ConstIter jsonElement = jsons.begin(); jsonElement != jsons.end(); ++jsonElement)
			{
				string jsonFileName = jsonElement->getChild("filename").getValue<string>();
				int channel = jsonElement->getChild("channel").getValue<int>();
				if (channel < mBatchass->getTexturesRef()->getTextureCount())
				{
					CI_LOG_V("asset filename: " + jsonFileName);
					mBatchass->getTexturesRef()->setTexture(channel, jsonFileName);
				}
				i++;
			}

		}
		catch (...)
		{
			CI_LOG_V("patchjson parsing error: " + mFile);
		}
	}
	else if (ext == "txt")
	{
		// try loading shader parts
		if (mBatchass->getShadersRef()->loadTextFile(mFile))
		{

		}
	}
	else if (ext == "")
	{
		// try loading image sequence from dir
		if (index < 1) index = 1;
		if (index > 3) index = 3;
		mBatchass->getTexturesRef()->createFromDir(mFile + "/", index);
		// or create thumbs from shaders
		mBatchass->getShadersRef()->createThumbsFromDir(mFile + "/");
	}
}
Пример #15
0
void JsonManager::destroy()
{
	CI_LOG_V("Destroying JsonManager");
	sJsonManager = nullptr;
	sJsonManagerInitialized = false;
}
void ReymentaServerApp::update()
{
	if (mFirstLaunch) {
		CI_LOG_V("update begin");
		CI_LOG_V(getElapsedFrames());
	}
	mParameterBag->iFps = getAverageFps();
	mParameterBag->sFps = toString(floor(mParameterBag->iFps));
	getWindow()->setTitle("(" + mParameterBag->sFps + " fps) Server");
	if (mParameterBag->iGreyScale)
	{
		mParameterBag->controlValues[1] = mParameterBag->controlValues[2] = mParameterBag->controlValues[3];
		mParameterBag->controlValues[5] = mParameterBag->controlValues[6] = mParameterBag->controlValues[7];
	}

	mParameterBag->iChannelTime[0] = getElapsedSeconds();
	mParameterBag->iChannelTime[1] = getElapsedSeconds() - 1;
	mParameterBag->iChannelTime[3] = getElapsedSeconds() - 2;
	mParameterBag->iChannelTime[4] = getElapsedSeconds() - 3;
	//
	if (mParameterBag->mUseTimeWithTempo)
	{
		mParameterBag->iGlobalTime = mParameterBag->iTempoTime*mParameterBag->iTimeFactor;
	}
	else
	{
		mParameterBag->iGlobalTime = getElapsedSeconds();
	}
	mParameterBag->iGlobalTime *= mParameterBag->iSpeedMultiplier;

	if (ui::GetDrawData() != NULL) {
		if (mBatchass->isRemoteClientActive()) {
			// Count
			int cmd_count = 0;
			int vtx_count = 0;
			for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
			{
				const ImDrawList * cmd_list = ui::GetDrawData()->CmdLists[n];
				const ImDrawVert * vtx_src = cmd_list->VtxBuffer.begin();
				cmd_count += cmd_list->CmdBuffer.size();
				vtx_count += cmd_list->VtxBuffer.size();
			}

			// Send 
			static int sendframe = 0;
			if (sendframe++ >= 240) // every 2 frames, @TWEAK
			{
				sendframe = 0;
				if (cmd_count > 0 || vtx_count > 0) {

					mBatchass->preparePacketFrame(cmd_count, vtx_count);
					// Add all drawcmds
					Cmd cmd;
					for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
					{
						const ImDrawList* cmd_list = ui::GetDrawData()->CmdLists[n];
						const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end();
						for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != pcmd_end; pcmd++)
						{
							cmd.Set(*pcmd);
							mBatchass->Write(cmd);
						}
					}
					// Add all vtx
					Vtx vtx;
					for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
					{
						const ImDrawList* cmd_list = ui::GetDrawData()->CmdLists[n];
						const ImDrawVert* vtx_src = cmd_list->VtxBuffer.begin();
						int vtx_remaining = cmd_list->VtxBuffer.size();
						while (vtx_remaining-- > 0)
						{
							vtx.Set(*vtx_src++);
							mBatchass->Write(vtx);
						}
					}
					// Send
					mBatchass->SendPacket();
				}
			}
		}
		ImGuiIO& io = ImGui::GetIO();

		// Setup resolution (every frame to accommodate for window resizing)
		int w, h;
		int display_w, display_h;

		// Setup time step
		static double time = 0.0f;
		const double current_time = getElapsedSeconds();
		io.DeltaTime = (float)(current_time - time);
		time = current_time;
	}

	// @RemoteImgui begin
	/*ImGui::RemoteUpdate();
	ImGui::RemoteInput input;
	if (ImGui::RemoteGetInput(input))
	{
	ImGuiIO& io = ImGui::GetIO();
	for (int i = 0; i < 256; i++)
	io.KeysDown[i] = input.KeysDown[i];
	io.KeyCtrl = input.KeyCtrl;
	io.KeyShift = input.KeyShift;
	io.MousePos = input.MousePos;
	io.MouseDown[0] = (input.MouseButtons & 1);
	io.MouseDown[1] = (input.MouseButtons & 2) != 0;
	io.MouseWheel = (float)input.MouseWheel;
	}
	else*/
	// @RemoteImgui end
	{
		// Setup inputs
		// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
		//double mouse_x, mouse_y;
		//glfwGetCursorPos(window, &mouse_x, &mouse_y);
		//mouse_x *= (float)display_w / w;                                                               // Convert mouse coordinates to pixels
		//mouse_y *= (float)display_h / h;
		//io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);                                          // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
		//io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;  // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
		//io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0;
	}
	mBatchass->update();
	mProg->uniform("iGlobalTime", static_cast<float>(getElapsedSeconds()));
	//mProg->uniform("iMouse", mMouseCoord);
	//mProg->uniform("iChannel0", 0);

	if (mFirstLaunch) {
		CI_LOG_V("update end");
	}

}
Пример #17
0
JsonManager::~JsonManager()
{
	CI_LOG_V("JsonManagerDestroyed");
}
void ReymentaServerApp::draw()
{
	if (mFirstLaunch) {
		CI_LOG_V("draw begin");
	}
	// clear the window and set the drawing color to white
	gl::clear();
	gl::color(Color::white());
	// draw the fbos
	mBatchass->getTexturesRef()->draw();
	gl::enableAlphaBlending();
	//gl::setMatricesWindow(mParameterBag->mRenderWidth, mParameterBag->mRenderHeight);
	if (mImage) {
		// iterate over the warps and draw their content
		for (auto &warp : mWarps) {
			// there are two ways you can use the warps:
			if (mUseBeginEnd) {
				// a) issue your draw commands between begin() and end() statements
				warp->begin();

				// in this demo, we want to draw a specific area of our image,
				// but if you want to draw the whole image, you can simply use: gl::draw( mImage );
				gl::draw(mImage, mSrcArea, warp->getBounds());

				warp->end();
			}
			else {
				// b) simply draw a texture on them (ideal for video)

				// in this demo, we want to draw a specific area of our image,
				// but if you want to draw the whole image, you can simply use: warp->draw( mImage );
				warp->draw(mBatchass->getTexturesRef()->getTexture(11), mSrcArea);
			}
		}
	}
	gl::disableAlphaBlending();
	//imgui
	ui::NewFrame();

	gl::setMatricesWindow(getWindowSize());
	xPos = margin;
	yPos = margin + 30;

#pragma region Info

	ui::SetNextWindowSize(ImVec2(largePreviewW + 20, largePreviewH), ImGuiSetCond_Once);
	ui::SetNextWindowPos(ImVec2(xPos, yPos), ImGuiSetCond_Once);
	sprintf_s(buf, "Fps %c %d###fps", "|/-\\"[(int)(ImGui::GetTime() / 0.25f) & 3], (int)mParameterBag->iFps);
	ui::Begin(buf);
	{
		ImGui::PushItemWidth(mParameterBag->mPreviewFboWidth);
		// fps
		static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); }
		static int values_offset = 0;
		static float refresh_time = -1.0f;
		if (ui::GetTime() > refresh_time + 1.0f / 6.0f)
		{
			refresh_time = ui::GetTime();
			values[values_offset] = mParameterBag->iFps;
			values_offset = (values_offset + 1) % values.size();
		}
		if (mParameterBag->iFps < 12.0) ui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 0, 0, 1));
		ui::PlotLines("FPS", &values.front(), (int)values.size(), values_offset, mParameterBag->sFps.c_str(), 0.0f, 300.0f, ImVec2(0, 30));
		if (mParameterBag->iFps < 12.0) ui::PopStyleColor();

		// Checkbox
		ui::Checkbox("Tex", &showTextures);
		ui::SameLine();
		ui::Checkbox("Fbos", &showFbos);
		ui::SameLine();
		ui::Checkbox("Shada", &showShaders);

		ui::Checkbox("Audio", &showAudio);
		ui::SameLine();
		ui::Checkbox("Cmd", &showConsole);
		ui::SameLine();
		ui::Checkbox("OSC", &showOSC);

		ui::Checkbox("MIDI", &showMidi);
		ui::SameLine();
		ui::Checkbox("Test", &showTest);
		if (ui::Button("Save Params"))
		{
			// save warp settings
			mBatchass->getWarpsRef()->save("warps1.xml");
			// save params
			mParameterBag->save();
		}

		mParameterBag->iDebug ^= ui::Button("Debug");
		ui::SameLine();
		mParameterBag->mRenderThumbs ^= ui::Button("Thumbs");
		ui::PopItemWidth();
		if (ui::Button("Stop Loading")) mBatchass->stopLoading();
	}
	ui::End();
	xPos += largePreviewW + 20 + margin;

#pragma endregion Info


#pragma region WebSockets
	// websockets
	ui::SetNextWindowSize(ImVec2(largePreviewW + 20, largePreviewH), ImGuiSetCond_Once);
	ui::SetNextWindowPos(ImVec2(xPos, yPos), ImGuiSetCond_Once);
	ui::Begin("WebSockets server");
	{
		if (mParameterBag->mIsWebSocketsServer)
		{
			ui::Text("WS Server %d", mParameterBag->mWebSocketsPort);
			ui::Text("IP %s", mParameterBag->mWebSocketsHost.c_str());
		}
		else
		{
			ui::Text("WS Client %d", mParameterBag->mWebSocketsPort);
			ui::Text("IP %s", mParameterBag->mWebSocketsHost.c_str());
		}
		if (ui::Button("Connect")) { mBatchass->wsConnect(); }
		ui::SameLine();
		if (ui::Button("Ping")) { mBatchass->wsPing(); }
	}

	ui::End();
	xPos += largePreviewW + 20 + margin;
#pragma endregion WebSockets


	// console
	if (showConsole)
	{
		ui::SetNextWindowSize(ImVec2((w + margin) * mParameterBag->MAX, largePreviewH), ImGuiSetCond_Once);
		ui::SetNextWindowPos(ImVec2(xPos, yPos), ImGuiSetCond_Once);
		ShowAppConsole(&showConsole);
		if (mParameterBag->newMsg)
		{
			mParameterBag->newMsg = false;
			mConsole->AddLog(mParameterBag->mMsg.c_str());
		}
	}
	if (showTest)
	{
		ui::ShowTestWindow();
		ui::ShowStyleEditor();
	}

#pragma region MIDI

	// MIDI window
	if (showMidi)
	{
		ui::SetNextWindowSize(ImVec2(largePreviewW + 20, largePreviewH), ImGuiSetCond_Once);
		ui::SetNextWindowPos(ImVec2(xPos, yPos), ImGuiSetCond_Once);
		ui::Begin("MIDI");
		{
			sprintf_s(buf, "Enable");
			if (ui::Button(buf)) mBatchass->midiSetup();
			if (ui::CollapsingHeader("MidiIn", "20", true, true))
			{
				ui::Columns(2, "data", true);
				ui::Text("Name"); ui::NextColumn();
				ui::Text("Connect"); ui::NextColumn();
				ui::Separator();

				for (int i = 0; i < mBatchass->midiInCount(); i++)
				{
					ui::Text(mBatchass->midiInPortName(i).c_str()); ui::NextColumn();

					if (mBatchass->midiInConnected(i))
					{
						sprintf_s(buf, "Disconnect %d", i);
					}
					else
					{
						sprintf_s(buf, "Connect %d", i);
					}

					if (ui::Button(buf))
					{
						if (mBatchass->midiInConnected(i))
						{
							mBatchass->midiInClosePort(i);
						}
						else
						{
							mBatchass->midiInOpenPort(i);
						}
					}
					ui::NextColumn();
					ui::Separator();
				}
				ui::Columns(1);
			}
		}
		ui::End();
		xPos += largePreviewW + 20 + margin;
		yPos = margin;

	}
#pragma endregion MIDI

#pragma region OSC

	if (showOSC && mParameterBag->mOSCEnabled)
	{
		ui::SetNextWindowSize(ImVec2(largeW, largeH), ImGuiSetCond_Once);
		ui::SetNextWindowPos(ImVec2(xPos, yPos), ImGuiSetCond_Once);
		ui::Begin("OSC router");
		{
			ui::Text("Sending to host %s", mParameterBag->mOSCDestinationHost.c_str());
			ui::SameLine();
			ui::Text(" on port %d", mParameterBag->mOSCDestinationPort);
			ui::Text("Sending to 2nd host %s", mParameterBag->mOSCDestinationHost2.c_str());
			ui::SameLine();
			ui::Text(" on port %d", mParameterBag->mOSCDestinationPort2);
			ui::Text(" Receiving on port %d", mParameterBag->mOSCReceiverPort);

			static char str0[128] = "/live/play";
			static int i0 = 0;
			static float f0 = 0.0f;
			ui::InputText("address", str0, IM_ARRAYSIZE(str0));
			ui::InputInt("track", &i0);
			ui::InputFloat("clip", &f0, 0.01f, 1.0f);
			if (ui::Button("Send")) { mBatchass->sendOSCIntMessage(str0, i0); }
		}
		ui::End();
		xPos += largeW + margin;
	}
#pragma endregion OSC

	ui::Render();

	gl::ScopedGlslProg shader(mBatchass->getShadersRef()->getLiveShader());
	//gl::ScopedGlslProg shader(mProg);

	gl::draw(mMesh);
	if (mFirstLaunch) {
		CI_LOG_V("draw end");
		mFirstLaunch = false;
	}

}
Пример #19
0
// static
void VM::closeFileCallback(void* file)
{
	CI_LOG_V( "bang" );

	fclose(reinterpret_cast<FILE*>(file));
}
Пример #20
0
// static
void VM::shutdownIsolateCallback( void *callbackData )
{
	CI_LOG_V( "bang" );
}
void ReymentaServerApp::setup()
{
	// parameters
	mParameterBag = ParameterBag::create();
	mParameterBag->mLiveCode = true;
	mParameterBag->mRenderThumbs = false;
	loadShader(getAssetPath("default.fs"));
	// utils
	mBatchass = Batchass::create(mParameterBag);
	CI_LOG_V("reymenta setup");
	mFirstLaunch = true;

	setWindowSize(mParameterBag->mMainWindowWidth, mParameterBag->mMainWindowHeight);
	// 12 fps is enough for a router
	setFrameRate(120.0f);
	setWindowPos(ivec2(0, 40));

	// setup shaders and textures
	mBatchass->setup();

	mParameterBag->mMode = MODE_WARP;
	mParameterBag->iResolution.x = mParameterBag->mRenderWidth;
	mParameterBag->iResolution.y = mParameterBag->mRenderHeight;
	mParameterBag->mRenderResolution = ivec2(mParameterBag->mRenderWidth, mParameterBag->mRenderHeight);

	CI_LOG_V("createRenderWindow, resolution:" + toString(mParameterBag->iResolution.x) + "x" + toString(mParameterBag->iResolution.y));
	mParameterBag->mRenderResoXY = vec2(mParameterBag->mRenderWidth, mParameterBag->mRenderHeight);
	mParameterBag->mRenderPosXY = ivec2(mParameterBag->mRenderX, mParameterBag->mRenderY);

	// instanciate the console class
	mConsole = AppConsole::create(mParameterBag, mBatchass);

	// imgui
	margin = 3;
	inBetween = 3;
	// mPreviewFboWidth 80 mPreviewFboHeight 60 margin 10 inBetween 15 mPreviewWidth = 160;mPreviewHeight = 120;
	w = mParameterBag->mPreviewFboWidth + margin;
	h = mParameterBag->mPreviewFboHeight * 2.3;
	largeW = (mParameterBag->mPreviewFboWidth + margin) * 4;
	largeH = (mParameterBag->mPreviewFboHeight + margin) * 5;
	largePreviewW = mParameterBag->mPreviewWidth + margin;
	largePreviewH = (mParameterBag->mPreviewHeight + margin) * 2.4;
	displayHeight = mParameterBag->mMainDisplayHeight - 50;
	mouseGlobal = false;
	showConsole = showGlobal = showTextures = showAudio = showMidi = showChannels = showShaders = true;
	showTest = showTheme = showOSC = showFbos = false;
	/* set ui window and io events callbacks
	   with autorender == false, we have to use NewFrame and Render
	   but we have access to DrawData to send to remoteImGui
	   void Renderer::initFontTexture()
	   {
	   unsigned char* pixels;
	   int width, height;
	   ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
	   mFontTexture = gl::Texture::create( pixels, GL_RGBA, width, height, gl::Texture::Format().magFilter(GL_LINEAR).minFilter(GL_LINEAR) );
	   ImGui::GetIO().Fonts->ClearTexData();
	   ImGui::GetIO().Fonts->TexID = (void *)(intptr_t) mFontTexture->getId();
	   }
	  
	ui::initialize(ui::Options().autoRender(false).fonts({
		{ getAssetPath("KontrapunktBob-Light.ttf"), 12 },
		{ getAssetPath("KontrapunktBob-Bold.ttf"), 20 },
		{ getAssetPath("DroidSans.ttf"), 12 }
	})
	.fontGlyphRanges("DroidSans", { 0xf000, 0xf06e, 0 })); */
	ui::initialize(ui::Options().autoRender(false));

	// warping
	mUseBeginEnd = false;
	updateWindowTitle();
	disableFrameRate();

	// initialize warps
	mSettings = getAssetPath("") / "warps.xml";
	if (fs::exists(mSettings)) {
		// load warp settings from file if one exists
		mWarps = Warp::readSettings(loadFile(mSettings));
	}
	else {
		// otherwise create a warp from scratch
		mWarps.push_back(WarpBilinear::create());
		mWarps.push_back(WarpPerspective::create());
		mWarps.push_back(WarpPerspectiveBilinear::create());
	}

	// load test image
	try {
		mImage = gl::Texture::create(loadImage(loadAsset("help.jpg")),
			gl::Texture2d::Format().loadTopDown().mipmap(true).minFilter(GL_LINEAR_MIPMAP_LINEAR));

		//mSrcArea = mImage->getBounds();

		// adjust the content size of the warps
		Warp::setSize(mWarps, mImage->getSize());
	}
	catch (const std::exception &e) {
		console() << e.what() << std::endl;
	}
	mSrcArea = Area(0, 0, mParameterBag->mFboWidth*4, mParameterBag->mFboHeight*4);
	mMesh = gl::VboMesh::create(geom::Rect());
}
Пример #22
0
	gl::GlslProgRef VDFbo::getShader() {
		auto &uniforms = mFboTextureShader->getActiveUniforms();
		for (const auto &uniform : uniforms) {
			//CI_LOG_V(mFboTextureShader->getLabel() + ", getShader uniform name:" + uniform.getName());
			if (mVDAnimation->isExistingUniform(uniform.getName())) {
				int uniformType = mVDAnimation->getUniformType(uniform.getName());
				switch (uniformType)
				{
				case 0:
					// float
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getFloatUniformValueByName(uniform.getName()));
					break;
				case 1:
					// sampler2D
					mFboTextureShader->uniform(uniform.getName(), mInputTextureIndex);
					break;
				case 2:
					// vec2
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getVec2UniformValueByName(uniform.getName()));
					break;
				case 3:
					// vec3
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getVec3UniformValueByName(uniform.getName()));
					break;
				case 4:
					// vec4
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getVec4UniformValueByName(uniform.getName()));
					break;
				case 5:
					// int
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getIntUniformValueByName(uniform.getName()));
					break;
				case 6:
					// bool
					mFboTextureShader->uniform(uniform.getName(), mVDAnimation->getBoolUniformValueByName(uniform.getName()));
					break;
				default:
					break;
				}
			}
			else {
				if (uniform.getName() != "ciModelViewProjection") {
					mVDSettings->mMsg = mShaderName + ", uniform not found:" + uniform.getName();
					CI_LOG_V(mVDSettings->mMsg);
				}
			}
		}
		// feedback
		/*auto &fbuniforms = mFeedbackShader->getActiveUniforms();
		for (const auto &uniform : fbuniforms) {
			//CI_LOG_V(mFboTextureShader->getLabel() + ", getShader uniform name:" + uniform.getName());
			if (mVDAnimation->isExistingUniform(uniform.getName())) {
				int uniformType = mVDAnimation->getUniformType(uniform.getName());
				switch (uniformType)
				{
				case 0:
					// float
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getFloatUniformValueByName(uniform.getName()));
					break;
				case 1:
					// sampler2D
					mFeedbackShader->uniform(uniform.getName(), mCurrentFeedbackIndex);
					break;
				case 2:
					// vec2
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getVec2UniformValueByName(uniform.getName()));
					break;
				case 3:
					// vec3
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getVec3UniformValueByName(uniform.getName()));
					break;
				case 4:
					// vec4
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getVec4UniformValueByName(uniform.getName()));
					break;
				case 5:
					// int
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getIntUniformValueByName(uniform.getName()));
					break;
				case 6:
					// bool
					mFeedbackShader->uniform(uniform.getName(), mVDAnimation->getBoolUniformValueByName(uniform.getName()));
					break;
				default:
					break;
				}
			}
			else {
				if (uniform.getName() != "ciModelViewProjection") {
					mVDSettings->mMsg =  "feedback shader, uniform not found:" + uniform.getName();
					CI_LOG_V(mVDSettings->mMsg);
				}
			}
		}*/
		return mFboTextureShader;
	}
Пример #23
0
// file callbacks have been copied verbatum from included sample... plus verbose logging. don't event know yet if we need them
// static
void* VM::openFileCallback(const char* name, bool write)
{
	CI_LOG_V( "name: " << name << ", write mode: " << boolalpha << write << dec );
	
	return fopen(name, write ? "w" : "r");
}
Пример #24
0
 void Scene::update()
 {
     CI_LOG_V("base scene updating...");
     mSceneManager->update();
     CI_LOG_V("base scene updated");
 }
Пример #25
0
// static
void VM::writeFileCallback(const void* data, intptr_t length, void* file)
{
	CI_LOG_V( "bang" );

	fwrite(data, 1, length, reinterpret_cast<FILE*>(file));
}
Пример #26
0
NanoTexture::~NanoTexture() {
    CI_LOG_V("NanoTexture Destroyed");
}
Пример #27
0
NanoTexture::NanoTexture() {
    CI_LOG_V("NanoTexture Created");
}
Пример #28
0
    void Scene::initialize( const std::vector<ActorUId>& persistent_actors )
    {
        mSceneManager = EventManager::create("Scene "+mName+" Manager");
        Controller::get()->eventManager()->addListener(fastdelegate::MakeDelegate(this, &Scene::handleInitGUI), InitGUIEvent::TYPE);
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneUpdate), SceneUpdateEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleReturnActorCreate), ReturnActorCreatedEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleScenePreDraw), ScenePreDrawEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneDraw), SceneDrawEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleShutDown), ShutDownEvent::TYPE );
        
        if( !persistent_actors.empty() ){
            for(auto &id : persistent_actors)
            {
                auto actor_weak = ActorManager::get()->retreiveUnique(id);
                mActors.insert( std::make_pair(id, actor_weak) );
            }
        }
        
        auto init = ConfigManager::get()->retreiveActorsForScene( mName );
        
        ///call to inherited initialize for sub classes to pulll custom shit out of the config
        initialize( ConfigManager::get()->retreiveScene(mName) );
        
        try {
            
            //TODO: the problem with persistent actors is how to manage state across scenes, how to identify actors of the same type across scenes that are persistent, one solution is destroy all and reload referencing a serialized state file that is written out and read back in or something
            //for now, just sending across actors marked 'persistent' and not including them in the config for the next scene, the state has to be handled at runtime then
            
            auto & actors = init.getChildren();
            
            auto it = actors.begin();
            auto end = actors.end();
            for(;it!=end;++it){
                auto actor_name = it->getValueForKey("name");
                CI_LOG_V("found actor: "+actor_name);

                auto onInit = it->getValueForKey<bool>( "create_on_scene_init" );
                auto persistent = it->getValueForKey<bool>( "persistent" );
                
                if( persistent ){
                    //make sure its not already in there
                   if( !ec::ActorManager::get()->actorExists( ec::getHash(actor_name) ) ){
                       if( onInit ){
                           //make sure it shuld be created on scene init
                           CI_LOG_V("creating actor: "+actor_name);
                           Controller::get()->eventManager()->triggerEvent( CreateActorEvent::create( mName, actor_name) );
                       }
                    }
                }else if (onInit){
                    //make sure it shuld be created on scene init
                    CI_LOG_V("creating actor: "+actor_name);
                    Controller::get()->eventManager()->triggerEvent( CreateActorEvent::create( mName, actor_name) );

                }

                
            }
            
        } catch (const ci::JsonTree::ExcChildNotFound &e) {
            CI_LOG_E("actors not found in init");
        }
        
      
        ///POST INITIALIZE ALL ACTORS
        auto actor = mActors.begin();
        auto end = mActors.end();
        
        while( actor != end )
        {
            if(auto a = (*actor).second.lock()){
                a->postInit();
                ++actor;
            }else{
                CI_LOG_E("Actor is missing");
                ec::Controller::get()->eventManager()->triggerEvent(DestoryActorEvent::create((*actor).first));
                actor = mActors.erase(actor);
            }
        }
        
        postInit();
        
        ///run setup events;
        manager()->update();
        
    }