Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Latest commit

 

History

History
History
196 lines (166 loc) · 5.85 KB

File metadata and controls

196 lines (166 loc) · 5.85 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// clang-format off
#include "EngineThread.h"
#include "ContainerWindow.h"
#include "Engine.h"
#include "EngineWindow.h"
#include "helpers\win32_misc.h"
#include "utils.h"
// clang-format on
namespace engine {
using EM = engine::Engine::Messages;
void EngineThread::run() {
TRACK_CALL_TEXT(PFC_string_formatter() << AppNameInternal << " EngineThread");
CoInitializeScope com_enable{};
engineWindow.makeContextCurrent();
// We can only destroy the Engine while EngineThread is beeing destroyed,
// since mainthread callbacks held by EngineThread might reference Engine objects.
std::optional<Engine> engine;
try {
engine.emplace(*this, engineWindow, styleManager);
engine->mainLoop();
} catch (std::exception& e) {
runInMainThread([&] {
engineWindow.container.destroyEngineWindow((PFC_string_formatter()
<< "Engine died with exception:\n"
<< e.what())
.c_str());
});
while (nullptr == dynamic_cast<EM::StopThread*>(messageQueue.pop().get())) {
// Going through the message queue has two purposes:
// 1. We wait for and find StopThread messages
// 2. We abandon any promises that are enqueued
}
}
}
void EngineThread::sendMessage(unique_ptr<::engine_messages::Message>&& msg) {
messageQueue.push(std::move(msg));
}
EngineThread::EngineThread(EngineWindow& engineWindow, StyleManager& styleManager)
: engineWindow(engineWindow), styleManager(styleManager), PlaylistCallback(*this) {
instances.insert(this);
styleManager.setChangeHandler([&] { this->on_style_change(); });
play_callback_reregister(flag_on_playback_new_track, true);
//reregister playlist manager
playlist_manager::get()->register_callback(this,
flag_on_item_focus_change |
flag_on_items_added |
flag_on_items_removed |
flag_on_items_reordered |
flag_on_items_selection_change |
flag_on_playlist_activate |
flag_on_playlist_renamed |
flag_on_playlists_removed);
std::packaged_task<void(EngineThread*)> task(&EngineThread::run);
thread = std::thread(std::move(task), this);
}
EngineThread::~EngineThread() {
instances.erase(this);
styleManager.setChangeHandler([] {});
this->send<EM::StopThread>();
// If the shutdown causes an exception, we need a second
// message to shut down the exception handler.
this->send<EM::StopThread>();
if (thread.joinable())
thread.join();
}
HWND EngineThread::GetEngineWindowWnd() {
return engineWindow.hWnd;
}
size_t EngineThread::GetDispFlags() {
return engineWindow.container.GetDisplayFlag();
}
bool EngineThread::GetCoverDispFlagU(DispFlags flg) {
return engineWindow.container.GetCoverDispFlagU(flg);
}
void EngineThread::SetCoverDispFlagU(DispFlags flg, bool val) {
return engineWindow.container.SetCoverDispFlagU(flg, val);
}
bool EngineThread::IsWholeLibrary() {
return engineWindow.container.coverIsWholeLibrary();
}
//serves playlist callback engine thread parent
bool EngineThread::IsSourcePlaylistOn(t_size playlist, PlSrcFilter mode) {
return engineWindow.container.IsSourcePlaylistOn(playlist, mode);
}
void EngineThread::GetState(src_state& srcstate, bool init) {
return engineWindow.container.GetState(srcstate, init);
}
void EngineThread::GetPlaylistSource(pfc::string& out, bool activesource, bool bguid) {
if (activesource) {
if (bguid) {
out = engineWindow.container.GetSourceActivePlaylistGUID();
} else {
out = engineWindow.container.GetSourceActivePlaylistName();
}
} else {
if (bguid) {
out = engineWindow.container.GetSourcePlaylistGUID();
} else {
out = engineWindow.container.GetSourcePlaylistName();
}
}
}
void EngineThread::SetPlaylistSource(pfc::string strval, bool activesource, bool bguid) {
if (activesource) {
if (bguid) {
engineWindow.container.SetSourceActivePlaylistGUID(strval);
} else {
engineWindow.container.SetSourceActivePlaylistName(strval);
}
} else {
if (bguid) {
engineWindow.container.SetSourcePlaylistGUID(strval);
} else {
engineWindow.container.SetSourcePlaylistName(strval);
}
}
}
//..
t_size EngineThread::FindSourcePlaylist(PlSrcFilter mode) const {
return engineWindow.container.FindSourcePlaylist(mode);
}
void EngineThread::invalidateWindow() {
RedrawWindow(engineWindow.hWnd, nullptr, nullptr, RDW_INVALIDATE);
}
const metadb_handle_list_ref EngineThread::getEngineWindowSelection() {
return engineWindow.getSelection(engineWindow.container.coverIsWholeLibrary());
}
std::unordered_set<EngineThread*> EngineThread::instances{};
void EngineThread::forEach(std::function<void(EngineThread&)> f) {
for (auto instance : instances) {
f(*instance);
}
}
void EngineThread::on_style_change() {
send<EM::TextFormatChangedMessage>();
invalidateWindow();
}
void EngineThread::on_playback_new_track(metadb_handle_ptr p_track) {
send<EM::PlaybackNewTrack>(p_track);
}
void EngineThread::on_items_added(metadb_handle_list_cref p_data) {
send<EM::LibraryItemsAdded>(p_data, libraryVersion);
}
void EngineThread::on_items_removed(metadb_handle_list_cref p_data) {
send<EM::LibraryItemsRemoved>(p_data, libraryVersion);
}
void EngineThread::on_items_modified(metadb_handle_list_cref p_data) {
send<EM::LibraryItemsModified>(p_data, libraryVersion);
}
void EngineThread::runInMainThread(std::function<void()> f) {
callbackHolder.addCallback(f);
}
CallbackHolder::CallbackHolder() : deadPtr(make_shared<bool>(false)) {}
CallbackHolder::~CallbackHolder() noexcept {
PFC_ASSERT(core_api::is_main_thread());
*deadPtr = true;
}
void CallbackHolder::addCallback(std::function<void()> f) {
fb2k::inMainThread([f, deadPtr = this->deadPtr] {
TRACK_CALL_TEXT(PFC_string_formatter() << AppNameInternal << "::inMainThread");
if (!*deadPtr) {
f();
}
});
}
} // namespace engine
Morty Proxy This is a proxified and sanitized view of the page, visit original site.