1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
//-------------------------------------------------------------------------------------------------------
// VST Plug-Ins SDK
// Version 2.4 $Date: 2006/11/13 09:08:28 $
//
// Category : VST 2.x SDK Samples
// Filename : minieditor.cpp
// Created by : Steinberg
// Description : VST Mini Host Editor
//
// � 2006, Steinberg Media Technologies, All Rights Reserved
//-------------------------------------------------------------------------------------------------------
#include "pluginterfaces/vst2.x/aeffectx.h"
#if _WIN32
#include <windows.h>
#elif TARGET_API_MAC_CARBON
#include <Carbon/Carbon.h>
static pascal OSStatus windowHandler (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData);
static pascal void idleTimerProc (EventLoopTimerRef inTimer, void* inUserData);
#endif
#include <stdio.h>
#if _WIN32
//-------------------------------------------------------------------------------------------------------
struct MyDLGTEMPLATE: DLGTEMPLATE
{
WORD ext[3];
MyDLGTEMPLATE ()
{
memset (this, 0, sizeof (*this));
};
};
static INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static AEffect* theEffect = 0;
#endif
//-------------------------------------------------------------------------------------------------------
bool checkEffectEditor (AEffect* effect)
{
if ((effect->flags & effFlagsHasEditor) == 0)
{
printf ("This plug does not have an editor!\n");
return false;
}
#if _WIN32
theEffect = effect;
MyDLGTEMPLATE t;
t.style = WS_POPUPWINDOW|WS_DLGFRAME|DS_MODALFRAME|DS_CENTER;
t.cx = 100;
t.cy = 100;
DialogBoxIndirectParam (GetModuleHandle (0), &t, 0, (DLGPROC)EditorProc, (LPARAM)effect);
theEffect = 0;
#elif TARGET_API_MAC_CARBON
WindowRef window;
Rect mRect = {0, 0, 300, 300};
OSStatus err = CreateNewWindow (kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCompositingAttribute | kWindowAsyncDragAttribute | kWindowStandardHandlerAttribute, &mRect, &window);
if (err != noErr)
{
printf ("HOST> Could not create mac window !\n");
return false;
}
static EventTypeSpec eventTypes[] = {
{ kEventClassWindow, kEventWindowClose }
};
InstallWindowEventHandler (window, windowHandler, GetEventTypeCount (eventTypes), eventTypes, window, NULL);
printf ("HOST> Open editor...\n");
effect->dispatcher (effect, effEditOpen, 0, 0, window, 0);
ERect* eRect = 0;
printf ("HOST> Get editor rect..\n");
effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
if (eRect)
{
int width = eRect->right - eRect->left;
int height = eRect->bottom - eRect->top;
Rect bounds;
GetWindowBounds (window, kWindowContentRgn, &bounds);
bounds.right = bounds.left + width;
bounds.bottom = bounds.top + height;
SetWindowBounds (window, kWindowContentRgn, &bounds);
}
RepositionWindow (window, NULL, kWindowCenterOnMainScreen);
ShowWindow (window);
EventLoopTimerRef idleEventLoopTimer;
InstallEventLoopTimer (GetCurrentEventLoop (), kEventDurationSecond / 25., kEventDurationSecond / 25., idleTimerProc, effect, &idleEventLoopTimer);
RunAppModalLoopForWindow (window);
RemoveEventLoopTimer (idleEventLoopTimer);
printf ("HOST> Close editor..\n");
effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);
ReleaseWindow (window);
#endif
return true;
}
#if _WIN32
//-------------------------------------------------------------------------------------------------------
INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
AEffect* effect = theEffect;
switch(msg)
{
//-----------------------
case WM_INITDIALOG :
{
SetWindowText (hwnd, "VST Editor");
SetTimer (hwnd, 1, 20, 0);
if (effect)
{
printf ("HOST> Open editor...\n");
effect->dispatcher (effect, effEditOpen, 0, 0, hwnd, 0);
printf ("HOST> Get editor rect..\n");
ERect* eRect = 0;
effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
if (eRect)
{
int width = eRect->right - eRect->left;
int height = eRect->bottom - eRect->top;
if (width < 100)
width = 100;
if (height < 100)
height = 100;
RECT wRect;
SetRect (&wRect, 0, 0, width, height);
AdjustWindowRectEx (&wRect, GetWindowLong (hwnd, GWL_STYLE), FALSE, GetWindowLong (hwnd, GWL_EXSTYLE));
width = wRect.right - wRect.left;
height = wRect.bottom - wRect.top;
SetWindowPos (hwnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
}
}
} break;
//-----------------------
case WM_TIMER :
if (effect)
effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
break;
//-----------------------
case WM_CLOSE :
{
KillTimer (hwnd, 1);
printf ("HOST> Close editor..\n");
if (effect)
effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);
EndDialog (hwnd, IDOK);
} break;
}
return 0;
}
#elif TARGET_API_MAC_CARBON
//-------------------------------------------------------------------------------------------------------
pascal void idleTimerProc (EventLoopTimerRef inTimer, void *inUserData)
{
AEffect* effect = (AEffect*)inUserData;
effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
}
//-------------------------------------------------------------------------------------------------------
pascal OSStatus windowHandler (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
OSStatus result = eventNotHandledErr;
WindowRef window = (WindowRef) inUserData;
UInt32 eventClass = GetEventClass (inEvent);
UInt32 eventKind = GetEventKind (inEvent);
switch (eventClass)
{
case kEventClassWindow:
{
switch (eventKind)
{
case kEventWindowClose:
{
QuitAppModalLoopForWindow (window);
break;
}
}
break;
}
}
return result;
}
#endif
|