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
197
198
199
200
201
202
203
204
205
#![allow(dead_code)]
use std::error::Error;
use std::io::Read;
use super::binary_reader::BinaryReader;
use super::soundfont_version::SoundFontVersion;
#[non_exhaustive]
pub struct SoundFontInfo {
pub(crate) version: SoundFontVersion,
pub(crate) target_sound_engine: String,
pub(crate) bank_name: String,
pub(crate) rom_name: String,
pub(crate) rom_version: SoundFontVersion,
pub(crate) creation_date: String,
pub(crate) author: String,
pub(crate) target_product: String,
pub(crate) copyright: String,
pub(crate) comments: String,
pub(crate) tools: String,
}
impl SoundFontInfo {
pub(crate) fn new<R: Read>(reader: &mut R) -> Result<Self, Box<dyn Error>> {
let chunk_id = BinaryReader::read_four_cc(reader)?;
if chunk_id != "LIST" {
return Err(format!("The LIST chunk was not found.").into());
}
let end = BinaryReader::read_i32(reader)?;
let mut pos: i32 = 0;
let list_type = BinaryReader::read_four_cc(reader)?;
if list_type != "INFO" {
return Err(format!(
"The type of the LIST chunk must be 'INFO', but was '{list_type}'."
)
.into());
}
pos += 4;
let mut version: Option<SoundFontVersion> = None;
let mut target_sound_engine: Option<String> = None;
let mut bank_name: Option<String> = None;
let mut rom_name: Option<String> = None;
let mut rom_version: Option<SoundFontVersion> = None;
let mut creation_date: Option<String> = None;
let mut author: Option<String> = None;
let mut target_product: Option<String> = None;
let mut copyright: Option<String> = None;
let mut comments: Option<String> = None;
let mut tools: Option<String> = None;
while pos < end {
let id = BinaryReader::read_four_cc(reader)?;
pos += 4;
let size = BinaryReader::read_i32(reader)?;
pos += 4;
if id == "ifil" {
version = Some(SoundFontVersion::new(reader)?);
} else if id == "isng" {
target_sound_engine = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "INAM" {
bank_name = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "irom" {
rom_name = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "iver" {
rom_version = Some(SoundFontVersion::new(reader)?);
} else if id == "ICRD" {
creation_date = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "IENG" {
author = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "IPRD" {
target_product = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "ICOP" {
copyright = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "ICMT" {
comments = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else if id == "ISFT" {
tools = Some(BinaryReader::read_fixed_length_string(reader, size)?);
} else {
return Err(format!("The INFO list contains an unknown ID '{id}'.").into());
}
pos += size;
}
let version = match version {
Some(value) => value,
None => SoundFontVersion::default(),
};
let target_sound_engine = match target_sound_engine {
Some(value) => value,
None => String::new(),
};
let bank_name = match bank_name {
Some(value) => value,
None => String::new(),
};
let rom_name = match rom_name {
Some(value) => value,
None => String::new(),
};
let rom_version = match rom_version {
Some(value) => value,
None => SoundFontVersion::default(),
};
let creation_date = match creation_date {
Some(value) => value,
None => String::new(),
};
let author = match author {
Some(value) => value,
None => String::new(),
};
let target_product = match target_product {
Some(value) => value,
None => String::new(),
};
let copyright = match copyright {
Some(value) => value,
None => String::new(),
};
let comments = match comments {
Some(value) => value,
None => String::new(),
};
let tools = match tools {
Some(value) => value,
None => String::new(),
};
Ok(Self {
version: version,
target_sound_engine: target_sound_engine,
bank_name: bank_name,
rom_name: rom_name,
rom_version: rom_version,
creation_date: creation_date,
author: author,
target_product: target_product,
copyright: copyright,
comments: comments,
tools: tools,
})
}
pub fn get_version(&self) -> &SoundFontVersion {
&self.version
}
pub fn get_target_sound_engine(&self) -> &str {
&self.target_sound_engine
}
pub fn get_bank_name(&self) -> &str {
&self.bank_name
}
pub fn get_rom_name(&self) -> &str {
&self.rom_name
}
pub fn get_rom_version(&self) -> &SoundFontVersion {
&self.rom_version
}
pub fn get_creation_date(&self) -> &str {
&self.creation_date
}
pub fn get_author(&self) -> &str {
&self.author
}
pub fn get_target_product(&self) -> &str {
&self.target_product
}
pub fn get_copyright(&self) -> &str {
&self.copyright
}
pub fn get_comments(&self) -> &str {
&self.comments
}
pub fn get_tools(&self) -> &str {
&self.tools
}
}