# HG changeset patch # User Chris Cannam # Date 1191854678 0 # Node ID 26397b84e6a265b5141e5290f9c6193dff8dc501 # Parent 4c5bfe0f8502057e09c5629d2bf17abedd2f4ff3 * Add labelling option for instants inserted through tapping (closes FR#1674184) Needs some refinement still, but it's almost functionally complete diff -r 4c5bfe0f8502 -r 26397b84e6a2 main/MainWindow.cpp --- a/main/MainWindow.cpp Fri Oct 05 16:31:30 2007 +0000 +++ b/main/MainWindow.cpp Mon Oct 08 14:44:38 2007 +0000 @@ -24,6 +24,7 @@ #include "data/model/WaveFileModel.h" #include "data/model/SparseOneDimensionalModel.h" #include "data/model/NoteModel.h" +#include "data/model/Labeller.h" #include "view/ViewManager.h" #include "base/Preferences.h" #include "layer/WaveformLayer.h" @@ -141,6 +142,7 @@ m_documentModified(false), m_openingAudioFile(false), m_abandoning(false), + m_labeller(0), m_preferencesDialog(0), m_layerTreeView(0), m_keyReference(new KeyReference()) @@ -339,6 +341,16 @@ oscTimer->start(1000); } + Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter; + settings.beginGroup("MainWindow"); + labellerType = (Labeller::ValueType) + settings.value("labellertype", (int)labellerType).toInt(); + int cycle = settings.value("labellercycle", 4).toInt(); + settings.endGroup(); + + m_labeller = new Labeller(labellerType); + m_labeller->setCounterCycleSize(cycle); + setupMenus(); setupToolbars(); setupHelpMenu(); @@ -735,6 +747,41 @@ connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool))); m_keyReference->registerShortcut(action); menu->addAction(action); + + QMenu *numberingMenu = menu->addMenu(tr("Set Instant Numbering")); + QActionGroup *numberingGroup = new QActionGroup(this); + + Labeller::TypeNameMap types = m_labeller->getTypeNames(); + for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) { + if (i->first == Labeller::ValueFromLabel) continue; + action = new QAction(i->second, this); + connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering())); + action->setCheckable(true); + action->setChecked(m_labeller->getType() == i->first); + numberingGroup->addAction(action); + numberingMenu->addAction(action); + m_numberingActions[action] = (int)i->first; + } + + QMenu *cycleMenu = menu->addMenu(tr("Set Instant Counter Cycle")); + QActionGroup *cycleGroup = new QActionGroup(this); + + int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 10, 12, 16 }; + for (int i = 0; i < sizeof(cycles)/sizeof(cycles[0]); ++i) { + action = new QAction(QString("%1").arg(cycles[i]), this); + connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle())); + action->setCheckable(true); + action->setChecked(cycles[i] == m_labeller->getCounterCycleSize()); + cycleGroup->addAction(action); + cycleMenu->addAction(action); + } + + action = new QAction(tr("Re-Number Selected Instants"), this); + action->setStatusTip(tr("Re-number the selected instants using the current labelling scheme")); + connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants())); + connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool))); +// m_keyReference->registerShortcut(action); + menu->addAction(action); } void @@ -1896,6 +1943,7 @@ emit canPaste(haveCurrentEditableLayer && haveClipboardContents); emit canInsertInstant(haveCurrentPane); emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection); + emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection); emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection); emit canClearSelection(haveSelection); emit canEditSelection(haveSelection && haveCurrentEditableLayer); @@ -2342,17 +2390,115 @@ (model); if (sodm) { - SparseOneDimensionalModel::Point point - (frame, QString("%1").arg(sodm->getPointCount() + 1)); - CommandHistory::getInstance()->addCommand - (new SparseOneDimensionalModel::AddPointCommand(sodm, point, - tr("Add Points")), - true, true); // bundled + SparseOneDimensionalModel::Point point(frame, ""); + + SparseOneDimensionalModel::Point prevPoint(0); + bool havePrevPoint = false; + + SparseOneDimensionalModel::EditCommand *command = + new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point")); + + if (m_labeller->actingOnPrevPoint()) { + + SparseOneDimensionalModel::PointList prevPoints = + sodm->getPreviousPoints(frame); + + if (!prevPoints.empty()) { + prevPoint = *prevPoints.begin(); + havePrevPoint = true; + } + } + + if (m_labeller) { + + m_labeller->setSampleRate(sodm->getSampleRate()); + + if (havePrevPoint) { + command->deletePoint(prevPoint); + } + + m_labeller->label + (point, havePrevPoint ? &prevPoint : 0); + + if (havePrevPoint) { + command->addPoint(prevPoint); + } + } + + command->addPoint(point); + + command->setName(tr("Add Point at %1 s") + .arg(RealTime::frame2RealTime + (frame, + sodm->getSampleRate()) + .toText(false).c_str())); + + command->finish(); } } } void +MainWindow::setInstantsNumbering() +{ + QAction *a = dynamic_cast(sender()); + if (!a) return; + + int type = m_numberingActions[a]; + + if (m_labeller) m_labeller->setType(Labeller::ValueType(type)); + + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("labellertype", type); + settings.endGroup(); +} + +void +MainWindow::setInstantsCounterCycle() +{ + QAction *a = dynamic_cast(sender()); + if (!a) return; + + int cycle = a->text().toInt(); + if (cycle == 0) return; + + if (m_labeller) m_labeller->setCounterCycleSize(cycle); + + + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("labellercycle", cycle); + settings.endGroup(); +} + +void +MainWindow::renumberInstants() +{ + Pane *pane = m_paneStack->getCurrentPane(); + if (!pane) return; + + Layer *layer = dynamic_cast(pane->getSelectedLayer()); + if (!layer) return; + + MultiSelection ms(m_viewManager->getSelection()); + + Model *model = layer->getModel(); + SparseOneDimensionalModel *sodm = dynamic_cast + (model); + if (!sodm) return; + + if (!m_labeller) return; + + Labeller labeller(*m_labeller); + labeller.setSampleRate(sodm->getSampleRate()); + + // This uses a command + + labeller.labelAll(*sodm, &ms); +} + +void MainWindow::importAudio() { QString path = getOpenFileName(FileFinder::AudioFile); diff -r 4c5bfe0f8502 -r 26397b84e6a2 main/MainWindow.h --- a/main/MainWindow.h Fri Oct 05 16:31:30 2007 +0000 +++ b/main/MainWindow.h Mon Oct 08 14:44:38 2007 +0000 @@ -54,6 +54,7 @@ class OSCQueue; class OSCMessage; class KeyReference; +class Labeller; class MainWindow : public QMainWindow @@ -108,6 +109,7 @@ void canPaste(bool); void canInsertInstant(bool); void canInsertInstantsAtBoundaries(bool); + void canRenumberInstants(bool); void canDeleteCurrentLayer(bool); void canZoom(bool); void canScroll(bool); @@ -210,6 +212,9 @@ void insertInstant(); void insertInstantAt(size_t); void insertInstantsAtBoundaries(); + void setInstantsNumbering(); + void setInstantsCounterCycle(); + void renumberInstants(); void documentModified(); void documentRestored(); @@ -298,6 +303,8 @@ bool m_openingAudioFile; bool m_abandoning; + Labeller *m_labeller; + int m_lastPlayStatusSec; mutable QString m_myStatusMessage; @@ -342,6 +349,9 @@ typedef std::map ToolActionMap; ToolActionMap m_toolActions; + typedef std::map NumberingActionMap; + NumberingActionMap m_numberingActions; + void setupMenus(); void setupFileMenu(); void setupEditMenu();