Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 221:e06a0124c662 templating
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
author | Chris Cannam |
---|---|
date | Wed, 27 Apr 2011 14:46:06 +0100 |
parents | 0b1886cee2cf |
children | ed5804224121 |
comparison
equal
deleted
inserted
replaced
220:0b1886cee2cf | 221:e06a0124c662 |
---|---|
688 Clipboard &clipboard = m_viewManager->getClipboard(); | 688 Clipboard &clipboard = m_viewManager->getClipboard(); |
689 if (!clipboard.empty()) { | 689 if (!clipboard.empty()) { |
690 long firstEventFrame = clipboard.getPoints()[0].getFrame(); | 690 long firstEventFrame = clipboard.getPoints()[0].getFrame(); |
691 long offset = 0; | 691 long offset = 0; |
692 if (firstEventFrame < 0) { | 692 if (firstEventFrame < 0) { |
693 offset = long(pos) - firstEventFrame; | 693 offset = (long)pos - firstEventFrame; |
694 } else if (firstEventFrame < pos) { | 694 } else if (firstEventFrame < pos) { |
695 offset = pos - firstEventFrame; | 695 offset = pos - (unsigned long)firstEventFrame; |
696 } else { | 696 } else { |
697 offset = -(firstEventFrame - pos); | 697 offset = -((unsigned long)firstEventFrame - pos); |
698 } | 698 } |
699 pasteRelative(offset); | 699 pasteRelative(offset); |
700 } | 700 } |
701 } | 701 } |
702 | 702 |
1101 if (mode == AskUser) { | 1101 if (mode == AskUser) { |
1102 if (getMainModel()) { | 1102 if (getMainModel()) { |
1103 | 1103 |
1104 QSettings settings; | 1104 QSettings settings; |
1105 settings.beginGroup("MainWindow"); | 1105 settings.beginGroup("MainWindow"); |
1106 bool prevSetAsMain = settings.value("newsessionforaudio", true).toBool(); | 1106 int lastMode = settings.value("lastaudioopenmode", 0).toBool(); |
1107 settings.endGroup(); | 1107 settings.endGroup(); |
1108 bool setAsMain = true; | 1108 int imode = 0; |
1109 | 1109 |
1110 QStringList items; | 1110 QStringList items; |
1111 items << tr("Replace the existing main waveform") | 1111 items << tr("Close the current session and start a new one") |
1112 << tr("Load this file into a new waveform pane"); | 1112 << tr("Replace the main audio file in this session") |
1113 << tr("Add the audio file to this session"); | |
1113 | 1114 |
1114 bool ok = false; | 1115 bool ok = false; |
1115 QString item = ListInputDialog::getItem | 1116 QString item = ListInputDialog::getItem |
1116 (this, tr("Select target for import"), | 1117 (this, tr("Select target for import"), |
1117 tr("<b>Select a target for import</b><p>You already have an audio waveform loaded.<br>What would you like to do with the new audio file?"), | 1118 tr("<b>Select a target for import</b><p>You already have an audio file loaded.<br>What would you like to do with the new audio file?"), |
1118 items, prevSetAsMain ? 0 : 1, &ok); | 1119 items, lastMode, &ok); |
1119 | 1120 |
1120 if (!ok || item.isEmpty()) { | 1121 if (!ok || item.isEmpty()) { |
1121 delete newModel; | 1122 delete newModel; |
1122 m_openingAudioFile = false; | 1123 m_openingAudioFile = false; |
1123 return FileOpenCancelled; | 1124 return FileOpenCancelled; |
1124 } | 1125 } |
1125 | 1126 |
1126 setAsMain = (item == items[0]); | 1127 for (int i = 0; i < items.size(); ++i) { |
1128 if (item == items[i]) imode = i; | |
1129 } | |
1130 | |
1127 settings.beginGroup("MainWindow"); | 1131 settings.beginGroup("MainWindow"); |
1128 settings.setValue("newsessionforaudio", setAsMain); | 1132 settings.setValue("lastaudioopenmode", imode); |
1129 settings.endGroup(); | 1133 settings.endGroup(); |
1130 | 1134 |
1131 if (setAsMain) mode = ReplaceMainModel; | 1135 mode = (AudioFileOpenMode)imode; |
1132 else mode = CreateAdditionalModel; | |
1133 | 1136 |
1134 } else { | 1137 } else { |
1135 mode = ReplaceMainModel; | 1138 // no main model: make a new session |
1139 mode = ReplaceSession; | |
1136 } | 1140 } |
1137 } | 1141 } |
1138 | 1142 |
1139 if (mode == ReplaceCurrentPane) { | 1143 if (mode == ReplaceCurrentPane) { |
1140 | 1144 |
1141 Pane *pane = m_paneStack->getCurrentPane(); | 1145 Pane *pane = m_paneStack->getCurrentPane(); |
1142 if (pane) { | 1146 if (pane) { |
1143 if (getMainModel()) { | 1147 if (getMainModel()) { |
1144 View::ModelSet models(pane->getModels()); | 1148 View::ModelSet models(pane->getModels()); |
1145 if (models.find(getMainModel()) != models.end()) { | 1149 if (models.find(getMainModel()) != models.end()) { |
1150 // Current pane contains main model: replace that | |
1146 mode = ReplaceMainModel; | 1151 mode = ReplaceMainModel; |
1147 } | 1152 } |
1153 // Otherwise the current pane has a non-default model, | |
1154 // which we will deal with later | |
1148 } else { | 1155 } else { |
1149 mode = ReplaceMainModel; | 1156 // We have no main model, so start a new session with |
1157 // optional template | |
1158 mode = ReplaceSession; | |
1150 } | 1159 } |
1151 } else { | 1160 } else { |
1161 // We seem to have no current pane! Oh well | |
1152 mode = CreateAdditionalModel; | 1162 mode = CreateAdditionalModel; |
1153 } | 1163 } |
1154 } | 1164 } |
1155 | 1165 |
1156 if (mode == CreateAdditionalModel && !getMainModel()) { | 1166 if (mode == CreateAdditionalModel && !getMainModel()) { |
1167 mode = ReplaceSession; | |
1168 } | |
1169 | |
1170 bool loadedTemplate = false; | |
1171 | |
1172 if (mode == ReplaceSession) { | |
1173 | |
1174 if (templateName.length() != 0) { | |
1175 QString tplPath = "file::templates/" + templateName + ".xml"; | |
1176 std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl; | |
1177 FileOpenStatus tplStatus = openSessionFile(tplPath); | |
1178 if (tplStatus != FileOpenFailed) { | |
1179 loadedTemplate = true; | |
1180 } | |
1181 } | |
1182 | |
1183 if (!loadedTemplate) { | |
1184 closeSession(); | |
1185 createDocument(); | |
1186 } | |
1187 | |
1157 mode = ReplaceMainModel; | 1188 mode = ReplaceMainModel; |
1158 } | |
1159 | |
1160 bool loadedTemplate = false; | |
1161 if ((mode == ReplaceMainModel) && (templateName.length() != 0)) { | |
1162 QString tplPath = "file::templates/" + templateName + ".xml"; | |
1163 std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl; | |
1164 FileOpenStatus tplStatus = openSessionFile(tplPath); | |
1165 if(tplStatus != FileOpenFailed) { | |
1166 loadedTemplate = true; | |
1167 mode = ReplaceMainModel; | |
1168 } | |
1169 } | 1189 } |
1170 | 1190 |
1171 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation())); | 1191 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation())); |
1172 | 1192 |
1173 if (mode == ReplaceMainModel) { | 1193 if (mode == ReplaceMainModel) { |
1703 | 1723 |
1704 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation())); | 1724 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation())); |
1705 | 1725 |
1706 std::set<Model *> added; | 1726 std::set<Model *> added; |
1707 | 1727 |
1708 for (int i = 0; i < models.size(); ++i) { | 1728 for (int i = 0; i < (int)models.size(); ++i) { |
1709 | 1729 |
1710 Model *m = models[i]; | 1730 Model *m = models[i]; |
1711 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m); | 1731 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m); |
1712 | 1732 |
1713 if (w) { | 1733 if (w) { |
1728 | 1748 |
1729 m_document->addLayerToView(pane, layer); | 1749 m_document->addLayerToView(pane, layer); |
1730 | 1750 |
1731 added.insert(w); | 1751 added.insert(w); |
1732 | 1752 |
1733 for (int j = 0; j < models.size(); ++j) { | 1753 for (int j = 0; j < (int)models.size(); ++j) { |
1734 | 1754 |
1735 Model *dm = models[j]; | 1755 Model *dm = models[j]; |
1736 | 1756 |
1737 if (dm == m) continue; | 1757 if (dm == m) continue; |
1738 if (dm->getSourceModel() != m) continue; | 1758 if (dm->getSourceModel() != m) continue; |
1786 added.insert(dm); | 1806 added.insert(dm); |
1787 } | 1807 } |
1788 } | 1808 } |
1789 } | 1809 } |
1790 | 1810 |
1791 for (int i = 0; i < models.size(); ++i) { | 1811 for (int i = 0; i < (int)models.size(); ++i) { |
1792 | 1812 |
1793 Model *m = models[i]; | 1813 Model *m = models[i]; |
1794 | 1814 |
1795 if (added.find(m) == added.end()) { | 1815 if (added.find(m) == added.end()) { |
1796 | 1816 |