-
Notifications
You must be signed in to change notification settings - Fork 2
/
host.h
61 lines (48 loc) · 1.44 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
#ifndef _HOST_H_
#define _HOST_H_
#include <SDL2/SDL.h> // SDL_Log
#include <stdexcept>
#include <vector>
#include "UiPlugin.h"
#include "host/zicHost.h"
#include "plugins/audio/valueInterface.h"
AudioPluginHandlerInterface* audioPluginHandler = NULL;
int hostThread(void* data)
{
AudioPluginHandler::get().loop();
return 0;
}
AudioPlugin& getPlugin(const char* name, int16_t track = -1)
{
if (!audioPluginHandler) {
throw std::runtime_error("Host not loaded");
}
if (strcmp(name, "UI") == 0) {
return UiPlugin::get();
}
return audioPluginHandler->getPlugin(name, track);
}
void sendAudioEvent(AudioEventType event)
{
if (!audioPluginHandler) {
throw std::runtime_error("Host not loaded");
}
audioPluginHandler->sendEvent(event);
}
bool loadHost(std::string hostConfigPath, const char *pluginConfig)
{
if (audioPluginHandler) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Host already loaded\n");
return true;
}
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Initializing host\n");
audioPluginHandler = initHost(hostConfigPath.c_str(), pluginConfig);
if (!audioPluginHandler) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error initializing host\n");
return false;
}
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting host in SDL thread\n");
SDL_Thread* thread = SDL_CreateThread(hostThread, "host", NULL);
return true;
}
#endif