Skip to content

Commit

Permalink
#1058 App: Don't panic if MIDI device not UTF-8 encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Jul 25, 2024
1 parent 624f34b commit 174c4a2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helgobox"
version = "2.16.0"
version = "2.16.1"
authors = ["Benjamin Klum <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/plugin/auto_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn get_suitability_of_controller_preset_for_controller(
// If the controller doesn't have a name / is not available, it can't match an output port pattern.
return ControllerSuitability::NotSuitable;
};
let out_dev_name = out_dev_name.into_string();
let out_dev_name = out_dev_name.to_string_lossy();
if midi_output_port_patterns_match(patterns, &out_dev_name) {
identity_pattern_suitability
} else {
Expand Down
4 changes: 2 additions & 2 deletions main/src/infrastructure/plugin/backbone_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2660,8 +2660,8 @@ async fn maybe_create_controller_for_device(
let out_port_name = Reaper::get()
.midi_output_device_by_id(out_dev_id)
.name()
.ok_or("MIDI output device doesn't return name / is not available")?
.into_string();
.ok_or("MIDI output device doesn't return name / is not available")?;
let out_port_name = out_port_name.to_string_lossy();
tracing::info!(msg = "Input not yet used. Finding matching controller preset...", %out_port_name);
let controller_preset = controller_preset_manager
.find_controller_preset_compatible_with_device(
Expand Down
12 changes: 10 additions & 2 deletions main/src/infrastructure/proto/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ impl MidiInputDevice {
pub fn from_engine(dev: reaper_high::MidiInputDevice) -> Self {
MidiInputDevice {
id: dev.id().get() as _,
name: dev.name().unwrap_or_default().into_string(),
name: dev
.name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
status: MidiDeviceStatus::from_engine(dev.is_open(), dev.is_connected()).into(),
}
}
Expand All @@ -260,7 +264,11 @@ impl MidiOutputDevice {
pub fn from_engine(dev: reaper_high::MidiOutputDevice) -> Self {
MidiOutputDevice {
id: dev.id().get() as _,
name: dev.name().unwrap_or_default().into_string(),
name: dev
.name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
status: MidiDeviceStatus::from_engine(dev.is_open(), dev.is_connected()).into(),
}
}
Expand Down
14 changes: 3 additions & 11 deletions main/src/infrastructure/ui/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::infrastructure::ui::Item;
use camino::Utf8Path;
use indexmap::IndexMap;
use reaper_high::{FxChainContext, MidiInputDevice, MidiOutputDevice, Reaper};
use std::ffi::CString;

use base::hash_util::NonCryptoIndexMap;
use derive_more::Display;
use helgobox_api::persistence::VirtualControlElementCharacter;
use reaper_medium::ReaperString;
use std::iter;
use strum::IntoEnumIterator;
use swell_ui::menu_tree::{
Expand Down Expand Up @@ -243,16 +243,8 @@ pub fn get_midi_output_device_list_label(dev: MidiOutputDevice) -> String {
)
}

fn get_midi_device_list_label(name: ReaperString, raw_id: u8, status: MidiDeviceStatus) -> String {
format!(
"MIDI: [{}] {}{}",
raw_id,
// Here we don't rely on the string to be UTF-8 because REAPER doesn't have influence on
// how MIDI devices encode their name. Indeed a user reported an error related to that:
// https://github.com/helgoboss/helgobox/issues/78
name.into_inner().to_string_lossy(),
status
)
fn get_midi_device_list_label(name: CString, raw_id: u8, status: MidiDeviceStatus) -> String {
format!("MIDI: [{}] {}{}", raw_id, name.to_string_lossy(), status)
}

pub fn extension_menu() -> Menu<&'static str> {
Expand Down

0 comments on commit 174c4a2

Please sign in to comment.