//------------------------------------------------------------------------// bool MusicManager::LoadDLS(ScriptNode* pNode) { FN("MusicManager::LoadDLS()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for DLS identifier"); // Make sure the segment ID doesn't already exist IDLSMap::iterator itr = m_DLSMap.find(pNode->GetString()); if(itr != m_DLSMap.end()) return true; DLSInit init; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) init.m_sFileName = pChildNode->GetString(); pChildNode = pChildNode->GetSibling(); } IDLS* pDLS; if(!AudioMgr()->CreateDLS(pDLS)) return false; if(!pDLS->Init(init)) return false; m_pCurrentDLS = pDLS; // Insert the segment into the map m_DLSMap.insert(make_pair(pNode->GetString(), pDLS)); return true; }
//------------------------------------------------------------------------// bool MusicManager::LoadThemeNode(ScriptNode* pNode, Theme* pTheme) { FN("MusicManager::LoadThemeNode()"); if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for theme node"); ISegment* pSegmentSource = 0; Theme* pThemeSource = 0; // First look for matching segments based on the id value ISegmentMap::iterator itr = m_SegmentMap.find(pNode->GetString()); if(itr == m_SegmentMap.end()) { // Next, look for matching themes ThemeMap::iterator itor = m_ThemeMap.find(pNode->GetString()); if(itor == m_ThemeMap.end()) return Error::Handle("Unknown id %s in theme node", pNode->GetString()); pThemeSource = itor->second; if(!pTheme->CreateNode(pThemeSource)) return Error::Handle("Could not create theme node"); } else { pSegmentSource = itr->second; if(!pTheme->CreateNode(pSegmentSource)) return Error::Handle("Could not create theme node"); } ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "Dest") == 0) { itr = m_SegmentMap.find(pChildNode->GetString()); if(itr == m_SegmentMap.end()) return Error::Handle("Unknown id %s in theme node", pChildNode->GetString()); ISegment* pDest = itr->second; if(pThemeSource) { if(!pTheme->CreateTransition(pThemeSource, pDest)) return Error::Handle("Error creating theme node transition"); } else { if(!pTheme->CreateTransition(pSegmentSource, pDest)) return Error::Handle("Error creating theme node transition"); } } else { return Error::Handle("Unknown syntax or keyword in theme node"); } pChildNode = pChildNode->GetSibling(); } return true; }
void InteractiveRender::parentChanged( GraphComponent *child, GraphComponent *oldParent ) { ScriptNode *n = ancestor<ScriptNode>(); if( n ) { setContext( n->context() ); } else { setContext( new Context() ); } }
ScriptNode *SceneGraph::findScriptNode(char *name) { if (!name || strlen(name) <= 0) return NULL; for (ScriptNode *node = findScriptNode(); node; node = node->nextTraversal()) { const char *nodeName = node->getName(); if (nodeName && strlen(nodeName)) { if (!strcmp(name, nodeName)) return node; } } return NULL; }
void Node::removeSFNodes() { SceneGraph *sg = getSceneGraph(); if (sg) { for (ScriptNode *script = sg->findScriptNode(); script; script=script->nextTraversal()) { for (int n=0; n<script->getNFields(); n++) { Field *field = script->getField(n); if (field->getType() == fieldTypeSFNode) { SFNode *sfnode = (SFNode *)field; if (sfnode->getValue() == this) sfnode->setValue((Node *)NULL); } } } } }
void Action::enact( ActionPtr action ) { ScriptNode *s = IECore::runTimeCast<ScriptNode>( action->subject() ); if( !s ) { s = action->subject()->ancestor<ScriptNode>(); } if( s ) { s->addAction( action ); } else { action->doAction(); } }
//------------------------------------------------------------------------// bool MusicManager::LoadSegment(ScriptNode* pNode) { FN("MusicManager::LoadSegment()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound identifier"); // Make sure the segment ID doesn't already exist ISegmentMap::iterator itr = m_SegmentMap.find(pNode->GetString()); if(itr != m_SegmentMap.end()) return true; SegmentInit init; ScriptNode* pChildNode = pNode->GetChild(); init.m_pDLS = m_pCurrentDLS; while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) init.m_sFileName = pChildNode->GetString(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) init.m_bLooping = pChildNode->GetBool(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "Music") == 0) init.m_bMusic = pChildNode->GetBool(); else if(MUSMGR_STRCMP(pChildNode->GetName(), "DLS") == 0) { IDLSMap::iterator itr = m_DLSMap.find(pChildNode->GetString()); if(itr != m_DLSMap.end()) init.m_pDLS = itr->second; } pChildNode = pChildNode->GetSibling(); } ISegment* pSegment; if(!AudioMgr()->CreateSegment(pSegment)) return false; if(!pSegment->Init(init)) return false; // Insert the segment into the map m_SegmentMap.insert(make_pair(pNode->GetString(), pSegment)); return true; }
void BoxIO::setup( const Plug *plug ) { if( inPlugInternal() ) { throw IECore::Exception( "Plugs already set up" ); } addChild( plug->createCounterpart( inPlugName(), Plug::In ) ); addChild( plug->createCounterpart( outPlugName(), Plug::Out ) ); inPlugInternal()->setFlags( Plug::Serialisable, true ); outPlugInternal()->setFlags( Plug::Serialisable, true ); applyDynamicFlag( inPlugInternal() ); applyDynamicFlag( outPlugInternal() ); MetadataAlgo::copy( plug, m_direction == Plug::In ? inPlugInternal() : outPlugInternal(), /* exclude = */ "layout:*" ); setupNoduleSectionMetadata( m_direction == Plug::In ? outPlugInternal() : inPlugInternal(), plug ); if( m_direction == Plug::Out ) { setupPassThrough(); } else { outPlugInternal()->setInput( inPlugInternal() ); } // We also want to set up our promoted plug. But if we're // being created from a script execution, we don't need to // do that ourselves because it'll have been serialised into // the script. ScriptNode *script = scriptNode(); if( !script || !script->isExecuting() ) { setupPromotedPlug(); } }
void UndoDiagramModuleCutActionFn(void *info) { TransformNode *dgmNode = ((UndoDiagramModuleCut *)info)->mpDiagramNode; CDiagramClipboard *clipboard = ((UndoDiagramModuleCut *)info)->mpClipboard; CDiagram dgm(dgmNode); int nModule = clipboard->getNModuleNodes(); ScriptNode* (*moduleNode)[2] = new (ScriptNode *[nModule][2]); for (int n=0; n<nModule; n++) { CModule orgModule(clipboard->getModuleNode(n)); CModule copyModule(orgModule.getModuleType()); copyModule.setPositionX(orgModule.getPositionX()); copyModule.setPositionY(orgModule.getPositionY()); dgm.addModule(©Module); moduleNode[n][0] = orgModule.getScriptNode(); moduleNode[n][1] = copyModule.getScriptNode(); } int nRoute = clipboard->getNRoutes(); for (n=0; n<nRoute; n++) { Route *route = clipboard->getRoute(n); ScriptNode *outModule = (ScriptNode *)route->getEventOutNode(); for (int i=0; i<nModule; i++) { if (moduleNode[i][0] == outModule) { outModule = moduleNode[i][1]; break; } } ScriptNode *inModule = (ScriptNode *)route->getEventInNode(); for (i=0; i<nModule; i++) { if (moduleNode[i][0] == inModule) { inModule = moduleNode[i][1]; break; } } GetWorld()->getSceneGraph()->addRoute(outModule->getName(), route->getEventOutField()->getName(), inModule->getName(), route->getEventInField()->getName()); } delete []moduleNode; delete clipboard; }
void closeDevice() { g_Player.Release(); g_Device.Release(); g_Depth.Release(); g_Image.Release(); g_IR.Release(); g_Audio.Release(); g_scriptNode.Release(); g_Context.Release(); }
void CleanUpExit() { recorder.Release(); g_player.Release(); g_image.Release(); g_scriptNode.Release(); g_context.Release(); g_hands.Release(); g_gesture.Release(); free(g_pTexMap); exit(1); }
//------------------------------------------------------------------------// bool MusicManager::LoadTheme(ScriptNode* pNode) { FN("MusicManager::LoadTheme()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for theme identifier"); Theme* pTheme = 0; // Make sure the theme ID doesn't already exist ThemeMap::iterator itr = m_ThemeMap.find(pNode->GetString()); if(itr != m_ThemeMap.end()) pTheme = itr->second; else pTheme = new Theme; if(!pTheme) return false; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(MUSMGR_STRCMP(pChildNode->GetName(), "Src") == 0) { if(!LoadThemeNode(pChildNode, pTheme)) return false; } else if(MUSMGR_STRCMP(pChildNode->GetName(), "Interlude") == 0) { pTheme->SetInterlude(pChildNode->GetBool()); } else return false; pChildNode = pChildNode->GetSibling(); } // Insert the theme into the map m_ThemeMap.insert(make_pair(pNode->GetString(), pTheme)); return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadSoundScape(ScriptNode* pNode) { FN("SoundManager::LoadSoundScape()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for soundscape identifier"); // Just return true if the soundscape is already registered if(IsSoundScapeRegistered(pNode->GetString())) return true; SoundScapeInternalInit init; BackgroundElement bge; PeriodicElement pe; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "Periodic") == 0) { if(!LoadPeriodic(pChildNode, pe)) return false; init.m_aPeriodic.push_back(pe); } else if(SNDMGR_STRCMP(pChildNode->GetName(), "Background") == 0) { if(!LoadBackground(pChildNode, bge)) return false; init.m_aBackground.push_back(bge); } else return false; pChildNode = pChildNode->GetSibling(); } // Insert the sound definition into the map m_SSMap.insert(make_pair(pNode->GetString(), init)); DebugOut(4, "Registering Soundscape \"%s\" in sound manager", pNode->GetString()); return true; }
//------------------------------------------------------------------------// bool MusicManager::LoadScript(string sFileName) { if(!IsInitialized()) return Error::Handle("Music manager is not initialized"); Script script; if(!m_Loader.Load(sFileName, script)) return Error::Handle("Could not load script %s", sFileName.c_str()); ScriptNode* pNode = script.GetRoot(); while(pNode) { // Look for named "DLS" nodes in the script if(MUSMGR_STRCMP(pNode->GetName(), "DLS") == 0) { if(!LoadDLS(pNode)) return false; } // Look for named "Segment" nodes in the script else if(MUSMGR_STRCMP(pNode->GetName(), "Segment") == 0) { if(!LoadSegment(pNode)) return false; } // Look for named "Theme" nodes in the script else if(MUSMGR_STRCMP(pNode->GetName(), "Theme") == 0) { if(!LoadTheme(pNode)) return false; } else { return Error::Handle("Unrecognized keyword in music script"); } // advance to the next sibling node if one exists pNode = pNode->GetSibling(); }; return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadScript(string sFileName) { FN("SoundManager::LoadScript()"); CHECK_INIT(); Script script; if(!m_Loader.Load(sFileName, script)) return Error::Handle("Could not load script %s", sFileName.c_str()); ScriptNode* pNode = script.GetRoot(); while(pNode) { // Look for named "Sound" nodes in the script if(SNDMGR_STRCMP(pNode->GetName(), "Sound") == 0) { if(!LoadSound(pNode)) return false; } // Look for named "Sound3D" nodes in the script else if(SNDMGR_STRCMP(pNode->GetName(), "Sound3D") == 0) { if(!LoadSound3D(pNode)) return false; } // Look for named "soundscape" nodes in the script else if(SNDMGR_STRCMP(pNode->GetName(), "SoundScape") == 0) { if(!LoadSoundScape(pNode)) return false; } // advance to the next sibling node if one exists pNode = pNode->GetSibling(); }; return true; }
void AddSFString(char *string) { switch (GetCurrentNodeType()) { case VRML_NODETYPE_ANCHOR_PARAMETER: { ((AnchorNode *)GetCurrentNodeObject())->addParameter(string); } break; case VRML_NODETYPE_ANCHOR_URL: { ((AnchorNode *)GetCurrentNodeObject())->addUrl(string); } break; case VRML_NODETYPE_INLINE_URL: { ((InlineNode *)GetCurrentNodeObject())->addUrl(string); } break; case VRML_NODETYPE_AUDIOCLIP_URL: { AudioClipNode *aclip = (AudioClipNode *)GetCurrentNodeObject(); aclip->addUrl(string); } break; case VRML_NODETYPE_BACKGROUND_BACKURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addBackUrl(string); } break; case VRML_NODETYPE_BACKGROUND_BOTTOMURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addBottomUrl(string); } break; case VRML_NODETYPE_BACKGROUND_FRONTURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addFrontUrl(string); } break; case VRML_NODETYPE_BACKGROUND_LEFTURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addLeftUrl(string); } break; case VRML_NODETYPE_BACKGROUND_RIGHTURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addRightUrl(string); } break; case VRML_NODETYPE_BACKGROUND_TOPURL: { BackgroundNode *bg = (BackgroundNode *)GetCurrentNodeObject(); bg->addTopUrl(string); } break; case VRML_NODETYPE_FONTSTYLE_JUSTIFY: { FontStyleNode *fs = (FontStyleNode *)GetCurrentNodeObject(); fs->addJustify(string); } break; case VRML_NODETYPE_IMAGETEXTURE_URL: { ImageTextureNode *image = (ImageTextureNode *)GetCurrentNodeObject(); image->addUrl(string); } break; case VRML_NODETYPE_MOVIETEXTURE_URL: { MovieTextureNode *image = (MovieTextureNode *)GetCurrentNodeObject(); image->addUrl(string); } break; case VRML_NODETYPE_NAVIGATIONINFO_TYPE: { NavigationInfoNode *navInfo = (NavigationInfoNode *)GetCurrentNodeObject(); navInfo->addType(string); } break; case VRML_NODETYPE_SCRIPT_URL: { ScriptNode *script = (ScriptNode *)GetCurrentNodeObject(); script->addUrl(string); } break; case VRML_NODETYPE_TEXT_STRING: { TextNode *text = (TextNode *)GetCurrentNodeObject(); text->addString(string); } break; case VRML_NODETYPE_WORLDINFO_INFO: { WorldInfoNode *worldInfo = (WorldInfoNode *)GetCurrentNodeObject(); worldInfo->addInfo(string); } break; } }
//------------------------------------------------------------------------// bool SoundManager::LoadPeriodic(ScriptNode* pNode, PeriodicElement& pe) { FN("SoundManager::LoadPeriodic()"); // Check to see if the node has the "default" keyword, meaning it should // clear all values to their original defaults. if((pNode->GetDataType() == Script::VARIABLE) && (strcmp(pNode->GetVariable(), "Default") == 0)) pe.Clear(); ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "Sound3D") == 0) pe.m_sSound3DID = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitch") == 0) pe.m_Init.m_fMinPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitch") == 0) pe.m_Init.m_fMaxPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDelay") == 0) pe.m_Init.m_fMinDelay = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxDelay") == 0) pe.m_Init.m_fMaxDelay = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "XRange") == 0) pe.m_Init.m_fXRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "YRange") == 0) pe.m_Init.m_fYRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ZRange") == 0) pe.m_Init.m_fZRange = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDistance") == 0) pe.m_Init.m_fMinDistance = pChildNode->GetReal(); else return false; pChildNode = pChildNode->GetSibling(); } return true; }
void Plug::parentChanging( Gaffer::GraphComponent *newParent ) { if( getFlags( Dynamic ) ) { // When a dynamic plug is removed from a node, we // need to propagate dirtiness based on that. We // must call DependencyNode::affects() now, while the // plug is still a child of the node, but we push // scope so that the emission of plugDirtiedSignal() // is deferred until parentChanged() when the operation // is complete. It is essential that exceptions don't // prevent us getting to parentChanged() where we pop // scope, so propateDirtiness() takes care of handling // exceptions thrown by DependencyNode::affects(). pushDirtyPropagationScope(); if( node() ) { propagateDirtinessForParentChange( this ); } } // This method manages the connections between plugs when // additional child plugs are added or removed. We only // want to react to these changes when they are first made - // after this our own actions will have been recorded in the // undo buffer anyway and will be undone/redone automatically. // So here we early out if we're in such an Undo/Redo situation. ScriptNode *scriptNode = ancestor<ScriptNode>(); scriptNode = scriptNode ? scriptNode : ( newParent ? newParent->ancestor<ScriptNode>() : NULL ); if( scriptNode && ( scriptNode->currentActionStage() == Action::Undo || scriptNode->currentActionStage() == Action::Redo ) ) { return; } // Now we can take the actions we need to based on the new parent // we're getting. if( !newParent ) { // We're losing our parent - remove all our connections first. // this must be done here (rather than in a parentChangedSignal() slot) // because we need a current parent for the operation to be undoable. setInput( 0 ); // Deal with outputs whose parent is an output of our parent. // For these we actually remove the destination plug itself, // so that the parent plugs may remain connected. if( Plug *oldParent = parent<Plug>() ) { for( OutputContainer::iterator it = m_outputs.begin(); it!=m_outputs.end(); ) { Plug *output = *it++; Plug *outputParent = output->parent<Plug>(); if( outputParent && outputParent->getInput<Plug>() == oldParent ) { // We're removing the child precisely so that the parent connection // remains valid, so we can block its updateInputFromChildInputs() call. assert( outputParent->m_skipNextUpdateInputFromChildInputs == false ); ScopedAssignment<bool> blocker( outputParent->m_skipNextUpdateInputFromChildInputs, true ); outputParent->removeChild( output ); } } } // Remove any remaining output connections. removeOutputs(); } else if( Plug *newParentPlug = IECore::runTimeCast<Plug>( newParent ) ) { // we're getting a new parent - update its input connection from // all the children including the pending one. newParentPlug->updateInputFromChildInputs( this ); // and add a new child plug to any of its outputs to maintain // the output connections. const OutputContainer &outputs = newParentPlug->outputs(); for( OutputContainer::const_iterator it = outputs.begin(), eIt = outputs.end(); it != eIt; ++it ) { Plug *output = *it; if( output->acceptsChild( this ) ) { PlugPtr outputChildPlug = createCounterpart( getName(), direction() ); { // We're adding the child so that the parent connection remains valid, // but the parent connection wouldn't be considered valid until the // child has both been added and had its input connected. We therefore // block the call to updateInputFromChildInputs() to keep the parent // connection intact. assert( output->m_skipNextUpdateInputFromChildInputs == false ); ScopedAssignment<bool> blocker( output->m_skipNextUpdateInputFromChildInputs, true ); output->addChild( outputChildPlug ); } outputChildPlug->setInput( this, /* setChildInputs = */ true, /* updateParentInput = */ false ); } } } }
/* * Function: ~KinectMonitor (Destructor) * * Releases all the production nodes and the context. */ KinectMonitor::~KinectMonitor() { scriptNode.Release(); depthGenerator.Release(); userGenerator.Release(); context.Release(); }
int main() { XnStatus nRetVal = XN_STATUS_OK; Context context; ScriptNode scriptNode; EnumerationErrors errors; XnUInt32 min_z1, min_z2, min_z3, maxGrad, distVal; const char *fn = NULL; if (fileExists(SAMPLE_XML_PATH)) fn = SAMPLE_XML_PATH; else if (fileExists(SAMPLE_XML_PATH_LOCAL)) fn = SAMPLE_XML_PATH_LOCAL; else { printf("Could not find '%s' nor '%s'. Aborting.\n" , SAMPLE_XML_PATH, SAMPLE_XML_PATH_LOCAL); return XN_STATUS_ERROR; } printf("Reading config from: '%s'\n", fn); nRetVal = context.InitFromXmlFile(fn, scriptNode, &errors); if (nRetVal == XN_STATUS_NO_NODE_PRESENT) { XnChar strError[1024]; errors.ToString(strError, 1024); printf("%s\n", strError); return (nRetVal); } else if (nRetVal != XN_STATUS_OK) { printf("Open failed: %s\n", xnGetStatusString(nRetVal)); return (nRetVal); } DepthGenerator depth; nRetVal = context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth); CHECK_RC(nRetVal, "Find depth generator"); XnFPSData xnFPS; nRetVal = xnFPSInit(&xnFPS, 180); CHECK_RC(nRetVal, "FPS Init"); DepthMetaData depthMD; //Initialize WiringPi if(wiringPiSetup() == -1) exit(1); //Enable SoftPWM on pin 1,2 and 3 softPwmCreate(1, 0, RANGE); softPwmCreate(2, 0, RANGE); softPwmCreate(3, 0, RANGE); while (!xnOSWasKeyboardHit()) { nRetVal = context.WaitOneUpdateAll(depth); if (nRetVal != XN_STATUS_OK) { printf("UpdateData failed: %s\n", xnGetStatusString(nRetVal)); continue; } xnFPSMarkFrame(&xnFPS); depth.GetMetaData(depthMD); const XnDepthPixel* pDepthMap = depthMD.Data(); int XRes = depthMD.XRes(); int YRes = depthMD.YRes(); //To find closest pixel value in Zone 1, Zone 2 and Zone 3 min_z1 = getClosestPixel( 0 , 0, (XRes / 2) , YRes, depthMD); min_z2 = getClosestPixel( (XRes / 4), 0, (3 * XRes / 4), YRes, depthMD); min_z3 = getClosestPixel( (XRes / 2), 0, XRes , YRes, depthMD); double in_low = 600; double in_high = 2000; double in_diff = in_high - in_low; double out_low = 51; double out_high = 973; double out_diff = out_high - out_low; distVal = min_z1; XnUInt32 pwm_val1 = ( (out_diff) / ((in_diff)*(in_diff)*(in_diff)) ) * ((in_high - distVal) * (in_high - distVal) * (in_high - distVal)) + out_low; distVal = min_z2; XnUInt32 pwm_val2 = ( (out_diff) / ((in_diff)*(in_diff)*(in_diff)) ) * ((in_high - distVal) * (in_high - distVal) * (in_high - distVal)) + out_low; distVal = min_z3; XnUInt32 pwm_val3 = ( (out_diff) / ((in_diff)*(in_diff)*(in_diff)) ) * ((in_high - distVal) * (in_high - distVal) * (in_high - distVal)) + out_low; // Zone 1 - Left side (pin ) if (pwm_val1 < out_low) pwm_val1 = 0; // if object too far, set DUTY CYCLE to 0 if (min_z1 == 9000.0) pwm_val1 = out_high; //if object too close, set DUTY CYCLE to max (here, 95%) if (min_z1 < 600) pwm_val1 = out_high; // Zone 2 - Center (pin ) if (pwm_val2 < out_low) pwm_val2 = 0; // if object too far, set DUTY CYCLE to 0 if (min_z2 == 9000.0) pwm_val2 = out_high; //if object too close, set DUTY CYCLE to max (here, 95%) if (min_z2 < 600) pwm_val2 = out_high; // Zone 3 - Right side (pin ) if (pwm_val3 < out_low) pwm_val3 = 0; // if object too far, set DUTY CYCLE to 0 if (min_z3 == 9000.0) pwm_val3 = out_high; //if object too close, set DUTY CYCLE to max (here, 95%) if (min_z3 < 600) pwm_val3 = out_high; pwm_val1 = ((pwm_val1 - out_low) / (1.0 * out_diff)) * 100.0; pwm_val2 = ((pwm_val2 - out_low) / (1.0 * out_diff)) * 100.0; pwm_val3 = ((pwm_val3 - out_low) / (1.0 * out_diff)) * 100.0; softPwmWrite(1,(int)pwm_val1); softPwmWrite(2,(int)pwm_val2); softPwmWrite(3,(int)pwm_val3); if ( (depthMD.FrameID() % 30) == 0) { printf("Frame %d", depthMD.FrameID()); printf("\n"); printf("Zone 1 value is %u \t", pwm_val1); printf("Zone 2 value is %u \t", pwm_val2); printf("Zone 3 value is %u \n", pwm_val3); printf("Zone1 min_dis %u \t", min_z1); printf("Zone2 min_dis %u \t", min_z2); printf("Zone3 min_dis %u \n", min_z3); //To find a gradient value for the floor //maxGrad = getGradient( 5, 0, (YRes/2) + 1, depthMD.XRes(), depthMD.YRes(), depthMD); //printf("Frame %d max gradient for Floor is: %u. FPS: %f\n\n", depthMD.FrameID(), maxGrad, xnFPSCalc(&xnFPS)); } } softPwmWrite(1,0); softPwmWrite(2,0); softPwmWrite(3,0); //release the nodes depth.Release(); scriptNode.Release(); context.Release(); return 0; }
//------------------------------------------------------------------------// bool SoundManager::LoadSound(ScriptNode* pNode) { FN("SoundManager::LoadSound()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound identifier"); // Just return true if the sound is already registered if(IsSoundRegistered(pNode->GetString())) return true; SoundPool pool; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) pool.m_Init.m_sFileName = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) pool.m_Init.m_bLooping = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Streaming") == 0) pool.m_Init.m_bStreaming = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Music") == 0) pool.m_Init.m_bMusic = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Volume") == 0) pool.m_Init.m_Prop.m_fVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pan") == 0) pool.m_Init.m_Prop.m_fPan = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pitch") == 0) pool.m_Init.m_Prop.m_fPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ReadCursor") == 0) pool.m_Init.m_Prop.m_nReadCursor = pChildNode->GetInteger(); else return Error::Handle("Syntax error in Sound definition"); pChildNode = pChildNode->GetSibling(); } // Insert the sound definition into the map m_SndMap.insert(make_pair(pNode->GetString(), pool)); DebugOut(4, "Registering Sound \"%s\" in sound manager", pNode->GetString()); return true; }
//------------------------------------------------------------------------// bool SoundManager::LoadSound3D(ScriptNode* pNode) { FN("SoundManager::LoadSound3D()"); // We use string ids in this scripting system if(pNode->GetDataType() != Script::STRING) return Error::Handle("No id found for sound3d identifier"); // Just return true if the sound3d is already registered if(IsSound3DRegistered(pNode->GetString())) return true; Sound3DPool pool; ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "FileName") == 0) pool.m_Init.m_sFileName = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Looping") == 0) pool.m_Init.m_bLooping = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Streaming") == 0) pool.m_Init.m_bStreaming = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Music") == 0) pool.m_Init.m_bMusic = pChildNode->GetBool(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Position") == 0) pool.m_Init.m_Prop.m_vPosition = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Velocity") == 0) pool.m_Init.m_Prop.m_vVelocity = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ConeOrientation") == 0) pool.m_Init.m_Prop.m_vConeOrientation = pChildNode->GetVector(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "InsideConeAngle") == 0) pool.m_Init.m_Prop.m_nInsideConeAngle = pChildNode->GetInteger(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "OutsideConeAngle") == 0) pool.m_Init.m_Prop.m_nOutsideConeAngle = pChildNode->GetInteger(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ConeOutsideVolume") == 0) pool.m_Init.m_Prop.m_fConeOutsideVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinDistance") == 0) pool.m_Init.m_Prop.m_fMinDistance = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxDistance") == 0) pool.m_Init.m_Prop.m_fMaxDistance = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Mode") == 0) { if(pChildNode->GetDataType() == Script::INTEGER) { pool.m_Init.m_Prop.m_nMode = pChildNode->GetInteger(); } else { if(SNDMGR_STRCMP(pChildNode->GetString(), "Normal") == 0) pool.m_Init.m_Prop.m_nMode = MODE_NORMAL; else if(SNDMGR_STRCMP(pChildNode->GetString(), "HeadRelative") == 0) pool.m_Init.m_Prop.m_nMode = MODE_HEADRELATIVE; else if(SNDMGR_STRCMP(pChildNode->GetString(), "Disable") == 0) pool.m_Init.m_Prop.m_nMode = MODE_DISABLE; } } else if(SNDMGR_STRCMP(pChildNode->GetName(), "Volume") == 0) pool.m_Init.m_Prop.m_fVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "Pitch") == 0) pool.m_Init.m_Prop.m_fPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "ReadCursor") == 0) pool.m_Init.m_Prop.m_nReadCursor = pChildNode->GetInteger(); else { return Error::Handle("Syntax error in Sound3D definition"); } pChildNode = pChildNode->GetSibling(); } // Insert the sound3d definition into the map m_Snd3DMap.insert(make_pair(pNode->GetString(), pool)); DebugOut(4, "Registering Sound3D \"%s\" in sound manager", pNode->GetString()); return true; }
void Reference::load( const std::string &fileName ) { ScriptNode *script = scriptNode(); if( !script ) { throw IECore::Exception( "Reference::load called without ScriptNode" ); } // if we're doing a reload, then we want to maintain any values and // connections that our external plugs might have. but we also need to // get those existing plugs out of the way during the load, so that the // incoming plugs don't get renamed. std::map<std::string, Plug *> previousPlugs; for( PlugIterator it( this ); it != it.end(); ++it ) { Plug *plug = it->get(); if( isReferencePlug( plug ) ) { previousPlugs[plug->getName()] = plug; plug->setName( "__tmp__" + plug->getName().string() ); } } for( PlugIterator it( userPlug() ); it != it.end(); ++it ) { Plug *plug = it->get(); previousPlugs[plug->relativeName( this )] = plug; plug->setName( "__tmp__" + plug->getName().string() ); } // if we're doing a reload, then we also need to delete all our child // nodes to make way for the incoming nodes. int i = (int)(children().size()) - 1; while( i >= 0 ) { if( Node *node = getChild<Node>( i ) ) { removeChild( node ); } i--; } // load the reference. we use continueOnError=true to get everything possible // loaded, but if any errors do occur we throw an exception at the end of this // function. this means that the caller is still notified of errors via the // exception mechanism, but we leave ourselves in the best state possible for // the case where ScriptNode::load( continueOnError = true ) will ignore the // exception that we throw. const bool errors = script->executeFile( fileName, this, /* continueOnError = */ true ); fileNamePlug()->setValue( fileName ); // transfer connections and values from the old plugs onto the corresponding new ones. for( std::map<std::string, Plug *>::const_iterator it = previousPlugs.begin(), eIt = previousPlugs.end(); it != eIt; ++it ) { Plug *oldPlug = it->second; Plug *newPlug = descendant<Plug>( it->first ); if( newPlug ) { try { if( newPlug->direction() == Plug::In && oldPlug->direction() == Plug::In ) { if( Plug *oldInput = oldPlug->getInput<Plug>() ) { newPlug->setInput( oldInput ); } else { ValuePlug *oldValuePlug = runTimeCast<ValuePlug>( oldPlug ); ValuePlug *newValuePlug = runTimeCast<ValuePlug>( newPlug ); if( oldValuePlug && newValuePlug ) { newValuePlug->setFrom( oldValuePlug ); } } } else if( newPlug->direction() == Plug::Out && oldPlug->direction() == Plug::Out ) { for( Plug::OutputContainer::const_iterator oIt = oldPlug->outputs().begin(), oeIt = oldPlug->outputs().end(); oIt != oeIt; ) { Plug *outputPlug = *oIt; ++oIt; // increment now because the setInput() call invalidates our iterator. outputPlug->setInput( newPlug ); } } } catch( const std::exception &e ) { msg( Msg::Warning, boost::str( boost::format( "Loading \"%s\" onto \"%s\"" ) % fileName % getName().c_str() ), e.what() ); } } // remove the old plug now we're done with it. oldPlug->parent<GraphComponent>()->removeChild( oldPlug ); } // make the loaded plugs non-dynamic, because we don't want them // to be serialised in the script the reference is in - the whole // point is that they are referenced. for( RecursivePlugIterator it( this ); it != it.end(); ++it ) { if( isReferencePlug( it->get() ) ) { (*it)->setFlags( Plug::Dynamic, false ); } } if( errors ) { throw Exception( boost::str( boost::format( "Error loading reference \"%s\"" ) % fileName ) ); } }
//------------------------------------------------------------------------// bool SoundManager::LoadBackground(ScriptNode* pNode, BackgroundElement& bge) { FN("SoundManager::LoadBackground()"); // Check to see if the node has the "Default" keyword, meaning it should // clear all values to their original defaults. if((pNode->GetDataType() == Script::VARIABLE) && (strcmp(pNode->GetVariable(), "Default") == 0)) bge.Clear(); ScriptNode* pChildNode = pNode->GetChild(); while(pChildNode) { if(SNDMGR_STRCMP(pChildNode->GetName(), "Sound") == 0) bge.m_sSoundID = pChildNode->GetString(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinVolume") == 0) bge.m_Init.m_fMinVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxVolume") == 0) bge.m_Init.m_fMaxVolume = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinVolumeTime") == 0) bge.m_Init.m_fMinVolumeTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxVolumeTime") == 0) bge.m_Init.m_fMaxVolumeTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitch") == 0) bge.m_Init.m_fMinPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitch") == 0) bge.m_Init.m_fMaxPitch = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MinPitchTime") == 0) bge.m_Init.m_fMinPitchTime = pChildNode->GetReal(); else if(SNDMGR_STRCMP(pChildNode->GetName(), "MaxPitchTime") == 0) bge.m_Init.m_fMaxPitchTime = pChildNode->GetReal(); else return false; pChildNode = pChildNode->GetSibling(); } return true; }
void ScriptLoader::_parseNodes(std::ifstream &stream, ScriptNode *parent) { typedef std::pair<std::string, ScriptNode*> ScriptItem; while (true) { switch (mToken) { //Node case TOKEN_Text: { //Add the new node ScriptNode *newNode; if (parent) { newNode = parent->addChild(mTokenValue); } else { newNode = new ScriptNode(0, mTokenValue); } //Get values _nextToken(stream); std::string valueStr; int i=0; while (mToken == TOKEN_Text) { if (i == 0) valueStr += mTokenValue; else valueStr += " " + mTokenValue; _nextToken(stream); ++i; } newNode->setValue(valueStr); //Add root nodes to scriptList if (!parent) { std::string key; if (newNode->getValue() == "") throw std::runtime_error("Root node must have a name (\"" + newNode->getName() + "\")"); key = newNode->getValue(); m_scriptList.insert(ScriptItem(key, newNode)); } _skipNewLines(stream); //Add any sub-nodes if (mToken == TOKEN_OpenBrace) { //Parse nodes _nextToken(stream); _parseNodes(stream, newNode); //Check for matching closing brace if (mToken != TOKEN_CloseBrace) { throw std::runtime_error("Parse Error: Expecting closing brace"); } _nextToken(stream); _skipNewLines(stream); } newNode->mFileName = mCurrentFileName; break; } //Out of place brace case TOKEN_OpenBrace: throw std::runtime_error("Parse Error: Opening brace out of plane"); break; //Return if end of nodes have been reached case TOKEN_CloseBrace: return; //Return if reached end of file case TOKEN_EOF: return; case TOKEN_NewLine: _nextToken(stream); break; } }; }
int main() { XnStatus nRetVal = XN_STATUS_OK; Context context; ScriptNode scriptNode; EnumerationErrors errors; const char *fn = NULL; if (fileExists(SAMPLE_XML_PATH)) fn = SAMPLE_XML_PATH; else if (fileExists(SAMPLE_XML_PATH_LOCAL)) fn = SAMPLE_XML_PATH_LOCAL; else { printf("Could not find '%s' nor '%s'. Aborting.\n" , SAMPLE_XML_PATH, SAMPLE_XML_PATH_LOCAL); return XN_STATUS_ERROR; } printf("Reading config from: '%s'\n", fn); nRetVal = context.InitFromXmlFile(fn, scriptNode, &errors); if (nRetVal == XN_STATUS_NO_NODE_PRESENT) { XnChar strError[1024]; errors.ToString(strError, 1024); printf("%s\n", strError); return (nRetVal); } else if (nRetVal != XN_STATUS_OK) { printf("Open failed: %s\n", xnGetStatusString(nRetVal)); return (nRetVal); } DepthGenerator depth; nRetVal = context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth); CHECK_RC(nRetVal, "Find depth generator"); XnFPSData xnFPS; nRetVal = xnFPSInit(&xnFPS, 180); CHECK_RC(nRetVal, "FPS Init"); DepthMetaData depthMD; while (!xnOSWasKeyboardHit()) { nRetVal = context.WaitOneUpdateAll(depth); if (nRetVal != XN_STATUS_OK) { printf("UpdateData failed: %s\n", xnGetStatusString(nRetVal)); continue; } xnFPSMarkFrame(&xnFPS); depth.GetMetaData(depthMD); printf("Frame %d Middle point is: %u. FPS: %f\n", depthMD.FrameID(), depthMD(depthMD.XRes() / 2, depthMD.YRes() / 2), xnFPSCalc(&xnFPS)); } depth.Release(); scriptNode.Release(); context.Release(); return 0; }
int main(int argc, char* argv[]) { XnStatus nRetVal = XN_STATUS_OK; Context context; EnumerationErrors errors; Mode mode; // default mode #if XN_PLATFORM == XN_PLATFORM_WIN32 mode = MODE_PLAY; #else mode = MODE_RECORD; #endif // check if mode was provided by user if (argc > 1) { if (strcmp(argv[1], "play") == 0) { mode = MODE_PLAY; } else if (strcmp(argv[1], "record") == 0) { mode = MODE_RECORD; } else { printUsage(argv[0]); return -1; } } // make sure mode is valid #if XN_PLATFORM != XN_PLATFORM_WIN32 if (mode == MODE_PLAY) { printf("Playing is not supported on this platform!\n"); return -1; } #endif ScriptNode scriptNode; nRetVal = context.InitFromXmlFile(SAMPLE_XML_PATH, scriptNode); if (nRetVal == XN_STATUS_NO_NODE_PRESENT) { XnChar strError[1024]; errors.ToString(strError, 1024); printf("%s\n", strError); return (nRetVal); } else if (nRetVal != XN_STATUS_OK) { printf("Open failed: %s\n", xnGetStatusString(nRetVal)); return (nRetVal); } // find audio nodes AudioGenerator gens[nSupportedNodes]; XnUInt32 nNodes = 0; NodeInfoList list; nRetVal = context.EnumerateExistingNodes(list, XN_NODE_TYPE_AUDIO); CHECK_RC(nRetVal, "Enumerate audio nodes"); for (NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it) { NodeInfo info = *it; nRetVal = info.GetInstance(gens[nNodes]); CHECK_RC(nRetVal, "Get audio node"); nNodes++; } if (nNodes == 0) { printf("No audio node was found!\n"); return -1; } if (mode == MODE_PLAY) { nRetVal = play(context, gens, nNodes); } else if (mode == MODE_RECORD) { nRetVal = record(context, gens, nNodes); } scriptNode.Release(); for (int i = 0; i < nSupportedNodes; ++i) gens[i].Release(); context.Release(); return nRetVal; }