--own music system which basics on simple tracks
--реализовать плавное затухание

MusicTrack = {
	type = "Sound",

	Properties = {
		MusicFile="",
		iVolume=255,
		bLoop=0,	-- Loop sound.
		bOnce=0,
		bEnabled=1,
		FadeTime=3,
	},
	Editor={
		Model="Objects/Editor/Sound.cgf",
	},	
}
---------------------------------------------------
---------------------------------------------------
function MusicTrack:OnSave(stm)
	stm:WriteInt(self.HintCount);
end

function MusicTrack:OnLoad(stm)
	self:OnReset();
end
---------------------------------------------------
--------------------EVENTS-------------------------
---------------------------------------------------
function MusicTrack:Event_Play( sender )
	if(self.started~=0) then
		return
	end
	self:Play();
end

function MusicTrack:Event_Stop( sender )
	self:StopSound();
end

function MusicTrack:Event_Enable( sender )
	self.Properties.bEnabled = 1;
end

function MusicTrack:Event_Disable( sender )
	self.Properties.bEnabled = 0;
end
---------------------------------------------------
---------------------------------------------------
function MusicTrack:OnWrite( stm )
end

function MusicTrack:OnRead( stm )
end
---------------------------------------------------
---------------------------------------------------
function MusicTrack:LoadSound()
	if (self.sound ~= nil) then
		self:StopSound();
	end
	if (self.Properties.MusicFile ~= "") then
		self.MusicFile = Sound:LoadStreamSound(SOUND_MUSIC+SOUND_UNSCALABLE);
end

function MusicTrack:StopSound()

	if (self.bEnabled == 0 ) then 
		do return end;
	end

	if (self.sound ~= nil ) then
		Sound:StopSound(self.sound);
		self.sound = nil;
	end
	self.started = 0;
end