]> git.sesse.net Git - kdenlive/blob - src/audiosignal.cpp
36de4b825a7547ab3a262ed7a4bccc436c17e531
[kdenlive] / src / audiosignal.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Marco Gittler (g.marco@freenet.de)              *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "audiosignal.h"
21
22 #include <QVBoxLayout>
23 #include <QLabel>
24 #include <QPainter>
25 #include <QDebug>
26 #include <QList>
27
28
29 AudioSignal::AudioSignal(QWidget *parent): QWidget(parent)
30 {
31     //QVBoxLayout *vbox=new QVBoxLayout(this);
32     //label=new QLabel();
33     //vbox->addWidget(label);
34     setMinimumHeight(10);
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;
39 }
40
41
42 void AudioSignal::showAudio(const QByteArray arr)
43 {
44     channels = arr;
45     if (peeks.count()!=channels.count()){
46         peeks=QByteArray(channels.count(),0);
47         peekage=QByteArray(channels.count(),0);
48     }
49     for (int chan=0;chan<peeks.count();chan++)
50     {
51         peekage[chan]=peekage[chan]+1;
52         if (  peeks.at(chan)<arr.at(chan) ||  peekage.at(chan)>50 )
53         {
54             peekage[chan]=0;
55             peeks[chan]=arr[chan];
56         }
57     }
58     update();
59 }
60 void AudioSignal::paintEvent(QPaintEvent* /*e*/)
61 {
62     QPainter p(this);
63     //p.begin();
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++) {
73             if (maxx > 0) {
74                 p.fillRect(x * xdelta, y1, maxx > xdelta ? xdelta - 1 : maxx - 1, _h, QBrush(col.at(x), Qt::SolidPattern));
75                 maxx -= xdelta;
76             }
77         }
78         p.fillRect(peeks.at(i)*width()/127-2,y1,3,_h,QBrush(Qt::black,Qt::SolidPattern));
79     }
80     p.end();
81 }
82 #include "audiosignal.moc"