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(DockWindowActivate);
62
63 if (gErrorCount > 0)
64 return 0;
65
66 pRec->Register("hookcommand", (void*) ReaperExtBase::HookCommandProc);
67 pRec->Register("toggleaction", (void*) ReaperExtBase::ToggleActionCallback);
68
69 AddExtensionsMainMenu();
70
71 gParent = pRec->hwnd_main;
72
73 HMENU hMenu = GetSubMenu(GetMenu(gParent),
74#ifdef OS_WIN
75 8
76#else // OS X has one extra menu
77 9
78#endif
79 );
80
81 int menuIdx = 6;
82
83 for(auto& action : gActions)
84 {
85 if(action.addMenuItem)
86 {
87 MENUITEMINFO mi={sizeof(MENUITEMINFO),};
88 mi.fMask = MIIM_TYPE | MIIM_ID;
89 mi.fType = MFT_STRING;
90 mi.dwTypeData = LPSTR(action.accel.desc);
91 mi.wID = action.accel.accel.cmd;
92 InsertMenuItem(hMenu, menuIdx++, TRUE, &mi);
93 }
94 }
95
96 return 1;
97 }
98 else
99 {
100 return 0;
101 }
102 }
103};
104
105
106#ifndef OS_WIN
107#define SWELL_DLG_FLAGS_AUTOGEN SWELL_DLG_WS_FLIPPED//|SWELL_DLG_WS_RESIZABLE
108#include "swell-dlggen.h"
109#include "main.rc_mac_dlg"
110#undef BEGIN
111#undef END
112#include "swell-menugen.h"
113#include "main.rc_mac_menu"
114float iplug::GetScaleForHWND(HWND hWnd)
115{
116 return 1.f;
117}
118#else
119
120UINT(WINAPI* __GetDpiForWindow)(HWND);
121
122float GetScaleForHWND(HWND hWnd)
123{
124 if (!__GetDpiForWindow)
125 {
126 HINSTANCE h = LoadLibraryA("user32.dll");
127 if (h) *(void**)&__GetDpiForWindow = GetProcAddress(h, "GetDpiForWindow");
128
129 if (!__GetDpiForWindow)
130 return 1;
131 }
132
133 int dpi = __GetDpiForWindow(hWnd);
134
135 if (dpi != USER_DEFAULT_SCREEN_DPI)
136 return static_cast<float>(dpi) / USER_DEFAULT_SCREEN_DPI;
137
138 return 1;
139}
140
141#endif
Helper struct for registering Reaper Actions.