BpmSlider = class(DragArea, function(o, x, y, w, h, synth)
	DragArea.init(o, x, y, w, h)
	o.woodBg = sprites["bpmSliderBg.png"]
	o.backgroundSlide = Object(0,0,o.woodBg:getWidth(), o.woodBg:getHeight())
	o.backgroundSlide.sprite = o.woodBg
	o.sliderOffset = 6
	o.sliderOffset = o.sliderOffset* r_scale/2
	o.synth = synth
	
	o.sliderPos = calcPosFromBpm(o.synth.bpm)
	
	o.sliderSprite = sprites["bpmSliderWindow.png"]
	
	local sliderPosition = (o.pos.x+o.w-o.sliderSprite:getWidth())*o.sliderPos

	o.sliderObject = Object(sliderPosition,o.pos.y-o.sliderOffset, o.sliderSprite:getWidth(),o.sliderSprite:getHeight())

	o.sliderObject.sprite = o.sliderSprite
	o.bpmText = StringObject(0,0,math.floor(calcBpmFromPos(o.sliderPos)))
	o.bpmText:setPosition(o.sliderObject.pos.x+o.sliderObject.w/2-o.bpmText.w/2, o.sliderObject.pos.y+o.sliderObject.h/2-o.bpmText.h/2)
end)
function BpmSlider:draw()
	-- draw the background
	for i=0,math.ceil(self.w/self.backgroundSlide.w) do
		self.backgroundSlide.pos.x, self.backgroundSlide.pos.y = i*self.backgroundSlide.w, self.pos.y
		self.backgroundSlide:draw()
	end
	self.sliderObject:draw()
	self.bpmText:draw()
end
function BpmSlider:onStart(x, y, id)
	return false
end
function BpmSlider:onPress(x, y, id)
	return false
end
function BpmSlider:onMove(x, y, id)
	local p = Vec2(x, y)
	p:sub(self.lastPos[id])
	-- because we are just a horizontal slider, limit the slide to one axis
	p.y = 0
	local sliderX = self.sliderObject.pos.x + p.x
	self.sliderObject.pos.x = math.min(self.w-self.sliderObject.w, math.max(self.pos.x, sliderX))
	local theBpm = math.min(1.0,(math.max(0.0, (self.sliderObject.pos.x)/(self.w-self.sliderObject.w))))

	if math.floor(calcBpmFromPos(theBpm)) ~= self.bpmText.string then
		-- this is a 0 - 1 that can be used for adjusting the bpm
		pd:startList("fromOF")
		pd:addSymbol("bpm")
		pd:addFloat(theBpm) -- 0, 1 for the bpm
		pd:finish("fromOF")
		self.bpmText:setValue(math.floor(calcBpmFromPos(theBpm)))
		self.synth.bpm = calcBpmFromPos(theBpm)
		self.bpmText:setPosition(self.sliderObject.pos.x+self.sliderObject.w/2-self.bpmText.w/2, self.sliderObject.pos.y+self.sliderObject.h/2-	self.bpmText.h/2)
	end
end
function calcBpmFromPos(pos)
	return pos*120+60
end
function calcPosFromBpm(bpm)
	return (bpm-60)/120
end

-- mainState = WrapperState(Group());
-- mainState:changeState(GalaxyState(mainSynth))
-- mainState.substate.menuButton.onPress()
