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
16REAPER_PLUGIN_HINSTANCE gHINSTANCE;
17HWND gParent;
18HWND gHWND = NULL;
19std::unique_ptr<PLUG_CLASS_NAME> gPlug;
20RECT gPrevBounds;
21int gErrorCount = 0;
22
25{
26 int* pToggle = nullptr;
27 gaccel_register_t accel = {{0,0,0}, ""};
28 std::function<void()> func;
29 bool addMenuItem = false;
30};
31
32std::vector<ReaperAction> gActions;
33
34//TODO: don't #include cpp here
35#include "ReaperExtBase.cpp"
36
37// super nasty looking macro here but allows importing functions from Reaper with simple looking code
38#define IMPAPI(x) if (!((*((void **)&(x)) = (void*) pRec->GetFunc(#x)))) gErrorCount++;
39
40#pragma mark - ENTRY POINT
41extern "C"
42{
43 REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t* pRec)
44 {
45 gHINSTANCE = hInstance;
46
47 if (pRec)
48 {
49 if (pRec->caller_version != REAPER_PLUGIN_VERSION || !pRec->GetFunc)
50 return 0;
51
52 gPlug = std::make_unique<PLUG_CLASS_NAME>(pRec);
53
54 // initialize API function pointers from Reaper
55 IMPAPI(Main_OnCommand);
56 IMPAPI(GetResourcePath);
57 IMPAPI(AddExtensionsMainMenu);
58 IMPAPI(AttachWindowTopmostButton);
59 IMPAPI(ShowConsoleMsg);
60 IMPAPI(DockWindowAdd);
61 IMPAPI(DockWindowAddEx);
62 IMPAPI(DockWindowRemove);
63 IMPAPI(DockWindowActivate);
64 IMPAPI(DockIsChildOfDock);
65 IMPAPI(get_ini_file);
66 IMPAPI(EnsureNotCompletelyOffscreen);
67
68 if (gErrorCount > 0)
69 return 0;
70
71 pRec->Register("hookcommand", (void*) ReaperExtBase::HookCommandProc);
72 pRec->Register("toggleaction", (void*) ReaperExtBase::ToggleActionCallback);
73
74 AddExtensionsMainMenu();
75
76 gParent = pRec->hwnd_main;
77
78 HMENU hMenu = GetSubMenu(GetMenu(gParent),
79#ifdef OS_WIN
80 8
81#else // OS X has one extra menu
82 9
83#endif
84 );
85
86 int menuIdx = 6;
87
88 for(auto& action : gActions)
89 {
90 if(action.addMenuItem)
91 {
92 MENUITEMINFO mi={sizeof(MENUITEMINFO),};
93 mi.fMask = MIIM_TYPE | MIIM_ID;
94 mi.fType = MFT_STRING;
95 mi.dwTypeData = LPSTR(action.accel.desc);
96 mi.wID = action.accel.accel.cmd;
97 InsertMenuItem(hMenu, menuIdx++, TRUE, &mi);
98 }
99 }
100
101 return 1;
102 }
103 else
104 {
105 return 0;
106 }
107 }
108};
109
110
111#ifndef OS_WIN
112#define SWELL_DLG_FLAGS_AUTOGEN SWELL_DLG_WS_FLIPPED|SWELL_DLG_WS_RESIZABLE
113#include "swell-dlggen.h"
114#include "main.rc_mac_dlg"
115#undef BEGIN
116#undef END
117#include "swell-menugen.h"
118#include "main.rc_mac_menu"
119float iplug::GetScaleForHWND(HWND hWnd)
120{
121 return 1.f;
122}
123#else
124
125UINT(WINAPI* __GetDpiForWindow)(HWND);
126
127float GetScaleForHWND(HWND hWnd)
128{
129 if (!__GetDpiForWindow)
130 {
131 HINSTANCE h = LoadLibraryA("user32.dll");
132 if (h) *(void**)&__GetDpiForWindow = GetProcAddress(h, "GetDpiForWindow");
133
134 if (!__GetDpiForWindow)
135 return 1;
136 }
137
138 int dpi = __GetDpiForWindow(hWnd);
139
140 if (dpi != USER_DEFAULT_SCREEN_DPI)
141 return static_cast<float>(dpi) / USER_DEFAULT_SCREEN_DPI;
142
143 return 1;
144}
145
146#endif
Helper struct for registering Reaper Actions.