1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
Graph::Graph( const string & path )
{
SF_INFO fileInfos;
SNDFILE* audFile = sf_open(path.c_str(), SFM_READ, &fileInfos);
// stock point to draw
QVector<QPointF> v;
// stock current frame
double currentFrame[2];
// go to start of data
sf_seek(audFile,0,SEEK_SET);
// readings frames
for (sf_count_t i=0;i<fileInfos.frames;i++){
// reading frame i
sf_read_double(audFile,currentFrame,fileInfos.channels);
// stock frame points
v.append(QPointF(i,currentFrame[0]));
v.append(QPointF(i, fileInfos.channels == 1?0:currentFrame[1]));
}
// create plot
string fileName=path.substr(path.find_last_of("/\\")+1);
QwtPlot* mp = new QwtPlot( QwtText("WaveForm - "+ QString::fromStdString(fileName)));
mp->setWindowTitle( mp->title().text() );
// create curve
QwtPlotCurve* c = new QwtPlotCurve(QString::fromStdString(fileName));
// set curve datas
c->setSamples(QPolygonF(v));
// attache curve to plot
c->attach(mp);
//create the markers
leftMarker = new QwtPlotMarker();
leftMarker->setLineStyle(QwtPlotMarker::VLine);
leftMarker->setLinePen(QPen(Qt::red));
leftMarker->setLabel(QString::fromUtf8("Beginning"));
leftMarker->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
leftMarker->setXValue(0);
rightMarker = new QwtPlotMarker();
rightMarker->setLineStyle(QwtPlotMarker::VLine);
rightMarker->setLinePen(QPen(Qt::red));
rightMarker->setLabel(QString::fromUtf8("End"));
rightMarker->setLabelAlignment(Qt::AlignLeft|Qt::AlignTop);
rightMarker->setXValue(fileInfos.frames);
leftMarker->attach(mp);
rightMarker->attach(mp);
// replot
mp->replot();
// return plot
waveForm= mp;
frames=fileInfos.frames;
sf_close(audFile);
} |
Partager