# HG changeset patch # User Chris Cannam # Date 1303911966 -3600 # Node ID e06a0124c662e31d5c8c93db8aefde7d419aac9c # Parent 0b1886cee2cff440a6cc759fe2433e6e013ccb79 Add ReplaceSession open mode for audio files, which discards the session and creates a new one using the template if available. Currently this is available as an additional option in the AskUser mode dialog -- this might bear future simplification. Addresses first bit of #148 diff -r 0b1886cee2cf -r e06a0124c662 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Wed Apr 27 11:33:48 2011 +0100 +++ b/framework/MainWindowBase.cpp Wed Apr 27 14:46:06 2011 +0100 @@ -690,11 +690,11 @@ long firstEventFrame = clipboard.getPoints()[0].getFrame(); long offset = 0; if (firstEventFrame < 0) { - offset = long(pos) - firstEventFrame; + offset = (long)pos - firstEventFrame; } else if (firstEventFrame < pos) { - offset = pos - firstEventFrame; + offset = pos - (unsigned long)firstEventFrame; } else { - offset = -(firstEventFrame - pos); + offset = -((unsigned long)firstEventFrame - pos); } pasteRelative(offset); } @@ -1103,19 +1103,20 @@ QSettings settings; settings.beginGroup("MainWindow"); - bool prevSetAsMain = settings.value("newsessionforaudio", true).toBool(); + int lastMode = settings.value("lastaudioopenmode", 0).toBool(); settings.endGroup(); - bool setAsMain = true; + int imode = 0; QStringList items; - items << tr("Replace the existing main waveform") - << tr("Load this file into a new waveform pane"); + items << tr("Close the current session and start a new one") + << tr("Replace the main audio file in this session") + << tr("Add the audio file to this session"); bool ok = false; QString item = ListInputDialog::getItem (this, tr("Select target for import"), - tr("Select a target for import
You already have an audio waveform loaded.
What would you like to do with the new audio file?"),
- items, prevSetAsMain ? 0 : 1, &ok);
+ tr("Select a target for import
You already have an audio file loaded.
What would you like to do with the new audio file?"),
+ items, lastMode, &ok);
if (!ok || item.isEmpty()) {
delete newModel;
@@ -1123,16 +1124,19 @@
return FileOpenCancelled;
}
- setAsMain = (item == items[0]);
+ for (int i = 0; i < items.size(); ++i) {
+ if (item == items[i]) imode = i;
+ }
+
settings.beginGroup("MainWindow");
- settings.setValue("newsessionforaudio", setAsMain);
+ settings.setValue("lastaudioopenmode", imode);
settings.endGroup();
- if (setAsMain) mode = ReplaceMainModel;
- else mode = CreateAdditionalModel;
+ mode = (AudioFileOpenMode)imode;
} else {
- mode = ReplaceMainModel;
+ // no main model: make a new session
+ mode = ReplaceSession;
}
}
@@ -1143,31 +1147,47 @@
if (getMainModel()) {
View::ModelSet models(pane->getModels());
if (models.find(getMainModel()) != models.end()) {
+ // Current pane contains main model: replace that
mode = ReplaceMainModel;
}
+ // Otherwise the current pane has a non-default model,
+ // which we will deal with later
} else {
- mode = ReplaceMainModel;
+ // We have no main model, so start a new session with
+ // optional template
+ mode = ReplaceSession;
}
} else {
+ // We seem to have no current pane! Oh well
mode = CreateAdditionalModel;
}
}
if (mode == CreateAdditionalModel && !getMainModel()) {
+ mode = ReplaceSession;
+ }
+
+ bool loadedTemplate = false;
+
+ if (mode == ReplaceSession) {
+
+ if (templateName.length() != 0) {
+ QString tplPath = "file::templates/" + templateName + ".xml";
+ std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl;
+ FileOpenStatus tplStatus = openSessionFile(tplPath);
+ if (tplStatus != FileOpenFailed) {
+ loadedTemplate = true;
+ }
+ }
+
+ if (!loadedTemplate) {
+ closeSession();
+ createDocument();
+ }
+
mode = ReplaceMainModel;
}
- bool loadedTemplate = false;
- if ((mode == ReplaceMainModel) && (templateName.length() != 0)) {
- QString tplPath = "file::templates/" + templateName + ".xml";
- std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl;
- FileOpenStatus tplStatus = openSessionFile(tplPath);
- if(tplStatus != FileOpenFailed) {
- loadedTemplate = true;
- mode = ReplaceMainModel;
- }
- }
-
emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
if (mode == ReplaceMainModel) {
@@ -1705,7 +1725,7 @@
std::set