Beispiel #1
0
void AudioScale::paintEvent(QPaintEvent*)
{
    QPainter p(this);
    const int h = IEC_Scale(-dbscale[0]) * height() - 2;
    foreach (int i, dbscale) {
        if (height() > width()) {
            if (i != dbscale[0]) {
                double xf = IEC_Scale(i) * h;
                QString s = QString().sprintf("%d", i);
                p.drawText(width() - fontMetrics().width(s), height() - xf - 1, s);
            }
        } else {
            double xf = IEC_Scale(i) * (double) width();
            p.drawText(xf * 40.0/42.0 - 10, height() - 2, QString().sprintf("%d", i));
        }
    }
    p.end();
}
Beispiel #2
0
void AudioSignal::paintEvent(QPaintEvent* /*e*/)
{
    if (!m_aMonitoringEnabled->isChecked() || !isVisible()) {
        return;
    }
    QPainter p(this);
    int numchan = channels.size();
    bool horiz=width() > height();
    int dbsize = fontMetrics().width("-60") + 2;
    bool showdb=width()>(dbsize+2);
    const int h = IEC_Scale(-dbscale.at(0)) * height() - 2;

    //valpixel=1.0 for 127, 1.0+(1/40) for 1 short oversample, 1.0+(2/40) for longer oversample
    for (int i = 0; i < numchan; i++) {
        double valpixel=valueToPixel((double)(unsigned char)channels[i]/127.0);
        int maxx=  h  * valpixel;
        int xdelta= h / 42 ;
        int _y2= (showdb?width()-dbsize:width () ) / numchan - 1  ;
        int _y1= (showdb?width()-dbsize:width() ) *i/numchan;
        int _x2= maxx >  xdelta ? xdelta - 3 : maxx - 3 ;
        if (horiz){
            dbsize=9;
            showdb=height()>(dbsize);
            maxx=width()*valpixel; 
            xdelta = width() / 42;
            _y2=( showdb?height()-dbsize:height() ) / numchan - 1 ;
            _y1= (showdb?height()-dbsize:height() ) * i/numchan;
            _x2= maxx >  xdelta ? xdelta - 1 : maxx - 1;
        }

        for (int x = 0; x <= 42; x++) {
            int _x1= x *xdelta;
            QColor sig=Qt::green;
            //value of actual painted digit
            double ival=(double)_x1/(double)xdelta/42.0;
            if (ival > 40.0/42.0){
                sig=Qt::red;
            }else if ( ival > 37.0/42.0){
                sig=Qt::darkYellow;
            }else if ( ival >30.0/42.0){
                sig=Qt::yellow;
            }
            if (maxx > 0) {
                if (horiz){
                    p.fillRect(_x1, _y1, _x2, _y2, QBrush(sig, Qt::SolidPattern) );
                }else{
                    p.fillRect(_y1+dbsize, height()-_x1, _y2,-_x2, QBrush(sig, Qt::SolidPattern) );
                }
                maxx -= xdelta;
            }
        }
        int xp=valueToPixel((double)peeks.at(i)/127.0)*(horiz?width():h)-2;
        p.fillRect(horiz?xp:_y1+dbsize, horiz?_y1:height()-xdelta-xp, horiz?3:_y2, horiz?_y2:3, QBrush(Qt::black,Qt::SolidPattern));

    }
    if (showdb){
        //draw db value at related pixel
        for (int l=0;l<dbscale.size();l++){
            if (!horiz){
                double xf = IEC_Scale(dbscale.at(l)) * h;
                p.drawText(0, height() - xf + 2, QString().sprintf("%s%d",dbscale.at(l)>=0?"  ":"",dbscale.at(l)));
            }else{
                double xf = IEC_Scale(dbscale.at(l)) * (double) width();
                p.drawText(xf*40/42-10,height()-2, QString().sprintf("%d",dbscale.at(l)));
            }
        }
    }
    p.end();
}
Beispiel #3
0
double AudioSignal::valueToPixel(double in)
{
	return IEC_Scale(log10(in) * 20.0);
}