+ while (!status.cancel) {
+ framecnt_t const nread = source->read (data.get(), nframes * channels);
+ if (nread == 0) {
+ break;
+ }
+
+ peak = compute_peak (data.get(), nread * channels, peak);
+
+ read_count += nread / channels;
+ status.progress = 0.5 * read_count / (source->ratio() * source->length() * channels);
+ }
+
+ if (peak >= 1) {
+ /* we are out of range: compute a gain to fix it */
+ gain = (1 - FLT_EPSILON) / peak;
+ }
+
+ source->seek (0);
+ progress_multiplier = 0.5;
+ progress_base = 0.5;
+ }
+
+ framecnt_t read_count = 0;
+
+ while (!status.cancel) {
+
+ framecnt_t nread, nfread;
+ uint32_t x;
+ uint32_t chn;
+
+ if ((nread = source->read (data.get(), nframes * channels)) == 0) {
+#ifdef PLATFORM_WINDOWS
+ /* Flush the data once we've finished importing the file. Windows can */
+ /* cache the data for very long periods of time (perhaps not writing */
+ /* it to disk until Ardour closes). So let's force it to flush now. */
+ for (chn = 0; chn < channels; ++chn)
+ if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(newfiles[chn])) != 0)
+ afs->flush ();
+#endif