comparison main/MainWindow.cpp @ 211:11ca12902c6a

* Further naming change: Transformer -> ModelTransformer. The Transform class now describes a thing that can be done, and the ModelTransformer does it to a Model.
author Chris Cannam
date Wed, 07 Nov 2007 12:59:01 +0000
parents 92306bafbbe6
children 1fa0d271fd2c ddbde90773b0
comparison
equal deleted inserted replaced
210:92306bafbbe6 211:11ca12902c6a
58 #include "data/fileio/MIDIFileWriter.h" 58 #include "data/fileio/MIDIFileWriter.h"
59 #include "data/fileio/BZipFileDevice.h" 59 #include "data/fileio/BZipFileDevice.h"
60 #include "data/fileio/FileSource.h" 60 #include "data/fileio/FileSource.h"
61 #include "data/fft/FFTDataServer.h" 61 #include "data/fft/FFTDataServer.h"
62 #include "base/RecentFiles.h" 62 #include "base/RecentFiles.h"
63 #include "plugin/transform/TransformerFactory.h" 63 #include "plugin/transform/TransformFactory.h"
64 #include "plugin/transform/ModelTransformerFactory.h"
64 #include "base/PlayParameterRepository.h" 65 #include "base/PlayParameterRepository.h"
65 #include "base/XmlExportable.h" 66 #include "base/XmlExportable.h"
66 #include "base/CommandHistory.h" 67 #include "base/CommandHistory.h"
67 #include "base/Profiler.h" 68 #include "base/Profiler.h"
68 #include "base/Clipboard.h" 69 #include "base/Clipboard.h"
120 m_transformsMenu(0), 121 m_transformsMenu(0),
121 m_playbackMenu(0), 122 m_playbackMenu(0),
122 m_existingLayersMenu(0), 123 m_existingLayersMenu(0),
123 m_sliceMenu(0), 124 m_sliceMenu(0),
124 m_recentFilesMenu(0), 125 m_recentFilesMenu(0),
125 m_recentTransformersMenu(0), 126 m_recentTransformsMenu(0),
126 m_rightButtonMenu(0), 127 m_rightButtonMenu(0),
127 m_rightButtonLayerMenu(0), 128 m_rightButtonLayerMenu(0),
128 m_rightButtonTransformersMenu(0), 129 m_rightButtonTransformsMenu(0),
129 m_rightButtonPlaybackMenu(0), 130 m_rightButtonPlaybackMenu(0),
130 m_soloAction(0), 131 m_soloAction(0),
131 m_soloModified(false), 132 m_soloModified(false),
132 m_prevSolo(false), 133 m_prevSolo(false),
133 m_ffwdAction(0), 134 m_ffwdAction(0),
301 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer")); 302 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
302 m_rightButtonLayerMenu->setTearOffEnabled(true); 303 m_rightButtonLayerMenu->setTearOffEnabled(true);
303 m_rightButtonMenu->addSeparator(); 304 m_rightButtonMenu->addSeparator();
304 } 305 }
305 306
306 if (m_rightButtonTransformersMenu) { 307 if (m_rightButtonTransformsMenu) {
307 m_rightButtonTransformersMenu->clear(); 308 m_rightButtonTransformsMenu->clear();
308 } else { 309 } else {
309 m_rightButtonTransformersMenu = m_rightButtonMenu->addMenu(tr("&Transformer")); 310 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
310 m_rightButtonTransformersMenu->setTearOffEnabled(true); 311 m_rightButtonTransformsMenu->setTearOffEnabled(true);
311 m_rightButtonMenu->addSeparator(); 312 m_rightButtonMenu->addSeparator();
312 } 313 }
313 314
314 if (!m_mainMenusCreated) { 315 if (!m_mainMenusCreated) {
315 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu); 316 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
318 319
319 setupFileMenu(); 320 setupFileMenu();
320 setupEditMenu(); 321 setupEditMenu();
321 setupViewMenu(); 322 setupViewMenu();
322 setupPaneAndLayerMenus(); 323 setupPaneAndLayerMenus();
323 setupTransformersMenu(); 324 setupTransformsMenu();
324 325
325 m_mainMenusCreated = true; 326 m_mainMenusCreated = true;
326 } 327 }
327 328
328 void 329 void
1159 1160
1160 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane 1161 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
1161 } 1162 }
1162 1163
1163 void 1164 void
1164 MainWindow::setupTransformersMenu() 1165 MainWindow::setupTransformsMenu()
1165 { 1166 {
1166 if (m_transformsMenu) { 1167 if (m_transformsMenu) {
1167 m_transformActions.clear(); 1168 m_transformActions.clear();
1168 m_transformActionsReverse.clear(); 1169 m_transformActionsReverse.clear();
1169 m_transformsMenu->clear(); 1170 m_transformsMenu->clear();
1171 m_transformsMenu = menuBar()->addMenu(tr("&Transform")); 1172 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
1172 m_transformsMenu->setTearOffEnabled(true); 1173 m_transformsMenu->setTearOffEnabled(true);
1173 } 1174 }
1174 1175
1175 TransformList transforms = 1176 TransformList transforms =
1176 TransformerFactory::getInstance()->getAllTransforms(); 1177 TransformFactory::getInstance()->getAllTransforms();
1177 1178
1178 vector<QString> types = 1179 vector<QString> types =
1179 TransformerFactory::getInstance()->getAllTransformerTypes(); 1180 TransformFactory::getInstance()->getAllTransformTypes();
1180 1181
1181 map<QString, map<QString, SubdividingMenu *> > categoryMenus; 1182 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
1182 map<QString, map<QString, SubdividingMenu *> > makerMenus; 1183 map<QString, map<QString, SubdividingMenu *> > makerMenus;
1183 1184
1184 map<QString, SubdividingMenu *> byPluginNameMenus; 1185 map<QString, SubdividingMenu *> byPluginNameMenus;
1185 map<QString, map<QString, QMenu *> > pluginNameMenus; 1186 map<QString, map<QString, QMenu *> > pluginNameMenus;
1186 1187
1187 set<SubdividingMenu *> pendingMenus; 1188 set<SubdividingMenu *> pendingMenus;
1188 1189
1189 m_recentTransformersMenu = m_transformsMenu->addMenu(tr("&Recent Transforms")); 1190 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
1190 m_recentTransformersMenu->setTearOffEnabled(true); 1191 m_recentTransformsMenu->setTearOffEnabled(true);
1191 m_rightButtonTransformersMenu->addMenu(m_recentTransformersMenu); 1192 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
1192 connect(&m_recentTransformers, SIGNAL(recentChanged()), 1193 connect(&m_recentTransforms, SIGNAL(recentChanged()),
1193 this, SLOT(setupRecentTransformersMenu())); 1194 this, SLOT(setupRecentTransformsMenu()));
1194 1195
1195 m_transformsMenu->addSeparator(); 1196 m_transformsMenu->addSeparator();
1196 m_rightButtonTransformersMenu->addSeparator(); 1197 m_rightButtonTransformsMenu->addSeparator();
1197 1198
1198 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) { 1199 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
1199 1200
1200 if (i != types.begin()) { 1201 if (i != types.begin()) {
1201 m_transformsMenu->addSeparator(); 1202 m_transformsMenu->addSeparator();
1202 m_rightButtonTransformersMenu->addSeparator(); 1203 m_rightButtonTransformsMenu->addSeparator();
1203 } 1204 }
1204 1205
1205 QString byCategoryLabel = tr("%1 by Category").arg(*i); 1206 QString byCategoryLabel = tr("%1 by Category").arg(*i);
1206 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel, 1207 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
1207 20, 40); 1208 20, 40);
1208 byCategoryMenu->setTearOffEnabled(true); 1209 byCategoryMenu->setTearOffEnabled(true);
1209 m_transformsMenu->addMenu(byCategoryMenu); 1210 m_transformsMenu->addMenu(byCategoryMenu);
1210 m_rightButtonTransformersMenu->addMenu(byCategoryMenu); 1211 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
1211 pendingMenus.insert(byCategoryMenu); 1212 pendingMenus.insert(byCategoryMenu);
1212 1213
1213 vector<QString> categories = 1214 vector<QString> categories =
1214 TransformerFactory::getInstance()->getTransformerCategories(*i); 1215 TransformFactory::getInstance()->getTransformCategories(*i);
1215 1216
1216 for (vector<QString>::iterator j = categories.begin(); 1217 for (vector<QString>::iterator j = categories.begin();
1217 j != categories.end(); ++j) { 1218 j != categories.end(); ++j) {
1218 1219
1219 QString category = *j; 1220 QString category = *j;
1250 1251
1251 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i); 1252 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
1252 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel); 1253 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
1253 byPluginNameMenus[*i]->setTearOffEnabled(true); 1254 byPluginNameMenus[*i]->setTearOffEnabled(true);
1254 m_transformsMenu->addMenu(byPluginNameMenus[*i]); 1255 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
1255 m_rightButtonTransformersMenu->addMenu(byPluginNameMenus[*i]); 1256 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
1256 pendingMenus.insert(byPluginNameMenus[*i]); 1257 pendingMenus.insert(byPluginNameMenus[*i]);
1257 1258
1258 QString byMakerLabel = tr("%1 by Maker").arg(*i); 1259 QString byMakerLabel = tr("%1 by Maker").arg(*i);
1259 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40); 1260 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
1260 byMakerMenu->setTearOffEnabled(true); 1261 byMakerMenu->setTearOffEnabled(true);
1261 m_transformsMenu->addMenu(byMakerMenu); 1262 m_transformsMenu->addMenu(byMakerMenu);
1262 m_rightButtonTransformersMenu->addMenu(byMakerMenu); 1263 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
1263 pendingMenus.insert(byMakerMenu); 1264 pendingMenus.insert(byMakerMenu);
1264 1265
1265 vector<QString> makers = 1266 vector<QString> makers =
1266 TransformerFactory::getInstance()->getTransformerMakers(*i); 1267 TransformFactory::getInstance()->getTransformMakers(*i);
1267 1268
1268 for (vector<QString>::iterator j = makers.begin(); 1269 for (vector<QString>::iterator j = makers.begin();
1269 j != makers.end(); ++j) { 1270 j != makers.end(); ++j) {
1270 1271
1271 QString maker = *j; 1272 QString maker = *j;
1328 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); 1329 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
1329 m_transformActions[action] = transforms[i].identifier; 1330 m_transformActions[action] = transforms[i].identifier;
1330 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); 1331 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
1331 action->setStatusTip(transforms[i].description); 1332 action->setStatusTip(transforms[i].description);
1332 1333
1333 // cerr << "Transformer: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl; 1334 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
1334 1335
1335 if (pluginNameMenus[type].find(pluginName) == 1336 if (pluginNameMenus[type].find(pluginName) ==
1336 pluginNameMenus[type].end()) { 1337 pluginNameMenus[type].end()) {
1337 1338
1338 SubdividingMenu *parentMenu = byPluginNameMenus[type]; 1339 SubdividingMenu *parentMenu = byPluginNameMenus[type];
1358 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin(); 1359 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
1359 i != pendingMenus.end(); ++i) { 1360 i != pendingMenus.end(); ++i) {
1360 (*i)->entriesAdded(); 1361 (*i)->entriesAdded();
1361 } 1362 }
1362 1363
1363 setupRecentTransformersMenu(); 1364 setupRecentTransformsMenu();
1364 } 1365 }
1365 1366
1366 void 1367 void
1367 MainWindow::setupHelpMenu() 1368 MainWindow::setupHelpMenu()
1368 { 1369 {
1417 m_recentFilesMenu->addAction(action); 1418 m_recentFilesMenu->addAction(action);
1418 } 1419 }
1419 } 1420 }
1420 1421
1421 void 1422 void
1422 MainWindow::setupRecentTransformersMenu() 1423 MainWindow::setupRecentTransformsMenu()
1423 { 1424 {
1424 m_recentTransformersMenu->clear(); 1425 m_recentTransformsMenu->clear();
1425 vector<QString> transforms = m_recentTransformers.getRecent(); 1426 vector<QString> transforms = m_recentTransforms.getRecent();
1426 for (size_t i = 0; i < transforms.size(); ++i) { 1427 for (size_t i = 0; i < transforms.size(); ++i) {
1427 TransformerActionReverseMap::iterator ti = 1428 TransformActionReverseMap::iterator ti =
1428 m_transformActionsReverse.find(transforms[i]); 1429 m_transformActionsReverse.find(transforms[i]);
1429 if (ti == m_transformActionsReverse.end()) { 1430 if (ti == m_transformActionsReverse.end()) {
1430 std::cerr << "WARNING: MainWindow::setupRecentTransformersMenu: " 1431 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
1431 << "Unknown transform \"" << transforms[i].toStdString() 1432 << "Unknown transform \"" << transforms[i].toStdString()
1432 << "\" in recent transforms list" << std::endl; 1433 << "\" in recent transforms list" << std::endl;
1433 continue; 1434 continue;
1434 } 1435 }
1435 if (i == 0) { 1436 if (i == 0) {
1436 ti->second->setShortcut(tr("Ctrl+T")); 1437 ti->second->setShortcut(tr("Ctrl+T"));
1437 m_keyReference->registerShortcut 1438 m_keyReference->registerShortcut
1438 (tr("Repeat Transformer"), 1439 (tr("Repeat Transform"),
1439 ti->second->shortcut(), 1440 ti->second->shortcut(),
1440 tr("Re-select the most recently run transform")); 1441 tr("Re-select the most recently run transform"));
1441 } 1442 }
1442 m_recentTransformersMenu->addAction(ti->second); 1443 m_recentTransformsMenu->addAction(ti->second);
1443 } 1444 }
1444 } 1445 }
1445 1446
1446 void 1447 void
1447 MainWindow::setupExistingLayersMenus() 1448 MainWindow::setupExistingLayersMenus()
2798 m_document->addLayerToView(pane, newLayer); 2799 m_document->addLayerToView(pane, newLayer);
2799 m_paneStack->setCurrentLayer(pane, newLayer); 2800 m_paneStack->setCurrentLayer(pane, newLayer);
2800 return; 2801 return;
2801 } 2802 }
2802 2803
2803 TransformerActionMap::iterator i = m_transformActions.find(action); 2804 TransformActionMap::iterator i = m_transformActions.find(action);
2804 2805
2805 if (i == m_transformActions.end()) { 2806 if (i == m_transformActions.end()) {
2806 2807
2807 LayerActionMap::iterator i = m_layerActions.find(action); 2808 LayerActionMap::iterator i = m_layerActions.find(action);
2808 2809
2833 m_paneStack->setCurrentLayer(pane, newLayer); 2834 m_paneStack->setCurrentLayer(pane, newLayer);
2834 2835
2835 return; 2836 return;
2836 } 2837 }
2837 2838
2838 TransformerId transform = i->second; 2839 TransformId transform = i->second;
2839 TransformerFactory *factory = TransformerFactory::getInstance(); 2840 ModelTransformerFactory *factory = ModelTransformerFactory::getInstance();
2840 2841
2841 QString configurationXml; 2842 QString configurationXml;
2842 2843
2843 int channel = -1; 2844 int channel = -1;
2844 // pick up the default channel from any existing layers on the same pane 2845 // pick up the default channel from any existing layers on the same pane
2863 size_t endFrame = 0; 2864 size_t endFrame = 0;
2864 m_viewManager->getSelection().getExtents(startFrame, endFrame); 2865 m_viewManager->getSelection().getExtents(startFrame, endFrame);
2865 if (endFrame > startFrame) duration = endFrame - startFrame; 2866 if (endFrame > startFrame) duration = endFrame - startFrame;
2866 else startFrame = 0; 2867 else startFrame = 0;
2867 2868
2868 Model *inputModel = factory->getConfigurationForTransformer(transform, 2869 Model *inputModel = factory->getConfigurationForTransformer
2869 candidateInputModels, 2870 (transform,
2870 context, 2871 candidateInputModels,
2871 configurationXml, 2872 context,
2872 m_playSource, 2873 configurationXml,
2873 startFrame, 2874 m_playSource,
2874 duration); 2875 startFrame,
2876 duration);
2877
2875 if (!inputModel) return; 2878 if (!inputModel) return;
2876 2879
2877 // std::cerr << "MainWindow::addLayer: Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << "\"" << std::endl; 2880 // std::cerr << "MainWindow::addLayer: Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << "\"" << std::endl;
2878 2881
2879 Layer *newLayer = m_document->createDerivedLayer(transform, 2882 Layer *newLayer = m_document->createDerivedLayer(transform,
2882 configurationXml); 2885 configurationXml);
2883 2886
2884 if (newLayer) { 2887 if (newLayer) {
2885 m_document->addLayerToView(pane, newLayer); 2888 m_document->addLayerToView(pane, newLayer);
2886 m_document->setChannel(newLayer, context.channel); 2889 m_document->setChannel(newLayer, context.channel);
2887 m_recentTransformers.add(transform); 2890 m_recentTransforms.add(transform);
2888 m_paneStack->setCurrentLayer(pane, newLayer); 2891 m_paneStack->setCurrentLayer(pane, newLayer);
2889 } 2892 }
2890 2893
2891 updateMenuStates(); 2894 updateMenuStates();
2892 } 2895 }
3705 if (getMainModel() && 3708 if (getMainModel() &&
3706 pane && 3709 pane &&
3707 message.getArgCount() == 1 && 3710 message.getArgCount() == 1 &&
3708 message.getArg(0).canConvert(QVariant::String)) { 3711 message.getArg(0).canConvert(QVariant::String)) {
3709 3712
3710 TransformerId transform = message.getArg(0).toString(); 3713 TransformId transform = message.getArg(0).toString();
3711 3714
3712 Layer *newLayer = m_document->createDerivedLayer 3715 Layer *newLayer = m_document->createDerivedLayer
3713 (transform, 3716 (transform,
3714 getMainModel(), 3717 getMainModel(),
3715 TransformerFactory::getInstance()->getDefaultContextForTransformer 3718 ModelTransformerFactory::getInstance()->getDefaultContextForTransformer
3716 (transform, getMainModel()), 3719 (transform, getMainModel()),
3717 ""); 3720 "");
3718 3721
3719 if (newLayer) { 3722 if (newLayer) {
3720 m_document->addLayerToView(pane, newLayer); 3723 m_document->addLayerToView(pane, newLayer);
3721 m_recentTransformers.add(transform); 3724 m_recentTransforms.add(transform);
3722 m_paneStack->setCurrentLayer(pane, newLayer); 3725 m_paneStack->setCurrentLayer(pane, newLayer);
3723 } 3726 }
3724 } 3727 }
3725 3728
3726 } else { 3729 } else {