comparison framework/MainWindowBase.cpp @ 184:f701c0c686e5

* Add "Insert Item at Selection" (wording could be improved!)
author Chris Cannam
date Mon, 28 Sep 2009 10:39:13 +0000
parents da514e36839a
children 9f49d0f1bd20
comparison
equal deleted inserted replaced
183:da514e36839a 184:f701c0c686e5
32 #include "layer/TimeValueLayer.h" 32 #include "layer/TimeValueLayer.h"
33 #include "layer/Colour3DPlotLayer.h" 33 #include "layer/Colour3DPlotLayer.h"
34 #include "layer/SliceLayer.h" 34 #include "layer/SliceLayer.h"
35 #include "layer/SliceableLayer.h" 35 #include "layer/SliceableLayer.h"
36 #include "layer/ImageLayer.h" 36 #include "layer/ImageLayer.h"
37 #include "layer/NoteLayer.h"
38 #include "layer/RegionLayer.h"
37 39
38 #include "widgets/ListInputDialog.h" 40 #include "widgets/ListInputDialog.h"
39 #include "widgets/CommandHistory.h" 41 #include "widgets/CommandHistory.h"
40 #include "widgets/ProgressDialog.h" 42 #include "widgets/ProgressDialog.h"
41 #include "widgets/MIDIFileImportDialog.h" 43 #include "widgets/MIDIFileImportDialog.h"
369 (haveCurrentLayer && 371 (haveCurrentLayer &&
370 currentLayer->isLayerEditable()); 372 currentLayer->isLayerEditable());
371 bool haveCurrentTimeInstantsLayer = 373 bool haveCurrentTimeInstantsLayer =
372 (haveCurrentLayer && 374 (haveCurrentLayer &&
373 dynamic_cast<TimeInstantLayer *>(currentLayer)); 375 dynamic_cast<TimeInstantLayer *>(currentLayer));
376 bool haveCurrentDurationLayer =
377 (haveCurrentLayer &&
378 (dynamic_cast<NoteLayer *>(currentLayer) ||
379 dynamic_cast<RegionLayer *>(currentLayer)));
374 bool haveCurrentColour3DPlot = 380 bool haveCurrentColour3DPlot =
375 (haveCurrentLayer && 381 (haveCurrentLayer &&
376 dynamic_cast<Colour3DPlotLayer *>(currentLayer)); 382 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
377 bool haveClipboardContents = 383 bool haveClipboardContents =
378 (m_viewManager && 384 (m_viewManager &&
402 emit canFfwd(true); 408 emit canFfwd(true);
403 emit canRewind(true); 409 emit canRewind(true);
404 emit canPaste(haveClipboardContents); 410 emit canPaste(haveClipboardContents);
405 emit canInsertInstant(haveCurrentPane); 411 emit canInsertInstant(haveCurrentPane);
406 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); 412 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
413 emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer);
407 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection); 414 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
408 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); 415 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
409 emit canClearSelection(haveSelection); 416 emit canClearSelection(haveSelection);
410 emit canEditSelection(haveSelection && haveCurrentEditableLayer); 417 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
411 emit canSave(m_sessionFile != "" && m_documentModified); 418 emit canSave(m_sessionFile != "" && m_documentModified);
751 for (MultiSelection::SelectionList::iterator i = selections.begin(); 758 for (MultiSelection::SelectionList::iterator i = selections.begin();
752 i != selections.end(); ++i) { 759 i != selections.end(); ++i) {
753 size_t start = i->getStartFrame(); 760 size_t start = i->getStartFrame();
754 size_t end = i->getEndFrame(); 761 size_t end = i->getEndFrame();
755 if (start != end) { 762 if (start != end) {
756 insertInstantAt(i->getStartFrame()); 763 insertInstantAt(start);
757 insertInstantAt(i->getEndFrame()); 764 insertInstantAt(end);
758 } 765 }
759 } 766 }
760 } 767 }
761 768
762 void 769 void
841 .toText(false).c_str())); 848 .toText(false).c_str()));
842 849
843 Command *c = command->finish(); 850 Command *c = command->finish();
844 if (c) CommandHistory::getInstance()->addCommand(c, false); 851 if (c) CommandHistory::getInstance()->addCommand(c, false);
845 } 852 }
853 }
854 }
855
856 void
857 MainWindowBase::insertItemAtSelection()
858 {
859 MultiSelection::SelectionList selections = m_viewManager->getSelections();
860 for (MultiSelection::SelectionList::iterator i = selections.begin();
861 i != selections.end(); ++i) {
862 size_t start = i->getStartFrame();
863 size_t end = i->getEndFrame();
864 if (start < end) {
865 insertItemAt(start, end - start);
866 }
867 }
868 }
869
870 void
871 MainWindowBase::insertItemAt(size_t frame, size_t duration)
872 {
873 Pane *pane = m_paneStack->getCurrentPane();
874 if (!pane) {
875 return;
876 }
877
878 // ugh!
879
880 size_t alignedStart = pane->alignFromReference(frame);
881 size_t alignedEnd = pane->alignFromReference(frame + duration);
882 if (alignedStart >= alignedEnd) return;
883 size_t alignedDuration = alignedEnd - alignedStart;
884
885 Command *c = 0;
886
887 QString name = tr("Add Item at %1 s")
888 .arg(RealTime::frame2RealTime
889 (alignedStart,
890 getMainModel()->getSampleRate())
891 .toText(false).c_str());
892
893 Layer *layer = pane->getSelectedLayer();
894 if (!layer) return;
895
896 RegionModel *rm = dynamic_cast<RegionModel *>(layer->getModel());
897 if (rm) {
898 RegionModel::Point point(alignedStart,
899 rm->getValueMinimum(),
900 alignedDuration,
901 "");
902 RegionModel::EditCommand *command =
903 new RegionModel::EditCommand(rm, tr("Add Point"));
904 command->addPoint(point);
905 command->setName(name);
906 c = command->finish();
907 }
908
909 if (c) {
910 CommandHistory::getInstance()->addCommand(c, false);
911 return;
912 }
913
914 NoteModel *nm = dynamic_cast<NoteModel *>(layer->getModel());
915 if (nm) {
916 NoteModel::Point point(alignedStart,
917 rm->getValueMinimum(),
918 alignedDuration,
919 1.f,
920 "");
921 NoteModel::EditCommand *command =
922 new NoteModel::EditCommand(nm, tr("Add Point"));
923 command->addPoint(point);
924 command->setName(name);
925 c = command->finish();
926 }
927
928 if (c) {
929 CommandHistory::getInstance()->addCommand(c, false);
930 return;
846 } 931 }
847 } 932 }
848 933
849 void 934 void
850 MainWindowBase::renumberInstants() 935 MainWindowBase::renumberInstants()