/
IPlugReaperVST2.h
167 lines (137 loc) · 5.35 KB
/
IPlugReaperVST2.h
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
/*
==============================================================================
This file is part of the iPlug 2 library
Oli Larkin et al. 2018 - https://www.olilarkin.co.uk
iPlug 2 is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the WDL license
- https://www.cockos.com/wdl/
==============================================================================
*/
#pragma once
#include "IPlugVST2.h"
#include "reaper_plugin.h"
#include "video_processor.h"
#define REAPERAPI_IMPLEMENT
#include "reaper_plugin_functions.h"
bool (*DoFxLastTweakParmCtxMenu2)(void* pFXDSP, void* pHWND, int xpos, int ypos, const char* headerStr);
class IPlugReaperVST2 : public IPlugVST2
{
public:
IPlugReaperVST2(IPlugInstanceInfo instanceInfo, IPlugConfig config)
: IPlugVST2(instanceInfo, config)
{
int errorCount = REAPERAPI_LoadAPI([this](const char* str) {
return (void*) mHostCallback(NULL, 0xdeadbeef, 0xdeadf00d, 0, (void*) str, 0.0);
});
if (errorCount > 0)
LogToReaper("some errors when loading reaper api functions\n");
}
/** Pop up Reaper's "Last touched FX" dialog, in order to set envelopes etc for the last touched parameter
* @param pView platform view handle - in an IGraphics plug-in you can call IGraphics::GetWindow() to get this
* @param xpos x position on the screen to popup the menu. NOTE: screen coordinates! Can convert mouse position in IControls with IGraphics::ClientToScreen()
* @param ypos y position on the screen to popup the menu. NOTE: screen coordinates! Can convert mouse position in IControls with IGraphics::ClientToScreen() */
void CreateParameterPopup(void* pView, int xpos, int ypos)
{
void *pFXDSP = (void*)mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 4, NULL, 0.0f);
*(VstIntPtr *)&DoFxLastTweakParmCtxMenu2 = mHostCallback(NULL, 0xdeadbeef, 0xdeadf00d, 0, (void*) "DoFxLastTweakParmCtxMenu2", 0.0);
if(DoFxLastTweakParmCtxMenu2)
DoFxLastTweakParmCtxMenu2(pFXDSP, pView, xpos, ypos, NULL);
}
void SetTrackVolume(double gain)
{
MediaTrack* tr = GetReaperTrack();
if (tr != nullptr)
SetMediaTrackInfo_Value(tr, "D_VOL", gain);
}
void GetTakeName(WDL_String& str)
{
const char* name = ::GetTakeName(GetReaperTake());
if (name != nullptr)
str.Set(name);
}
void SetTakeName(const char* name)
{
MediaItem_Take* tk = GetReaperTake();
if (tk != nullptr)
{
GetSetMediaItemTakeInfo_String(tk, "P_NAME", const_cast<char*>(name), true);
UpdateArrange();
}
else
{
LogToReaper("Plugin is not loaded into a Reaper take\n");
}
}
void GetTrackName(WDL_String& str) override
{
char buf[2048];
if (GetSetMediaTrackInfo_String(GetReaperTrack(), "P_NAME", buf, false) == true)
{
str.Set(buf);
}
}
void SetTrackName(const char* name)
{
GetSetMediaTrackInfo_String(GetReaperTrack(), "P_NAME", const_cast<char*>(name), true);
UpdateArrange();
}
MediaTrack* GetReaperTrack()
{
return (MediaTrack*)mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 1, 0, 0.0);
}
MediaItem_Take* GetReaperTake()
{
return (MediaItem_Take*) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 2, 0, 0.0);
}
void GetTrackColor(int& r, int& g, int& b) override
{
MediaTrack* pTrack = GetReaperTrack();
ColorFromNative(::GetTrackColor(pTrack), &r, &g, &b);
}
void LogToReaper(const char* str)
{
if(ShowConsoleMsg != nullptr)
ShowConsoleMsg(str);
}
void InformHostOfAddedParams(int index, int numAddedParams)
{
int listadj[2] = {index, numAddedParams};
mAEffect.numParams = NParams();
mHostCallback(&mAEffect, audioMasterVendorSpecific, 0xdeadbeef, audioMasterAutomate, listadj, 0.0);
}
void InformHostOfRemovedParams(int index, int numRemovedParams)
{
int listadj[2] = {index, -numRemovedParams};
mAEffect.numParams = NParams();
mHostCallback(&mAEffect, audioMasterVendorSpecific, 0xdeadbeef, audioMasterAutomate, listadj, 0.0);
}
void InitializeVideo(void* staticProcessVideoFrame, void* staticGetVideoParam)
{
void* pCtx = (void*) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 4, NULL, 0.0f);
if (pCtx)
{
IREAPERVideoProcessor *(*video_CreateVideoProcessor)(void *fxctx, int version);
*(void**)&video_CreateVideoProcessor = (void *) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00d, 0, (void *) "video_CreateVideoProcessor", 0.0f);
if (video_CreateVideoProcessor)
{
mVideoProc = video_CreateVideoProcessor(pCtx, IREAPERVideoProcessor::REAPER_VIDEO_PROCESSOR_VERSION);
if (mVideoProc)
{
mVideoProc->userdata = this;
mVideoProc->process_frame = (IVideoFrame* (*)(IREAPERVideoProcessor*, const double*, int, double, double, int)) staticProcessVideoFrame;
mVideoProc->get_parameter_value = (bool (*)(IREAPERVideoProcessor*, int, double *)) staticGetVideoParam;
}
}
}
}
private:
// template<typename T>
// T (*GetFunc(VstInt32 p1, VstIntPtr p2, const char* str = NULL, float p3 = 0.f))()
// {
// T (*func)();
// *(long *)&func = mHostCallback(&mAEffect, 0xdeadbeef, p1, p2, (void*) str, p3);
// return func;
// }
IREAPERVideoProcessor* mVideoProc = nullptr;
};