commit e68d2de76f0bc3145bdea8e74b4cf3e6273d5ebd
parent 0e519f9f81916b3f379174f59d53b1a326b892dc
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 23 Nov 2015 15:11:09 -0500
more early refactoring
Diffstat:
3 files changed, 58 insertions(+), 19 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
@@ -5,30 +5,26 @@
static ReaPack reapack;
-bool commandHook(const int command, const int flag)
+bool commandHook(const int id, const int flag)
{
- if(command != reapack.actionId())
- return false;
-
- ShowMessageBox("Hello World!", "Test", 0);
- return true;
+ return reapack.execActions(id, flag);
}
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(
REAPER_PLUGIN_HINSTANCE instance, reaper_plugin_info_t *rec)
{
- reapack.instance = instance;
-
if(!rec || rec->caller_version != REAPER_PLUGIN_VERSION || !rec->GetFunc)
return 0;
if(REAPERAPI_LoadAPI(rec->GetFunc) > 0)
return 0;
- rec->Register("hookcommand", (void *)commandHook);
+ reapack.init(instance, rec);
- reapack.setActionId(rec->Register("command_id", (void *)"REAPACKMGR"));
- rec->Register("gaccel", &reapack.action);
+ reapack.setupAction("REAPACKMGR", "ReaPack: Package Manager",
+ &reapack.action, std::bind(&ReaPack::toggleWindow, reapack));
+
+ rec->Register("hookcommand", (void *)commandHook);
return 1;
}
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -1,6 +1,34 @@
#include "reapack.hpp"
-ReaPack::ReaPack()
+#include "reaper_plugin_functions.h"
+
+void ReaPack::init(REAPER_PLUGIN_HINSTANCE instance, reaper_plugin_info_t *rec)
+{
+ m_instance = instance;
+ m_rec = rec;
+ m_mainHandle = GetMainHwnd();
+}
+
+void ReaPack::setupAction(const char *name, const char *desc,
+ gaccel_register_t *action, ReaPackCallback callback)
+{
+ action->desc = desc;
+ action->accel.cmd = m_rec->Register("command_id", (void *)name);
+
+ m_rec->Register("gaccel", action);
+ m_actions[action->accel.cmd] = callback;
+}
+
+bool ReaPack::execActions(const int id, const int)
+{
+ if(!m_actions.count(id))
+ return false;
+
+ m_actions.at(id)();
+ return true;
+}
+
+void ReaPack::toggleWindow()
{
- action.desc = "ReaPack: Package Manager";
+ ShowMessageBox("Hello World!", "Test", 0);
}
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -1,16 +1,31 @@
#ifndef REAPACK_REAPACK_HPP
#define REAPACK_REAPACK_HPP
-#include "reaper_plugin.h"
+#include <functional>
+#include <map>
-struct ReaPack {
- ReaPack();
+#include "reaper_plugin.h"
- int actionId() const { return action.accel.cmd; }
- void setActionId(const int id) { action.accel.cmd = id; }
+typedef std::function<void()> ReaPackCallback;
- REAPER_PLUGIN_HINSTANCE instance = 0;
+class ReaPack {
+public:
gaccel_register_t action;
+
+ void init(REAPER_PLUGIN_HINSTANCE, reaper_plugin_info_t *);
+
+ void setupAction(const char *name, const char *desc,
+ gaccel_register_t *action, ReaPackCallback callback);
+ bool execActions(const int id, const int);
+
+ void toggleWindow();
+
+private:
+ std::map<int, ReaPackCallback> m_actions;
+
+ REAPER_PLUGIN_HINSTANCE m_instance;
+ reaper_plugin_info_t *m_rec;
+ HWND m_mainHandle;
};
#endif