/*
    CaPriCe Forever - Amstrad CPC 464/664/6128 emulator
    Copyright (C) 2014-2015 by Frédéric Coste

    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/>.
*/


#ifndef TFormPSGH
#define TFormPSGH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <VCLTee.Chart.hpp>
#include <VCLTee.Series.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
#include <VclTee.TeeGDIPlus.hpp>
#include "..\Settings\TSettings.h"
#include "..\Audio\TAudioContext.h"
//---------------------------------------------------------------------------
class TFormPSG : public TForm
{
__published:	// Composants gérés par l'EDI
  TGroupBox *GroupBoxMonitor;
  TGroupBox *GroupBoxLeftSample;
  TLabel *LabelLeftSampleMax;
  TLabel *LabelLeftSample;
  TPanel *PanelLeftSample;
  TPanel *PanelLeftSampleMax;
  TChart *ChartLeft;
  TFastLineSeries *Series1;
  TGroupBox *GroupBoxRightSample;
  TLabel *LabelRightSampleMax;
  TLabel *LabelRightSample;
  TPanel *PanelRightSample;
  TPanel *PanelRightSampleMax;
  TChart *ChartRight;
  TFastLineSeries *FastLineSeries1;
  TGroupBox *GroupBoxRegisters;
  TLabel *LabelReg0;
  TLabel *LabelReg1;
  TLabel *LabelReg15;
  TLabel *LabelReg2;
  TLabel *LabelReg8;
  TLabel *LabelReg4;
  TLabel *LabelReg5;
  TLabel *LabelReg6;
  TLabel *LabelReg7;
  TLabel *LabelReg9;
  TLabel *LabelReg3;
  TLabel *LabelReg10;
  TLabel *LabelReg11;
  TLabel *LabelReg12;
  TLabel *LabelReg13;
  TLabel *LabelReg14;
  TPanel *PanelFormatR0;
  TPanel *PanelFormatR1;
  TPanel *PanelFormatR2;
  TPanel *PanelFormatR3;
  TPanel *PanelFormatR4;
  TPanel *PanelFormatR5;
  TPanel *PanelFormatR6;
  TPanel *PanelFormatR7;
  TPanel *PanelFormatR8;
  TPanel *PanelFormatR9;
  TPanel *PanelFormatR10;
  TPanel *PanelFormatR11;
  TPanel *PanelFormatR12;
  TPanel *PanelFormatR13;
  TPanel *PanelFormatR14;
  TPanel *PanelFormatR15;
  TPanel *PanelReg0;
  TPanel *PanelReg1;
  TPanel *PanelReg2;
  TPanel *PanelReg3;
  TPanel *PanelReg4;
  TPanel *PanelReg5;
  TPanel *PanelReg6;
  TPanel *PanelReg7;
  TPanel *PanelReg8;
  TPanel *PanelReg9;
  TPanel *PanelReg10;
  TPanel *PanelReg11;
  TPanel *PanelReg12;
  TPanel *PanelReg13;
  TPanel *PanelReg14;
  TPanel *PanelReg15;
  TGroupBox *GroupBoxChannels;
  TPanel *PanelChannelAFreq;
  TPanel *PanelChannelBFreq;
  TPanel *PanelChannelCFreq;
  TPanel *PanelChannelANoise;
  TPanel *PanelChannelBNoise;
  TPanel *PanelChannelCNoise;
  TProgressBar *ProgressBarChannelAAmplitude;
  TProgressBar *ProgressBarChannelBAmplitude;
  TProgressBar *ProgressBarChannelCAmplitude;
  TGroupBox *GroupBoxEnvelope;
  TPanel *PanelEnveloppeFreq;
  TChart *ChartEnvelope;
  TFastLineSeries *FastLineSeries2;
  TPanel *PanelChannelAEnv;
  TPanel *PanelChannelBEnv;
  TPanel *PanelChannelCEnv;
  TPanel *PanelChannelA;
  TPanel *PanelChannelB;
  TPanel *PanelChannelC;
  TGroupBox *GroupBoxNoise;
  TPanel *PanelNoiseFreq;
	TPanel *PanelCheckMonitoring;
  void __fastcall FormShow(TObject *Sender);
  void __fastcall FormHide(TObject *Sender);
  void __fastcall FormResize(TObject *Sender);
  void __fastcall PanelLeftSampleMaxClick(TObject *Sender);
  void __fastcall PanelRightSampleMaxClick(TObject *Sender);
  void __fastcall PanelFormatClick(TObject *Sender);
  void __fastcall PanelChannelAClick(TObject *Sender);
  void __fastcall PanelChannelBClick(TObject *Sender);
  void __fastcall PanelChannelCClick(TObject *Sender);
  void __fastcall PanelButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall PanelButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall PanelCheckMonitoringClick(TObject *Sender);

private:	// Déclarations utilisateur
  //
  // Members
  //
  bool mMonitoring;
  bool mPaused;
  TSettings* mSettingsP;
  TAudioContext* mAudioContextP;
  tLong mLeftSampleMax;
  tLong mRightSampleMax;
  int mLoopLeft;
  int mLoopRight;
  int mLastEnvelopeShape;
  tULong mLastDisplayedRegisterSelected;
  tULong mLastDisplayedRegistersP[PSG_REGISTERS_NBELEMENT];
  bool mDisplayValueHexa[PSG_REGISTERS_NBELEMENT];
  TPanel* mPanelRegisterFormat[PSG_REGISTERS_NBELEMENT];
  TPanel* mPanelRegister[PSG_REGISTERS_NBELEMENT];
  TLabel* mLabelRegister[PSG_REGISTERS_NBELEMENT];

  //
  // Methods
  //
  AnsiString __fastcall GetTitle(void);
  inline void __fastcall SetAudioContext(TAudioContext* Value) { mAudioContextP=Value; };
  void __fastcall WMMove(TMessage &Message);
  void __fastcall SetSettings(TSettings* Value);
  bool __fastcall OnEmulatorEvent(tULong Condition, tNativeCPC* NativeCPC);
  void __fastcall InitRegisters(tNativeCPC* NativeCPC);
  void __fastcall UpdateRegisters(tNativeCPC* NativeCPC);
  void __fastcall UpdateRegisterFormat(int Index);
  void __fastcall UpdateRegister(int Index);
  void __fastcall UpdateChannels(tPSG* PSG);
  void __fastcall UpdateEnveloppe(tPSG* PSG);
  void __fastcall UpdateNoise(tPSG* PSG);
  void __fastcall StopMonitoring(void);

public:		// Déclarations utilisateur
  //
  // Properties
  //
  __property AnsiString Title = { read=GetTitle };
  __property TSettings* Settings = { write=SetSettings };
  __property TAudioContext* AudioContext = { write=SetAudioContext };

  //
  // API
  //
  __fastcall TFormPSG(TComponent* Owner);

#pragma option push -vi-
BEGIN_MESSAGE_MAP
  MESSAGE_HANDLER(WM_MOVE, TMessage, WMMove);
END_MESSAGE_MAP(TForm)
#pragma option pop
};
//---------------------------------------------------------------------------
extern PACKAGE TFormPSG *FormPSG;
//---------------------------------------------------------------------------
#endif
