# HG changeset patch # User Chris Cannam # Date 1138643516 0 # Node ID 3a506d25d95a3c5e27805e3a29950c233d39a6ec # Parent 1deb5f87a18ce1231b0e86f93399fa1550bfd095 * Add command history class, and basic undo/redo menus. No actual commands to undo/redo yet. Selecting the placeholders sometimes seems to cause a crash, so this looks a little uncertain so far. * Add Rename Layer * Remove models from playback when their layers are removed (and ref counts hit zero) * Don't hang around waiting so much when there's work to be done in the audio buffer fill thread * Put more sensible names on layers generated from transforms * Add basic editing to time-value layer like existing editing in time-instants layer, and make both of them snap to the appropriate resolution during drag diff -r 1deb5f87a18c -r 3a506d25d95a layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Mon Jan 30 13:19:42 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon Jan 30 17:51:56 2006 +0000 @@ -1103,31 +1103,19 @@ bool SpectrogramLayer::getXBinRange(int x, float &s0, float &s1) const { -// long startFrame; -// int zoomLevel; - size_t modelStart; - size_t modelEnd; - -// startFrame = m_view->getStartFrame(); -// zoomLevel = m_view->getZoomLevel(); - modelStart = m_model->getStartFrame(); - modelEnd = m_model->getEndFrame(); + size_t modelStart = m_model->getStartFrame(); + size_t modelEnd = m_model->getEndFrame(); // Each pixel column covers an exact range of sample frames: int f0 = getFrameForX(x) - modelStart; int f1 = getFrameForX(x + 1) - modelStart - 1; -/* - int f0 = startFrame + x * zoomLevel - modelStart; - int f1 = f0 + zoomLevel - 1; -*/ if (f1 < int(modelStart) || f0 > int(modelEnd)) return false; // And that range may be drawn from a possibly non-integral // range of spectrogram windows: size_t windowIncrement = getWindowIncrement(); - s0 = float(f0) / windowIncrement; s1 = float(f1) / windowIncrement; diff -r 1deb5f87a18c -r 3a506d25d95a layer/TimeInstantLayer.cpp --- a/layer/TimeInstantLayer.cpp Mon Jan 30 13:19:42 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Mon Jan 30 17:51:56 2006 +0000 @@ -348,6 +348,7 @@ long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); m_model->addPoint(m_editingPoint); m_editing = true; @@ -362,6 +363,7 @@ long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); m_model->deletePoint(m_editingPoint); m_editingPoint.frame = frame; m_model->addPoint(m_editingPoint); @@ -398,6 +400,7 @@ long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); m_model->deletePoint(m_editingPoint); m_editingPoint.frame = frame; m_model->addPoint(m_editingPoint); diff -r 1deb5f87a18c -r 3a506d25d95a layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Mon Jan 30 13:19:42 2006 +0000 +++ b/layer/TimeValueLayer.cpp Mon Jan 30 17:51:56 2006 +0000 @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -25,6 +26,8 @@ TimeValueLayer::TimeValueLayer(View *w) : Layer(w), m_model(0), + m_editing(false), + m_editingPoint(0, 0.0, tr("New Point")), m_colour(Qt::black), m_plotStyle(PlotConnectedPoints) { @@ -297,6 +300,30 @@ return returnFrame; } +int +TimeValueLayer::getYForValue(float value) const +{ + float min = m_model->getValueMinimum(); + float max = m_model->getValueMaximum(); + if (max == min) max = min + 1.0; + + int h = m_view->height(); + + return int(h - ((value - min) * h) / (max - min)); +} + +float +TimeValueLayer::getValueForY(int y) const +{ + float min = m_model->getValueMinimum(); + float max = m_model->getValueMaximum(); + if (max == min) max = min + 1.0; + + int h = m_view->height(); + + return min + (float(h - y) * float(max - min)) / h; +} + void TimeValueLayer::paint(QPainter &paint, QRect rect) const { @@ -359,9 +386,7 @@ const SparseTimeValueModel::Point &p(*i); int x = getXForFrame(p.frame); - int y = int(nearbyint(m_view->height() - - ((p.value - min) * m_view->height()) / - (max - min))); + int y = getYForValue(p.value); if (w < 1) w = 1; @@ -416,9 +441,7 @@ const SparseTimeValueModel::Point &q(*j); int nx = getXForFrame(q.frame); - int ny = int(nearbyint(m_view->height() - - ((q.value - min) * m_view->height()) / - (max - min))); + int ny = getYForValue(q.value); if (m_plotStyle == PlotConnectedPoints) { @@ -459,6 +482,92 @@ paint.setRenderHint(QPainter::Antialiasing, false); } +void +TimeValueLayer::drawStart(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; + + if (!m_model) return; + + long frame = getFrameForX(e->x()); + if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); + + float value = getValueForY(e->y()); + + m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point")); + m_model->addPoint(m_editingPoint); + m_editing = true; +} + +void +TimeValueLayer::drawDrag(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; + + if (!m_model || !m_editing) return; + + long frame = getFrameForX(e->x()); + if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); + + float value = getValueForY(e->y()); + + m_model->deletePoint(m_editingPoint); + m_editingPoint.frame = frame; + m_editingPoint.value = value; + m_model->addPoint(m_editingPoint); +} + +void +TimeValueLayer::drawEnd(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; + if (!m_model || !m_editing) return; + m_editing = false; +} + +void +TimeValueLayer::editStart(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; + + if (!m_model) return; + + SparseTimeValueModel::PointList points = getLocalPoints(e->x()); + if (points.empty()) return; + + m_editingPoint = *points.begin(); + m_editing = true; +} + +void +TimeValueLayer::editDrag(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; + + if (!m_model || !m_editing) return; + + long frame = getFrameForX(e->x()); + if (frame < 0) frame = 0; + frame = frame / m_model->getResolution() * m_model->getResolution(); + + float value = getValueForY(e->y()); + + m_model->deletePoint(m_editingPoint); + m_editingPoint.frame = frame; + m_editingPoint.value = value; + m_model->addPoint(m_editingPoint); +} + +void +TimeValueLayer::editEnd(QMouseEvent *e) +{ + std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; + if (!m_model || !m_editing) return; + m_editing = false; +} + QString TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const { diff -r 1deb5f87a18c -r 3a506d25d95a layer/TimeValueLayer.h --- a/layer/TimeValueLayer.h Mon Jan 30 13:19:42 2006 +0000 +++ b/layer/TimeValueLayer.h Mon Jan 30 17:51:56 2006 +0000 @@ -35,6 +35,14 @@ size_t &resolution, bool snapRight = true) const; + virtual void drawStart(QMouseEvent *); + virtual void drawDrag(QMouseEvent *); + virtual void drawEnd(QMouseEvent *); + + virtual void editStart(QMouseEvent *); + virtual void editDrag(QMouseEvent *); + virtual void editEnd(QMouseEvent *); + virtual const Model *getModel() const { return m_model; } void setModel(SparseTimeValueModel *model); @@ -64,9 +72,14 @@ void setProperties(const QXmlAttributes &attributes); protected: + int getYForValue(float value) const; + float getValueForY(int y) const; + SparseTimeValueModel::PointList getLocalPoints(int) const; SparseTimeValueModel *m_model; + bool m_editing; + SparseTimeValueModel::Point m_editingPoint; QColor m_colour; PlotStyle m_plotStyle; }; diff -r 1deb5f87a18c -r 3a506d25d95a widgets/Pane.cpp --- a/widgets/Pane.cpp Mon Jan 30 13:19:42 2006 +0000 +++ b/widgets/Pane.cpp Mon Jan 30 17:51:56 2006 +0000 @@ -579,7 +579,6 @@ Layer *layer = getSelectedLayer(); if (layer) { layer->drawDrag(e); - update(); } } else if (mode == ViewManager::EditMode) { @@ -587,7 +586,6 @@ Layer *layer = getSelectedLayer(); if (layer) { layer->editDrag(e); - update(); } } }