#include <VSTGLEditor.h>
Inheritance diagram for VSTGLEditor:
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. |
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.
Implement simple Mouse class (so we can hide and show the cursor, mainly).
Test key events.
|
|
Constructor.
|
|
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.) |
|
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). |
|
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. |
|
Called when there's a KeyDown event (GL because the VST headers already use onKeyDown).
Reimplemented in ExampleEditor. |
|
Called when there's a KeyUp event (GL because the VST headers already use onKeyUp).
|
|
Called when there's a MouseDown event. The buttons are numbered 1=left, 2=right, 3=middle. |
|
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. |
|
Called when there's a MouseUp event. The buttons are numbered 1=left, 2=right, 3=middle. |
|
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.) |
|
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(). |
|
You'd call this from your plugin if you wanted to update the gui when your parameters change.
|
|
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(). |
|
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. |
|
OSX: The pixel format we used.
|