Mercurial > hg > svapp
changeset 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 |
files | framework/MainWindowBase.cpp framework/MainWindowBase.h |
diffstat | 2 files changed, 90 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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<TimeInstantLayer *>(currentLayer)); + bool haveCurrentDurationLayer = + (haveCurrentLayer && + (dynamic_cast<NoteLayer *>(currentLayer) || + dynamic_cast<RegionLayer *>(currentLayer))); bool haveCurrentColour3DPlot = (haveCurrentLayer && dynamic_cast<Colour3DPlotLayer *>(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<RegionModel *>(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<NoteModel *>(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();
--- 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();