#pragma once

#include "MSETypes.h"

struct EmbeddedFileInfo
{
	MSE_SampleType sampleType;
	int samplerate;
	int channels;
	int reserved;	//for byte alignment
	MSE_Frame frames;
};

//interface for sound file reading, subclass such as MWaveFile or MEmbeddedSoundFile
//this class is not completely abstract, it handles embeded sound file writing

class MSE_API MSoundFile
{
public:
	MSoundFile() {};
	virtual ~MSoundFile() {};

	//open and validate the sound file, last two parameters are only used by MEmbeddedSoundFile
	virtual bool OpenFile(std::string& filename, FILE* compactfile = NULL, MSE_Size offset = 0) = 0;
	virtual void ReOpenIfNeeded() = 0;	//open sound file using saved filename
	virtual void CloseFile() = 0;
	
	//write the sound file info and samples into the compact file
	virtual void WriteIntoCompactFile(FILE* compactfile, MSE_SampleType bitdepth);

	//read frames to buffer, return the actual read frames count, 32bit or 16bit
	virtual MSE_Frame ReadFrames(float* buffer, MSE_Frame count) = 0;
	virtual MSE_Frame ReadFrames(short* buffer, MSE_Frame count) = 0;

	//jump to the frame from the beginning
	virtual void SeekFrames(MSE_Frame count) = 0;

	//If the file is opened and validated
	virtual bool IsReady() = 0;

	//Sample Rate
	virtual long GetSampleRate() = 0;

	//Number of Channels
	virtual int GetChannels() = 0;

	//Number of Frames
	virtual MSE_Frame GetFrames() = 0;

	//File size in bytes
	virtual MSE_Size GetSize() = 0;
	
	//Get bit depth
	virtual MSE_SampleType GetSampleType() = 0;

	//File name in std string
	virtual std::string& GetFilename() = 0;
	virtual std::string& GetFilenameShort();

	//some sound files can contain sampler information, we need them
	virtual bool HasSmplChunk() = 0;
	virtual bool HasLoopInfo() = 0;
	//Get loop frames info
	virtual MSE_Frame GetLoopStart() = 0;
	virtual MSE_Frame GetLoopEnd() = 0;
	//Get root note info
	virtual char GetRootNote() = 0;

protected:
	std::string m_ShortFilename;

};
