#ifndef LISTENER_TRACK_H
#define LISTENER_TRACK_H

#include "listener-external.h"

#include "double-track.h"


#include <memory>
#include <wx/combobox.h>
#include <wx/arrstr.h>

#include <boost/math/quaternion.hpp> //for using quaternion to change orientation
#include <boost/algorithm/string.hpp> //for splitting string

struct ListenerTrackSaveData
{
	
	//double track save data
	
	//position
	DDMap* time_value_map_posx_ptr;
	DDMap* time_value_map_posy_ptr;
	DDMap* time_value_map_posz_ptr;
	
	//orientation
	DDMap* time_value_map_orientw_ptr;
	DDMap* time_value_map_orientx_ptr;
	DDMap* time_value_map_orienty_ptr;
	DDMap* time_value_map_orientz_ptr;
	
};

//class to manipulate x,y z position of sound producer
class ListenerTrack : public Track
{
public:
	ListenerTrack(const wxString& title);


	DoubleTrack* GetReferenceToXTrack();
	DoubleTrack* GetReferenceToYTrack();
	DoubleTrack* GetReferenceToZTrack();

	DoubleTrack* GetReferenceToQuatWTrack();
	DoubleTrack* GetReferenceToQuatXTrack();
	DoubleTrack* GetReferenceToQuatYTrack();
	DoubleTrack* GetReferenceToQuatZTrack();

	//Listener Editing
	void SetReferenceToListenerToManipulate(Listener* thisListener);
	void SetReferenceToExternalListener(ListenerExternal* thisListenerExt);

	//Double Track related functions
	void SetupAxisForPositionVariable(double& start, double& end, double& resolution, int& numTick);
	void SetupAxisForOrientationVariable(double& start, double& end, double& resolution, int& numTick);

	void OnLeftMouseClick(wxMouseEvent& event);
	void OnRightMouseClick(wxCommandEvent& event);

	//Functions inherited from Track
	virtual void InitTrack(wxWindow* parent, std::vector <int> *timeTickVector);

	virtual void OnPaint(wxPaintEvent& event);
	virtual void OnScroll(wxScrollEvent& event);
	virtual void OnSize(wxSizeEvent& event);

	void SetReferenceToCurrentTimeVariable(double* thisTimeVariable);
	void SetReferenceToTimeTickVector(std::vector <int> *thisVector);

	std::vector <int> *GetReferenceToTimeTickVector();

	double GetCurrentTime();

	//function to call in timer loop, variable to manipulate gets changed here
	virtual void FunctionToCallInPlayState();
    virtual void FunctionToCallInPauseState();
    virtual void FunctionToCallInRewindState();
    virtual void FunctionToCallInFastForwardState();
    virtual void FunctionToCallInNullState();
    
    //save data
    ListenerTrackSaveData GetListenerTrackSaveData();
	void LoadListenerTrackSaveData(ListenerTrackSaveData& data);

private:
	Listener* listenerToManipulatePtr;
	ListenerExternal* listenerExternalPtr;

	DoubleTrack* xTrack;
	DoubleTrack* yTrack;
	DoubleTrack* zTrack;

	DoubleTrack* wQuatTrack;
	DoubleTrack* xQuatTrack;
	DoubleTrack* yQuatTrack;
	DoubleTrack* zQuatTrack;


	//variables to hold temporary values for listener position and orientation
	double tempX,tempY,tempZ,tempQuatX,tempQuatY,tempQuatZ,tempQuatW;

	//quaternions for intial forward vector and up vector directions
	boost::math::quaternion <float> forward_vector_quaternion;
	boost::math::quaternion <float> up_vector_quaternion;
	
	//listener track save data
	ListenerTrackSaveData m_saveData;
};

#endif
