mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Rearrange the try-catch in the thread handlers
It's a bit clearer this way. I would prefer using jthreads here, but we would still need this try-catch block since there's no way to cancel synchronous Boost.Asio socket operations other than closing the socket.
This commit is contained in:
@@ -132,8 +132,8 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
|||||||
// instead of asynchronous IO since communication has to be handled in
|
// instead of asynchronous IO since communication has to be handled in
|
||||||
// lockstep anyway
|
// lockstep anyway
|
||||||
host_callback_handler = std::thread([&]() {
|
host_callback_handler = std::thread([&]() {
|
||||||
try {
|
while (true) {
|
||||||
while (true) {
|
try {
|
||||||
// TODO: Think of a nicer way to structure this and the similar
|
// TODO: Think of a nicer way to structure this and the similar
|
||||||
// handler in `Vst2Bridge::handle_dispatch_midi_events`
|
// handler in `Vst2Bridge::handle_dispatch_midi_events`
|
||||||
receive_event(
|
receive_event(
|
||||||
@@ -159,10 +159,11 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
|||||||
&plugin, host_callback_function)(event);
|
&plugin, host_callback_function)(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// This happens when the sockets got closed because the plugin
|
||||||
|
// is being shut down
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// This happens when the sockets got closed because the plugin
|
|
||||||
// is being shut down
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -149,8 +149,8 @@ bool Vst2Bridge::should_skip_message_loop() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_dispatch() {
|
void Vst2Bridge::handle_dispatch() {
|
||||||
try {
|
while (true) {
|
||||||
while (true) {
|
try {
|
||||||
receive_event(
|
receive_event(
|
||||||
host_vst_dispatch, std::nullopt,
|
host_vst_dispatch, std::nullopt,
|
||||||
passthrough_event(
|
passthrough_event(
|
||||||
@@ -174,16 +174,17 @@ void Vst2Bridge::handle_dispatch() {
|
|||||||
// separately on a timer
|
// separately on a timer
|
||||||
return dispatch_result.get_future().get();
|
return dispatch_result.get_future().get();
|
||||||
}));
|
}));
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// The plugin has cut off communications, so we can shut down this
|
||||||
|
// host application
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// The plugin has cut off communications, so we can shut down this
|
|
||||||
// host application
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_dispatch_midi_events() {
|
void Vst2Bridge::handle_dispatch_midi_events() {
|
||||||
try {
|
while (true) {
|
||||||
while (true) {
|
try {
|
||||||
receive_event(
|
receive_event(
|
||||||
host_vst_dispatch_midi_events, std::nullopt, [&](Event& event) {
|
host_vst_dispatch_midi_events, std::nullopt, [&](Event& event) {
|
||||||
if (BOOST_LIKELY(event.opcode == effProcessEvents)) {
|
if (BOOST_LIKELY(event.opcode == effProcessEvents)) {
|
||||||
@@ -230,16 +231,17 @@ void Vst2Bridge::handle_dispatch_midi_events() {
|
|||||||
_2, _3, _4, _5, _6))(event);
|
_2, _3, _4, _5, _6))(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// The plugin has cut off communications, so we can shut down this
|
||||||
|
// host application
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// The plugin has cut off communications, so we can shut down this host
|
|
||||||
// application
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_parameters() {
|
void Vst2Bridge::handle_parameters() {
|
||||||
try {
|
while (true) {
|
||||||
while (true) {
|
try {
|
||||||
// Both `getParameter` and `setParameter` functions are passed
|
// Both `getParameter` and `setParameter` functions are passed
|
||||||
// through on this socket since they have a lot of overlap. The
|
// through on this socket since they have a lot of overlap. The
|
||||||
// presence of the `value` field tells us which one we're dealing
|
// presence of the `value` field tells us which one we're dealing
|
||||||
@@ -258,18 +260,19 @@ void Vst2Bridge::handle_parameters() {
|
|||||||
ParameterResult response{value};
|
ParameterResult response{value};
|
||||||
write_object(host_vst_parameters, response);
|
write_object(host_vst_parameters, response);
|
||||||
}
|
}
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// The plugin has cut off communications, so we can shut down this
|
||||||
|
// host application
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// The plugin has cut off communications, so we can shut down this host
|
|
||||||
// application
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2Bridge::handle_process_replacing() {
|
void Vst2Bridge::handle_process_replacing() {
|
||||||
std::vector<std::vector<float>> output_buffers(plugin->numOutputs);
|
std::vector<std::vector<float>> output_buffers(plugin->numOutputs);
|
||||||
|
|
||||||
try {
|
while (true) {
|
||||||
while (true) {
|
try {
|
||||||
auto request = read_object<AudioBuffers>(host_vst_process_replacing,
|
auto request = read_object<AudioBuffers>(host_vst_process_replacing,
|
||||||
process_buffer);
|
process_buffer);
|
||||||
|
|
||||||
@@ -320,10 +323,11 @@ void Vst2Bridge::handle_process_replacing() {
|
|||||||
|
|
||||||
AudioBuffers response{output_buffers, request.sample_frames};
|
AudioBuffers response{output_buffers, request.sample_frames};
|
||||||
write_object(host_vst_process_replacing, response, process_buffer);
|
write_object(host_vst_process_replacing, response, process_buffer);
|
||||||
|
} catch (const boost::system::system_error&) {
|
||||||
|
// The plugin has cut off communications, so we can shut down this
|
||||||
|
// host application
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (const boost::system::system_error&) {
|
|
||||||
// The plugin has cut off communications, so we can shut down this host
|
|
||||||
// application
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user