1use crate::{detail::common_properties, flex_data};
2
3const STATUS: u8 = 0x00;
4
5#[midi2_proc::generate_message(Via(crate::flex_data::FlexData), MinSizeUmp(4))]
9struct UnknownMetadataText {
10 #[property(common_properties::UmpMessageTypeProperty<{flex_data::UMP_MESSAGE_TYPE}>)]
11 ump_type: (),
12
13 #[property(flex_data::GroupProperty)]
14 group: crate::ux::u4,
15
16 #[property(flex_data::OptionalChannelProperty)]
17 optional_channel: Option<crate::ux::u4>,
18
19 #[property(flex_data::BankProperty<{flex_data::METADATA_TEXT_BANK}>)]
20 bank: (),
21
22 #[property(flex_data::StatusProperty<{STATUS}>)]
23 status: (),
24
25 #[property(flex_data::ConsistentFormatsProperty)]
26 #[readonly]
27 consisten_formats: (),
28
29 #[property(flex_data::text::TextWriteStrProperty)]
30 #[writeonly]
31 #[resize]
32 text: &str,
33
34 #[property(flex_data::text::TextReadBytesProperty)]
35 #[readonly]
36 text_bytes: flex_data::text::TextBytesIterator,
37
38 #[property(flex_data::text::TextReadStringProperty)]
39 #[readonly]
40 #[std]
41 text: std::string::String,
42}
43
44impl<B: crate::buffer::Ump> crate::traits::Size<B> for UnknownMetadataText<B> {
45 fn size(&self) -> usize {
46 flex_data::flex_data_dyn_size(&self.0)
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53 use crate::{traits::Grouped, ux::*};
54 use pretty_assertions::assert_eq;
55
56 #[test]
57 fn text_bytes() {
58 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
59 message.set_text("Gimme some signal!");
60 let _ = message.text_bytes();
61 }
62
63 #[test]
64 fn new() {
65 assert_eq!(
66 UnknownMetadataText::<std::vec::Vec<u32>>::new(),
67 UnknownMetadataText(std::vec![0xD010_0100, 0x0, 0x0, 0x0]),
68 )
69 }
70
71 #[test]
72 fn set_text() {
73 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
74 message.set_text("Gimme some signal!");
75 assert_eq!(
76 message,
77 UnknownMetadataText(std::vec![
78 0xD050_0100,
79 0x4769_6D6D,
80 0x6520_736F,
81 0x6D65_2073,
82 0xD0D0_0100,
83 0x6967_6E61,
84 0x6C21_0000,
85 0x0000_0000,
86 ])
87 )
88 }
89
90 #[test]
91 fn set_long_text() {
92 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
93 message.set_text("Synth wizardry: turning knobs and flipping switches until it sounds like a laser battle in space! 💫🔊🚀");
94 assert_eq!(
95 message,
96 UnknownMetadataText(std::vec![
97 0xD050_0100,
98 0x5379_6E74,
99 0x6820_7769,
100 0x7A61_7264,
101 0xD090_0100,
102 0x7279_3A20,
103 0x7475_726E,
104 0x696E_6720,
105 0xD090_0100,
106 0x6B6E_6F62,
107 0x7320_616E,
108 0x6420_666C,
109 0xD090_0100,
110 0x6970_7069,
111 0x6E67_2073,
112 0x7769_7463,
113 0xD090_0100,
114 0x6865_7320,
115 0x756E_7469,
116 0x6C20_6974,
117 0xD090_0100,
118 0x2073_6F75,
119 0x6E64_7320,
120 0x6C69_6B65,
121 0xD090_0100,
122 0x2061_206C,
123 0x6173_6572,
124 0x2062_6174,
125 0xD090_0100,
126 0x746C_6520,
127 0x696E_2073,
128 0x7061_6365,
129 0xD090_0100,
130 0x2120_F09F,
131 0x92AB_F09F,
132 0x948A_F09F,
133 0xD0D0_0100,
134 0x9A80_0000,
135 0x0000_0000,
136 0x0000_0000,
137 ])
138 )
139 }
140
141 #[test]
142 fn set_long_text_and_reset_to_short() {
143 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
144 message.set_text("Synth wizardry: turning knobs and flipping switches until it sounds like a laser battle in space! 💫🔊🚀");
145 message.set_text("Gimme some signal!");
146 assert_eq!(
147 message,
148 UnknownMetadataText(std::vec![
149 0xD050_0100,
150 0x4769_6D6D,
151 0x6520_736F,
152 0x6D65_2073,
153 0xD0D0_0100,
154 0x6967_6E61,
155 0x6C21_0000,
156 0x0000_0000,
157 ])
158 )
159 }
160
161 #[test]
162 fn set_group() {
163 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
164 message.set_text("Gimme some signal!");
165 message.set_group(u4::new(0xA));
166 assert_eq!(
167 message,
168 UnknownMetadataText(std::vec![
169 0xDA50_0100,
170 0x4769_6D6D,
171 0x6520_736F,
172 0x6D65_2073,
173 0xDAD0_0100,
174 0x6967_6E61,
175 0x6C21_0000,
176 0x0000_0000,
177 ])
178 )
179 }
180
181 #[test]
182 fn try_set_text() {
183 let mut message = UnknownMetadataText::<[u32; 8]>::new();
184 message
185 .try_set_text("Gimme some signal!")
186 .expect("Shouldn't fail");
187 assert_eq!(
188 message,
189 UnknownMetadataText([
190 0xD050_0100,
191 0x4769_6D6D,
192 0x6520_736F,
193 0x6D65_2073,
194 0xD0D0_0100,
195 0x6967_6E61,
196 0x6C21_0000,
197 0x0000_0000,
198 ])
199 )
200 }
201
202 #[test]
203 fn try_from() {
204 assert_eq!(
205 UnknownMetadataText::try_from(
206 &[
207 0xD050_0100,
208 0x4769_6D6D,
209 0x6520_736F,
210 0x6D65_2073,
211 0xD0D0_0100,
212 0x6967_6E61,
213 0x6C21_0000,
214 0x0000_0000,
215 ][..]
216 ),
217 Ok(UnknownMetadataText(
218 &[
219 0xD050_0100,
220 0x4769_6D6D,
221 0x6520_736F,
222 0x6D65_2073,
223 0xD0D0_0100,
224 0x6967_6E61,
225 0x6C21_0000,
226 0x0000_0000,
227 ][..]
228 )),
229 )
230 }
231
232 #[test]
233 fn try_from_inconsistent_status() {
234 assert_eq!(
235 UnknownMetadataText::try_from(
236 &[
237 0xD050_0100,
238 0x4769_6D6D,
239 0x6520_736F,
240 0x6D65_2073,
241 0xD0D0_0101,
242 0x6967_6E61,
243 0x6C21_0000,
244 0x0000_0000,
245 ][..]
246 ),
247 Err(crate::error::InvalidData("Incorrect message status")),
248 )
249 }
250
251 #[test]
252 fn try_from_inconsistent_bank() {
253 assert_eq!(
254 UnknownMetadataText::try_from(
255 &[
256 0xD050_0100,
257 0x4769_6D6D,
258 0x6520_736F,
259 0x6D65_2073,
260 0xD0D0_0200,
261 0x6967_6E61,
262 0x6C21_0000,
263 0x0000_0000,
264 ][..]
265 ),
266 Err(crate::error::InvalidData("Incorrect message bank")),
267 )
268 }
269
270 #[test]
271 fn try_from_inconsistent_groups() {
272 assert_eq!(
273 UnknownMetadataText::try_from(
274 &[
275 0xDA10_0100,
276 0x4769_6D6D,
277 0x6520_736F,
278 0x6D65_2073,
279 0xDBD0_0100,
280 0x6967_6E61,
281 0x6C21_0000,
282 0x0000_0000,
283 ][..]
284 ),
285 Err(crate::error::InvalidData(
286 crate::detail::helpers::ERR_INCONSISTENT_GROUPS
287 )),
288 )
289 }
290
291 #[test]
292 fn try_from_expected_start() {
293 assert_eq!(
294 UnknownMetadataText::try_from(
295 &[
296 0xD010_0100,
297 0x4769_6D6D,
298 0x6520_736F,
299 0x6D65_2073,
300 0xD0D0_0100,
301 0x6967_6E61,
302 0x6C21_0000,
303 0x0000_0000,
304 ][..]
305 ),
306 Err(crate::error::InvalidData(
307 crate::detail::helpers::ERR_SYSEX_EXPECTED_BEGIN
308 )),
309 )
310 }
311
312 #[test]
313 fn try_from_expected_end() {
314 assert_eq!(
315 UnknownMetadataText::try_from(
316 &[
317 0xD050_0100,
318 0x4769_6D6D,
319 0x6520_736F,
320 0x6D65_2073,
321 0xD090_0100,
322 0x6967_6E61,
323 0x6C21_0000,
324 0x0000_0000,
325 ][..]
326 ),
327 Err(crate::error::InvalidData(
328 crate::detail::helpers::ERR_SYSEX_EXPECTED_END
329 )),
330 )
331 }
332
333 #[test]
334 fn try_from_expected_complete() {
335 assert_eq!(
336 UnknownMetadataText::try_from(
337 &[0xD050_0100, 0x4769_6D6D, 0x6520_736F, 0x6D65_2073,][..]
338 ),
339 Err(crate::error::InvalidData(
340 crate::detail::helpers::ERR_SYSEX_EXPECTED_COMPLETE
341 )),
342 )
343 }
344
345 #[test]
346 fn try_from_expected_continue() {
347 assert_eq!(
348 UnknownMetadataText::try_from(
349 &[
350 0xD050_0100,
351 0x4769_6D6D,
352 0x6520_736F,
353 0x6D65_2073,
354 0xD050_0100,
355 0x4769_6D6D,
356 0x6520_736F,
357 0x6D65_2073,
358 0xD090_0100,
359 0x4769_6D6D,
360 0x6520_736F,
361 0x6D65_2073,
362 ][..]
363 ),
364 Err(crate::error::InvalidData(
365 crate::detail::helpers::ERR_SYSEX_EXPECTED_CONTINUE
366 )),
367 )
368 }
369
370 #[test]
371 fn read_text_bytes() {
372 assert_eq!(
373 UnknownMetadataText::try_from(
374 &[
375 0xD050_0100,
376 0x4769_6D6D,
377 0x6520_736F,
378 0x6D65_2073,
379 0xD0D0_0100,
380 0x6967_6E61,
381 0x6C21_0000,
382 0x0000_0000,
383 ][..]
384 )
385 .unwrap()
386 .text_bytes()
387 .collect::<std::vec::Vec<u8>>(),
388 std::vec![
389 0x47, 0x69, 0x6D, 0x6D, 0x65, 0x20, 0x73, 0x6F, 0x6D, 0x65, 0x20, 0x73, 0x69, 0x67,
390 0x6E, 0x61, 0x6C, 0x21,
391 ]
392 )
393 }
394
395 #[test]
396 fn read_empty_text_bytes() {
397 assert_eq!(
398 UnknownMetadataText::<std::vec::Vec<u32>>::new()
399 .text_bytes()
400 .collect::<std::vec::Vec<u8>>(),
401 std::vec::Vec::<u8>::new(),
402 )
403 }
404
405 #[test]
406 #[cfg(feature = "std")]
407 fn read_string() {
408 assert_eq!(
409 UnknownMetadataText::try_from(
410 &[
411 0xD050_0100,
412 0x4769_6D6D,
413 0x6520_736F,
414 0x6D65_2073,
415 0xD0D0_0100,
416 0x6967_6E61,
417 0x6C21_0000,
418 0x0000_0000,
419 ][..]
420 )
421 .unwrap()
422 .text(),
423 "Gimme some signal!",
424 )
425 }
426
427 #[test]
428 fn set_string_multiple_of_12_length() {
429 let mut message = UnknownMetadataText::<std::vec::Vec<u32>>::new();
430 message.set_text("Digital Audio Workstation - DAW36-16");
431 assert_eq!(
432 message,
433 UnknownMetadataText(std::vec![
434 0xD050_0100,
435 0x4469_6769,
436 0x7461_6C20,
437 0x4175_6469,
438 0xD090_0100,
439 0x6F20_576F,
440 0x726B_7374,
441 0x6174_696F,
442 0xD0D0_0100,
443 0x6E20_2D20,
444 0x4441_5733,
445 0x362D_3136,
446 ])
447 );
448 }
449
450 #[test]
451 fn data() {
452 assert_eq!(
453 UnknownMetadataText::try_from(
454 &[
455 0xD050_0100,
456 0x4469_6769,
457 0x7461_6C20,
458 0x4175_6469,
459 0xD090_0100,
460 0x6F20_576F,
461 0x726B_7374,
462 0x6174_696F,
463 0xD0D0_0100,
464 0x6E20_2D20,
465 0x4441_5733,
466 0x362D_3136,
467 ][..]
468 )
469 .unwrap()
470 .data(),
471 &[
472 0xD050_0100,
473 0x4469_6769,
474 0x7461_6C20,
475 0x4175_6469,
476 0xD090_0100,
477 0x6F20_576F,
478 0x726B_7374,
479 0x6174_696F,
480 0xD0D0_0100,
481 0x6E20_2D20,
482 0x4441_5733,
483 0x362D_3136,
484 ]
485 );
486 }
487
488 #[test]
489 fn packets() {
490 use crate::Packets;
491
492 let message = UnknownMetadataText::try_from(
493 &[
494 0xD050_0100,
495 0x4469_6769,
496 0x7461_6C20,
497 0x4175_6469,
498 0xD090_0100,
499 0x6F20_576F,
500 0x726B_7374,
501 0x6174_696F,
502 0xD0D0_0100,
503 0x6E20_2D20,
504 0x4441_5733,
505 0x362D_3136,
506 ][..],
507 )
508 .unwrap();
509 let mut packets = message.packets();
510 assert_eq!(
511 &*packets.next().unwrap(),
512 &[0xD050_0100, 0x4469_6769, 0x7461_6C20, 0x4175_6469,][..],
513 );
514 assert_eq!(
515 &*packets.next().unwrap(),
516 &[0xD090_0100, 0x6F20_576F, 0x726B_7374, 0x6174_696F,][..],
517 );
518 assert_eq!(
519 &*packets.next().unwrap(),
520 &[0xD0D0_0100, 0x6E20_2D20, 0x4441_5733, 0x362D_3136,][..],
521 );
522 assert_eq!(packets.next(), None);
523 }
524}