File: plugin-state-helpers.cpp

package info (click to toggle)
obs-advanced-scene-switcher 1.32.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,492 kB
  • sloc: xml: 297,593; cpp: 147,875; python: 387; sh: 280; ansic: 170; makefile: 33
file content (311 lines) | stat: -rw-r--r-- 6,162 bytes parent folder | download
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include "plugin-state-helpers.hpp"
#include "macro-settings.hpp"
#include "macro-signals.hpp"
#include "switcher-data.hpp"

namespace advss {

static std::mutex initMutex;
static std::mutex postLoadMutex;
static std::mutex mutex;

static std::vector<std::function<void()>> &getPluginInitSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getPluginPostLoadSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getPluginCleanupSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getResetIntervalSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getStartSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getStopSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

static std::vector<std::function<void(obs_data_t *)>> &getSaveSteps()
{
	static std::vector<std::function<void(obs_data_t *)>> steps;
	return steps;
}

static std::vector<std::function<void(obs_data_t *)>> &getLoadSteps()
{
	static std::vector<std::function<void(obs_data_t *)>> steps;
	return steps;
}

static std::vector<std::function<void()>> &getPostLoadSteps()
{
	static std::vector<std::function<void()>> steps;
	return steps;
}

void SavePluginSettings(obs_data_t *obj)
{
	GetSwitcher()->SaveSettings(obj);
}

void LoadPluginSettings(obs_data_t *obj)
{
	GetSwitcher()->LoadSettings(obj);
}

void AddSaveStep(std::function<void(obs_data_t *)> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getSaveSteps().emplace_back(step);
}

void AddLoadStep(std::function<void(obs_data_t *)> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getLoadSteps().emplace_back(step);
}

void AddPostLoadStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(postLoadMutex);
	getPostLoadSteps().emplace_back(step);
}

void AddIntervalResetStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getResetIntervalSteps().emplace_back(step);
}

void RunSaveSteps(obs_data_t *obj)
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &func : getSaveSteps()) {
		func(obj);
	}
}

void RunLoadSteps(obs_data_t *obj)
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &func : getLoadSteps()) {
		func(obj);
	}
}

void RunAndClearPostLoadSteps()
{
	std::lock_guard<std::mutex> lock(postLoadMutex);
	for (const auto &func : getPostLoadSteps()) {
		func();
	}
	getPostLoadSteps().clear();
}

void ClearPostLoadSteps()
{
	std::lock_guard<std::mutex> lock(postLoadMutex);
	getPostLoadSteps().clear();
}

void AddPluginInitStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(initMutex);
	getPluginInitSteps().emplace_back(step);
}

void AddPluginPostLoadStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getPluginPostLoadSteps().emplace_back(step);
}

void AddPluginCleanupStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getPluginCleanupSteps().emplace_back(step);
}

void RunPluginInitSteps()
{
	std::lock_guard<std::mutex> lock(initMutex);
	for (const auto &step : getPluginInitSteps()) {
		step();
	}
}

void RunPluginPostLoadSteps()
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &step : getPluginPostLoadSteps()) {
		step();
	}
}

void RunPluginCleanupSteps()
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &step : getPluginCleanupSteps()) {
		step();
	}
}

void RunIntervalResetSteps()
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &step : getResetIntervalSteps()) {
		step();
	}
}

void AddStartStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getStartSteps().emplace_back(step);
}

void AddStopStep(std::function<void()> step)
{
	std::lock_guard<std::mutex> lock(mutex);
	getStopSteps().emplace_back(step);
}

void RunStartSteps()
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &step : getStartSteps()) {
		step();
	}
}

void RunStopSteps()
{
	std::lock_guard<std::mutex> lock(mutex);
	for (const auto &step : getStopSteps()) {
		step();
	}
}

void StopPlugin()
{
	GetSwitcher()->Stop();
}

void StartPlugin()
{
	GetSwitcher()->Start();
}

bool PluginIsRunning()
{
	return GetSwitcher() && GetSwitcher()->th &&
	       GetSwitcher()->th->isRunning();
}

int GetIntervalValue()
{
	return GetSwitcher()->interval;
}

void SetPluginNoMatchBehavior(NoMatchBehavior behavior)
{
	GetSwitcher()->switchIfNotMatching = behavior;
}

NoMatchBehavior GetPluginNoMatchBehavior()
{
	return GetSwitcher()->switchIfNotMatching;
}

void SetNoMatchScene(const OBSWeakSource &scene)
{
	GetSwitcher()->nonMatchingScene.SetScene(scene);
}

std::string ForegroundWindowTitle()
{
	return GetSwitcher()->currentTitle;
}

std::string PreviousForegroundWindowTitle()
{
	return GetSwitcher()->lastTitle;
}

bool SettingsWindowIsOpened()
{
	return GetSwitcher()->settingsWindowOpened;
}

bool HighlightUIElementsEnabled()
{
	return GetSwitcher() && !GetSwitcher()->disableHints;
}

bool OBSIsShuttingDown()
{
	return GetSwitcher() && GetSwitcher()->obsIsShuttingDown;
}

bool InitialLoadIsComplete()
{
	return GetSwitcher()->startupLoadDone;
}

bool IsFirstInterval()
{
	return GetSwitcher()->firstInterval;
}

bool IsFirstIntervalAfterStop()
{
	return GetSwitcher()->firstIntervalAfterStop;
}

void SetMacroHighlightingEnabled(bool enable)
{
	auto &settings = GetGlobalMacroSettings();
	settings._highlightActions = enable;
	settings._highlightConditions = enable;
	settings._highlightExecuted = enable;

	obs_queue_task(
		OBS_TASK_UI,
		[](void *) {
			if (!SettingsWindowIsOpened()) {
				return;
			}
			MacroSignalManager::Instance()->HighlightChanged(
				GetGlobalMacroSettings()._highlightExecuted);
		},
		nullptr, false);
}

bool IsMacroHighlightingEnabled()
{
	const auto &settings = GetGlobalMacroSettings();
	return settings._highlightActions || settings._highlightConditions ||
	       settings._highlightExecuted;
}

} // namespace advss