----------------------------------
------------FUNCTIONS-------------
----------------------------------


function Receive(action, ...)
	local args = {...}
	if not ScriptReady then return end
	if action == "activate" then
		if not PlayingEnabled then
			Activate(args[1], args[2])
			specialPiano = args[3];
		end
	elseif action == "deactivate" then
		if PlayingEnabled then
			Deactivate()
		end
	elseif action == "DDD" or args[1] == "DDD" then
		if Player.Name == args[1] or Player.Name == action then
			Deactivate()
		end
	elseif action == "play" then
		for i,v in pairs(args[5]) do
			if v == "Fade" then
				fade = true
			end
		end
		if Player ~= args[1] then
			PlayNoteServer(args[2], args[3], args[4], args[5], args[6], args[7])
		end
	end
end

function Activate(cameraCFrame, sounds)
	PlayingEnabled = true
	MakeHumanoidConnections()
	MakeKeyboardConnections()
	MakeGuiConnections()
	SetCamera(cameraCFrame)
	SetSounds(sounds)
	ShowPiano()
end

function Deactivate()
	SpecialPiano = false
	PlayingEnabled = false
	BreakHumanoidConnections()
	BreakKeyboardConnections()
	BreakGuiConnections()
	HidePiano()
	HideSheets()
	ReturnCamera()	
	Jump()
end

function PlayNoteClient(note)
	PlayNoteSound(note)
	HighlightPianoKey(note)
	Connector:FireServer("play", note, Volume,Transposition.Value)
end

function PlayNoteServer(note, point, range, sounds, vol, special)
	PlayNoteSound(note, point, range, sounds, vol, SpecialPiano or special) -- just incase ;-;
end

function Abort()
	SpecialPiano = false;
	Connector:FireServer("abort")
end

function Transpose(value)
	Transposition.Value = Transposition.Value + value
	
	PianoGui.TransposeLabel.Text = "Transposition: " .. Transposition.Value
end

function VolumeChange(value)
	if (Volume + value <= 1.5) and (Volume + value >= 0.1) then
		Volume = Volume + value;
		PianoGui.VolumeLabel.Text = "Volume: " .. Volume * 100 .. "%";
	end
end
