/*******************************************************************************
*   @author Tomáš Pospíšil
*
*   Tento kód byl sestaven na základì tutoriálu, dostupného na adrese:
*   https://docs.juce.com/master/tutorial_looping_audio_sample_buffer.html.
*
*  ==============================================================================

   Some of the code is part of the JUCE tutorials.
   Copyright (c) 2020 - Raw Material Software Limited

   The code included in this file is provided under the terms of the ISC license
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
   To use, copy, modify, and/or distribute this software for any purpose with or
   without fee is hereby granted provided that the above copyright notice and
   this permission notice appear in all copies.

   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
   PURPOSE, ARE DISCLAIMED.

  ==============================================================================
  */

/*
  ==============================================================================

    This file contains the basic framework code for a JUCE plugin editor.

  ==============================================================================
*/

#pragma once

#include <JuceHeader.h>
#include "PluginProcessor.h"

//==============================================================================
/**
*/
class BufferUnderstandAudioProcessorEditor  : public juce::AudioProcessorEditor,
                                              public juce::AudioAppComponent
{
public:

    /*
    * Functions of this class.
    */
    BufferUnderstandAudioProcessorEditor (BufferUnderstandAudioProcessor&);
    ~BufferUnderstandAudioProcessorEditor() override;

    void openButtonClicked();
    void clearButtonClicked();
    void getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) override;
    void prepareToPlay(int, double) override;
    void releaseResources() override;
    void playButtonClicked(juce::AudioSampleBuffer filebuffer);

    //==============================================================================
    void paint (juce::Graphics&) override;
    void resized() override;

private:
    
    /*
    * Objects and variables of this class.
    */
    BufferUnderstandAudioProcessor& audioProcessor;

    bool play = false;

    juce::TextButton openButton;
    juce::TextButton clearButton;
    juce::TextButton playButton;

    std::unique_ptr<juce::FileChooser> chooser;

    juce::AudioFormatManager formatManager;
    juce::AudioSampleBuffer fileBuffer;
    juce::AudioSampleBuffer buffer;
    int position;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferUnderstandAudioProcessorEditor)
};
