VSTGLEditor Class Reference

Editor window for VST plugins, using OpenGL to handle all the drawing. More...

#include <VSTGLEditor.h>

Inheritance diagram for VSTGLEditor:

ExampleEditor List of all members.

Public Types

enum  WindowFlags {
  DefaultFlags = 0, WaitForVerticalSync, Antialias2x, Antialias4x,
  Antialias6x
}
 Enum containing various flags to set certain properties of the window. More...

Public Member Functions

 VSTGLEditor (AudioEffect *effect, WindowFlags flags=DefaultFlags)
 Constructor.
virtual ~VSTGLEditor ()
 Destructor.
bool getRect (ERect **rect)
 Returns the size of the editor, so the host can provide the correct-sized window.
bool open (void *ptr)
 Called by the host once the window's been created, so we can set stuff up in it.
virtual void guiOpen ()=0
 Called when the editor's window is opened.
void close ()
 Called by the host just before the window is destroyed/closed.
virtual void guiClose ()=0
 Called when the editor's window is closed.
virtual void onMouseDown (int button, int x, int y)
 Called when there's a MouseDown event.
virtual void onMouseMove (int x, int y)
 Called when there's a MouseMove event.
virtual void onMouseUp (int button, int x, int y)
 Called when there's a MouseUp event.
virtual void onMouseWheel (int wheel, int x, int y)
 Called when there's a MouseWheel event.
virtual void onGLKeyDown (const VstKeyCode &key)
 Called when there's a KeyDown event (GL because the VST headers already use onKeyDown).
virtual void onGLKeyUp (const VstKeyCode &key)
 Called when there's a KeyUp event (GL because the VST headers already use onKeyUp).
virtual void draw ()=0
 This is the method where everything gets drawn.
void refreshGraphics ()
 This method wraps draw().
virtual void setParameter (int index, float value)
 You'd call this from your plugin if you wanted to update the gui when your parameters change.
int getX () const
 Returns the x position of the window/context.
int getY () const
 Returns the y position of the window/context.
int getWidth () const
 Returns the width of the window/context.
int getHeight () const
 Returns the height of the window/context.
void updateBounds (int x, int y)
 OSX: Used to update our context's bounds if the host changes them.
int getBoundsX () const
 OSX: Returns the boundsX value.
int getBoundsY () const
 OSX: Returns the boundsY value.
WindowRef getWindowRef () const
 OSX: Returns our WindowRef.

Static Public Member Functions

static LONG WINAPI GLWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 Windows: Message loop - we use this to intercept mouse messages, among other things.
static pascal OSStatus macEventHandler (EventHandlerCallRef handler, EventRef event, void *userData)
 OSX: Message loop - we use this to intercept mouse messages, among other things.

Protected Member Functions

void setupContext ()
 Helper method, needs to be called before any drawing takes place.
void swapBuffers ()
 Helper method, needs to be called after drawing has taken place.
void setRect (int x, int y, int width, int height)
 Call this to set your window's bounds in subclass constructors.

Private Member Functions

void createWindow ()
 Used to create the actual window when open() is called.
void setupVSync ()
 Helper method: Used to setup Vertical Sync.
void setupAntialiasing ()
 Helper method: Tries to set up hardware antialiasing.

Private Attributes

HGLRC glRenderingContext
 Windows: Windows rendering context.
HWND tempHWnd
 Windows: Holds a handle to the window we created in createWindow().
HDC dc
 Windows: Device context for our window.
PIXELFORMATDESCRIPTOR pixelformat
 Windows: The pixel format we want to use for the window.
AGLContext context
 OSX: OS X rendering context.
AGLPixelFormat pixels
 OSX: The pixel format we used.
GrafPtr port
 OSX: Saved in setupContext(), to be used in swapBuffers().
EventHandlerRef eventHandlerRef
 OSX: Reference to our event handler.
WindowRef window
 Our window.
int boundsX
 OSX: Our context's actual bounds (x).
int boundsY
 OSX: Our context's actual bounds (y).
ControlDefSpec controlSpec
 OSX: The control class reference for our dummy HIView.
CFStringRef classId
 OSX: Id for our dummy HI class.
ControlRef controlRef
 OSX: Our dummy HIView (necessary for VST 2.4).
ERect _rect
 The rect our opengl context is contained within.
bool useVSync
 Whether or not to use Vertical Sync.
int antialiasing
 The level of antialiasing to use.

Detailed Description

Editor window for VST plugins, using OpenGL to handle all the drawing.

This is a fairly basic implementation - it'll set up an opengl context for you, and provides a couple of options (vertical sync, antialiasing) for that context, and the usual mouse and key event methods.

It's derived from AEffEditor, so that class' methods are available, but note that VSTGLEditor subclasses should not use the open() and close() methods - to make the interface a bit more object-oriented, and hopefully, easier to use, subclasses should use guiOpen() and guiClose() instead. VSTGLEditor uses open() and close() to set up and clean up various platform-specific variables, and call the aforementioned methods when it's safe to do so. This means you no longer have to put the ugly VSTGLEditor::open(ptr); line at the top of your open() method.

If you're upgrading from the previous version of VSTGL, please make sure you move your open() and close() code to guiOpen() and guiClose(), respectively. The other change is that idle() is no longer hardwired to update the gui - it's now up to your subclass to decide if you want to do it that way (I've included a simple message-based timer class to provide a better update frequency as an alternative). To update the opengl context, call refreshGraphics() - this will make sure the context's set up, call draw(), and then swap the buffers to display your changes on screen.

See also:
Timer
Todo:
Shared contexts?

Implement simple Mouse class (so we can hide and show the cursor, mainly).

Test key events.


Member Enumeration Documentation

enum VSTGLEditor::WindowFlags
 

Enum containing various flags to set certain properties of the window.

Enumerator:
DefaultFlags  Specifies a default opengl window.
WaitForVerticalSync  Specifies that drawing may only take place between the monitor's vertical refreshes.
Antialias2x  Specifies the drawing should use 2x hardware antialiasing if the graphics card supports it.
Antialias4x  Specifies the drawing should use 4x hardware antialiasing if the graphics card supports it.
Antialias6x  Specifies the drawing should use 6x hardware antialiasing if the graphics card supports it.


Constructor & Destructor Documentation

VSTGLEditor::VSTGLEditor AudioEffect *  effect,
WindowFlags  flags = DefaultFlags
 

Constructor.

Parameters:
effect Pointer to the plugin class.
flags An OR-ed combination of flags to set certain attributes of the opengl window. The antialias flags are mutually exclusive. Note: I have observed very high cpu usage on my windows laptop if I have multiple VSTGL windows open with the WaitForVerticalSync flag set. I suspect it's probably a graphics card issue (mine's an ATI Mobility Radeon 9600/9700 series apparently), but not having another windows machine to test on I don't know for sure - it works fine on my macmini. Also note that not all graphics cards can support hardware antialiasing - it might be safest to use 2x or 4x just in case.
See also:
WindowFlags


Member Function Documentation

void VSTGLEditor::close  ) 
 

Called by the host just before the window is destroyed/closed.

We hide this from subclasses, because we need to do platform-specific stuff in it. Subclasses can use guiClose() to be informed of the editor's window being closed.

DO NOT ATTEMPT TO OVERRIDE THIS!!!! (The compiler probably won't throw up an error, but the opengl context will not be cleaned up, which could be very bad.)

void VSTGLEditor::createWindow  )  [private]
 

Used to create the actual window when open() is called.

Only necessary on Windows (and only really for Tracktion, which does things kind of strange).

virtual void VSTGLEditor::draw  )  [pure virtual]
 

This is the method where everything gets drawn.

It's into here that you'll want to put your drawing code in subclasses.

Implemented in ExampleEditor.

virtual void VSTGLEditor::onGLKeyDown const VstKeyCode &  key  )  [inline, virtual]
 

Called when there's a KeyDown event (GL because the VST headers already use onKeyDown).

Todo:
test whether the key mapping's correct.

Reimplemented in ExampleEditor.

virtual void VSTGLEditor::onGLKeyUp const VstKeyCode &  key  )  [inline, virtual]
 

Called when there's a KeyUp event (GL because the VST headers already use onKeyUp).

Todo:
test whether the key mapping's correct.

virtual void VSTGLEditor::onMouseDown int  button,
int  x,
int  y
[inline, virtual]
 

Called when there's a MouseDown event.

The buttons are numbered 1=left, 2=right, 3=middle.

virtual void VSTGLEditor::onMouseMove int  x,
int  y
[inline, virtual]
 

Called when there's a MouseMove event.

Note that you may find (on Windows anyway) that the x and y values are outside the bounds of your editor if youd drag the mouse outside it.

virtual void VSTGLEditor::onMouseUp int  button,
int  x,
int  y
[inline, virtual]
 

Called when there's a MouseUp event.

The buttons are numbered 1=left, 2=right, 3=middle.

bool VSTGLEditor::open void *  ptr  ) 
 

Called by the host once the window's been created, so we can set stuff up in it.

We hide this from subclasses, because we need to do platform-specific stuff in it. Subclasses can use guiOpen() to be informed of the editor's window is opened.

DO NOT ATTEMPT TO OVERRIDE THIS!!!! (The compiler probably won't throw up an error, but the opengl context will not be set up, resulting in a blank window, and possibly a crash.)

void VSTGLEditor::refreshGraphics  ) 
 

This method wraps draw().

This method performs necessary setup and cleanup for a draw() operation - what it does is call setupContext(), draw(), swapBuffers(). If you want to update your graphics repeatedly, the simplest thing to do is just stick this in idle().

virtual void VSTGLEditor::setParameter int  index,
float  value
[inline, virtual]
 

You'd call this from your plugin if you wanted to update the gui when your parameters change.

Todo:
Is it really necessary to have this in VSTGLEditor?

void VSTGLEditor::setupAntialiasing  )  [private]
 

Helper method: Tries to set up hardware antialiasing.

Checks if hardware antialiasing is supported, and switches it on if it is. This method is only called if the user specified one of the Antialias WindowFlags in the class' constructor.

Because of the different way the OS' work, this only sets up antialiasing on Windows - for OSX it's done in open().

void VSTGLEditor::setupVSync  )  [private]
 

Helper method: Used to setup Vertical Sync.

Checks if Vertical Sync is supported, and switches it on if it is. This method is only called if the user specified WaitForVerticalSync as one of the flags to the class' constructor.


Member Data Documentation

AGLPixelFormat VSTGLEditor::pixels [private]
 

OSX: The pixel format we used.

Todo:
Should make this cross-platform, and allow subclasses to set it(?).


The documentation for this class was generated from the following files:
Generated on Mon Aug 7 19:03:50 2006 for VSTGL by  doxygen 1.4.5