mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Use same style for optional and avoid double check
I did not know that `std::optional::value()` did checked access. And I still prefer a more explicit .has_value() over boolean conversion, but this seems to be the accepted way to do this.
This commit is contained in:
+12
-12
@@ -153,8 +153,8 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
const std::optional<EventPayload> value_payload =
|
||||
data_converter.read_value(opcode, value);
|
||||
|
||||
if (logging.has_value()) {
|
||||
auto [logger, is_dispatch] = logging.value();
|
||||
if (logging) {
|
||||
auto [logger, is_dispatch] = *logging;
|
||||
logger.log_event(is_dispatch, opcode, index, value, payload, option,
|
||||
value_payload);
|
||||
}
|
||||
@@ -172,8 +172,8 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
response = read_object<EventResult>(socket);
|
||||
}
|
||||
|
||||
if (logging.has_value()) {
|
||||
auto [logger, is_dispatch] = logging.value();
|
||||
if (logging) {
|
||||
auto [logger, is_dispatch] = *logging;
|
||||
logger.log_event_response(is_dispatch, opcode, response.return_value,
|
||||
response.payload, response.value_payload);
|
||||
}
|
||||
@@ -209,15 +209,15 @@ void receive_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
std::optional<std::pair<Logger&, bool>> logging,
|
||||
F callback) {
|
||||
auto event = read_object<Event>(socket);
|
||||
if (logging.has_value()) {
|
||||
auto [logger, is_dispatch] = logging.value();
|
||||
if (logging) {
|
||||
auto [logger, is_dispatch] = *logging;
|
||||
logger.log_event(is_dispatch, event.opcode, event.index, event.value,
|
||||
event.payload, event.option, event.value_payload);
|
||||
}
|
||||
|
||||
EventResult response = callback(event);
|
||||
if (logging.has_value()) {
|
||||
auto [logger, is_dispatch] = logging.value();
|
||||
if (logging) {
|
||||
auto [logger, is_dispatch] = *logging;
|
||||
logger.log_event_response(is_dispatch, event.opcode,
|
||||
response.return_value, response.payload,
|
||||
response.value_payload);
|
||||
@@ -308,9 +308,9 @@ auto passthrough_event(AEffect* plugin, F callback) {
|
||||
// data through the value argument.
|
||||
void* data = std::visit(read_payload_fn, event.payload);
|
||||
intptr_t value = event.value;
|
||||
if (event.value_payload.has_value()) {
|
||||
if (event.value_payload) {
|
||||
value = reinterpret_cast<intptr_t>(
|
||||
std::visit(read_payload_fn, event.value_payload.value()));
|
||||
std::visit(read_payload_fn, *event.value_payload));
|
||||
}
|
||||
|
||||
const intptr_t return_value = callback(
|
||||
@@ -388,9 +388,9 @@ auto passthrough_event(AEffect* plugin, F callback) {
|
||||
const EventResultPayload response_data =
|
||||
std::visit(write_payload_fn, event.payload);
|
||||
std::optional<EventResultPayload> value_response_data = std::nullopt;
|
||||
if (event.value_payload.has_value()) {
|
||||
if (event.value_payload) {
|
||||
value_response_data =
|
||||
std::visit(write_payload_fn, event.value_payload.value());
|
||||
std::visit(write_payload_fn, *event.value_payload);
|
||||
}
|
||||
|
||||
EventResult response{return_value, response_data, value_response_data};
|
||||
|
||||
@@ -158,8 +158,8 @@ void Logger::log_event(bool is_dispatch,
|
||||
}
|
||||
|
||||
const auto opcode_name = opcode_to_string(is_dispatch, opcode);
|
||||
if (opcode_name.has_value()) {
|
||||
message << opcode_name.value();
|
||||
if (opcode_name) {
|
||||
message << *opcode_name;
|
||||
} else {
|
||||
message << "<opcode = " << opcode << ">";
|
||||
}
|
||||
@@ -169,7 +169,7 @@ void Logger::log_event(bool is_dispatch,
|
||||
|
||||
// Only used during `effSetSpeakerArrangement` and
|
||||
// `effGetSpeakerArrangement`
|
||||
if (value_payload.has_value()) {
|
||||
if (value_payload) {
|
||||
std::visit(
|
||||
overload{
|
||||
[&](auto) {},
|
||||
@@ -177,7 +177,7 @@ void Logger::log_event(bool is_dispatch,
|
||||
message << "<" << speaker_arrangement.speakers.size()
|
||||
<< " input_speakers>, ";
|
||||
}},
|
||||
value_payload.value());
|
||||
*value_payload);
|
||||
}
|
||||
|
||||
std::visit(
|
||||
@@ -248,7 +248,7 @@ void Logger::log_event_response(
|
||||
|
||||
// Only used during `effSetSpeakerArrangement` and
|
||||
// `effGetSpeakerArrangement`
|
||||
if (value_payload.has_value()) {
|
||||
if (value_payload) {
|
||||
std::visit(
|
||||
overload{
|
||||
[&](auto) {},
|
||||
@@ -256,7 +256,7 @@ void Logger::log_event_response(
|
||||
message << ", <" << speaker_arrangement.speakers.size()
|
||||
<< " input_speakers>";
|
||||
}},
|
||||
value_payload.value());
|
||||
*value_payload);
|
||||
}
|
||||
|
||||
std::visit(
|
||||
|
||||
@@ -63,9 +63,9 @@ Configuration Configuration::load_for(const fs::path& yabridge_path) {
|
||||
// to default configuration settings if it doesn't exist
|
||||
const std::optional<fs::path> config_file =
|
||||
find_dominating_file("yabridge.toml", yabridge_path);
|
||||
if (!config_file.has_value()) {
|
||||
if (!config_file) {
|
||||
return Configuration();
|
||||
}
|
||||
|
||||
return Configuration(config_file.value(), yabridge_path);
|
||||
return Configuration(*config_file, yabridge_path);
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
||||
create_logger_prefix(socket_endpoint.path()))),
|
||||
wine_version(get_wine_version()),
|
||||
vst_host(
|
||||
config.group.has_value()
|
||||
config.group
|
||||
? std::unique_ptr<HostProcess>(
|
||||
std::make_unique<GroupHost>(io_context,
|
||||
logger,
|
||||
vst_plugin_path,
|
||||
socket_endpoint.path(),
|
||||
config.group.value(),
|
||||
*config.group,
|
||||
host_vst_dispatch))
|
||||
: std::unique_ptr<HostProcess>(
|
||||
std::make_unique<IndividualHost>(io_context,
|
||||
@@ -554,9 +554,9 @@ float PluginBridge::get_parameter(AEffect* /*plugin*/, int index) {
|
||||
response = read_object<ParameterResult>(host_vst_parameters);
|
||||
}
|
||||
|
||||
logger.log_get_parameter_response(response.value.value());
|
||||
logger.log_get_parameter_response(*response.value);
|
||||
|
||||
return response.value.value();
|
||||
return *response.value;
|
||||
}
|
||||
|
||||
void PluginBridge::set_parameter(AEffect* /*plugin*/, int index, float value) {
|
||||
@@ -575,7 +575,7 @@ void PluginBridge::set_parameter(AEffect* /*plugin*/, int index, float value) {
|
||||
logger.log_set_parameter_response();
|
||||
|
||||
// This should not contain any values and just serve as an acknowledgement
|
||||
assert(!response.value.has_value());
|
||||
assert(!response.value);
|
||||
}
|
||||
|
||||
void PluginBridge::log_init_message() {
|
||||
@@ -602,8 +602,8 @@ void PluginBridge::log_init_message() {
|
||||
<< config.matched_file.value_or("<defaults>").string() << "'"
|
||||
<< std::endl;
|
||||
init_msg << "hosting mode: '";
|
||||
if (config.group.has_value()) {
|
||||
init_msg << "plugin group \"" << config.group.value() << "\"";
|
||||
if (config.group) {
|
||||
init_msg << "plugin group \"" << *config.group << "\"";
|
||||
} else {
|
||||
init_msg << "individually";
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ std::string create_logger_prefix(const fs::path& socket_path) {
|
||||
std::optional<fs::path> find_wineprefix() {
|
||||
std::optional<fs::path> dosdevices_dir =
|
||||
find_dominating_file("dosdevices", find_vst_plugin(), fs::is_directory);
|
||||
if (!dosdevices_dir.has_value()) {
|
||||
if (!dosdevices_dir) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ bp::environment set_wineprefix() {
|
||||
}
|
||||
|
||||
const auto wineprefix_path = find_wineprefix();
|
||||
if (wineprefix_path.has_value()) {
|
||||
if (wineprefix_path) {
|
||||
env["WINEPREFIX"] = wineprefix_path->string();
|
||||
}
|
||||
|
||||
|
||||
@@ -245,10 +245,9 @@ void Vst2Bridge::handle_parameters() {
|
||||
// presence of the `value` field tells us which one we're dealing
|
||||
// with.
|
||||
auto request = read_object<Parameter>(host_vst_parameters);
|
||||
if (request.value.has_value()) {
|
||||
if (request.value) {
|
||||
// `setParameter`
|
||||
plugin->setParameter(plugin, request.index,
|
||||
request.value.value());
|
||||
plugin->setParameter(plugin, request.index, *request.value);
|
||||
|
||||
ParameterResult response{std::nullopt};
|
||||
write_object(host_vst_parameters, response);
|
||||
@@ -477,8 +476,8 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
// Return a pointer to the `VstTimeInfo` object written in
|
||||
// the function above
|
||||
VstTimeInfo* time_info_pointer = nullptr;
|
||||
if (time_info.has_value()) {
|
||||
time_info_pointer = &time_info.value();
|
||||
if (time_info) {
|
||||
time_info_pointer = &*time_info;
|
||||
}
|
||||
|
||||
return reinterpret_cast<intptr_t>(time_info_pointer);
|
||||
|
||||
@@ -26,8 +26,8 @@ Win32Timer::Win32Timer(HWND window_handle,
|
||||
}
|
||||
|
||||
Win32Timer::~Win32Timer() {
|
||||
if (timer_id.has_value()) {
|
||||
KillTimer(window_handle, timer_id.value());
|
||||
if (timer_id) {
|
||||
KillTimer(window_handle, *timer_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user