# HG changeset patch # User Chris Cannam # Date 1254134353 0 # Node ID f701c0c686e5117037e55202ebd1dfeccdae598a # Parent da514e36839a1ee9537f07fdb447653fa959260c * Add "Insert Item at Selection" (wording could be improved!) diff -r da514e36839a -r f701c0c686e5 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Wed Sep 23 11:19:43 2009 +0000 +++ b/framework/MainWindowBase.cpp Mon Sep 28 10:39:13 2009 +0000 @@ -34,6 +34,8 @@ #include "layer/SliceLayer.h" #include "layer/SliceableLayer.h" #include "layer/ImageLayer.h" +#include "layer/NoteLayer.h" +#include "layer/RegionLayer.h" #include "widgets/ListInputDialog.h" #include "widgets/CommandHistory.h" @@ -371,6 +373,10 @@ bool haveCurrentTimeInstantsLayer = (haveCurrentLayer && dynamic_cast(currentLayer)); + bool haveCurrentDurationLayer = + (haveCurrentLayer && + (dynamic_cast(currentLayer) || + dynamic_cast(currentLayer))); bool haveCurrentColour3DPlot = (haveCurrentLayer && dynamic_cast(currentLayer)); @@ -404,6 +410,7 @@ emit canPaste(haveClipboardContents); emit canInsertInstant(haveCurrentPane); emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); + emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer); emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection); emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); emit canClearSelection(haveSelection); @@ -753,8 +760,8 @@ size_t start = i->getStartFrame(); size_t end = i->getEndFrame(); if (start != end) { - insertInstantAt(i->getStartFrame()); - insertInstantAt(i->getEndFrame()); + insertInstantAt(start); + insertInstantAt(end); } } } @@ -847,6 +854,84 @@ } void +MainWindowBase::insertItemAtSelection() +{ + MultiSelection::SelectionList selections = m_viewManager->getSelections(); + for (MultiSelection::SelectionList::iterator i = selections.begin(); + i != selections.end(); ++i) { + size_t start = i->getStartFrame(); + size_t end = i->getEndFrame(); + if (start < end) { + insertItemAt(start, end - start); + } + } +} + +void +MainWindowBase::insertItemAt(size_t frame, size_t duration) +{ + Pane *pane = m_paneStack->getCurrentPane(); + if (!pane) { + return; + } + + // ugh! + + size_t alignedStart = pane->alignFromReference(frame); + size_t alignedEnd = pane->alignFromReference(frame + duration); + if (alignedStart >= alignedEnd) return; + size_t alignedDuration = alignedEnd - alignedStart; + + Command *c = 0; + + QString name = tr("Add Item at %1 s") + .arg(RealTime::frame2RealTime + (alignedStart, + getMainModel()->getSampleRate()) + .toText(false).c_str()); + + Layer *layer = pane->getSelectedLayer(); + if (!layer) return; + + RegionModel *rm = dynamic_cast(layer->getModel()); + if (rm) { + RegionModel::Point point(alignedStart, + rm->getValueMinimum(), + alignedDuration, + ""); + RegionModel::EditCommand *command = + new RegionModel::EditCommand(rm, tr("Add Point")); + command->addPoint(point); + command->setName(name); + c = command->finish(); + } + + if (c) { + CommandHistory::getInstance()->addCommand(c, false); + return; + } + + NoteModel *nm = dynamic_cast(layer->getModel()); + if (nm) { + NoteModel::Point point(alignedStart, + rm->getValueMinimum(), + alignedDuration, + 1.f, + ""); + NoteModel::EditCommand *command = + new NoteModel::EditCommand(nm, tr("Add Point")); + command->addPoint(point); + command->setName(name); + c = command->finish(); + } + + if (c) { + CommandHistory::getInstance()->addCommand(c, false); + return; + } +} + +void MainWindowBase::renumberInstants() { Pane *pane = m_paneStack->getCurrentPane(); diff -r da514e36839a -r f701c0c686e5 framework/MainWindowBase.h --- a/framework/MainWindowBase.h Wed Sep 23 11:19:43 2009 +0000 +++ b/framework/MainWindowBase.h Mon Sep 28 10:39:13 2009 +0000 @@ -129,6 +129,7 @@ void canPaste(bool); void canInsertInstant(bool); void canInsertInstantsAtBoundaries(bool); + void canInsertItemAtSelection(bool); void canRenumberInstants(bool); void canDeleteCurrentLayer(bool); void canZoom(bool); @@ -224,6 +225,8 @@ virtual void insertInstant(); virtual void insertInstantAt(size_t); virtual void insertInstantsAtBoundaries(); + virtual void insertItemAtSelection(); + virtual void insertItemAt(size_t, size_t); virtual void renumberInstants(); virtual void documentModified();