Audacity Zooms from a fixed point, from the left. I need to zoom from an arbitrary point off of a fixed point and luckily I was able to make something after looking at one of Neuro Fuzzy's (genius) snippets and this is exactly what I need but one thing is still missing. I need to Zoom not from the centre of the screen but rather the mouse point, the math on this is confusing me but I think it will hit me at some point... I hope.
type vector2
x as float
y as float
endtype
type vector3
x as float
y as float
z as float
endtype
global _vector2 as vector2
global _vector3 as vector3
global _mouseDrag as byte
global _mouseDragPos as vector2
global _zoomCenter as vector2
global _mouse as vector3
global _mousemove as vector3
global _oldMouse as vector3
global _perPixelUnit as float
global _pos as vector2
global _zoom as float
global _zoomVal as float
global _mouseclick as byte
global _screenWidth as float
global _screenHeight as float
global _p0 as vector2
global _p1 as vector2
_screenWidth = screen width()
_screenHeight = screen height()
global dim _point(100) as vector2
sync on : sync rate 60
_perPixelUnit = 1
_zoom = 1
_zoomVal = 0
for n = 1 to 100
_point(n).x = _point(n-1).x - rnd(200)
_point(n).y = rnd(1000)
next
do : cls rgb(56,56,56)
_mouse.x = mousex()
_mouse.y = mousey()
_mouse.z = mousez()
_mousemove.z = mousemovez()
_mouseclick = mouseclick()
if not _mouseclick
_mouseDrag = 0
_mouseDragPos.x = 0
_mouseDragPos.y = 0
endif
if _mouseDrag = 0
if _mouseclick
_mouseDrag = 1
_mouseDragPos.x = (_mouse.x/(_perPixelUnit*_zoom)) - _pos.x
_mouseDragPos.y = (_mouse.y/(_perPixelUnit*_zoom)) - _pos.y
endif
endif
if _mouseDrag
_pos.x = (_mouse.x/(_perPixelUnit*_zoom)) - _mouseDragPos.x
_pos.y = (_mouse.y/(_perPixelUnit*_zoom)) - _mouseDragPos.y
endif
_zoom = 2 ^ _zoomVal
inc _zoomVal, (_mousemove.z * .001)
convertGlobalToLocal( 0, 0 )
a2FillBox _vector2.x-2, 0, _vector2.x+2, _screenHeight, rgb(82,82,82)
a2FillBox 0, _vector2.y-2, _screenWidth, _vector2.y+2, rgb(0,0,0)
a2StartLineBatch 1000
for n = 1 to 100
convertGlobalToLocal( _point(n-1).x, _point(n-1).y ) : _p0 = _vector2
convertGlobalToLocal( _point(n).x, _point(n).y ) : _p1 = _vector2
a2Line _p0.x, _p0.y, _p1.x, _p1.y, rgb(0,255,255)
a2FillBox _p0.x-2, _p0.y-2,_p0.x+2, _p0.y+2, rgb(255,0,0)
next
a2FillBox _p1.x-2, _p1.y-2,_p1.x+2, _p1.y+2, rgb(255,0,0)
a2EndBatch
set cursor 0,0
print "Mouseclick to drag, Mousewheel to zoom"
sync
loop
function convertGlobalToLocal( x as float, y as float )
_vector2.x = -((x - _pos.x)*(_perPixelUnit*_zoom))+0.5*_screenWidth
_vector2.y = -((y - _pos.y)*(_perPixelUnit*_zoom))+0.5*_screenHeight
endfunction
Note: this requires Advanced2d plugin cause trying to display only a few lines with stock DBP commands is ridiculous.