iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
ReaperExtBase.h
Go to the documentation of this file.
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
19#include "IPlugTimer.h"
21#include "wdlstring.h"
22
23struct reaper_plugin_info_t;
24struct project_config_extension_t;
25class ProjectStateContext;
26
27BEGIN_IPLUG_NAMESPACE
28
29#pragma pack(push, 4)
32{
33 RECT r; // Window rect when floating
34 int state; // Bit 0 = visible, Bit 1 = docked
35 int whichdock; // Docker index when docked
36};
37#pragma pack(pop)
38
40class ReaperExtBase : public EDITOR_DELEGATE_CLASS
41{
42public:
43 ReaperExtBase(reaper_plugin_info_t* pRec);
44
45 virtual ~ReaperExtBase();
46
47 //IEditorDelegate
48 void BeginInformHostOfParamChangeFromUI(int paramIdx) override {}; // NO-OP
49
50 void EndInformHostOfParamChangeFromUI(int paramIdx) override {}; // NO-OP
51
52 bool EditorResizeFromUI(int viewWidth, int viewHeight, bool needsPlatformResize) override;
53
55 virtual void OnIdle() {}; // NO-OP
56
61 virtual void OnActionRun(int commandId, int flag) {}; // NO-OP
62
66 virtual void SaveProjectState(ProjectStateContext* ctx) {}; // NO-OP
67
71 virtual bool LoadProjectStateLine(const char* line) { return false; };
72
76 virtual void OnBeginLoadProjectState(bool isUndo) {}; // NO-OP
77
90 void RegisterAction(const char* actionName, std::function<void()> func, bool addMenuItem = false, int* pToggle = nullptr, const char* contextMenuId = nullptr, const char* menuLabel = nullptr/*, IKeyPress keyCmd*/);
91
93 void ShowHideMainWindow();
94
96 void ToggleDocking();
97
99 bool IsDocked() const { return (mDockState.state & 2) == 2; }
100
103 int* GetWindowTogglePtr() { return &mWindowToggle; }
104
108 int* GetDockTogglePtr() { return &mDockToggle; }
109
112 void SetDockId(const char* id) { mDockId.Set(id); }
113
117 void SetMenuName(const char* name) { mMenuName.Set(name); }
118
119public:
120 // Reaper calls back to this when it wants to execute an action registered by the extension plugin
121 static bool HookCommandProc(int command, int flag);
122
123 // Reaper calls back to this when it wants to know an actions toggle state
124 static int ToggleActionCallback(int command);
125
126 // Reaper calls back to this when building a customizable menu, so we can add
127 // registered actions to context menus (e.g. the media item right-click menu)
128 static void MenuHook(const char* menuidstr, void* menu, int flag);
129
130 // Reaper calls back to this after every main-section action ("hookpostcommand")
131 static void PostCommandProc(int command, int flag);
132
133 // "projectconfig" callbacks - forwarded to the OnBeginLoadProjectState /
134 // LoadProjectStateLine / SaveProjectState virtuals on the running instance
135 static void BeginLoadProjectState(bool isUndo, project_config_extension_t* reg);
136 static bool ProcessExtensionLine(const char* line, ProjectStateContext* ctx, bool isUndo, project_config_extension_t* reg);
137 static void SaveExtensionConfig(ProjectStateContext* ctx, bool isUndo, project_config_extension_t* reg);
138
139private:
140 static WDL_DLGRET MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
141
142 void OnTimer(Timer& t);
143 void CreateMainWindow();
144 void DestroyMainWindow();
145 void SaveDockState();
146 void LoadDockState();
147 void EnsureStateLoaded();
148 void UpdateToggleStates();
149
150 reaper_plugin_info_t* mRec = nullptr;
151 std::unique_ptr<Timer> mTimer;
152 ReaperExtDockState mDockState = {};
153 WDL_FastString mDockId;
154 WDL_FastString mMenuName;
155 bool mSaveStateOnDestroy = true;
156 bool mStateLoaded = false;
157 int mWindowToggle = 0;
158 int mDockToggle = 0;
159};
160
161END_IPLUG_NAMESPACE
Used for choosing an editor delegate.
This file includes classes for implementing timers - in order to get a regular callback on the main t...
State structure for dock window persistence - matches SWS pattern.
Definition: ReaperExtBase.h:32
Reaper extension base class interface.
Definition: ReaperExtBase.h:41
void RegisterAction(const char *actionName, std::function< void()> func, bool addMenuItem=false, int *pToggle=nullptr, const char *contextMenuId=nullptr, const char *menuLabel=nullptr)
Registers an action with the REAPER extension system.
void ShowHideMainWindow()
Toggles the visibility of the main extension window.
bool IsDocked() const
Returns true if the window is currently docked.
Definition: ReaperExtBase.h:99
virtual void OnActionRun(int commandId, int flag)
Called after any action in the main section runs (via "hookpostcommand").
Definition: ReaperExtBase.h:61
virtual void SaveProjectState(ProjectStateContext *ctx)
Called (via "projectconfig") when the project is being saved, so the extension can persist state into...
Definition: ReaperExtBase.h:66
virtual bool LoadProjectStateLine(const char *line)
Called (via "projectconfig") for each project line not consumed by Reaper.
Definition: ReaperExtBase.h:71
void ToggleDocking()
Toggles between docked and floating state.
void SetMenuName(const char *name)
Sets the title of the submenu that this extension's actions are added to, inside REAPER's Extensions ...
int * GetWindowTogglePtr()
Toggle state for an action that shows/hides the main window.
int * GetDockTogglePtr()
Toggle state for an action that docks/undocks the main window.
virtual void OnBeginLoadProjectState(bool isUndo)
Called (via "projectconfig") before project state is loaded (also on "new project").
Definition: ReaperExtBase.h:76
void SetDockId(const char *id)
Sets the unique identifier used for dock state persistence.
virtual void OnIdle()
Called during idle processing - override to perform periodic tasks.
Definition: ReaperExtBase.h:55
Base class for timer.
Definition: IPlugTimer.h:40