ksynth 0.18.0

Patch manipulation for Kawai digital synths
Documentation
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
//! System Exclusive data definitions for K5000.
//!

use std::convert::TryFrom;
use std::fmt;

use num_enum::TryFromPrimitive;
use bit::BitIndex;
use strum_macros;

use crate::{
    Ranged,
    SystemExclusiveData,
    ParseError,
    MIDIChannel
};

/// Kawai K5000 System Exclusive functions.
#[derive(Debug, Eq, PartialEq, Copy, Clone, TryFromPrimitive)]
#[repr(u8)]
pub enum Function {
    OneBlockDumpRequest = 0x00,
    AllBlockDumpRequest = 0x01,
    ParameterSend = 0x10,
    TrackControl = 0x11,
    OneBlockDump = 0x20,
    AllBlockDump = 0x21,
    ModeChange = 0x31,
    Remote = 0x32,
    WriteComplete = 0x40,
    WriteError = 0x41,
    WriteErrorByProtect = 0x42,
    WriteErrorByMemoryFull = 0x44,
    WriteErrorByNoExpandedMemory = 0x45,
}

/// K5000 System Exclusive message.
pub struct Message {
    pub channel: MIDIChannel,
    pub function: Function,
    pub function_data: Vec<u8>,
    pub subdata: Vec<u8>,
    pub patch_data: Vec<u8>,
}

impl SystemExclusiveData for Message {
    fn from_bytes(data: &[u8]) -> Result<Self, ParseError> {
        Ok(Message {
            channel: MIDIChannel::new(data[2].into()),
            function: Function::try_from(data[3]).unwrap(),
            function_data: Vec::<u8>::new(),  // TODO: fix this
            subdata: Vec::<u8>::new(),  // TODO: fix this
            patch_data: data[3..].to_vec(),
        })
    }

    fn to_bytes(&self) -> Vec<u8> {
        let mut result: Vec<u8> = Vec::new();

        result.push(0x40); // Kawai manufacturer ID
        result.push(self.channel.value() as u8);

        result.push(self.function as u8);
        result.extend(&self.function_data);
        result.extend(&self.subdata);
        result.extend(&self.patch_data);

        result
    }

    fn data_size() -> usize {
        todo!("Compute K5000 message size")
    }
}


/// Cardinality of SysEx message (one patch or block of patches).
#[derive(Debug, PartialEq, Copy, Clone, strum_macros::Display)]
#[repr(u8)]
pub enum Cardinality {
    One = 0x20,
    Block = 0x21,
}

impl From<Cardinality> for u8 {
    fn from(c: Cardinality) -> Self {
        c as u8
    }
}

/// K5000 bank identifier.
#[derive(
    Debug,
    Eq, PartialEq,
    Clone, Copy,
    strum_macros::Display, strum_macros::EnumString
)]
#[repr(u8)]
pub enum BankIdentifier {
    A = 0x00,
    B = 0x01,
    // there is no Bank C
    D = 0x02,  // only on K5000S/R
    E = 0x03,
    F = 0x04,
}

impl From<BankIdentifier> for u8 {
    fn from(b: BankIdentifier) -> Self {
        b as u8
    }
}

impl TryFrom<u8> for BankIdentifier {
    type Error = ();

    fn try_from(b: u8) -> Result<Self, Self::Error> {
        match b {
            x if x == BankIdentifier::A as u8 => Ok(BankIdentifier::A),
            x if x == BankIdentifier::B as u8 => Ok(BankIdentifier::B),
            x if x == BankIdentifier::D as u8 => Ok(BankIdentifier::D),
            x if x == BankIdentifier::E as u8 => Ok(BankIdentifier::E),
            x if x == BankIdentifier::F as u8 => Ok(BankIdentifier::F),
            _ => Err(()),
        }
    }
}

/// Patch kind.
#[derive(Debug, PartialEq, Copy, Clone)]
#[repr(u8)]
pub enum PatchKind {
    Single = 0x00,
    Multi = 0x20, // combi on K5000W
    DrumKit = 0x10,
    DrumInstrument = 0x11,
}

impl From<PatchKind> for u8 {
    fn from(val: PatchKind) -> Self {
        val as u8
    }
}

impl fmt::Display for PatchKind {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", match *self {
            PatchKind::Single => "Single",
            PatchKind::Multi => "Multi/Combi",
            PatchKind::DrumKit => "Drum Kit",
            PatchKind::DrumInstrument => "Drum Instrument"
        })
    }
}

/// System Exclusive dump header.
#[derive(Debug, PartialEq)]
pub struct Header {
    pub channel: MIDIChannel,
    pub cardinality: Cardinality,
    pub bank_identifier: Option<BankIdentifier>,
    pub kind: PatchKind,
    pub sub_bytes: Vec<u8>,
}

impl Header {
    /// Identifies a dump header from a byte vector.
    ///
    /// Returns `Some(Header)` if the header could be parsed,
    /// `None` otherwise.
    ///
    /// # Arguments
    ///
    /// * `buf` - a byte vector with the header data
    pub fn identify_vec(buf: &[u8]) -> Option<Header> {
        let channel = MIDIChannel::new((buf[0] + 1).into()); // use 1...16
        let result = match &buf[1..] {
            // One ADD Bank A (see 3.1.1b)
            [0x20, 0x00, 0x0A, 0x00, 0x00, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: Some(BankIdentifier::A),
                    kind: PatchKind::Single,
                    sub_bytes: vec![*sub1]
                })
            },

            // One PCM Bank B (see 3.1.1d)
            [0x20, 0x00, 0x0A, 0x00, 0x01, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: Some(BankIdentifier::B),
                    kind: PatchKind::Single,
                    sub_bytes: vec![*sub1]
                })
            },

            // One ADD Bank D (see 3.1.1k)
            [0x20, 0x00, 0x0A, 0x00, 0x02, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: Some(BankIdentifier::D),
                    kind: PatchKind::Single,
                    sub_bytes: vec![*sub1]
                })
            },

            // One Exp Bank E (see 3.1.1m)
            [0x20, 0x00, 0x0A, 0x00, 0x03, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: Some(BankIdentifier::E),
                    kind: PatchKind::Single,
                    sub_bytes: vec![*sub1],
                })
            },

            // One Exp Bank F (see 3.1.1o)
            [0x20, 0x00, 0x0A, 0x00, 0x04, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: Some(BankIdentifier::F),
                    kind: PatchKind::Single,
                    sub_bytes: vec![*sub1],
                })
            },

            // One Multi/Combi (see 3.1.1i)
            [0x20, 0x00, 0x0A, 0x20, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: None,
                    kind: PatchKind::Multi,
                    sub_bytes: vec![*sub1],
                })
            },

            // Block ADD Bank A (see 3.1.1a)
            [0x21, 0x00, 0x0A, 0x00, 0x00, tone_map @ ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: Some(BankIdentifier::A),
                    kind: PatchKind::Single,
                    sub_bytes: Vec::from(tone_map),
                })
            },

            // Block PCM Bank B -- all PCM data, no tone map
            [0x21, 0x00, 0x0A, 0x00, 0x01, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: Some(BankIdentifier::B),
                    kind: PatchKind::Single,
                    sub_bytes: vec![],
                })
            },

            // Block ADD Bank D (see 3.1.1j)
            [0x21, 0x00, 0x0A, 0x00, 0x02, tone_map @ ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: Some(BankIdentifier::D),
                    kind: PatchKind::Single,
                    sub_bytes: Vec::from(tone_map),
                })
            },

            // Block Exp Bank E (see 3.1.1l)
            [0x21, 0x00, 0x0A, 0x00, 0x03, tone_map @ ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: Some(BankIdentifier::E),
                    kind: PatchKind::Single,
                    sub_bytes: Vec::from(tone_map),
                })
            },

            // Block Exp Bank F (see 3.1.1n)
            [0x21, 0x00, 0x0A, 0x00, 0x04, tone_map @ ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: Some(BankIdentifier::F),
                    kind: PatchKind::Single,
                    sub_bytes: Vec::from(tone_map),
                })
            },

            // Block Multi/Combi (see 3.1.1h)
            [0x21, 0x00, 0x0A, 0x20, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: None,
                    kind: PatchKind::Multi,
                    sub_bytes: vec![],
                })
            },

            // One drum kit (see 3.1.1e)
            [0x20, 0x00, 0x0A, 0x10, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: None,
                    kind: PatchKind::DrumKit,
                    sub_bytes: vec![],
                })
            },

            // One drum instrument (see 3.1.1g)
            [0x20, 0x00, 0x0A, 0x11, sub1, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::One,
                    bank_identifier: None,
                    kind: PatchKind::DrumInstrument,
                    sub_bytes: vec![*sub1],
                })
            },

            // Block drum instrument (see 3.1.1f)
            [0x21, 0x00, 0x0A, 0x11, ..] => {
                Some(Header {
                    channel,
                    cardinality: Cardinality::Block,
                    bank_identifier: None,
                    kind: PatchKind::DrumInstrument,
                    sub_bytes: vec![],
                })
            },

            // All others (must have this arm with slice patterns)
            _ => { None }
        };

        match result {
            Some(mut header) => {
                // If we have a tone map, cut any excess bytes
                if header.sub_bytes.len() > 1 {
                    header.sub_bytes.truncate(19);
                }
                Some(header)
            },
            None => None,
        }

    }

    // Returns the size of this dump command in bytes
    pub fn size(&self) -> usize {
        let mut count =
            1 // channel     ("3rd" in K5000 MIDI spec)
            + 1 // cardinality ("4th" in K5000 MIDI spec)
            + 1 // 0x00 ("5th")
            + 1 // 0x0A ("6th")
            + 1; // kind ("7th")

        if self.kind == PatchKind::Single {
                count += 1;  // for bank identifier
        }

        count += self.sub_bytes.len();  // 0 to max 19 (if block tone map present)
        count
    }
}

impl fmt::Display for Header {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{} {} {}, sub-bytes={:02X?}",
            self.cardinality,
            self.kind,
            if let Some(bank) = &self.bank_identifier {
                bank.to_string()
            } else {
                String::from("N/A")
            },
            self.sub_bytes
        )
    }
}

impl SystemExclusiveData for Header {
    fn from_bytes(data: &[u8]) -> Result<Self, ParseError> {
        if let Some(header) = Header::identify_vec(&data) {
            Ok(header)
        }
        else {
            Err(ParseError::InvalidData(0, "unidentified header".to_string()))
        }
    }

    fn to_bytes(&self) -> Vec<u8> {
        let mut result = vec![
            // Every dump command header has the MIDI channel.
            // into() converts channel to SysEx-compatible u8
            // (from 1...16 to 0...15)
            self.channel.value() as u8,

            self.cardinality.into(),

            // Every command header has these constant bytes:
            0x00,
            0x0A,

            // Kind is "7th" byte in the MIDI manual
            self.kind.into(),
        ];

        // Only single patches need a bank
        if self.kind == PatchKind::Single {
            result.push(self.bank_identifier.unwrap().into());
        }

        // Add any sub-bytes (zero or more).
        // For drum kit and drum instrument, and "Block PCM Bank B",
        // sub-bytes will be empty.
        result.extend(&self.sub_bytes);

        result
    }

    fn data_size() -> usize {
        unimplemented!()  // a header has no static size
    }
}

pub const MAX_TONE_COUNT: u8 = 128;

pub struct ToneMap {
    included: [bool; MAX_TONE_COUNT as usize],
}

impl ToneMap {
    pub fn new() -> Self {
        ToneMap { included: [false; MAX_TONE_COUNT as usize] }
    }

    pub fn is_included(&self, tone_number: u8) -> bool {
        self.included[tone_number as usize]
    }

    pub fn included_count(&self) -> usize {
        self.included.into_iter().filter(|b| *b).count()
    }
}

impl fmt::Display for ToneMap {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut output = String::from("");
        for i in 0..MAX_TONE_COUNT {
            if self.included[i as usize] {
                output.push_str(&format!("{} ", i + 1));
            }
        }
        write!(f, "{}", output)
    }
}

impl SystemExclusiveData for ToneMap {
    fn from_bytes(data: &[u8]) -> Result<Self, ParseError> {
        let mut included = [false; MAX_TONE_COUNT as usize];

        let mut i = 0;
        let mut tone_number = 0;
        while tone_number < MAX_TONE_COUNT {
            for n in 0..7 {
                //eprintln!("data[{}].bit({}) = {}  tone_number={}",
                //    i, n, data[i].bit(n), tone_number);
                included[tone_number as usize] = data[i].bit(n);
                tone_number += 1;
                if tone_number == MAX_TONE_COUNT {
                    break;
                }
            }
            i += 1;
        }

        Ok(ToneMap { included })
    }

    fn to_bytes(&self) -> Vec<u8> {
        let mut result = Vec::<u8>::new();

        // First, chunk the included bits into groups of seven.
        // This will result in 19 chunks, with two values in the last one.
        // Then distribute them evenly into bytes, six in each, starting
        // from the least significant bit. Start with a zero byte so that
        // the most significant bit is initialized to zero. For the last
        // byte, only the two least significant bits can ever be set.

        let chunks = self.included.chunks(7);
        for chunk in chunks {
            let mut byte = 0u8;  // all bits are initially zero
            for (n, bit) in chunk.iter().enumerate() {
                byte.set_bit(n, *bit);
            }
            result.push(byte);
        }

        assert_eq!(result.len(), ToneMap::data_size());

        result
    }

    fn data_size() -> usize { 19 }
}


#[cfg(test)]
mod tests {
    use super::{*};

    #[test]
    fn test_one_add_bank_a() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00 ]; // One ADD Bank A
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: Some(BankIdentifier::A),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_one_add_bank_d() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x00, 0x02, 0x00 ]; // One ADD Bank D
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: Some(BankIdentifier::D),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_one_exp_bank_e() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x00, 0x03, 0x00 ]; // One Exp Bank E
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: Some(BankIdentifier::E),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_one_exp_bank_f() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x00, 0x04, 0x00 ]; // One Exp Bank F
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: Some(BankIdentifier::F),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_one_multi() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x20, 0x00 ]; // One Multi
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: None,
                kind: PatchKind::Multi,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_block_add_bank_a() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x00, 0x00,
            /* tone map of 19 bytes follows */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];  // Block ADD Bank A

        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: Some(BankIdentifier::A),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00; 19]
            }
        );
    }

    #[test]
    fn test_block_add_bank_d() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x00, 0x02,
                    /* tone map of 19 bytes follows */
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];  // Block ADD Bank D
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: Some(BankIdentifier::D),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00; 19]
            }
        );
    }

    #[test]
    fn test_block_exp_bank_e() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x00, 0x03,
            /* tone map of 19 bytes follows */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];  // Block Exp Bank E
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: Some(BankIdentifier::E),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00; 19]
            }
        );
    }

    #[test]
    fn test_block_exp_bank_f() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x00, 0x04,
            /* tone map of 19 bytes follows */
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];  // Block Exp Bank F
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: Some(BankIdentifier::F),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00; 19]
            }
        );
    }

    #[test]
    fn test_block_multi() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x20 ]; // Block Multi
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: None,
                kind: PatchKind::Multi,
                sub_bytes: vec![]
            }
        );
    }

    #[test]
    fn test_one_pcm_bank_b() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x00, 0x01, 0x00 ]; // One PCM Bank B
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: Some(BankIdentifier::B),
                kind: PatchKind::Single,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_block_pcm_bank_b() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x00, 0x01 ]; // Block PCM Bank B
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: Some(BankIdentifier::B),
                kind: PatchKind::Single,
                sub_bytes: vec![]
            }
        );
    }

    #[test]
    fn test_one_drum_kit() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x10 ]; // One Drum Kit
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: None,
                kind: PatchKind::DrumKit,
                sub_bytes: vec![]
            }
        );
    }

    #[test]
    fn test_one_drum_instrument() {
        let cmd: Vec<u8> = vec![ 0x00, 0x20, 0x00, 0x0A, 0x11, 0x00 ]; // One Drum Instrument
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::One,
                bank_identifier: None,
                kind: PatchKind::DrumInstrument,
                sub_bytes: vec![0x00]
            }
        );
    }

    #[test]
    fn test_block_drum_instrument() {
        let cmd: Vec<u8> = vec![ 0x00, 0x21, 0x00, 0x0A, 0x11 ]; // Block Drum Instrument
        assert_eq!(
            Header::identify_vec(&cmd).unwrap(),
            Header {
                channel: MIDIChannel::new(1),
                cardinality: Cardinality::Block,
                bank_identifier: None,
                kind: PatchKind::DrumInstrument,
                sub_bytes: vec![]
            }
        );
    }
}