//    tonalisa - software to look at overtone-structures
//    Copyright (C) 2016  Dominik Schmidt-Philipp
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
#include <QtQuick/QQuickPaintedItem>
#include "frequencyview.h"

FrequencyView::FrequencyView(QQuickItem *parent)
  :QQuickPaintedItem(parent)
{
  paint_coord = true;
  paint_grid = true;
  paint_fft = false;  paint_fft = false;
  paint_peaks = true;
  m_sampleRate = 48000.0;
  m_fftData.reserve(1024);
  m_fftSize = m_fftData.size() * 2;

}

// Interface
//--------------------------------------------------------------------
// getter functions:
bool FrequencyView::paintAxes() {
  return paint_coord;
}
bool FrequencyView::paintGrid() {
  return paint_grid;
}
bool FrequencyView::paintFFT() {
  return paint_fft;
}
bool FrequencyView::paintPeaks() {
  return paint_peaks;
}
QList<double> FrequencyView::fftData() {
  return m_fftData;
}
double FrequencyView::sampleRate() const {
  return m_sampleRate;
}
QList<double> FrequencyView::peaks() {
  return m_peaks;
}
QList<double> FrequencyView::grid() {
  return m_grid;
}
int FrequencyView::gridTunedStep() const {
  return m_gridTunedStep;
}
double FrequencyView::gridPitch() const {
  return m_gridPitch;
}
double FrequencyView::gridLowest() const {
  return m_gridLowest;
}
double FrequencyView::gridHighest() const {
  return m_gridHighest;
}
double FrequencyView::pointerFreq() const {
  return m_pointerFreq;
}
double FrequencyView::pointerAmp() const {
  return m_pointerAmp;
}
QPointF FrequencyView::pointerPos() {
  return m_pointerPos;
}

// setter functions:
void FrequencyView::setPaintAxes(const bool &paint) {
  if( paint_coord != paint ) {
    paint_coord = paint;
    update();
  }
}
void FrequencyView::setPaintGrid(const bool &paint) {
  if( paint_grid != paint ) {
    paint_grid = paint;
    update();
  }
}
void FrequencyView::setPaintFFT(const bool &paint) {
  if( paint_fft != paint ) {
    paint_fft = paint;
    update();
  }
}
void FrequencyView::setPaintPeaks(const bool &paint) {
  if( paint_peaks != paint ) {
    paint_peaks = paint;
    update();
  }
}
void FrequencyView::setFftData(const QList<double> &fftData){
  if ( paint_fft ) {
    m_fftData = fftData;
    m_fftSize = m_fftData.size() * 2;
    update();
  }
}
void FrequencyView::setSampleRate(const double &sampleRate)
{
  if ( m_sampleRate != sampleRate ) {
    m_sampleRate = sampleRate;
    emit sampleRateChanged();
  }
}
void FrequencyView::setPeaks(const QList<double> &peaks) {
  if ( paint_peaks ) {
    m_peaks = peaks;
    update();
  }
}
void FrequencyView::setGrid(const QList<double> &grid) {

}
void FrequencyView::calculateGrid(){}
void FrequencyView::setGridTunedStep(const int &gridTunedStep) {
  if(m_gridTunedStep != gridTunedStep) {
    m_gridTunedStep = gridTunedStep;
  }
}
void FrequencyView::setGridPitch(const double &gridPitch) {
  if(m_gridPitch != gridPitch) {
    m_gridPitch = gridPitch;
    calculateGrid();
    emit gridPitchChanged();
  }
}
void FrequencyView::setGridLowest(const double &gridLowest) {
  if(m_gridLowest != gridLowest) {
    m_gridLowest = gridLowest;
  }
  calculateGrid();
}
void FrequencyView::setGridHighest(const double &gridHighest) {
  if(m_gridHighest != gridHighest) {
    m_gridHighest = gridHighest;
  }
  calculateGrid();
}
void FrequencyView::setPointerFreq(const double &pointerFreq) {
  if ( m_pointerFreq != pointerFreq ) {
    m_pointerFreq = pointerFreq;
    emit pointerFreqChanged();
  }
}

void FrequencyView::setPointerAmp(const double &pointerAmp) {
  if ( m_pointerAmp != pointerAmp ) {
    m_pointerAmp = pointerAmp;
    emit pointerAmpChanged();
  }
}

void FrequencyView::paint(QPainter *painter){}
