void printMenu(char choice[],char path[],char input[]) { system("clear"); printf("********************************\n"); printf("* *\n"); printf("* Hang Man! *\n"); printf("* *\n"); printf("* ************** *\n"); printf("* * Play! * *\n"); printf("* ************** *\n"); printf("* *\n"); printf("* ************** *\n"); printf("* * Settings! * *\n"); printf("* ************** *\n"); printf("* *\n"); printf("* *\n"); printf("********************************\n"); scanf("%s",input); if(strcmp(input,"play")== 0||strcmp(input,"Play")== 0) { playGame(path); } else if(strcmp(input,"settings")== 0||strcmp(input,"Settings")== 0) { printSettings(); } }
void AgentF::exec(const QStringList& parm) { if(mFilu->hasError()) return; // mCmd->regCmds("this...") is done in ctor ! // mCmd->regOpts("verbose"); if(mCmd->cmdLineLooksBad(parm)) return; if(mCmd->has("verbose")) setVerboseLevel(FUNC, mCmd->cmdLine()); if(mCmd->wantHelp()) { mCmd->inCmdBrief("full", tr("Download eod bars of all FIs")); mCmd->inCmdBrief("info", tr("Print some settings and more")); CmdClass::allBriefIn(mCmd); Depots::briefIn(mCmd); Scanner::briefIn(mCmd); Exporter::briefIn(mCmd); mCmd->inOptBrief("verbose", "<Level>" , tr("How talkative has it to be. Level can be 0-3 or " "Quiet Info Ample Max")); } else { QStringList cmd = parm; cmd.removeAt(0); record(FUNC, tr("Exec: %1").arg(cmd.join(" "))); } if(mCmd->needHelp(1)) { if(mCmd->printThisWay("<Command> [<ParmList>] [<SubCommand> [<ParmList>]]..")) return; mCmd->printComment(tr("Calling a command without any parameter may give a hint like --help.")); mCmd->printComment(tr("But of cause not if no parameter is needed e.g at 'full'.")); mCmd->aided(); return; } // Look for each known command and call the related function if(mKnownCmds.contains(mCmd->cmd())) cmdExec(mCmd->cmd()); else if(mCmd->hasCmd("full")) updateAllBars(); else if(mCmd->hasCmd("exp")) exxport(); else if(mCmd->hasCmd("scan")) scan(); else if(mCmd->hasCmd("depots")) depots(); else if(mCmd->hasCmd("info")) printSettings(); else { fatal(FUNC, QString("Unsupported command: %1").arg(mCmd->cmd())); } }
RTCORE_API void rtcCommit (RTCScene scene) { cout << "in rtcCommit " << endl; CATCH_BEGIN; TRACE(rtcCommit); VERIFY_HANDLE(scene); ((Scene*)scene)->build(); printSettings(); cout << "end rtcCommit " << endl; CATCH_END; }
// Получаем настройки из файла struct Settings *getSettings(char *path) { struct Settings *settings = malloc(sizeof(struct Settings)); memset(settings, 0, sizeof(struct Settings)); size_t length; char **strings = readStringsFromFile(path, &length); settings->maxThreads = 1; settings->maxThreads = parseString("MaxThreads:", strings, length); settings->port = parseString("Port:", strings, length); settings->connectionTimeout = parseString("ConnectionTimeout:", strings, length); settings->maxPasswordAttempts = parseString("MaxPasswordAttempts:", strings, length); settings->timeoutCheckFrequency = parseString("TimeoutCheckFrequency:", strings, length); clearStrings(strings, length); printSettings(settings); return settings; }
/** * @brief Initializes data values and configures the sensor with desired modules * @param _device XsDevice from Xsens API */ mtiG::mtiG(XsDevice * _device, int argc, char ** argv):device(_device){ ros::param::get("~override", override_settings); parseOptions(argc, argv); if(override_settings){ //configures Xsensor device with mSettings ROS_DEBUG("OVERRIDE MODE"); configure(); }else{ // uses the current device settings - to be used in conjunction with Windows GUI tool ROS_DEBUG("UNALTERED MODE"); } readSettings(); printSettings(); sensorData = SensorData(mSettings); messageMaker = new MessageMaker(sensorData); // Advertise all messages published in this node, uses mSettings advertise(); }
int main(int argc, char *argv[]) { int i, result; progname = strrchr(argv[0], '/'); if (progname == NULL) progname = argv[0]; else progname++; if (argc == 1) usage(); for (i = 0; i < MAX_SCORES; i++) { scoreNames[i] = NULL; scores[i] = NULL; } for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] == '-') { switch (arg[1]) { case 'a': if (++i >= argc) usage(); rescaleFactor = atof(argv[i]); if (fabs(rescaleFactor) > 2.0) rescaleFactor = 2.0; break; case 'B': if (++i >= argc) usage(); framesPerBuffer = atof(argv[i]); if (framesPerBuffer < MIN_FRAMES_PER_BUF) framesPerBuffer = MIN_FRAMES_PER_BUF; break; case 'c': if (++i >= argc) usage(); numOutChannels = atof(argv[i]); if (numOutChannels < 1) numOutChannels = 1; break; case 'd': if (++i >= argc) usage(); totalDuration = atof(argv[i]); if (totalDuration < 0.0) totalDuration = 0.0; // kinda stupid break; case 'h': usage(); break; #ifdef HAVE_PORTAUDIO case 'n': withAudio = 0; scoreDelayTime = 0.0; break; #endif case 'q': printJobOutput = 0; break; case 'r': if (++i >= argc) usage(); sampleRate = atof(argv[i]); if (sampleRate < 8000) // be more stringent? sampleRate = 8000; break; case 'v': verbose = 1; break; case 'y': if (++i >= argc) usage(); scoreDelayTime = atof(argv[i]); if (scoreDelayTime < 0.0) scoreDelayTime = 0.0; break; //FIXME: others: call flush after each score? call destroy after each? default: usage(); } } else { const char *name = arg; /* verify that filename ends in ".sco" */ char *p = strrchr(name, '.'); if (p == NULL || strncmp(p, ".sco", 4L)) { fprintf(stderr, "Score names must end in \".sco\" (%s).\n", name); exit(-1); } if (numScores < MAX_SCORES) { scoreNames[numScores] = name; numScores++; } else { fprintf(stderr, "No more than %d scores allowed.\n", MAX_SCORES); exit(-1); } } } #ifdef HAVE_PORTAUDIO if (withAudio) { result = initAudio(); if (result) return -1; } #endif result = initRTcmix(); if (result) return -1; result = loadScores(); if (result) return -1; printSettings(); playScores(); for (i = 0; i < numScores; i++) if (scores[i]) free(scores[i]); result = deleteRTcmix(); #ifdef HAVE_PORTAUDIO if (withAudio) result = deleteAudio(); #endif return result; }
void serialUI(void) { if (commandRetrived == 1) { if (commandType == 0) { checkCmd(); commandRetrived = 0; } if (commandType == 1) { if (setCmd == 0) { //this is to send in data. the data is not yet flashed led_switch(2); //data can be send in at any time also at flight time //it will be used with the next cycle print_uart0("FCm0;storing setting %d;00#",setupCache.settingNum); setToInSettings(); //fill the runtime struct with the settings setTempToInSetting(setupCache.settingNum); //save settings to ram cache commandRetrived = 0; } if (setCmd == 1) { print_uart0("FCm0;flashing settings;00#"); //here we write all the settings from ram to flash enginesOff(); //this is to save some of the flashing cycles. led_switch(3); //we could flash with any retrieved setting but that engineStatus = 0; //just helps abusing the flash cycles so its a manual //step to really save to flash writeSetup(); ADCStandstillValues(); //also we reset the ADCOffset commandRetrived = 0; initFCRuntime(); ledTest(); } } if (commandType == 2) { updateAcdRate(); commandRetrived = 0; } if (commandType == 3) { retriveSetting(); printSettings(); commandRetrived = 0; } if (commandType == 4) { if (I2CcmdType == I2CMODE_WRITEADDRESS){ if (updateYGE == 0) { I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0Start(); } } if (I2CcmdType == I2CMODE_STARTUP_TARGET){ if (updateYGE == 0) { I2C0Stop(); I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0Start(); } } commandRetrived = 0; } } }
int main(int argc, char* argv[]){ bool small = false; //if true, program run with the -s mod int h, w; //height and width of the board int cycles=5000; //number of cycles to run the current seed int row, col; //size of the terminal int waitMS; //time to wait in micro seconds (1,000,000 = 1 sec) between cycles parseEntryArgs(argc, argv, h, w, waitMS, small); //parse cmd args initscr(); //start nCurses noecho(); //set no echo curs_set(0); //hide cursor getmaxyx(stdscr,row,col); //get size of terminal int menuStartRow = 3 + (h/2); //start row for menus (half way down board) int boardStartColumn = (col - w) / 2; //start column for board bool bpass = false; //set to false until terminal is correct size if (small == true && row > 25 && col > 81){ //going to run with -s bpass = true; } else if(small == false && row > 53 && col > 151){ //going to run without -s bpass = true; } if(bpass == true){ //terminal is correct size char mch; do{ clear(); printHeader(col,row); printMenu(menuStartRow, col); refresh(); GameOfLife game(h, w); //initialize gameOfLife object game.setLiveDeadChars('X',' '); //set symbols game.initVectors(); //setup vectors switch(mch = getch()){ case 'r':{ //generate random seed game.setInitParamsRandom(); //set seed to random runGame(game, boardStartColumn, col, waitMS, cycles); //run seed break;} case 'u':{ //use presets std::string fileName = "seeds/"; clear(); printHeader(col,row); if (runPresetMenu(game, fileName, menuStartRow, col)==true){ game.setInitParams(fileName); runGame(game, boardStartColumn, col, waitMS, cycles); } break;} case 's':{ clear(); printHeader(col,row); printSettings(waitMS, menuStartRow, col, small); break;} case 'e':{ break;} default: break; } }while(mch != 'e'); } else{ //terminal is too small curs_set(1); //show cursor endwin(); //turn off nCurses std::cout << "\nPlease resize the terminal to at least 54 rows x 152 columns." << "\nYour current terminal size is:" << "\n\tRows: " << row << "\n\tColumns: " << col << "\nAlternatively, run the program with cmd -s" << " (minimum terminal size: 26 rows X 82 columns)" << "\n\t./GameOfLife -s\n" << std::endl; return 1; } curs_set(1); //show cursor endwin(); //turn off nCurses return 0; }
RTCORE_API void rtcInit(const char* cfg) { cout << "in rtcInit " << endl; Lock<MutexSys> lock(g_mutex); TRACE(rtcInit); CATCH_BEGIN; if (g_initialized) { g_mutex.unlock(); process_error(RTC_INVALID_OPERATION,"already initialized"); g_mutex.lock(); return; } g_initialized = true; /* reset global state */ initSettings(); if (cfg != NULL) { size_t pos = 0; do { std::string tok = parseIdentifier (cfg,pos); if (tok == "threads" && parseSymbol(cfg,'=',pos)) { g_numThreads = parseInt(cfg,pos); #if defined(__MIC__) if (!(g_numThreads == 1 || (g_numThreads % 4) == 0)) { g_mutex.unlock(); process_error(RTC_INVALID_OPERATION,"Xeon Phi supports only number of threads % 4 == 0, or threads == 1"); g_mutex.lock(); return; } #endif } else if (tok == "isa" && parseSymbol (cfg,'=',pos)) { std::string isa = parseIdentifier (cfg,pos); if (isa == "sse" ) cpu_features = SSE; else if (isa == "sse2") cpu_features = SSE2; else if (isa == "sse3") cpu_features = SSE3; else if (isa == "ssse3") cpu_features = SSSE3; else if (isa == "sse41") cpu_features = SSE41; else if (isa == "sse42") cpu_features = SSE42; else if (isa == "avx") cpu_features = AVX; else if (isa == "avxi") cpu_features = AVXI; else if (isa == "avx2") cpu_features = AVX2; } else if ((tok == "tri_accel" || tok == "accel") && parseSymbol (cfg,'=',pos)) g_tri_accel = parseIdentifier (cfg,pos); else if ((tok == "tri_builder" || tok == "builder") && parseSymbol (cfg,'=',pos)) g_tri_builder = parseIdentifier (cfg,pos); else if ((tok == "tri_traverser" || tok == "traverser") && parseSymbol (cfg,'=',pos)) g_tri_traverser = parseIdentifier (cfg,pos); else if ((tok == "tri_accel_mb" || tok == "accel_mb") && parseSymbol (cfg,'=',pos)) g_tri_accel = parseIdentifier (cfg,pos); else if ((tok == "tri_builder_mb" || tok == "builder_mb") && parseSymbol (cfg,'=',pos)) g_tri_builder = parseIdentifier (cfg,pos); else if ((tok == "tri_traverser_mb" || tok == "traverser_mb") && parseSymbol (cfg,'=',pos)) g_tri_traverser = parseIdentifier (cfg,pos); else if (tok == "hair_accel" && parseSymbol (cfg,'=',pos)) g_hair_accel = parseIdentifier (cfg,pos); else if (tok == "hair_builder" && parseSymbol (cfg,'=',pos)) g_hair_builder = parseIdentifier (cfg,pos); else if (tok == "hair_traverser" && parseSymbol (cfg,'=',pos)) g_hair_traverser = parseIdentifier (cfg,pos); else if (tok == "hair_builder_replication_factor" && parseSymbol (cfg,'=',pos)) g_hair_builder_replication_factor = parseInt (cfg,pos); else if (tok == "verbose" && parseSymbol (cfg,'=',pos)) g_verbose = parseInt (cfg,pos); else if (tok == "benchmark" && parseSymbol (cfg,'=',pos)) g_benchmark = parseInt (cfg,pos); else if (tok == "flags") { g_scene_flags = 0; if (parseSymbol (cfg,'=',pos)) { do { std::string flag = parseIdentifier (cfg,pos); if (flag == "static" ) g_scene_flags |= RTC_SCENE_STATIC; else if (flag == "dynamic") g_scene_flags |= RTC_SCENE_DYNAMIC; else if (flag == "compact") g_scene_flags |= RTC_SCENE_COMPACT; else if (flag == "coherent") g_scene_flags |= RTC_SCENE_COHERENT; else if (flag == "incoherent") g_scene_flags |= RTC_SCENE_INCOHERENT; else if (flag == "high_quality") g_scene_flags |= RTC_SCENE_HIGH_QUALITY; else if (flag == "robust") g_scene_flags |= RTC_SCENE_ROBUST; } while (parseSymbol (cfg,',',pos)); } } } while (findNext (cfg,',',pos)); } if (g_verbose >= 1) { std::cout << "Embree Ray Tracing Kernels " << __EMBREE_VERSION__ << " (" << __DATE__ << ")" << std::endl; std::cout << " Compiler : " << getCompilerName() << std::endl; std::cout << " Platform : " << getPlatformName() << std::endl; std::cout << " CPU : " << stringOfCPUFeatures(getCPUFeatures()) << std::endl; std::cout << " Features : "; #if defined(__USE_RAY_MASK__) std::cout << "raymasks "; #endif #if defined (__BACKFACE_CULLING__) std::cout << "backfaceculling "; #endif #if defined(__INTERSECTION_FILTER__) std::cout << "intersection_filter "; #endif #if defined(__BUFFER_STRIDE__) std::cout << "bufferstride "; #endif std::cout << std::endl; #if defined (__MIC__) #if defined(__BUFFER_STRIDE__) std::cout << " WARNING: enabled 'bufferstride' support will lower BVH build performance" << std::endl; #endif #endif } /* CPU has to support at least SSE2 */ #if !defined (__MIC__) if (!has_feature(SSE2)) { g_mutex.unlock(); process_error(RTC_UNSUPPORTED_CPU,"CPU does not support SSE2"); g_mutex.lock(); return; } #endif g_error = createTls(); g_error_function = NULL; init_globals(); cout << "in rtcInit(), BVH4Register() " << endl; #if !defined(__MIC__) cout << "BVH4Register()" << endl; BVH4Register(); #else cout << "BVH4iRegister() " << endl; BVH4iRegister(); #endif cout << "BVH4MBRegister() " << endl; BVH4MBRegister(); BVH4HairRegister(); #if defined(__TARGET_AVX__) cout << "BVH8Register() " << endl; if (has_feature(AVX)) { BVH8Register(); } #endif InstanceIntersectorsRegister(); //if (g_verbose >= 2) printSettings(); TaskScheduler::create(g_numThreads); cout << " end rtcInit " << endl; CATCH_END; }
int main(int argc, char** argv) { if (argc < 2) { printf("Usage: %s 10.68.0.20 [255.255.255.0] [0.0.0.0]\n", argv[0]); return 0; } char nm[] = "255.255.255.0"; char* netmask = nm; if (argc >= 3) { netmask = argv[2]; } char gw[] = "0.0.0.0"; char* gateway = gw; if (argc >= 4) { gateway = argv[3]; } prosilica::init(); // Make sure we call prosilica::fini() on exit. boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(prosilica::fini)); // Check if camera IP is already set char* ip_address = argv[1]; unsigned long IP = inet_addr(ip_address); tPvCameraInfo info; tPvIpSettings conf; tPvErr err = PvCameraInfoByAddr(IP, &info, &conf); if (!err) { printf("Camera found at requested IP address:\n"); printSettings(info, conf); } else { printf("No camera found at %s, trying to change settings of a local camera...\n", ip_address); size_t num_cams = prosilica::numCameras(); if (num_cams == 0) { printf("ERROR: No camera detected. Is it plugged in?\n"); return 1; } if (num_cams == 2) { printf("ERROR: Multiple cameras (%u) found. Do you have more than one plugged in?\n", (unsigned)num_cams); return 1; } printf("Detected camera.\n"); unsigned long uid = prosilica::getGuid(0); if (PvCameraInfo(uid, &info)) { printf("ERROR: could not retrieve camera info.\n"); return 1; } if (PvCameraIpSettingsGet(uid, &conf)) { printf("ERROR: could not retrieve camera IP settings.\n"); return 1; } printf("Original settings:\n"); printSettings(info, conf); printf("Applying new settings...\n"); conf.ConfigMode = ePvIpConfigPersistent; //conf.ConfigMode = ePvIpConfigDhcp; conf.CurrentIpAddress = conf.PersistentIpAddr = IP; conf.CurrentIpSubnet = conf.PersistentIpSubnet = inet_addr(netmask); conf.CurrentIpGateway = conf.PersistentIpGateway = inet_addr(gateway); if (PvCameraIpSettingsChange(uid, &conf)) { printf("ERROR: Failed to apply the new settings\n"); return 1; } printf("New settings:\n"); printSettings(info, conf); } return 0; }
/** * This function is used to save settings inside the XML file. * 1) check if the XML document already exhists; * 2) if so, use it and possibly update it with new attribute/values; * 3) if not, then create the new attribute e set the value for it */ void SettingsManager::saveSettings() { ofLogVerbose(" sett man ") << "save settings "; XML.clear(); // try to load the XML settings document if( !XML.load("settings.xml") ) { ofLogError(" sett man ") << "\t'settings.xml' doesn't exist. I'll create a new one."; XML.addChild("settings"); } else { ofLogNotice(" sett man ") << "\t'settings.xml' already exist. I'll use it!"; } // Now go through all the settings and check // if the local XML handler contains them. // If not then create the new settings. /* BPM settings *************************************/ XML.reset(); if( !XML.setTo("bpm") ) { //cout << "tag 'general' not found! I'll create a new one!" << endl; XML.addChild("bpm"); XML.setTo("bpm"); } XML.setAttribute("value", ofToString( customs.bpm.value ) ); XML.setAttribute("min", ofToString( customs.bpm.min ) ); XML.setAttribute("max", ofToString( customs.bpm.max ) ); /* OSC settings *************************************/ XML.reset(); if( !XML.setTo("OSC") ) { //cout << "tag 'OSC' not found! I'll create a new one!" << endl; XML.addChild("OSC"); XML.setTo("OSC"); } XML.setAttribute("host", ofToString( customs.osc.host ) ); XML.setAttribute("listen", ofToString( customs.osc.listen ) ); XML.setAttribute("send", ofToString( customs.osc.send ) ); XML.setAttribute("status", ofToString( customs.osc.status ) ); /* TUIO settings ************************************/ XML.reset(); if( !XML.setTo("TUIO") ) { cout << "tag 'TUIO' not found! I'll create a new one!" << endl; XML.addChild("TUIO"); XML.setTo("TUIO"); } XML.setAttribute("listen", ofToString( customs.tuio.listen ) ); XML.setAttribute("status", ofToString( customs.tuio.status) ); XML.reset(); /* Aspect settings **********************************/ if( !XML.setTo("aspect") ) { XML.addChild("aspect"); XML.setTo("aspect"); } /* Background settings ******************************/ if( !XML.setTo("background") ) { cout << "tag 'background' not found! I'll create a new one!" << endl; XML.addChild("background"); XML.setTo("background"); } XML.setAttribute("r", ofToString( customs.aspect.background.r ) ); XML.setAttribute("g", ofToString( customs.aspect.background.g ) ); XML.setAttribute("b", ofToString( customs.aspect.background.b ) ); XML.setToParent(); /* Fbo settings *************************************/ if( !XML.setTo("fbo") ) { cout << "tag 'fbo' not found! I'll create a new one!" << endl; XML.addChild("fbo"); XML.setTo("fbo"); } XML.setAttribute("r", ofToString( customs.aspect.fbo.r ) ); XML.setAttribute("g", ofToString( customs.aspect.fbo.g ) ); XML.setAttribute("b", ofToString( customs.aspect.fbo.b ) ); XML.setToParent(); /* Playhead settings ********************************/ if( !XML.setTo("playhead") ) { cout << "tag 'playhead' not found! I'll create a new one!" << endl; XML.addChild("playhead"); XML.setTo("playhead"); } XML.setAttribute("r", ofToString( customs.aspect.playhead.r ) ); XML.setAttribute("g", ofToString( customs.aspect.playhead.g ) ); XML.setAttribute("b", ofToString( customs.aspect.playhead.b ) ); XML.setToParent(); /* Distorion settings *******************************/ if( !XML.setTo("distorsion") ) { cout << "tag 'distorsion' not found! I'll create a new one!" << endl; XML.addChild("distorsion"); XML.setTo("distorsion"); } XML.setAttribute("moveX", ofToString( customs.aspect.distorsion.moveX ) ); XML.setAttribute("moveY", ofToString( customs.aspect.distorsion.moveY ) ); XML.setAttribute("rotX", ofToString( customs.aspect.distorsion.rotX ) ); XML.setAttribute("rotZ", ofToString( customs.aspect.distorsion.rotZ ) ); XML.setAttribute("scale", ofToString( customs.aspect.distorsion.scale ) ); /* FIDUCIAL Generic settings ************************/ // XML.reset(); // if( !XML.setTo("fiducials/fadetime") ) { // //cout << "tag 'fiducials/fadetime' NOT found! I'll create a new one!" << endl; // if( !XML.setTo("fiducials") ) { // //cout << "tag 'fiducials' NOT found! I'll create a new one!" << endl; // XML.addChild("fiducials"); // XML.setTo("fiducials"); // } // XML.addChild("fadetime"); // XML.setTo("fadetime"); // } // XML.setAttribute("in", ofToString( customs.fiducials.fadetime.in ) ); // XML.setAttribute("out", ofToString( customs.fiducials.fadetime.out ) ); XML.reset(); if( !XML.setTo("fiducials") ) { //cout << "tag 'fiducials/fadetime' NOT found! I'll create a new one!" << endl; XML.addChild("fiducials"); XML.setTo("fiducials"); } XML.setAttribute("size", ofToString( customs.fiducials.size ) ); if( !XML.setTo("fadetime") ) { //cout << "tag 'fiducials/fadetime' NOT found! I'll create a new one!" << endl; XML.addChild("fadetime"); XML.setTo("fadetime"); } XML.setAttribute("in", ofToString( customs.fiducials.fadetime.in ) ); XML.setAttribute("out", ofToString( customs.fiducials.fadetime.out ) ); XML.setToParent(); /* FIDUCIAL Percussion settings *********************/ if( !XML.setTo("percussions") ) { XML.addChild("percussions"); XML.setTo("percussions"); } //XML.setAttribute("size", ofToString( customs.fiducials.percussions.size ) ); if( !XML.setTo("triggertime") ) { XML.addChild("triggertime"); XML.setTo("triggertime"); } XML.setAttribute("in", ofToString( customs.fiducials.percussions.triggertime.in ) ); XML.setAttribute("out", ofToString( customs.fiducials.percussions.triggertime.out ) ); XML.setToParent(); /* KICK */ if( !XML.setTo("kick") ) { XML.addChild("kick"); XML.setTo("kick"); } XML.setAttribute("fid", ofToString( customs.fiducials.percussions.kick.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.percussions.kick.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.percussions.kick.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.percussions.kick.color.b ) ); XML.setTo("../../"); /* SNARE */ if( !XML.setTo("snare") ) { XML.addChild("snare"); XML.setTo("snare"); } XML.setAttribute("fid", ofToString( customs.fiducials.percussions.snare.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.percussions.snare.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.percussions.snare.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.percussions.snare.color.b ) ); XML.setTo("../../"); /* HIHAT */ if( !XML.setTo("hihat") ) { XML.addChild("hihat"); XML.setTo("hihat"); } XML.setAttribute("fid", ofToString( customs.fiducials.percussions.hihat.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.percussions.hihat.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.percussions.hihat.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.percussions.hihat.color.b ) ); XML.setTo("../../"); // <-- we are inside 'percussion' tag XML.setToParent(); // <-- now we are inside 'fiducials' tag if( !XML.setTo("metro") ) { XML.addChild("metro"); XML.setTo("metro"); } XML.setAttribute("fid", ofToString( customs.fiducials.metro.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.metro.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.metro.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.metro.color.b ) ); XML.setToParent(); // <-- now we are inside 'metro' tag if( !XML.setTo("meter") ) { XML.addChild("meter"); XML.setTo("meter"); } XML.setAttribute("angleRange", ofToString( customs.fiducials.metro.meter.angleRange ) ); XML.setAttribute("angleGap", ofToString( customs.fiducials.metro.meter.angleGap ) ); XML.setAttribute("radius", ofToString( customs.fiducials.metro.meter.radius ) ); XML.setAttribute("w", ofToString( customs.fiducials.metro.meter.w ) ); if( !XML.setTo("backColor") ) { XML.addChild("backColor"); XML.setTo("backColor"); } XML.setAttribute("r", ofToString( customs.fiducials.metro.meter.backColor.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.metro.meter.backColor.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.metro.meter.backColor.b ) ); XML.setToParent(); // <-- now we are inside 'meter' tag if( !XML.setTo("frontColor") ) { XML.addChild("frontColor"); XML.setTo("frontColor"); } XML.setAttribute("r", ofToString( customs.fiducials.metro.meter.frontColor.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.metro.meter.frontColor.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.metro.meter.frontColor.b ) ); XML.setTo("../../"); // <-- we are inside 'metro' tag XML.setToParent(); // <-- now we are inside 'fiducials' tag if( !XML.setTo("bass") ) { XML.addChild("bass"); XML.setTo("bass"); } XML.setAttribute("fid", ofToString( customs.fiducials.bass.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.bass.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.bass.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.bass.color.b ) ); XML.setTo("../../"); // <-- we are inside 'fiducial' tag if( !XML.setTo("pad") ) { XML.addChild("pad"); XML.setTo("pad"); } XML.setAttribute("fid", ofToString( customs.fiducials.pad.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.pad.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.pad.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.pad.color.b ) ); XML.setTo("../../"); // <-- we are inside 'fiducial' tag if( !XML.setTo("chords") ) { XML.addChild("chords"); XML.setTo("chords"); } if( !XML.setTo("chord1") ) { XML.addChild("chord1"); XML.setTo("chord1"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord1.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord1.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord1.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord1.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag if( !XML.setTo("chord2") ) { XML.addChild("chord2"); XML.setTo("chord2"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord2.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord2.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord2.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord2.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag if( !XML.setTo("chord3") ) { XML.addChild("chord3"); XML.setTo("chord3"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord3.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord3.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord3.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord3.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag if( !XML.setTo("chord4") ) { XML.addChild("chord4"); XML.setTo("chord4"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord4.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord4.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord4.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord4.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag if( !XML.setTo("chord5") ) { XML.addChild("chord5"); XML.setTo("chord5"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord5.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord5.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord5.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord5.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag if( !XML.setTo("chord6") ) { XML.addChild("chord6"); XML.setTo("chord6"); } XML.setAttribute("fid", ofToString( customs.fiducials.chords.chord6.fid ) ); if( !XML.setTo("color") ) { XML.addChild("color"); XML.setTo("color"); } XML.setAttribute("r", ofToString( customs.fiducials.chords.chord6.color.r ) ); XML.setAttribute("g", ofToString( customs.fiducials.chords.chord6.color.g ) ); XML.setAttribute("b", ofToString( customs.fiducials.chords.chord6.color.b ) ); XML.setTo("../../"); // <-- we are inside 'chords' tag /* Save the file ************************************/ if( XML.save("settings.xml") ) ofLogNotice(" sett man ") << "\tSaving succeded!"; else ofLogError(" sett man ") << "\tSaving failed."; printSettings(); }
void SettingsManager::loadSettings() { ofLogVerbose(" sett man ") << "load settings "; XML.clear(); // try to load the XML settings document if( !XML.load("settings.xml") ) { ofLogError(" sett man ") << "\tLoading 'settings.xml' failed"; return; } ofLogNotice(" sett man ") << "\tLoading 'settings.xml' succeeded!"; // Custom settings already contains default values // because of the initialization of the structures // but, if we found a custom value/attribute // for the parameter inside the XML file, we use it. string s = ""; /* BPM settings *************************************/ s = "//bpm[@value]"; if( XML.exists(s) ) customs.bpm.value = ofToInt( XML.getAttribute(s) ); s = "//bpm[@min]"; if( XML.exists(s) ) customs.bpm.min = ofToInt( XML.getAttribute(s) ); s = "//bpm[@max]"; if( XML.exists(s) ) customs.bpm.max = ofToInt( XML.getAttribute(s) ); /* OSC settings *************************************/ s = "//OSC[@status]"; if( XML.exists(s) ) customs.osc.status = XML.getAttribute(s); s = "//OSC[@host]"; if( XML.exists(s) ) customs.osc.host = XML.getAttribute(s); s = "//OSC[@send]"; if( XML.exists(s) ) customs.osc.send = XML.getAttribute(s); s = "//OSC[@listen]"; if( XML.exists(s) ) customs.osc.listen = XML.getAttribute(s); /* TUIO settings ************************************/ s = "//TUIO[@status]"; if( XML.exists(s) ) customs.tuio.status = XML.getAttribute(s); s = "//TUIO[@port]"; if( XML.exists(s) ) customs.tuio.listen = XML.getAttribute(s); /* Aspect settings **********************************/ /* Background ***************************************/ s = "//aspect/background[@r]"; if( XML.exists(s) ) customs.aspect.background.r = ofToInt( XML.getAttribute(s) ); s = "//aspect/background[@g]"; if( XML.exists(s) ) customs.aspect.background.g = ofToInt( XML.getAttribute(s) ); s = "//aspect/background[@b]"; if( XML.exists(s) ) customs.aspect.background.b = ofToInt( XML.getAttribute(s) ); /* Fbo **********************************************/ s = "//aspect/fbo[@r]"; if( XML.exists(s) ) customs.aspect.fbo.r = ofToInt( XML.getAttribute(s) ); s = "//aspect/fbo[@g]"; if( XML.exists(s) ) customs.aspect.fbo.g = ofToInt( XML.getAttribute(s) ); s = "//aspect/fbo[@b]"; if( XML.exists(s) ) customs.aspect.fbo.b = ofToInt( XML.getAttribute(s) ); /* Playhead *****************************************/ s = "//aspect/playhead[@r]"; if( XML.exists(s) ) customs.aspect.playhead.r = ofToInt( XML.getAttribute(s) ); s = "//aspect/playhead[@g]"; if( XML.exists(s) ) customs.aspect.playhead.g = ofToInt( XML.getAttribute(s) ); s = "//aspect/playhead[@b]"; if( XML.exists(s) ) customs.aspect.playhead.b = ofToInt( XML.getAttribute(s) ); /* Distorion settings *******************************/ s = "//aspect/distorsion[@moveX]"; if( XML.exists(s) ) customs.aspect.distorsion.moveX = ofToFloat( XML.getAttribute(s) ); s = "//aspect/distorsion[@moveY]"; if( XML.exists(s) ) customs.aspect.distorsion.moveY = ofToFloat( XML.getAttribute(s) ); s = "//aspect/distorsion[@rotX]"; if( XML.exists(s) ) customs.aspect.distorsion.rotX = ofToFloat( XML.getAttribute(s) ); s = "//aspect/distorsion[@rotZ]"; if( XML.exists(s) ) customs.aspect.distorsion.rotZ = ofToFloat( XML.getAttribute(s) ); s = "//aspect/distorsion[@scale]"; if( XML.exists(s) ) customs.aspect.distorsion.scale = ofToFloat( XML.getAttribute(s) ); /* FIDUCIAL Generic settings ************************/ s = "//fiducials[@size]"; if( XML.exists(s) ) customs.fiducials.size = ofToInt( XML.getAttribute(s) ); s = "//fiducials/fadetime[@in]"; if( XML.exists(s) ) customs.fiducials.fadetime.in = ofToInt( XML.getAttribute(s) ); s = "//fiducials/fadetime[@out]"; if( XML.exists(s) ) customs.fiducials.fadetime.out = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL PERCUSSION settings *********************/ s = "//fiducials/percussions/triggertime[@in]"; if( XML.exists(s) ) customs.fiducials.percussions.triggertime.in = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/triggertime[@out]"; if( XML.exists(s) ) customs.fiducials.percussions.triggertime.out = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL PERCUSSION KICK settings ****************/ s = "//fiducials/percussions/kick[@fid]"; if( XML.exists(s) ) customs.fiducials.percussions.kick.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/kick/color[@b]"; if( XML.exists(s) ) customs.fiducials.percussions.kick.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/kick/color[@g]"; if( XML.exists(s) ) customs.fiducials.percussions.kick.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/kick/color[@r]"; if( XML.exists(s) ) customs.fiducials.percussions.kick.color.r = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL PERCUSSION SNARE settings ***************/ s = "//fiducials/percussions/snare[@fid]"; if( XML.exists(s) ) customs.fiducials.percussions.snare.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/snare/color[@b]"; if( XML.exists(s) ) customs.fiducials.percussions.snare.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/snare/color[@g]"; if( XML.exists(s) ) customs.fiducials.percussions.snare.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/snare/color[@r]"; if( XML.exists(s) ) customs.fiducials.percussions.snare.color.r = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL PERCUSSION HIHAT settings ***************/ s = "//fiducials/percussions/hihat[@fid]"; if( XML.exists(s) ) customs.fiducials.percussions.hihat.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/hihat/color[@b]"; if( XML.exists(s) ) customs.fiducials.percussions.hihat.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/hihat/color[@g]"; if( XML.exists(s) ) customs.fiducials.percussions.hihat.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/percussions/hihat/color[@r]"; if( XML.exists(s) ) customs.fiducials.percussions.hihat.color.r = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL METRO settings **************************/ s = "//fiducials/metro[@fid]"; if( XML.exists(s) ) customs.fiducials.metro.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/color[@b]"; if( XML.exists(s) ) customs.fiducials.metro.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/color[@g]"; if( XML.exists(s) ) customs.fiducials.metro.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/color[@r]"; if( XML.exists(s) ) customs.fiducials.metro.color.r = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter[@angleRange]"; if( XML.exists(s) ) customs.fiducials.metro.meter.angleRange = ofToFloat( XML.getAttribute(s) ); s = "//fiducials/metro/meter[@angleGap]"; if( XML.exists(s) ) customs.fiducials.metro.meter.angleGap = ofToFloat( XML.getAttribute(s) ); s = "//fiducials/metro/meter[@radius]"; if( XML.exists(s) ) customs.fiducials.metro.meter.radius = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter[@w]"; if( XML.exists(s) ) customs.fiducials.metro.meter.w = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/backColor[@r]"; if( XML.exists(s) ) customs.fiducials.metro.meter.backColor.r = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/backColor[@g]"; if( XML.exists(s) ) customs.fiducials.metro.meter.backColor.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/backColor[@b]"; if( XML.exists(s) ) customs.fiducials.metro.meter.backColor.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/frontColor[@r]"; if( XML.exists(s) ) customs.fiducials.metro.meter.frontColor.r = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/frontColor[@g]"; if( XML.exists(s) ) customs.fiducials.metro.meter.frontColor.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/metro/meter/frontColor[@b]"; if( XML.exists(s) ) customs.fiducials.metro.meter.frontColor.b = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL BASS settings ***************************/ s = "//fiducials/bass[@fid]"; if( XML.exists(s) ) customs.fiducials.bass.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/bass/color[@b]"; if( XML.exists(s) ) customs.fiducials.bass.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/bass/color[@g]"; if( XML.exists(s) ) customs.fiducials.bass.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/bass/color[@r]"; if( XML.exists(s) ) customs.fiducials.bass.color.r = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL PAD settings ****************************/ s = "//fiducials/pad[@fid]"; if( XML.exists(s) ) customs.fiducials.pad.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/pad/color[@b]"; if( XML.exists(s) ) customs.fiducials.pad.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/pad/color[@g]"; if( XML.exists(s) ) customs.fiducials.pad.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/pad/color[@r]"; if( XML.exists(s) ) customs.fiducials.pad.color.r = ofToInt( XML.getAttribute(s) ); /* FIDUCIAL CHORDS settings *************************/ /* CHORD 1 settings *********************************/ s = "//fiducials/chords/chord1[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord1.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord1/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord1.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord1/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord1.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord1/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord1.color.r = ofToInt( XML.getAttribute(s) ); /* CHORD 2 settings *********************************/ s = "//fiducials/chords/chord2[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord2.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord2/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord2.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord2/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord2.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord2/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord2.color.r = ofToInt( XML.getAttribute(s) ); /* CHORD 3 settings *********************************/ s = "//fiducials/chords/chord3[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord3.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord3/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord3.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord3/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord3.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord3/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord3.color.r = ofToInt( XML.getAttribute(s) ); /* CHORD 4 settings *********************************/ s = "//fiducials/chords/chord4[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord4.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord4/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord4.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord4/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord4.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord4/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord4.color.r = ofToInt( XML.getAttribute(s) ); /* CHORD 5 settings *********************************/ s = "//fiducials/chords/chord5[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord5.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord5/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord5.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord5/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord5.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord5/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord5.color.r = ofToInt( XML.getAttribute(s) ); /* CHORD 6 settings *********************************/ s = "//fiducials/chords/chord6[@fid]"; if( XML.exists(s) ) customs.fiducials.chords.chord6.fid = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord6/color[@b]"; if( XML.exists(s) ) customs.fiducials.chords.chord6.color.b = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord6/color[@g]"; if( XML.exists(s) ) customs.fiducials.chords.chord6.color.g = ofToInt( XML.getAttribute(s) ); s = "//fiducials/chords/chord6/color[@r]"; if( XML.exists(s) ) customs.fiducials.chords.chord6.color.r = ofToInt( XML.getAttribute(s) ); printSettings(); // loose any reference to the XML file XML.clear(); }
void SettingsManager::loadDefaults() { ofLogVerbose(" sett man ") << "load defaults"; customs = defaults; printSettings(); }
void D2V::index() { AVPacket packet; av_init_packet(&packet); while (av_read_frame(f->fctx, &packet) == 0) { if (stop_processing) { stop_processing = false; result = ProcessingCancelled; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } // Apparently we might receive packets from streams with AVDISCARD_ALL set, // and also from streams discovered late, probably. if (packet.stream_index != video_stream->index && !audio_files.count(packet.stream_index)) { av_free_packet(&packet); continue; } bool okay = true; if (packet.stream_index == video_stream->index) okay = handleVideoPacket(&packet); else okay = handleAudioPacket(&packet); if (!okay) { av_free_packet(&packet); result = ProcessingError; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } av_free_packet(&packet); } if (!isDataLineNull()) { reorderDataLineFlags(); lines.push_back(line); clearDataLine(); } if (!lines.size()) { result = ProcessingFinished; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } if (!printHeader()) { result = ProcessingError; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } if (!printSettings()) { result = ProcessingError; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } for (size_t i = 0; i < lines.size(); i++) { if (stop_processing) { stop_processing = false; result = ProcessingCancelled; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } if (!printDataLine(lines[i])) { result = ProcessingError; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } } if (!printStreamEnd()) { result = ProcessingError; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); return; } result = ProcessingFinished; fclose(d2v_file); closeAudioFiles(audio_files, f->fctx); }
int main(int argc, char **argv) { SHA1Context sha; uint8_t *buf; uint8_t res[20]; int i, j, k; FILE *fp = 0; settings_t theSettings; if (argc == 1) { usage(argv[0]); exit(1); } defaultSettings(&theSettings); readSettings(&theSettings, argc, argv); printSettings(&theSettings, stdout); theSettings.hashEntries = (hashEntry *) malloc(sizeof(hashEntry) * theSettings.numHashes); memset(theSettings.hashEntries, 0x00, sizeof(hashEntry)*theSettings.numHashes); fp = fopen(theSettings.fileName, "rb"); fseek(fp, theSettings.hashOffset, SEEK_SET); for (i = 0; i < theSettings.numHashes; i++) { //initHashEntry(&theSettings.hashEntries[i]); fread(theSettings.hashEntries[i].hash, sizeof(uint8_t), 20, fp); theSettings.hashEntries[i].hashOffset = ftell(fp); fseek(fp, theSettings.hashRelativeOffset, SEEK_CUR); printHashEntry(&theSettings.hashEntries[i], stdout); } buf = (uint8_t *) malloc(sizeof(uint8_t) * theSettings.maxHashLength); while (theSettings.curFileOffset < theSettings.maxFileOffset) { fseek(fp, theSettings.curFileOffset, SEEK_SET); fread(buf, sizeof(uint8_t), theSettings.maxHashLength, fp); // yeah okay so I should have called it "ts", wanna fight about it? for (theSettings.curHashLength = theSettings.minHashLength; theSettings.curHashLength <= theSettings.maxHashLength; theSettings.curHashLength++) { SHA1Reset(&sha); SHA1Input(&sha, buf, theSettings.curHashLength); SHA1Result(&sha, res); for (i = 0; i < theSettings.numHashes; i++) { k = 1; for (j = 0; j < 20; j++) { if (res[j] != theSettings.hashEntries[i].hash[j]) { k = 0; } } if (k) { printf("-------------------------------------\nMatch Found!\nHash Entry #%d\n", i); theSettings.hashEntries[i].fileOffset = theSettings.curFileOffset; theSettings.hashEntries[i].hashSize = theSettings.curHashLength; printHashEntry(&theSettings.hashEntries[i], stdout); theSettings.curFileOffset += theSettings.curHashLength-1; } } } theSettings.curFileOffset++; } }