1 /***************************************************************************
2 * Copyright (C) 2010 by Marco Gittler (g.marco@freenet.de) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "audiosignal.h"
22 #include <QVBoxLayout>
29 AudioSignal::AudioSignal(QWidget *parent): QWidget(parent)
31 //QVBoxLayout *vbox=new QVBoxLayout(this);
33 //vbox->addWidget(label);
36 col << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green ;
37 col << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow ;
38 col << Qt::darkYellow << Qt::darkYellow << Qt::darkYellow;
39 col << Qt::red << Qt::red;
43 void AudioSignal::showAudio(const QByteArray arr)
46 if (peeks.count()!=channels.count()){
47 peeks=QByteArray(channels.count(),0);
48 peekage=QByteArray(channels.count(),0);
50 for (int chan=0;chan<peeks.count();chan++)
52 peekage[chan]=peekage[chan]+1;
53 if ( peeks.at(chan)<arr.at(chan) || peekage.at(chan)>50 )
56 peeks[chan]=arr[chan];
61 void AudioSignal::paintEvent(QPaintEvent* /*e*/)
65 //p.fillRect(0,0,(unsigned char)channels[0]*width()/255,height()/2,QBrush(Qt::SolidPattern));
66 //p.fillRect(0,height()/2,(unsigned char)channels[1]*width()/255,height()/2,QBrush(Qt::SolidPattern));
67 int numchan = channels.size();
68 bool horiz=width() > height();
69 for (int i = 0; i < numchan; i++) {
70 int maxx= (unsigned char)channels[i] * (horiz ? width() : height() ) / 127;
71 int xdelta=(horiz ? width():height() ) /20 ;
72 int _y2= (horiz ? height() :width () ) / numchan - 1 ;
73 int _y1=(horiz ? height():width() ) *i/numchan;
74 int _x2=maxx > xdelta ? xdelta - (horiz?1:3) : maxx - (horiz ?1 :3 );
76 for (int x = 0; x < 20; x++) {
79 //p.fillRect(x * xdelta, y1, maxx > xdelta ? xdelta - 1 : maxx - 1, _h, QBrush(col.at(x), Qt::SolidPattern));
80 p.fillRect(horiz?_x1:_y1, horiz?_y1:height()-_x1, horiz?_x2:_y2,horiz? _y2:-_x2, QBrush(col.at(x), Qt::SolidPattern));
84 int xp=peeks.at(i)*(horiz?width():height())/127-2;
85 p.fillRect(horiz?xp:_y1,horiz?_y1:height()-xdelta-xp,horiz?3:_y2,horiz?_y2:3,QBrush(Qt::black,Qt::SolidPattern));
89 #include "audiosignal.moc"