#include "track.h"

Track::Track()
{
	// Set toggle.
	IsPlaying = FALSE;
}

VOID Track::Release()
{
	// Release the track data.
	if (Data != NULL)
	{
		Data->release();
		Data = NULL;
	}
}

Track::~Track() { }

HRESULT Track::GetTags()
{
	FMOD_TAG Tag;
	FMOD_RESULT Result;
	int numtags, numtagsupdated, count;

	// Get the number of tags in the file.
    Result = Data->getNumTags(&numtags, &numtagsupdated);

	// Loop through the tags.
    for (count=0; count < numtags; count++)
    {
        Result = Data->getTag(0, count, &Tag);

		if (Tag.type == FMOD_TAGTYPE_ID3V2)
		{
			if (Tag.datatype == FMOD_TAGDATATYPE_STRING)
			{
				std::string tagName = Tag.name;

				// Artist tag.
				if (tagName == "TPE1" || tagName == "TPE2")
					Artist = (const char*)Tag.data;

				// Title tag.
				if (tagName == "TIT2")
					Title = (const char*)Tag.data;

				// Album tag.
				if (tagName == "TALB")
					Album = (const char*)Tag.data;

				// Year tag.
				if (tagName == "TYER")
					Year = (const char*)Tag.data;
			}
		}
    }

	// If no artist tag was discovered, use unknown tag.
	if (Artist == "")
		Artist = "[Unknown Artist]";

	// If no title tag was discovered, use unknown tag.
	if (Title == "")
		Title = "[Unknown Title]";

	return S_OK;
}