diff framework/MainWindowBase.cpp @ 626:51ecc3e2d71c

Don't resample an incoming audio file to match the main model's rate, if the aim of importing is to replace the main model anyway
author Chris Cannam
date Tue, 09 Oct 2018 15:55:16 +0100
parents 22e455beee3b
children 7eafe977a1fc
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Wed Sep 12 15:58:35 2018 +0100
+++ b/framework/MainWindowBase.cpp	Tue Oct 09 15:55:16 2018 +0100
@@ -1452,7 +1452,8 @@
 }
 
 MainWindowBase::FileOpenStatus
-MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode,
+MainWindowBase::openAudio(FileSource source,
+                          AudioFileOpenMode mode,
                           QString templateName)
 {
     SVDEBUG << "MainWindowBase::openAudio(" << source.getLocation() << ") with mode " << mode << " and template " << templateName << endl;
@@ -1478,14 +1479,27 @@
 
     sv_samplerate_t rate = 0;
 
+    SVDEBUG << "Checking whether to preserve incoming audio file's sample rate"
+            << endl;
+    
     if (Preferences::getInstance()->getFixedSampleRate() != 0) {
         rate = Preferences::getInstance()->getFixedSampleRate();
+        SVDEBUG << "No: preferences specify fixed rate of " << rate << endl;
     } else if (Preferences::getInstance()->getResampleOnLoad()) {
         if (getMainModel()) {
-            rate = getMainModel()->getSampleRate();
+            if (mode == ReplaceSession || mode == ReplaceMainModel) {
+                SVDEBUG << "Preferences specify resampling additional models to match main model, but we are opening this file to replace the main model according to the open mode: therefore..." << endl;
+            } else {
+                rate = getMainModel()->getSampleRate();
+                SVDEBUG << "No: preferences specify resampling to match main model, whose rate is currently " << rate << endl;
+            }
         }
     }
 
+    if (rate == 0) {
+        SVDEBUG << "Yes, preserving incoming file rate" << endl;
+    }
+    
     ReadOnlyWaveFileModel *newModel = new ReadOnlyWaveFileModel(source, rate);
 
     if (!newModel->isOK()) {