iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
ReaperExt_include_in_plug_src.h
1
2#ifndef NO_IGRAPHICS
3#define BUNDLE_ID ""
4#define APP_GROUP_ID ""
5#include "IGraphics_include_in_plug_src.h"
6#endif
7
8#define REAPERAPI_IMPLEMENT
9void (*AttachWindowTopmostButton)(HWND hwnd);
10#include "reaper_plugin_functions.h"
11
12#include "resource.h"
13#include <vector>
14#include <map>
15#include <deque>
16#include <cstring>
17
18REAPER_PLUGIN_HINSTANCE gHINSTANCE;
19HWND gParent;
20HWND gHWND = NULL;
21std::unique_ptr<PLUG_CLASS_NAME> gPlug;
22RECT gPrevBounds;
23int gErrorCount = 0;
24
27{
28 int* pToggle = nullptr;
29 gaccel_register_t accel = {{0,0,0}, ""};
30 std::function<void()> func;
31 bool addMenuItem = false;
32 const char* contextMenuId = nullptr; // REAPER context menu to add this action to, if any
33 const char* menuLabel = nullptr; // label used in menus, defaults to the action name
34};
35
36// std::deque (not std::vector) so element addresses stay stable: REAPER keeps the
37// raw &gActions.back().accel pointer we register, which a vector realloc would dangle.
38std::deque<ReaperAction> gActions;
39
40// Persistent registration record for per-project state (see "projectconfig").
41// Must outlive registration, so it lives at file scope.
42project_config_extension_t gProjectConfig = {
43 ReaperExtBase::ProcessExtensionLine,
44 ReaperExtBase::SaveExtensionConfig,
45 ReaperExtBase::BeginLoadProjectState,
46 nullptr
47};
48
49//TODO: don't #include cpp here
50#include "ReaperExtBase.cpp"
51
52// super nasty looking macro here but allows importing functions from Reaper with simple looking code
53#define IMPAPI(x) if (!((*((void **)&(x)) = (void*) pRec->GetFunc(#x)))) gErrorCount++;
54
55#pragma mark - ENTRY POINT
56extern "C"
57{
58 REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t* pRec)
59 {
60 gHINSTANCE = hInstance;
61
62 if (pRec)
63 {
64 if (pRec->caller_version != REAPER_PLUGIN_VERSION || !pRec->GetFunc)
65 return 0;
66
67 gPlug = std::make_unique<PLUG_CLASS_NAME>(pRec);
68
69 // initialize API function pointers from Reaper
70 IMPAPI(Main_OnCommand);
71 IMPAPI(GetResourcePath);
72 IMPAPI(AddExtensionsMainMenu);
73 IMPAPI(AttachWindowTopmostButton);
74 IMPAPI(ShowConsoleMsg);
75 IMPAPI(DockWindowAdd);
76 IMPAPI(DockWindowAddEx);
77 IMPAPI(DockWindowRemove);
78 IMPAPI(DockWindowActivate);
79 IMPAPI(DockIsChildOfDock);
80 IMPAPI(get_ini_file);
81 IMPAPI(EnsureNotCompletelyOffscreen);
82
83 if (gErrorCount > 0)
84 return 0;
85
86 pRec->Register("hookcommand", (void*) ReaperExtBase::HookCommandProc);
87 pRec->Register("toggleaction", (void*) ReaperExtBase::ToggleActionCallback);
88 pRec->Register("hookcustommenu", (void*) ReaperExtBase::MenuHook);
89 pRec->Register("hookpostcommand", (void*) ReaperExtBase::PostCommandProc);
90 pRec->Register("projectconfig", (void*) &gProjectConfig);
91
92 // Creates the Extensions main menu if it doesn't exist yet. It is populated from
93 // ReaperExtBase::MenuHook(), which REAPER calls with menuidstr "Main extensions".
94 AddExtensionsMainMenu();
95
96 gParent = pRec->hwnd_main;
97
98 return 1;
99 }
100 else
101 {
102 return 0;
103 }
104 }
105};
106
107
108#ifndef OS_WIN
109#define SWELL_DLG_FLAGS_AUTOGEN SWELL_DLG_WS_FLIPPED|SWELL_DLG_WS_RESIZABLE
110#include "swell-dlggen.h"
111#include "main.rc_mac_dlg"
112#undef BEGIN
113#undef END
114#include "swell-menugen.h"
115#include "main.rc_mac_menu"
116float iplug::GetScaleForHWND(HWND hWnd)
117{
118 return 1.f;
119}
120#else
121
122UINT(WINAPI* __GetDpiForWindow)(HWND);
123
124float GetScaleForHWND(HWND hWnd)
125{
126 if (!__GetDpiForWindow)
127 {
128 HINSTANCE h = LoadLibraryA("user32.dll");
129 if (h) *(void**)&__GetDpiForWindow = GetProcAddress(h, "GetDpiForWindow");
130
131 if (!__GetDpiForWindow)
132 return 1;
133 }
134
135 int dpi = __GetDpiForWindow(hWnd);
136
137 if (dpi != USER_DEFAULT_SCREEN_DPI)
138 return static_cast<float>(dpi) / USER_DEFAULT_SCREEN_DPI;
139
140 return 1;
141}
142
143#endif
Helper struct for registering Reaper Actions.