Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 220:0b1886cee2cf templating
Merge from default branch
author | Chris Cannam |
---|---|
date | Wed, 27 Apr 2011 11:33:48 +0100 |
parents | 85e59c901de9 |
children | e06a0124c662 |
comparison
equal
deleted
inserted
replaced
210:143e1b56e81b | 220:0b1886cee2cf |
---|---|
64 | 64 |
65 #include "base/PlayParameterRepository.h" | 65 #include "base/PlayParameterRepository.h" |
66 #include "base/XmlExportable.h" | 66 #include "base/XmlExportable.h" |
67 #include "base/Profiler.h" | 67 #include "base/Profiler.h" |
68 #include "base/Preferences.h" | 68 #include "base/Preferences.h" |
69 #include "base/TempWriteFile.h" | |
70 #include "base/Exceptions.h" | |
69 | 71 |
70 #include "data/osc/OSCQueue.h" | 72 #include "data/osc/OSCQueue.h" |
71 #include "data/midi/MIDIInput.h" | 73 #include "data/midi/MIDIInput.h" |
72 | 74 |
73 #include <QApplication> | 75 #include <QApplication> |
674 } | 676 } |
675 | 677 |
676 void | 678 void |
677 MainWindowBase::paste() | 679 MainWindowBase::paste() |
678 { | 680 { |
681 pasteRelative(0); | |
682 } | |
683 | |
684 void | |
685 MainWindowBase::pasteAtPlaybackPosition() | |
686 { | |
687 unsigned long pos = getFrame(); | |
688 Clipboard &clipboard = m_viewManager->getClipboard(); | |
689 if (!clipboard.empty()) { | |
690 long firstEventFrame = clipboard.getPoints()[0].getFrame(); | |
691 long offset = 0; | |
692 if (firstEventFrame < 0) { | |
693 offset = long(pos) - firstEventFrame; | |
694 } else if (firstEventFrame < pos) { | |
695 offset = pos - firstEventFrame; | |
696 } else { | |
697 offset = -(firstEventFrame - pos); | |
698 } | |
699 pasteRelative(offset); | |
700 } | |
701 } | |
702 | |
703 void | |
704 MainWindowBase::pasteRelative(int offset) | |
705 { | |
679 Pane *currentPane = m_paneStack->getCurrentPane(); | 706 Pane *currentPane = m_paneStack->getCurrentPane(); |
680 if (!currentPane) return; | 707 if (!currentPane) return; |
681 | 708 |
682 Layer *layer = currentPane->getSelectedLayer(); | 709 Layer *layer = currentPane->getSelectedLayer(); |
683 | 710 |
684 Clipboard &clipboard = m_viewManager->getClipboard(); | 711 Clipboard &clipboard = m_viewManager->getClipboard(); |
685 // Clipboard::PointList contents = clipboard.getPoints(); | |
686 | 712 |
687 bool inCompound = false; | 713 bool inCompound = false; |
688 | 714 |
689 if (!layer || !layer->isLayerEditable()) { | 715 if (!layer || !layer->isLayerEditable()) { |
690 | 716 |
706 m_paneStack->setCurrentLayer(currentPane, layer); | 732 m_paneStack->setCurrentLayer(currentPane, layer); |
707 | 733 |
708 inCompound = true; | 734 inCompound = true; |
709 } | 735 } |
710 | 736 |
711 layer->paste(currentPane, clipboard, 0, true); | 737 layer->paste(currentPane, clipboard, offset, true); |
712 | 738 |
713 if (inCompound) CommandHistory::getInstance()->endCompoundOperation(); | 739 if (inCompound) CommandHistory::getInstance()->endCompoundOperation(); |
714 } | 740 } |
715 | 741 |
716 void | 742 void |
1047 MainWindowBase::FileOpenStatus | 1073 MainWindowBase::FileOpenStatus |
1048 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName) | 1074 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName) |
1049 { | 1075 { |
1050 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl; | 1076 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl; |
1051 | 1077 |
1078 if (templateName == "") templateName = "testtemplate"; | |
1079 | |
1052 if (!source.isAvailable()) return FileOpenFailed; | 1080 if (!source.isAvailable()) return FileOpenFailed; |
1053 source.waitForData(); | 1081 source.waitForData(); |
1054 | 1082 |
1055 m_openingAudioFile = true; | 1083 m_openingAudioFile = true; |
1056 | 1084 |
1177 if (!source.isRemote()) m_audioFile = source.getLocalFilename(); | 1205 if (!source.isRemote()) m_audioFile = source.getLocalFilename(); |
1178 | 1206 |
1179 } else if (mode == CreateAdditionalModel) { | 1207 } else if (mode == CreateAdditionalModel) { |
1180 | 1208 |
1181 CommandHistory::getInstance()->startCompoundOperation | 1209 CommandHistory::getInstance()->startCompoundOperation |
1182 (tr("Import \"%1\"").arg(source.getLocation()), true); | 1210 (tr("Import \"%1\"").arg(source.getBasename()), true); |
1183 | 1211 |
1184 m_document->addImportedModel(newModel); | 1212 m_document->addImportedModel(newModel); |
1185 | 1213 |
1186 AddPaneCommand *command = new AddPaneCommand(this); | 1214 AddPaneCommand *command = new AddPaneCommand(this); |
1187 CommandHistory::getInstance()->addCommand(command); | 1215 CommandHistory::getInstance()->addCommand(command); |
1218 break; | 1246 break; |
1219 } | 1247 } |
1220 } | 1248 } |
1221 | 1249 |
1222 CommandHistory::getInstance()->startCompoundOperation | 1250 CommandHistory::getInstance()->startCompoundOperation |
1223 (tr("Import \"%1\"").arg(source.getLocation()), true); | 1251 (tr("Import \"%1\"").arg(source.getBasename()), true); |
1224 | 1252 |
1225 m_document->addImportedModel(newModel); | 1253 m_document->addImportedModel(newModel); |
1226 | 1254 |
1227 if (replace) { | 1255 if (replace) { |
1228 m_document->removeLayerFromView(pane, replace); | 1256 m_document->removeLayerFromView(pane, replace); |
1864 } | 1892 } |
1865 | 1893 |
1866 bool | 1894 bool |
1867 MainWindowBase::saveSessionFile(QString path) | 1895 MainWindowBase::saveSessionFile(QString path) |
1868 { | 1896 { |
1869 BZipFileDevice bzFile(path); | 1897 try { |
1870 if (!bzFile.open(QIODevice::WriteOnly)) { | 1898 |
1871 std::cerr << "Failed to open session file \"" << path.toStdString() | 1899 TempWriteFile temp(path); |
1872 << "\" for writing: " | 1900 |
1873 << bzFile.errorString().toStdString() << std::endl; | 1901 BZipFileDevice bzFile(temp.getTemporaryFilename()); |
1902 if (!bzFile.open(QIODevice::WriteOnly)) { | |
1903 std::cerr << "Failed to open session file \"" | |
1904 << temp.getTemporaryFilename().toStdString() | |
1905 << "\" for writing: " | |
1906 << bzFile.errorString().toStdString() << std::endl; | |
1907 return false; | |
1908 } | |
1909 | |
1910 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | |
1911 | |
1912 QTextStream out(&bzFile); | |
1913 toXml(out); | |
1914 out.flush(); | |
1915 | |
1916 QApplication::restoreOverrideCursor(); | |
1917 | |
1918 if (!bzFile.isOK()) { | |
1919 QMessageBox::critical(this, tr("Failed to write file"), | |
1920 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1921 .arg(path).arg(bzFile.errorString())); | |
1922 bzFile.close(); | |
1923 return false; | |
1924 } | |
1925 | |
1926 bzFile.close(); | |
1927 temp.moveToTarget(); | |
1928 return true; | |
1929 | |
1930 } catch (FileOperationFailed &f) { | |
1931 | |
1932 QMessageBox::critical(this, tr("Failed to write file"), | |
1933 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1934 .arg(path).arg(f.what())); | |
1874 return false; | 1935 return false; |
1875 } | 1936 } |
1876 | |
1877 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | |
1878 | |
1879 QTextStream out(&bzFile); | |
1880 toXml(out); | |
1881 out.flush(); | |
1882 | |
1883 QApplication::restoreOverrideCursor(); | |
1884 | |
1885 if (!bzFile.isOK()) { | |
1886 QMessageBox::critical(this, tr("Failed to write file"), | |
1887 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1888 .arg(path).arg(bzFile.errorString())); | |
1889 bzFile.close(); | |
1890 return false; | |
1891 } | |
1892 | |
1893 bzFile.close(); | |
1894 return true; | |
1895 } | 1937 } |
1896 | 1938 |
1897 void | 1939 void |
1898 MainWindowBase::toXml(QTextStream &out) | 1940 MainWindowBase::toXml(QTextStream &out) |
1899 { | 1941 { |
2044 | 2086 |
2045 void | 2087 void |
2046 MainWindowBase::showAllOverlays() | 2088 MainWindowBase::showAllOverlays() |
2047 { | 2089 { |
2048 m_viewManager->setOverlayMode(ViewManager::AllOverlays); | 2090 m_viewManager->setOverlayMode(ViewManager::AllOverlays); |
2091 } | |
2092 | |
2093 void | |
2094 MainWindowBase::toggleTimeRulers() | |
2095 { | |
2096 bool haveRulers = false; | |
2097 bool someHidden = false; | |
2098 | |
2099 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | |
2100 | |
2101 Pane *pane = m_paneStack->getPane(i); | |
2102 if (!pane) continue; | |
2103 | |
2104 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
2105 | |
2106 Layer *layer = pane->getLayer(j); | |
2107 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue; | |
2108 | |
2109 haveRulers = true; | |
2110 if (layer->isLayerDormant(pane)) someHidden = true; | |
2111 } | |
2112 } | |
2113 | |
2114 if (haveRulers) { | |
2115 | |
2116 bool show = someHidden; | |
2117 | |
2118 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | |
2119 | |
2120 Pane *pane = m_paneStack->getPane(i); | |
2121 if (!pane) continue; | |
2122 | |
2123 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
2124 | |
2125 Layer *layer = pane->getLayer(j); | |
2126 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue; | |
2127 | |
2128 layer->showLayer(pane, show); | |
2129 } | |
2130 } | |
2131 } | |
2049 } | 2132 } |
2050 | 2133 |
2051 void | 2134 void |
2052 MainWindowBase::toggleZoomWheels() | 2135 MainWindowBase::toggleZoomWheels() |
2053 { | 2136 { |