void VideoPreview::saveSettings() { qDebug("VideoPreview::saveSettings"); set->beginGroup("videopreview"); set->setValue("columns", cols()); set->setValue("rows", rows()); set->setValue("initial_step", initialStep()); set->setValue("max_width", maxWidth()); set->setValue("osd", displayOSD()); set->setValue("format", extractFormat()); set->setValue("save_last_directory", save_last_directory); if (save_last_directory) { set->setValue("last_directory", last_directory); } set->setValue("filename", videoFile()); set->setValue("dvd_device", DVDDevice()); set->setValue("show_info", toggleInfoAct->isChecked()); set->endGroup(); }
bool VideoPreview::showConfigDialog(QWidget *parent) { VideoPreviewConfigDialog d(parent); d.setVideoFile(videoFile()); d.setDVDDevice(DVDDevice()); d.setCols(cols()); d.setRows(rows()); d.setInitialStep(initialStep()); d.setMaxWidth(maxWidth()); d.setDisplayOSD(displayOSD()); d.setAspectRatio(aspectRatio()); d.setFormat(extractFormat()); d.setSaveLastDirectory(save_last_directory); if (d.exec() == QDialog::Accepted) { setVideoFile(d.videoFile()); setDVDDevice(d.DVDDevice()); setCols(d.cols()); setRows(d.rows()); setInitialStep(d.initialStep()); setMaxWidth(d.maxWidth()); setDisplayOSD(d.displayOSD()); setAspectRatio(d.aspectRatio()); setExtractFormat(d.format()); save_last_directory = d.saveLastDirectory(); return true; } return false; }
void KNMusicLyricsDownloader::downloadLyrics( uint identifier, const KNMusicDetailInfo &detailInfo) { //Check whether the identifier appears in the map or not. if(m_sourceMap.contains(identifier)) { //Pick out the request source from the map. KNMusicLyricsRequestSource source=m_sourceMap.value(identifier); //Check the source working state. if(source.isWorking) { //Need to cancel the source first. return; } //Create the new step. KNMusicLyricsStep request; //Save the detail info as the current working info. request.detailInfo=detailInfo; //Update the source. source.currentStep=request; //Set the working flag. source.isWorking=true; //Update the source to the map. m_sourceMap.insert(identifier, source); //Start the first step. initialStep(identifier, detailInfo); } else { //Start the new queue for the request source. KNMusicLyricsRequestSource source; //Save the detail info as the current working info. source.currentStep.detailInfo=detailInfo; //Set the working flag. source.isWorking=true; //Append the source to the map. m_sourceMap.insert(identifier, source); //Start the first step. initialStep(identifier, detailInfo); } }
void ClientMediaDownloader::step(Client *client) { if (!m_initial_step_done) { initialStep(client); m_initial_step_done = true; } // Remote media: check for completion of fetches if (m_httpfetch_active) { bool fetched_something = false; HTTPFetchResult fetchresult; while (httpfetch_async_get(m_httpfetch_caller, fetchresult)) { m_httpfetch_active--; fetched_something = true; // Is this a hashset (index.mth) or a media file? if (fetchresult.request_id < m_remotes.size()) remoteHashSetReceived(fetchresult); else remoteMediaReceived(fetchresult, client); } if (fetched_something) startRemoteMediaTransfers(); // Did all remote transfers end and no new ones can be started? // If so, request still missing files from the minetest server // (Or report that we have all files.) if (m_httpfetch_active == 0) { if (m_uncached_received_count < m_uncached_count) { infostream << "Client: Failed to remote-fetch " << (m_uncached_count-m_uncached_received_count) << " files. Requesting them" << " the usual way." << std::endl; } startConventionalTransfers(client); } } }
void VideoPreview::loadSettings() { qDebug("VideoPreview::loadSettings"); set->beginGroup("videopreview"); setCols(set->value("columns", cols()).toInt()); setRows(set->value("rows", rows()).toInt()); setInitialStep(set->value("initial_step", initialStep()).toInt()); setMaxWidth(set->value("max_width", maxWidth()).toInt()); setDisplayOSD(set->value("osd", displayOSD()).toBool()); setExtractFormat((ExtractFormat) set->value("format", extractFormat()).toInt()); save_last_directory = set->value("save_last_directory", save_last_directory).toBool(); last_directory = set->value("last_directory", last_directory).toString(); setVideoFile(set->value("filename", videoFile()).toString()); setDVDDevice(set->value("dvd_device", DVDDevice()).toString()); toggleInfoAct->setChecked(set->value("show_info", true).toBool()); set->endGroup(); }
/* * This routine is a bounds-constrained truncated-newton method. * the truncated-newton method is preconditioned by a limited-memory * quasi-newton method (this preconditioning strategy is developed * in this routine) with a further diagonal scaling * (see routine diagonalscaling). */ static tnc_rc tnc_minimize(int n, double x[], double *f, double gfull[], tnc_function *function, void *state, double xscale[], double xoffset[], double *fscale, double low[], double up[], tnc_message messages, int maxCGit, int maxnfeval, int *nfeval, int *niter, double eta, double stepmx, double accuracy, double fmin, double ftol, double xtol, double pgtol, double rescale, tnc_callback *callback) { double fLastReset, difnew, epsmch, epsred, oldgtp, difold, oldf, xnorm, newscale, gnorm, ustpmax, fLastConstraint, spe, yrsr, yksk, *temp = NULL, *sk = NULL, *yk = NULL, *diagb = NULL, *sr = NULL, *yr = NULL, *oldg = NULL, *pk = NULL, *g = NULL; double alpha = 0.0; /* Default unused value */ int i, icycle, oldnfeval, *pivot = NULL, frc; logical lreset, newcon, upd1, remcon; tnc_rc rc = TNC_ENOMEM; /* Default error */ *niter = 0; /* Allocate temporary vectors */ oldg = malloc(sizeof(*oldg)*n); if (oldg == NULL) goto cleanup; g = malloc(sizeof(*g)*n); if (g == NULL) goto cleanup; temp = malloc(sizeof(*temp)*n); if (temp == NULL) goto cleanup; diagb = malloc(sizeof(*diagb)*n); if (diagb == NULL) goto cleanup; pk = malloc(sizeof(*pk)*n); if (pk == NULL) goto cleanup; sk = malloc(sizeof(*sk)*n); if (sk == NULL) goto cleanup; yk = malloc(sizeof(*yk)*n); if (yk == NULL) goto cleanup; sr = malloc(sizeof(*sr)*n); if (sr == NULL) goto cleanup; yr = malloc(sizeof(*yr)*n); if (yr == NULL) goto cleanup; pivot = malloc(sizeof(*pivot)*n); if (pivot == NULL) goto cleanup; /* Initialize variables */ epsmch = mchpr1(); difnew = 0.0; epsred = 0.05; upd1 = TNC_TRUE; icycle = n - 1; newcon = TNC_TRUE; /* Uneeded initialisations */ lreset = TNC_FALSE; yrsr = 0.0; yksk = 0.0; /* Initial scaling */ scalex(n, x, xscale, xoffset); (*f) *= *fscale; /* initial pivot calculation */ setConstraints(n, x, pivot, xscale, xoffset, low, up); dcopy1(n, gfull, g); scaleg(n, g, xscale, *fscale); /* Test the lagrange multipliers to see if they are non-negative. */ for (i = 0; i < n; i++) if (-pivot[i] * g[i] < 0.0) pivot[i] = 0; project(n, g, pivot); /* Set initial values to other parameters */ gnorm = dnrm21(n, g); fLastConstraint = *f; /* Value at last constraint */ fLastReset = *f; /* Value at last reset */ if (messages & TNC_MSG_ITER) fprintf(stderr, " NIT NF F GTG\n"); if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Set the diagonal of the approximate hessian to unity. */ for (i = 0; i < n; i++) diagb[i] = 1.0; /* Start of main iterative loop */ while(TNC_TRUE) { /* Local minimum test */ if (dnrm21(n, g) <= pgtol * (*fscale)) { /* |PG| == 0.0 => local minimum */ dcopy1(n, gfull, g); project(n, g, pivot); if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |pg| = %g -> local minimum\n", dnrm21(n, g) / (*fscale)); rc = TNC_LOCALMINIMUM; break; } /* Terminate if more than maxnfeval evaluations have been made */ if (*nfeval >= maxnfeval) { rc = TNC_MAXFUN; break; } /* Rescale function if necessary */ newscale = dnrm21(n, g); if ((newscale > epsmch) && (fabs(log10(newscale)) > rescale)) { newscale = 1.0/newscale; *f *= newscale; *fscale *= newscale; gnorm *= newscale; fLastConstraint *= newscale; fLastReset *= newscale; difnew *= newscale; for (i = 0; i < n; i++) g[i] *= newscale; for (i = 0; i < n; i++) diagb[i] = 1.0; upd1 = TNC_TRUE; icycle = n - 1; newcon = TNC_TRUE; if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: fscale = %g\n", *fscale); } dcopy1(n, x, temp); project(n, temp, pivot); xnorm = dnrm21(n, temp); oldnfeval = *nfeval; /* Compute the new search direction */ frc = tnc_direction(pk, diagb, x, g, n, maxCGit, maxnfeval, nfeval, upd1, yksk, yrsr, sk, yk, sr, yr, lreset, function, state, xscale, xoffset, *fscale, pivot, accuracy, gnorm, xnorm, low, up); if (frc == -1) { rc = TNC_ENOMEM; break; } if (frc) { rc = TNC_USERABORT; break; } if (!newcon) { if (!lreset) { /* Compute the accumulated step and its corresponding gradient difference. */ dxpy1(n, sk, sr); dxpy1(n, yk, yr); icycle++; } else { /* Initialize the sum of all the changes */ dcopy1(n, sk, sr); dcopy1(n, yk, yr); fLastReset = *f; icycle = 1; } } dcopy1(n, g, oldg); oldf = *f; oldgtp = ddot1(n, pk, g); /* Maximum unconstrained step length */ ustpmax = stepmx / (dnrm21(n, pk) + epsmch); /* Maximum constrained step length */ spe = stepMax(ustpmax, n, x, pk, pivot, low, up, xscale, xoffset); if (spe > 0.0) { ls_rc lsrc; /* Set the initial step length */ alpha = initialStep(*f, fmin / (*fscale), oldgtp, spe); /* Perform the linear search */ lsrc = linearSearch(n, function, state, low, up, xscale, xoffset, *fscale, pivot, eta, ftol, spe, pk, x, f, &alpha, gfull, maxnfeval, nfeval); if (lsrc == LS_ENOMEM) { rc = TNC_ENOMEM; break; } if (lsrc == LS_USERABORT) { rc = TNC_USERABORT; break; } if (lsrc == LS_FAIL) { rc = TNC_LSFAIL; break; } /* If we went up to the maximum unconstrained step, increase it */ if (alpha >= 0.9 * ustpmax) { stepmx *= 1e2; if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: stepmx = %g\n", stepmx); } /* If we went up to the maximum constrained step, a new constraint was encountered */ if (alpha - spe >= -epsmch * 10.0) { newcon = TNC_TRUE; } else { /* Break if the linear search has failed to find a lower point */ if (lsrc != LS_OK) { if (lsrc == LS_MAXFUN) rc = TNC_MAXFUN; else rc = TNC_LSFAIL; break; } newcon = TNC_FALSE; } } else { /* Maximum constrained step == 0.0 => new constraint */ newcon = TNC_TRUE; } if (newcon) { if(!addConstraint(n, x, pk, pivot, low, up, xscale, xoffset)) { if(*nfeval == oldnfeval) { rc = TNC_NOPROGRESS; break; } } fLastConstraint = *f; } (*niter)++; /* Invoke the callback function */ if (callback) { unscalex(n, x, xscale, xoffset); callback(x, state); scalex(n, x, xscale, xoffset); } /* Set up parameters used in convergence and resetting tests */ difold = difnew; difnew = oldf - *f; /* If this is the first iteration of a new cycle, compute the percentage reduction factor for the resetting test */ if (icycle == 1) { if (difnew > difold * 2.0) epsred += epsred; if (difnew < difold * 0.5) epsred *= 0.5; } dcopy1(n, gfull, g); scaleg(n, g, xscale, *fscale); dcopy1(n, g, temp); project(n, temp, pivot); gnorm = dnrm21(n, temp); /* Reset pivot */ remcon = removeConstraint(oldgtp, gnorm, pgtol * (*fscale), *f, fLastConstraint, g, pivot, n); /* If a constraint is removed */ if (remcon) { /* Recalculate gnorm and reset fLastConstraint */ dcopy1(n, g, temp); project(n, temp, pivot); gnorm = dnrm21(n, temp); fLastConstraint = *f; } if (!remcon && !newcon) { /* No constraint removed & no new constraint : tests for convergence */ if (fabs(difnew) <= ftol * (*fscale)) { if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |fn-fn-1] = %g -> convergence\n", fabs(difnew) / (*fscale)); rc = TNC_FCONVERGED; break; } if (alpha * dnrm21(n, pk) <= xtol) { if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |xn-xn-1] = %g -> convergence\n", alpha * dnrm21(n, pk)); rc = TNC_XCONVERGED; break; } } project(n, g, pivot); if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Compute the change in the iterates and the corresponding change in the gradients */ if (!newcon) { for (i = 0; i < n; i++) { yk[i] = g[i] - oldg[i]; sk[i] = alpha * pk[i]; } /* Set up parameters used in updating the preconditioning strategy */ yksk = ddot1(n, yk, sk); if (icycle == (n - 1) || difnew < epsred * (fLastReset - *f)) lreset = TNC_TRUE; else { yrsr = ddot1(n, yr, sr); if (yrsr <= 0.0) lreset = TNC_TRUE; else lreset = TNC_FALSE; } upd1 = TNC_FALSE; } } if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Unscaling */ unscalex(n, x, xscale, xoffset); coercex(n, x, low, up); (*f) /= *fscale; cleanup: if (oldg) free(oldg); if (g) free(g); if (temp) free(temp); if (diagb) free(diagb); if (pk) free(pk); if (sk) free(sk); if (yk) free(yk); if (sr) free(sr); if (yr) free(yr); if (pivot) free(pivot); return rc; }