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
use crate::InputError;
/// Identity of the application hosting the plugins. VST3 receives the name; CLAP receives all
/// three fields. Audio Units have no equivalent identity callback in the current host API.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostIdentity {
/// Non-empty, at most 127 UTF-16 code units (the VST3 String128 limit).
pub name: String,
/// Application vendor; must not contain NUL.
pub vendor: String,
/// Application version; must not contain NUL.
pub version: String,
}
impl HostIdentity {
/// The host name, vendor and version plugins are told; validated when it is used.
#[must_use]
pub fn new(
name: impl Into<String>,
vendor: impl Into<String>,
version: impl Into<String>,
) -> HostIdentity {
HostIdentity {
name: name.into(),
vendor: vendor.into(),
version: version.into(),
}
}
/// Validates the common identity without truncating strings at a format boundary.
pub fn validate(&self) -> Result<(), InputError> {
if self.name.is_empty()
|| self.name.encode_utf16().count() > 127
|| [&self.name, &self.vendor, &self.version]
.iter()
.any(|s| s.contains('\0'))
{
return Err(InputError::HostIdentity);
}
Ok(())
}
}
/// Identity for standalone plughost tools and tests. Applications should supply their own.
impl Default for HostIdentity {
fn default() -> Self {
Self {
name: "plughost".to_owned(),
vendor: "plughost".to_owned(),
version: env!("CARGO_PKG_VERSION").to_owned(),
}
}
}