-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhost.h
137 lines (113 loc) · 3.14 KB
/
host.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
#ifndef _HOST_H_
#define _HOST_H_
#include <dlfcn.h>
#include <pthread.h>
#include <stdexcept>
#include <vector>
#include "log.h"
#include "plugins/audio/audioPlugin.h"
#define USE_HOST_SO
#ifdef USE_HOST_SO
#include "plugins/config/LuaConfig.h"
struct Host {
void (*hostScriptCallback)(char* key, char* value, const char* filename, std::vector<Var> variables);
AudioPluginHandlerInterface* (*load)(const char* scriptPath);
AudioPluginHandlerInterface* audioPluginHandler = NULL;
void (*midiHandler)(std::vector<unsigned char>* message);
}* host = NULL;
void hostScriptCallback(char* key, char* value, const char* filename, std::vector<Var> variables)
{
if (host) {
host->hostScriptCallback(key, value, filename, variables);
}
}
void midiHandler(std::vector<unsigned char>* message)
{
if (host) {
host->midiHandler(message);
}
}
AudioPlugin& getPlugin(const char* name, int16_t track = -1)
{
return host->audioPluginHandler->getPlugin(name, track);
}
void sendAudioEvent(AudioEventType event)
{
host->audioPluginHandler->sendEvent(event);
}
void* hostThread(void* = NULL)
{
if (host) {
host->audioPluginHandler->loop();
}
return NULL;
}
void loadHostPlugin()
{
if (host) {
logWarn("Host plugin already loaded");
return;
}
#ifdef IS_RPI
void* handle = dlopen("host/libzicHost.arm.so", RTLD_LAZY);
#else
void* handle = dlopen("host/libzicHost.x86.so", RTLD_LAZY);
#endif
if (!handle) {
logError("Cannot open host library libzicHost: %s", dlerror());
return;
}
dlerror();
host = new Host();
host->hostScriptCallback = (void (*)(char* key, char* value, const char* filename, std::vector<Var> variables))dlsym(handle, "hostScriptCallback");
const char* dlsym_error = dlerror();
if (dlsym_error) {
logError("Host plugin, cannot load symbol: %s", dlsym_error);
dlclose(handle);
return;
}
host->load = (AudioPluginHandlerInterface * (*)(const char* scriptPath)) dlsym(handle, "load");
dlsym_error = dlerror();
if (dlsym_error) {
logError("Host plugin, cannot load symbol: %s", dlsym_error);
dlclose(handle);
return;
}
host->audioPluginHandler = host->load(NULL);
host->midiHandler = (void (*)(std::vector<unsigned char>* message))dlsym(handle, "midiHandler");
dlsym_error = dlerror();
if (dlsym_error) {
logError("Host plugin, cannot load symbol: %s", dlsym_error);
dlclose(handle);
return;
}
}
#else
#include "host/AudioPluginHandler.h"
#include "host/config.h"
#include "plugins/audio/valueInterface.h"
void* hostThread(void* = NULL)
{
AudioPluginHandler::get().loop();
return NULL;
}
AudioPlugin& getPlugin(const char* name, int16_t track = -1)
{
return AudioPluginHandler::get().getPlugin(name, track);
}
void sendAudioEvent(AudioEventType event)
{
AudioPluginHandler::get().sendEvent(event);
}
void loadHostPlugin()
{
}
#endif
void startHostThread()
{
logDebug("Starting host in thread\n");
pthread_t ptid;
pthread_create(&ptid, NULL, &hostThread, NULL);
pthread_setname_np(ptid, "host");
}
#endif