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);
35 col << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green ;
36 col << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow ;
37 col << Qt::darkYellow << Qt::darkYellow << Qt::darkYellow;
38 col << Qt::red << Qt::red;
42 void AudioSignal::showAudio(const QByteArray arr)
45 if (peeks.count()!=channels.count()){
46 peeks=QByteArray(channels.count(),0);
47 peekage=QByteArray(channels.count(),0);
49 for (int chan=0;chan<peeks.count();chan++)
51 peekage[chan]=peekage[chan]+1;
52 if ( peeks.at(chan)<arr.at(chan) || peekage.at(chan)>50 )
55 peeks[chan]=arr[chan];
60 void AudioSignal::paintEvent(QPaintEvent* /*e*/)
64 //p.fillRect(0,0,(unsigned char)channels[0]*width()/255,height()/2,QBrush(Qt::SolidPattern));
65 //p.fillRect(0,height()/2,(unsigned char)channels[1]*width()/255,height()/2,QBrush(Qt::SolidPattern));
66 int numchan = channels.size();
67 for (int i = 0; i < numchan; i++) {
68 int maxx = (unsigned char)channels[i] * width() / 127;
69 int xdelta = width() / 20;
70 int y1 = height() * i / numchan;
71 int _h = height() / numchan - 1;
72 for (int x = 0; x < 20; x++) {
74 p.fillRect(x * xdelta, y1, maxx > xdelta ? xdelta - 1 : maxx - 1, _h, QBrush(col.at(x), Qt::SolidPattern));
78 p.fillRect(peeks.at(i)*width()/127-2,y1,3,_h,QBrush(Qt::black,Qt::SolidPattern));
82 #include "audiosignal.moc"