ot-tools-io 0.11.2

A library crate for reading/writing binary data files used by the Elektron Octatrack DPS-1.
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2026 Mike Robeson [dijksterhuis]
*/

//! Data structures for the Octatrack Project Settings 'Control Menu'.

use ot_tools_io_derive::{AsMutDerive, AsRefDerive};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use crate::projects::{
    parse_hashmap_string_value, parse_hashmap_string_value_bool, ProjectParseError,
};
use crate::settings::ProgChMidiChannel;

/// Convenience struct for all data related to the Octatrack Project Settings 'Control' Menu.

// todo: default
#[derive(
    Copy,
    Clone,
    Debug,
    Default,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct ControlMenu {
    /// 'Audio' page
    pub audio: AudioControlPage,

    /// 'Input' page
    pub input: InputControlPage,

    /// 'Sequencer' page
    pub sequencer: SequencerControlPage,

    /// 'MIDI Sequencer' page
    pub midi_sequencer: MidiSequencerControlPage,

    /// 'Memory' page
    pub memory: MemoryControlPage,

    /// 'Metronome' page
    pub metronome: MetronomeControlPage,

    /// 'Midi' sub menu
    pub midi: MidiSubMenu,
}

impl TryFrom<&HashMap<String, String>> for ControlMenu {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let audio = AudioControlPage::try_from(value)?;
        let input = InputControlPage::try_from(value)?;
        let sequencer = SequencerControlPage::try_from(value)?;
        let midi_sequencer = MidiSequencerControlPage {};
        let memory = MemoryControlPage::try_from(value)?;
        let metronome = MetronomeControlPage::try_from(value)?;
        let midi = MidiSubMenu::try_from(value)?;

        Ok(Self {
            audio,
            input,
            sequencer,
            midi_sequencer,
            memory,
            metronome,
            midi,
        })
    }
}

/// Convenience struct for all data related to the 'MIDI' sub-menu
/// within the Octatrack Project Settings 'Control' Menu.

// todo: default
#[derive(
    Copy,
    Clone,
    Debug,
    Default,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MidiSubMenu {
    pub control: MidiControlMidiPage,
    pub sync: MidiSyncMidiPage,
    pub channels: MidiChannelsMidiPage,
    // control_midi_turbo: todo!(),
}

impl TryFrom<&HashMap<String, String>> for MidiSubMenu {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let control = MidiControlMidiPage::try_from(value)?;
        let sync = MidiSyncMidiPage::try_from(value)?;
        let channels = MidiChannelsMidiPage::try_from(value)?;
        Ok(Self {
            control,
            sync,
            channels,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `AUDIO` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct AudioControlPage {
    /// `TRACK 8` setting. Whether Track 8 is a master audio track or not:
    /// - **NORMAL**: `false`
    /// - **MASTER**: `true`
    pub master_track: bool,

    /// `CUE CFG` setting. Behaviour for audio routing to CUE outputs.
    /// - **NORMAL** -> **CUE+TRACK** button combo sends audio to CUE out.
    /// - **STUDIO** -> Individual track volume controls for CUE out (unable to **CUE+TRACK**).
    pub cue_studio_mode: bool,
}

#[allow(clippy::derivable_impls)] // clear documentation for non-rustaceans
impl Default for AudioControlPage {
    fn default() -> Self {
        Self {
            master_track: false,
            cue_studio_mode: false,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for AudioControlPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let master_track = parse_hashmap_string_value_bool(value, "master_track", None)?;
        let cue_studio_mode = parse_hashmap_string_value_bool(value, "cue_studio_mode", None)?;

        Ok(Self {
            master_track,
            cue_studio_mode,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `INPUT` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct InputControlPage {
    /// dB level of noise gate for the AB external audio inputs.
    /// See Manual section 8.8 MIXER MENU
    pub gate_ab: u8,

    /// dB level of noise gate for the CD external audio inputs.
    /// See Manual section 8.8 MIXER MENU
    pub gate_cd: u8,

    /// See Manual section 8.6.2. INPUT.
    /// Adds a delay to incoming external audio signals. Controlled by the DIR setting on the MIXER page.
    pub input_delay_compensation: bool,
}

impl Default for InputControlPage {
    fn default() -> Self {
        Self {
            gate_ab: 127,
            gate_cd: 127,
            input_delay_compensation: false,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for InputControlPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let gate_ab = parse_hashmap_string_value::<u8>(value, "gate_ab", None)?;
        let gate_cd = parse_hashmap_string_value::<u8>(value, "gate_cd", None)?;
        let input_delay_compensation =
            parse_hashmap_string_value_bool(value, "input_delay_compensation", None)?;

        Ok(Self {
            gate_ab,
            gate_cd,
            input_delay_compensation,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `SEQUENCER` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct SequencerControlPage {
    /// `CHAIN AFTER` setting.
    /// When chained patterns start playing once the pattern is chosen.
    /// This is the global project level setting, but can be overidden for each pattern.
    /// Default setting is "PATTERN LENGTH".
    /// See Manual section 8.6.3. SEQUENCER.
    pub pattern_change_chain_behaviour: u8, // bool?

    /// `SILENCE TRACKS` setting
    /// Silence tracks when switching to a new pattern.
    /// See Manual section 8.6.3. SEQUENCER.
    pub pattern_change_auto_silence_tracks: bool,

    /// `LFO AUTO CHANGE` setting.
    /// Whether to retrigger LFOs when swtiching to a new pattern
    /// See Manual section 8.6.3. SEQUENCER.
    pub pattern_change_auto_trig_lfos: bool,
}

#[allow(clippy::derivable_impls)] // clear documentation for non-rustaceans
impl Default for SequencerControlPage {
    fn default() -> Self {
        SequencerControlPage {
            pattern_change_chain_behaviour: 0,
            pattern_change_auto_silence_tracks: false,
            pattern_change_auto_trig_lfos: false,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for SequencerControlPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let pattern_change_chain_behaviour =
            parse_hashmap_string_value::<u8>(value, "pattern_change_chain_behavior", None)?;
        let pattern_change_auto_silence_tracks =
            parse_hashmap_string_value_bool(value, "pattern_change_auto_trig_lfos", None)?;
        let pattern_change_auto_trig_lfos =
            parse_hashmap_string_value_bool(value, "pattern_change_auto_trig_lfos", None)?;

        Ok(Self {
            pattern_change_chain_behaviour,
            pattern_change_auto_silence_tracks,
            pattern_change_auto_trig_lfos,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `MIDI SEQUENCER` UI menu.
// TODO: ?!?!?!?! Where is the value for this??!?!?!
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MidiSequencerControlPage {}

#[allow(clippy::derivable_impls)] // clear documentation for non-rustaceans
impl Default for MidiSequencerControlPage {
    fn default() -> Self {
        Self {}
    }
}

/// `PROJECT` -> `CONTROL` -> `MEMORY` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MemoryControlPage {
    /// Whether samples can be loaded in 24-bit depth (16 bit depth samples are always oaded as 16 bit).
    /// Setting this to false loads all samples as 16 bit depth.
    /// See Manual section 8.6.5. MEMORY.
    pub load_24bit_flex: bool,

    /// Disabled forces all recorders to use track recorder memory (16 seconds per track).
    /// When enabled, track recorders can use free Flex RAM memory.
    /// See Manual section 8.6.5. MEMORY.
    pub dynamic_recorders: bool,

    /// Whether to record in 24 bit depth (`true`) or 16 bit depth (`false`).
    /// See Manual section 8.6.5. MEMORY.
    pub record_24bit: bool,

    /// How many active track recorders are available in a project. Controls whether TR1 through to TR8 are enabled / disabled.
    /// See Manual section 8.6.5. MEMORY.
    pub reserved_recorder_count: u8,

    /// How many 'sequencer steps' should be reserved for track recorders in RAM.
    /// See Manual section 8.6.5. MEMORY.
    pub reserved_recorder_length: u32,
}

impl Default for MemoryControlPage {
    fn default() -> Self {
        Self {
            load_24bit_flex: false,
            dynamic_recorders: false,
            record_24bit: false,
            reserved_recorder_count: 8,
            reserved_recorder_length: 16,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for MemoryControlPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let load_24bit_flex = parse_hashmap_string_value_bool(value, "load_24bit_flex", None)?;
        let dynamic_recorders = parse_hashmap_string_value_bool(value, "dynamic_recorders", None)?;
        let record_24bit = parse_hashmap_string_value_bool(value, "record_24bit", None)?;
        let reserved_recorder_count =
            parse_hashmap_string_value::<u8>(value, "reserved_recorder_count", None)?;
        let reserved_recorder_length =
            parse_hashmap_string_value::<u32>(value, "reserved_recorder_length", None)?;

        Ok(Self {
            load_24bit_flex,
            dynamic_recorders,
            record_24bit,
            reserved_recorder_count,
            reserved_recorder_length,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `METRONOME` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MetronomeControlPage {
    /// `TIME SIG. NUMER` setting in `PROJECT` -> `CONTROL` -> `METRONOME` UI menu.
    /// Controls the numerator for time signature (the 3 in 3/4).
    /// See Manual section 8.6.6 METRONOME
    pub metronome_time_signature: u8,

    /// `TIME SIG. DENOM` setting in `PROJECT` -> `CONTROL` -> `METRONOME` UI menu.
    /// Controls the numerator for time signature (the 3 in 3/4).
    /// See Manual section 8.6.6 METRONOME
    pub metronome_time_signature_denominator: u8,

    /// `PREROLL` setting in `PROJECT` -> `CONTROL` -> `METRONOME` UI menu.
    /// How many bars to prerolls with the metronome before playing a pattern.
    /// See Manual section 8.6.6 METRONOME
    pub metronome_preroll: u8,

    /// How loud to play the metronome on CUE outputs. Default is 32.
    /// See Manual section 8.6.6 METRONOME
    pub metronome_cue_volume: u8,

    /// How loud to play the metronome on MAIN outputs. Default is 0.
    /// See Manual section 8.6.6 METRONOME
    pub metronome_main_volume: u8,

    /// Pitch of the metronome clicks. Default is 12.
    /// See Manual section 8.6.6 METRONOME
    pub metronome_pitch: u8,

    /// Whether the metronome click has tonal characteristics or not. Default is `true` (enabled).
    /// See Manual section 8.6.6 METRONOME
    pub metronome_tonal: bool,

    /// Whether the metronome is active. Default is `false`.
    /// See Manual section 8.6.6 METRONOME
    pub metronome_enabled: bool,
}

impl Default for MetronomeControlPage {
    fn default() -> Self {
        Self {
            metronome_time_signature: 3,
            metronome_time_signature_denominator: 2,
            metronome_preroll: 0,
            metronome_cue_volume: 32,
            metronome_main_volume: 0,
            metronome_pitch: 12,
            metronome_tonal: true,
            metronome_enabled: false,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for MetronomeControlPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let metronome_time_signature =
            parse_hashmap_string_value::<u8>(value, "metronome_time_signature", None)?;
        let metronome_time_signature_denominator =
            parse_hashmap_string_value::<u8>(value, "metronome_time_signature_denominator", None)?;
        let metronome_preroll = parse_hashmap_string_value::<u8>(value, "metronome_preroll", None)?;
        let metronome_cue_volume =
            parse_hashmap_string_value::<u8>(value, "metronome_cue_volume", None)?;
        let metronome_main_volume =
            parse_hashmap_string_value::<u8>(value, "metronome_main_volume", None)?;
        let metronome_pitch = parse_hashmap_string_value::<u8>(value, "metronome_pitch", None)?;
        let metronome_tonal = parse_hashmap_string_value_bool(value, "metronome_tonal", None)?;
        let metronome_enabled = parse_hashmap_string_value_bool(value, "metronome_enabled", None)?;

        Ok(Self {
            metronome_time_signature,
            metronome_time_signature_denominator,
            metronome_preroll,
            metronome_cue_volume,
            metronome_main_volume,
            metronome_pitch,
            metronome_tonal,
            metronome_enabled,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `MIDI` -> `CONTROL` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MidiControlMidiPage {
    /// Whether samples can be loaded in 24-bit depth (16 bit depth samples are always odded as 16 bit).
    /// `AUDIO CC IN` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CONTROL` UI menu.
    /// Whether audio tracks respond to MIDI CC IN messages.
    ///
    /// See manual section 8.7.1 CONTROL.
    pub midi_audio_track_cc_in: bool,

    /// `AUDIO CC OUT` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CONTROL` UI menu.
    /// Whether audio tracks send MIDI CC OUT messages.
    /// Three options:
    /// - `INT`: No messages sent, knobs only affect Octatrack settings.
    /// - `EXT`: Sends CC OUT messages but they don't alter any Octatrack settings.
    /// - `INT+EXT`: Simultaneously affects Octatrack settings and sends CC OUT messages.
    ///
    /// See manual section 8.7.1 CONTROL.
    pub midi_audio_track_cc_out: u8,

    /// `AUDIO NOTE IN` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CONTROL` UI menu.
    /// Whether to receive MIDI NOTE IN messages on Audio tracks and how the audio tracks
    /// respond to those MIDI NOTE IN messages.
    /// - **OFF**: midi note has no effect.
    /// - **STANDARD**: standard note mapping (default).
    /// - **FOLLOW TM**: Track's current trig mode affects audio tracks (track/chromatic/slots).
    /// - **MAP/TRACK**: Uses MIDI MAP configuration on a per-track basis (track/chromatic/slots
    ///   disconnected from user trig mode of track).
    pub midi_audio_track_note_in: u8,

    /// `AUDIO NOTE OUT` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CONTROL` UI menu.
    /// Whether audio tracks send MIDI NOTE OUT messages. Three options:
    /// - `INT`: No messages sent, knobs only affect Octatrack settings.
    /// - `EXT`: Sends NOTE OUT messages but they don't alter any Octatrack settings.
    /// - `INT+EXT`: Simultaneously affects Octatrack settings and sends NOTE OUT messages.
    ///
    /// See manual section 8.7.1 CONTROL.
    pub midi_audio_track_note_out: u8,

    /// Unknown. MIDI channel to MIDI Track CC In messages n (1 - 16) ?
    pub midi_midi_track_cc_in: u8,
}

impl Default for MidiControlMidiPage {
    fn default() -> Self {
        Self {
            midi_audio_track_cc_in: true,
            midi_audio_track_cc_out: 3,
            midi_audio_track_note_in: 1,
            midi_audio_track_note_out: 3,
            midi_midi_track_cc_in: 1,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for MidiControlMidiPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let midi_audio_track_cc_in =
            parse_hashmap_string_value_bool(value, "midi_audio_trk_cc_in", None)?;

        let midi_audio_track_cc_out =
            parse_hashmap_string_value::<u8>(value, "midi_audio_trk_cc_out", None)?;

        let midi_audio_track_note_in =
            parse_hashmap_string_value::<u8>(value, "midi_audio_trk_note_in", None)?;

        let midi_audio_track_note_out =
            parse_hashmap_string_value::<u8>(value, "midi_audio_trk_note_out", None)?;

        let midi_midi_track_cc_in =
            parse_hashmap_string_value::<u8>(value, "midi_midi_trk_cc_in", None)?;

        Ok(Self {
            midi_audio_track_cc_in,
            midi_audio_track_cc_out,
            midi_audio_track_note_in,
            midi_audio_track_note_out,
            midi_midi_track_cc_in,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `MIDI` -> `SYNC` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MidiSyncMidiPage {
    /// `CLOCK SEND` setting.
    /// Whether MIDI clock sending is enabled/disabled
    /// See manual section 8.7.2 SYNC.
    pub midi_clock_send: bool,

    /// `CLOCK RECV` setting.
    /// Whether MIDI clock receiving is enabled/disabled
    /// See manual section 8.7.2 SYNC.
    pub midi_clock_receive: bool,

    /// `TRANS SEND` setting.
    /// Whether MIDI transport sending is enabled/disabled
    /// See manual section 8.7.2 SYNC.
    pub midi_transport_send: bool,

    /// `TRANS RECV` setting.
    /// Whether MIDI transport receiving is enabled/disabled
    /// See manual section 8.7.2 SYNC.
    pub midi_transport_receive: bool,

    /// `PROG CH SEND` setting.
    /// Whether MIDI Program Change sending is enabled/disabled
    /// See manual section 8.7.2 SYNC.
    pub midi_progchange_send: bool,

    /// `CHANNEL` setting.
    /// Channel to send MIDI Program Change messages on. `-1` = Auto, `0`-`15` = CH 1-16.
    /// See manual section 8.7.2 SYNC.
    pub midi_progchange_send_channel: ProgChMidiChannel,

    /// `PROG CH RECEIVE` setting.
    /// Whether MIDI Program Change receiving is enabled/disabled.
    /// See manual section 8.7.2 SYNC.
    pub midi_progchange_receive: bool,

    /// `CHANNEL` setting.
    /// Channel to receive MIDI Program Change messages on. `-1` = Auto, `0`-`15` = CH 1-16.
    /// See manual section 8.7.2 SYNC.
    pub midi_progchange_receive_channel: ProgChMidiChannel,
}

impl Default for MidiSyncMidiPage {
    fn default() -> Self {
        Self {
            midi_clock_send: false,
            midi_clock_receive: false,
            midi_transport_send: false,
            midi_transport_receive: false,
            midi_progchange_send: false,
            midi_progchange_send_channel: ProgChMidiChannel::Auto,
            midi_progchange_receive: false,
            midi_progchange_receive_channel: ProgChMidiChannel::Auto,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for MidiSyncMidiPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        /*
        WONTFIX: older OS versions seem to use non-boolean values for boolean settings.

        Some older projects seem to use different settings values for this.
        I had an OS 1.25E project (`ROMANT_DELETING`) where `MIDI_CLOCK_SEND=2`.
        But this is definitely boolean so `2` doesn't make sense here
        (see manual p. 40 and/or settings menu page).

        This probably applies to the other boolean values here. I probably won't fix
        this as it's an OS patching issue which can easily be fixed by users.
        */
        let midi_clock_send = parse_hashmap_string_value_bool(value, "midi_clock_send", None)?;

        // See WONTFIX note above. Observed in an old 1.25E project.
        let midi_clock_receive =
            parse_hashmap_string_value_bool(value, "midi_clock_receive", None)?;

        // See WONTFIX note above. Observed in an old 1.25E project.
        let midi_transport_send =
            parse_hashmap_string_value_bool(value, "midi_transport_send", None)?;

        // See WONTFIX note above. Observed in an old 1.25E project.
        let midi_transport_receive =
            parse_hashmap_string_value_bool(value, "midi_transport_receive", None)?;

        let midi_progchange_send =
            parse_hashmap_string_value_bool(value, "midi_program_change_send", None)?;

        let midi_progchange_send_channel = ProgChMidiChannel::try_from(
            &parse_hashmap_string_value::<i8>(value, "midi_program_change_send_ch", None)?,
        )?;

        let midi_progchange_receive =
            parse_hashmap_string_value_bool(value, "midi_program_change_receive", None)?;

        let midi_progchange_receive_channel = ProgChMidiChannel::try_from(
            &parse_hashmap_string_value::<i8>(value, "midi_program_change_receive_ch", None)?,
        )?;

        Ok(Self {
            midi_clock_send,
            midi_clock_receive,
            midi_transport_send,
            midi_transport_receive,
            midi_progchange_send,
            midi_progchange_send_channel,
            midi_progchange_receive,
            midi_progchange_receive_channel,
        })
    }
}

/// `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct MidiChannelsMidiPage {
    /// `TRIG CH 1` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 1 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch1: i8,

    /// `TRIG CH 2` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 2 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch2: i8,

    /// `TRIG CH 3` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 3 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch3: i8,

    /// `TRIG CH 4` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 4 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch4: i8,

    /// `TRIG CH 5` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 5 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch5: i8,

    /// `TRIG CH 6` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 6 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch6: i8,

    /// `TRIG CH 7` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 7 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch7: i8,

    /// `TRIG CH 8` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// MIDI Channel to send MIDI Trig 8 messages to (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_trig_ch8: i8,

    /// `AUTO CH` setting in `PROJECT` -> `CONTROL` -> `MIDI` -> `CHANNELS` UI menu.
    /// Auto MIDI Channel (1 - 16)
    /// See manual section 8.7.3 CHANNELS.
    ///
    /// NOTE: Can also be -1 for DISABLED
    pub midi_auto_channel: i8,
}

impl Default for MidiChannelsMidiPage {
    fn default() -> Self {
        Self {
            midi_trig_ch1: 0,
            midi_trig_ch2: 1,
            midi_trig_ch3: 2,
            midi_trig_ch4: 3,
            midi_trig_ch5: 4,
            midi_trig_ch6: 5,
            midi_trig_ch7: 6,
            midi_trig_ch8: 7,
            midi_auto_channel: 10,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for MidiChannelsMidiPage {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let midi_trig_ch1 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch1", None)?;
        let midi_trig_ch2 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch2", None)?;
        let midi_trig_ch3 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch3", None)?;
        let midi_trig_ch4 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch4", None)?;
        let midi_trig_ch5 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch5", None)?;
        let midi_trig_ch6 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch6", None)?;
        let midi_trig_ch7 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch7", None)?;
        let midi_trig_ch8 = parse_hashmap_string_value::<i8>(value, "midi_trig_ch8", None)?;
        let midi_auto_channel = parse_hashmap_string_value::<i8>(value, "midi_auto_channel", None)?;
        Ok(Self {
            midi_trig_ch1,
            midi_trig_ch2,
            midi_trig_ch3,
            midi_trig_ch4,
            midi_trig_ch5,
            midi_trig_ch6,
            midi_trig_ch7,
            midi_trig_ch8,
            midi_auto_channel,
        })
    }
}