Hi,
I have added two new properties to SegmentationView: "centre" and
"zoom". The first one controls whether the widget should centre the
view on current frame (obtained with
SegmentationDataSource::currentTime()), the second one sets the amount
of time in seconds which should be visible. By default "centre" is set
to false and "zoom" is set to 20, so SegmentationView default
behaviour hasn't changed. However, after calling
SegmentationView::setCentre(true) the widget displays segmentation in
a way better suited for using in Turnaround. Additionally, there's a
small triangle marker in the centre of the widget when in the second
mode.
I haven't tested it in NetworkEditor because I can't compile newest
NE, so if anyone can test it for me it'd be great.
Thanks,
Pawel
Index: NetworkEditor/src/widgets/SegmentationView.hxx
===================================================================
--- NetworkEditor/src/widgets/SegmentationView.hxx (revision 11935)
+++ NetworkEditor/src/widgets/SegmentationView.hxx (working copy)
@@ -16,6 +16,8 @@
Q_OBJECT
Q_PROPERTY(QColor lineColor READ lineColor WRITE setLineColor)
Q_PROPERTY(QColor pointColor READ pointColor WRITE setPointColor)
+ Q_PROPERTY(bool centre READ centre WRITE setCentre)
+ Q_PROPERTY(double zoom READ zoom WRITE setZoom)
enum Dimensions {
};
public:
@@ -24,6 +26,8 @@
, _dataSource(dataSource)
, _lineColor(Qt::green)
, _pointColor(Qt::white)
+ , _centre(false)
+ , _zoom(20.)
{
startTimer(50);
}
@@ -36,8 +40,18 @@
for (unsigned i=0; i<segmentation.onsets().size(); i++)
{
// double maxTime = segmentation.maxPosition();
- double maxTime = segmentation.offsets().back();
- double minTime = maxTime - 20.;
+ double maxTime, minTime;
+ if (_centre)
+ {
+ double currentTime = _dataSource->currentTime();
+ maxTime = currentTime + _zoom/2.;
+ minTime = currentTime - _zoom/2.;
+ }
+ else
+ {
+ maxTime = segmentation.offsets().back();
+ minTime = maxTime - _zoom;
+ }
if (maxTime<1) maxTime=1;
float onsetPosition = width()*(segmentation.onsets()[i]-minTime)/(maxTime-minTime);
float offsetPosition = width()*(segmentation.offsets()[i]-minTime)/(maxTime-minTime);
@@ -47,7 +61,17 @@
painter.setPen(QPen(_lineColor,3));
painter.setBrush(_pointColor);
painter.drawRects(segmentBoxes);
+
painter.setPen(Qt::black);
+
+ QPointF points[3] = {
+ QPointF(width()/2.0 - 3.0, 0.0),
+ QPointF(width()/2.0 + 3.0, 0.0),
+ QPointF(width()/2.0, 6.0),
+ };
+ if (_centre)
+ painter.drawConvexPolygon(points, 3);
+
for (unsigned i=0; i<segmentation.onsets().size(); i++)
{
painter.drawText(segmentBoxes[i], Qt::AlignCenter|Qt::TextWordWrap, segmentation.labels()[i].c_str());
@@ -75,6 +99,22 @@
{
return _lineColor;
}
+ void setCentre(bool centre)
+ {
+ _centre = centre;
+ }
+ bool centre() const
+ {
+ return _centre;
+ }
+ void setZoom(double zoom)
+ {
+ _zoom = zoom;
+ }
+ double zoom() const
+ {
+ return _zoom;
+ }
void timerEvent(QTimerEvent *event)
{
if ( !_dataSource) return;
@@ -85,6 +125,8 @@
CLAM::VM::SegmentationDataSource * _dataSource;
QColor _lineColor;
QColor _pointColor;
+ bool _centre;
+ double _zoom;
};
Index: NetworkEditor/src/widgets/SegmentationDataSource.hxx
===================================================================
--- NetworkEditor/src/widgets/SegmentationDataSource.hxx (revision 11935)
+++ NetworkEditor/src/widgets/SegmentationDataSource.hxx (working copy)
@@ -42,6 +42,10 @@
{
return true;
}
+ virtual double currentTime()
+ {
+ return 0.0;
+ }
};
/*
class DummySegmentationDataSource : public SegmentationDataSource
Index: Turnaround/src/Turnaround.cxx
===================================================================
--- Turnaround/src/Turnaround.cxx (revision 11935)
+++ Turnaround/src/Turnaround.cxx (working copy)
@@ -85,6 +85,7 @@
_vboxLayout->addWidget(_polarChromaPeaks);
_segmentationView = new SegmentationView(centralwidget);
+ _segmentationView->setCentre(true);
_vboxLayout->addWidget(_segmentationView);
_network.SetPlayer(new CLAM::PANetworkPlayer);
@@ -211,7 +212,7 @@
_chromaPeaksSource->setDataSource(1);
_chromaPeaksSource->updateData(chromaPeaksStorage.PositionStorage(), chromaPeaksStorage.MagnitudeStorage(), sampleRate, frameDivision);
_polarChromaPeaks->setDataSource(*_chromaPeaksSource);
-
+
CLAM::OutPort<CLAM::Segmentation> &segmentationOutput = (CLAM::OutPort<CLAM::Segmentation>&)(tonalAnalysis.GetOutPort("Chord Segmentation"));
_segmentationSource = new CLAM::VM::PoolSegmentationDataSource;
_segmentationSource->updateData(segmentationOutput.GetData());
@@ -245,5 +246,6 @@
_pcpSource->setCurrentTime(time);
_chordCorrelationSource->setCurrentTime(time);
_chromaPeaksSource->setCurrentTime(time);
+ _segmentationSource->setCurrentTime(time);
}
}
Index: Turnaround/src/PoolSegmentationDataSource.cxx
===================================================================
--- Turnaround/src/PoolSegmentationDataSource.cxx (revision 11935)
+++ Turnaround/src/PoolSegmentationDataSource.cxx (working copy)
@@ -23,6 +23,7 @@
CLAM::VM::PoolSegmentationDataSource::PoolSegmentationDataSource()
: _data(0)
+ , _currentTime(0.0)
{
}
@@ -30,3 +31,14 @@
{
_data = (CLAM::DiscontinuousSegmentation&)data;
}
+
+bool CLAM::VM::PoolSegmentationDataSource::setCurrentTime(double timeMiliseconds)
+{
+ _currentTime = timeMiliseconds;
+ return true;
+}
+
+double CLAM::VM::PoolSegmentationDataSource::currentTime()
+{
+ return _currentTime;
+}
Index: Turnaround/src/widgets/SegmentationView.hxx
===================================================================
--- Turnaround/src/widgets/SegmentationView.hxx (revision 11935)
+++ Turnaround/src/widgets/SegmentationView.hxx (working copy)
@@ -16,6 +16,8 @@
Q_OBJECT
Q_PROPERTY(QColor lineColor READ lineColor WRITE setLineColor)
Q_PROPERTY(QColor pointColor READ pointColor WRITE setPointColor)
+ Q_PROPERTY(bool centre READ centre WRITE setCentre)
+ Q_PROPERTY(double zoom READ zoom WRITE setZoom)
enum Dimensions {
};
public:
@@ -24,6 +26,8 @@
, _dataSource(dataSource)
, _lineColor(Qt::green)
, _pointColor(Qt::white)
+ , _centre(false)
+ , _zoom(20.)
{
startTimer(50);
}
@@ -36,8 +40,18 @@
for (unsigned i=0; i<segmentation.onsets().size(); i++)
{
// double maxTime = segmentation.maxPosition();
- double maxTime = segmentation.offsets().back();
- double minTime = maxTime - 20.;
+ double maxTime, minTime;
+ if (_centre)
+ {
+ double currentTime = _dataSource->currentTime();
+ maxTime = currentTime + _zoom/2.;
+ minTime = currentTime - _zoom/2.;
+ }
+ else
+ {
+ maxTime = segmentation.offsets().back();
+ minTime = maxTime - _zoom;
+ }
if (maxTime<1) maxTime=1;
float onsetPosition = width()*(segmentation.onsets()[i]-minTime)/(maxTime-minTime);
float offsetPosition = width()*(segmentation.offsets()[i]-minTime)/(maxTime-minTime);
@@ -47,7 +61,17 @@
painter.setPen(QPen(_lineColor,3));
painter.setBrush(_pointColor);
painter.drawRects(segmentBoxes);
+
painter.setPen(Qt::black);
+
+ QPointF points[3] = {
+ QPointF(width()/2.0 - 3.0, 0.0),
+ QPointF(width()/2.0 + 3.0, 0.0),
+ QPointF(width()/2.0, 6.0),
+ };
+ if (_centre)
+ painter.drawConvexPolygon(points, 3);
+
for (unsigned i=0; i<segmentation.onsets().size(); i++)
{
painter.drawText(segmentBoxes[i], Qt::AlignCenter|Qt::TextWordWrap, segmentation.labels()[i].c_str());
@@ -75,6 +99,22 @@
{
return _lineColor;
}
+ void setCentre(bool centre)
+ {
+ _centre = centre;
+ }
+ bool centre() const
+ {
+ return _centre;
+ }
+ void setZoom(double zoom)
+ {
+ _zoom = zoom;
+ }
+ double zoom() const
+ {
+ return _zoom;
+ }
void timerEvent(QTimerEvent *event)
{
if ( !_dataSource) return;
@@ -85,6 +125,8 @@
CLAM::VM::SegmentationDataSource * _dataSource;
QColor _lineColor;
QColor _pointColor;
+ bool _centre;
+ double _zoom;
};
Index: Turnaround/src/widgets/SegmentationDataSource.hxx
===================================================================
--- Turnaround/src/widgets/SegmentationDataSource.hxx (revision 11935)
+++ Turnaround/src/widgets/SegmentationDataSource.hxx (working copy)
@@ -42,6 +42,10 @@
{
return true;
}
+ virtual double currentTime()
+ {
+ return 0.0;
+ }
};
/*
class DummySegmentationDataSource : public SegmentationDataSource
Index: Turnaround/src/PoolSegmentationDataSource.hxx
===================================================================
--- Turnaround/src/PoolSegmentationDataSource.hxx (revision 11935)
+++ Turnaround/src/PoolSegmentationDataSource.hxx (working copy)
@@ -35,6 +35,8 @@
public:
PoolSegmentationDataSource();
void updateData(CLAM::Segmentation & data);
+ bool setCurrentTime(double timeMiliseconds);
+ double currentTime();
std::string getLabel(unsigned bin) const
{
@@ -55,6 +57,7 @@
private:
CLAM::DiscontinuousSegmentation _data;
+ double _currentTime;
};
}
}
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel