1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2020 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #ifndef GRAPHIQUEFOURIER_H
26 #define GRAPHIQUEFOURIER_H
27 
28 #include "qcustomplot.h"
29 #include "basetypes.h"
30 class QMenu;
31 
32 class GraphiqueFourier : public QCustomPlot
33 {
34     Q_OBJECT
35 
36 public:
37     explicit GraphiqueFourier(QWidget *parent = nullptr);
38     ~GraphiqueFourier();
39 
40     void setBackgroundColor(QColor color);
41     void setData(QByteArray baData, quint32 dwSmplRate);
setSampleName(QString name)42     void setSampleName(QString name) { _name = name; }
43     void setPos(quint32 posStart, quint32 posEnd, bool withReplot = true);
44     void setPos(quint32 posStart, quint32 posEnd, QList<double> &frequencies, QList<double> &factors,
45                 QList<int> &pitch, QList<int> &deltas, bool withReplot);
46     void getEstimation(int &pitch, int &correction);
47 
48 protected:
49     void mousePressEvent(QMouseEvent *event);
50     void paintEvent(QPaintEvent * event);
51 
52 private slots:
53     void exportPng();
54 
55 private:
56     class Peak
57     {
58     public:
Peak(double intensity,double frequency,int key,int delta)59         Peak(double intensity, double frequency, int key, int delta) :
60             _intensity(intensity),
61             _frequency(frequency),
62             _key(key),
63             _delta(delta)
64         {}
65 
66         double _intensity;
67         double _frequency;
68         int _key;
69         int _delta;
70     };
71 
72     QVector<float> _fData;
73     quint32 dwSmplRate;
74     QString _name;
75     QSharedPointer<QCPAxisTickerFixed> _fixedTickerX;
76     QSharedPointer<QCPAxisTickerFixed> _fixedTickerY;
77     QMenu * _menu;
78     int _key, _delta;
79     QList<Peak> _peaks;
80 
81     void resized();
82     void exportPng(QString fileName);
83     void dispFourier(QVector<float> vectFourier, float posMaxFourier);
84 };
85 
86 #endif // GRAPHIQUEFOURIER_H
87