iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugReaperVST2.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
13#include "IPlugVST2.h"
14#include "reaper_plugin.h"
15#include "video_processor.h"
16
17#define REAPERAPI_IMPLEMENT
18#include "reaper_plugin_functions.h"
19
20bool (*DoFxLastTweakParmCtxMenu2)(void* pFXDSP, void* pHWND, int xpos, int ypos, const char* headerStr);
21
22BEGIN_IPLUG_NAMESPACE
23
26{
27public:
28 IPlugReaperVST2(const InstanceInfo& info, const Config& config)
29 : IPlugVST2(info, config)
30 {
31 int errorCount = REAPERAPI_LoadAPI([this](const char* str) {
32 return (void*) mHostCallback(NULL, 0xdeadbeef, 0xdeadf00d, 0, (void*) str, 0.0);
33 });
34 if (errorCount > 0)
35 LogToReaper("some errors when loading reaper api functions\n");
36 }
37
42 void CreateParameterPopup(void* pView, int xpos, int ypos)
43 {
44 void *pFXDSP = (void*)mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 4, NULL, 0.0f);
45
46 *(VstIntPtr *)&DoFxLastTweakParmCtxMenu2 = mHostCallback(NULL, 0xdeadbeef, 0xdeadf00d, 0, (void*) "DoFxLastTweakParmCtxMenu2", 0.0);
47
48 if(DoFxLastTweakParmCtxMenu2)
49 DoFxLastTweakParmCtxMenu2(pFXDSP, pView, xpos, ypos, NULL);
50 }
51
52 void SetTrackVolume(double gain)
53 {
54 MediaTrack* tr = GetReaperTrack();
55
56 if (tr != nullptr)
57 SetMediaTrackInfo_Value(tr, "D_VOL", gain);
58 }
59
60 void GetTakeName(WDL_String& str)
61 {
62 const char* name = ::GetTakeName(GetReaperTake());
63 if (name != nullptr)
64 str.Set(name);
65 }
66
67 void SetTakeName(const char* name)
68 {
69 MediaItem_Take* tk = GetReaperTake();
70 if (tk != nullptr)
71 {
72 GetSetMediaItemTakeInfo_String(tk, "P_NAME", const_cast<char*>(name), true);
73 UpdateArrange();
74 }
75 else
76 {
77 LogToReaper("Plugin is not loaded into a Reaper take\n");
78 }
79 }
80
81 void GetTrackName(WDL_String& str) override
82 {
83 char buf[2048];
84 if (GetSetMediaTrackInfo_String(GetReaperTrack(), "P_NAME", buf, false) == true)
85 {
86 str.Set(buf);
87 }
88 }
89
90 void SetTrackName(const char* name)
91 {
92 GetSetMediaTrackInfo_String(GetReaperTrack(), "P_NAME", const_cast<char*>(name), true);
93 UpdateArrange();
94 }
95
96 MediaTrack* GetReaperTrack()
97 {
98 return (MediaTrack*)mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 1, 0, 0.0);
99 }
100
101 MediaItem_Take* GetReaperTake()
102 {
103 return (MediaItem_Take*) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 2, 0, 0.0);
104 }
105
106 void GetTrackColor(int& r, int& g, int& b) override
107 {
108 MediaTrack* pTrack = GetReaperTrack();
109
110 ColorFromNative(::GetTrackColor(pTrack), &r, &g, &b);
111 }
112
113 void LogToReaper(const char* str)
114 {
115 if(ShowConsoleMsg != nullptr)
116 ShowConsoleMsg(str);
117 }
118
119 void InformHostOfAddedParams(int index, int numAddedParams)
120 {
121 int listadj[2] = {index, numAddedParams};
122 mAEffect.numParams = NParams();
123 mHostCallback(&mAEffect, audioMasterVendorSpecific, 0xdeadbeef, audioMasterAutomate, listadj, 0.0);
124 }
125
126 void InformHostOfRemovedParams(int index, int numRemovedParams)
127 {
128 int listadj[2] = {index, -numRemovedParams};
129 mAEffect.numParams = NParams();
130 mHostCallback(&mAEffect, audioMasterVendorSpecific, 0xdeadbeef, audioMasterAutomate, listadj, 0.0);
131 }
132
133 void InitializeVideo(void* staticProcessVideoFrame, void* staticGetVideoParam)
134 {
135 void* pCtx = (void*) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00e, 4, NULL, 0.0f);
136
137 if (pCtx)
138 {
139 IREAPERVideoProcessor *(*video_CreateVideoProcessor)(void *fxctx, int version);
140 *(void**)&video_CreateVideoProcessor = (void *) mHostCallback(&mAEffect, 0xdeadbeef, 0xdeadf00d, 0, (void *) "video_CreateVideoProcessor", 0.0f);
141 if (video_CreateVideoProcessor)
142 {
143 mVideoProc = video_CreateVideoProcessor(pCtx, IREAPERVideoProcessor::REAPER_VIDEO_PROCESSOR_VERSION);
144 if (mVideoProc)
145 {
146 mVideoProc->userdata = this;
147 mVideoProc->process_frame = (IVideoFrame* (*)(IREAPERVideoProcessor*, const double*, int, double, double, int)) staticProcessVideoFrame;
148 mVideoProc->get_parameter_value = (bool (*)(IREAPERVideoProcessor*, int, double *)) staticGetVideoParam;
149 }
150 }
151 }
152 }
153
154private:
155// template<typename T>
156// T (*GetFunc(VstInt32 p1, VstIntPtr p2, const char* str = NULL, float p3 = 0.f))()
157// {
158// T (*func)();
159// *(long *)&func = mHostCallback(&mAEffect, 0xdeadbeef, p1, p2, (void*) str, p3);
160// return func;
161// }
162
163 IREAPERVideoProcessor* mVideoProc = nullptr;
164};
165
166IPlugReaperVST2* MakePlug(const InstanceInfo& info);
167
168END_IPLUG_NAMESPACE
Reaper specific VST2.4 API base class for an IPlug plug-in.
void CreateParameterPopup(void *pView, int xpos, int ypos)
Pop up Reaper's "Last touched FX" dialog, in order to set envelopes etc for the last touched paramete...
void GetTrackColor(int &r, int &g, int &b) override
Get the color of the track that the plug-in is inserted on.
void GetTrackName(WDL_String &str) override
Get the name of the track that the plug-in is inserted on.
VST2.4 API base class for an IPlug plug-in.
Definition: IPlugVST2.h:36