rytm_rs/object/settings/
types.rs

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
use crate::error::ConversionError;
use serde::{Deserialize, Serialize};

/// The six sequential square buttons on the right side of the Analog Rytm MKII. Fx mode off.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum ParameterMenuItem {
    Trig,
    #[default]
    Src,
    Smpl,
    Fltr,
    Amp,
    Lfo,
}

impl TryFrom<&str> for ParameterMenuItem {
    type Error = ConversionError;
    fn try_from(parameter_menu_item: &str) -> Result<Self, Self::Error> {
        match parameter_menu_item {
            "trig" => Ok(Self::Trig),
            "src" => Ok(Self::Src),
            "smpl" => Ok(Self::Smpl),
            "fltr" => Ok(Self::Fltr),
            "amp" => Ok(Self::Amp),
            "lfo" => Ok(Self::Lfo),
            _ => Err(ConversionError::Range {
                value: parameter_menu_item.to_string(),
                type_name: "ParameterMenuItem".into(),
            }),
        }
    }
}

impl From<ParameterMenuItem> for &str {
    fn from(parameter_menu_item: ParameterMenuItem) -> Self {
        match parameter_menu_item {
            ParameterMenuItem::Trig => "trig",
            ParameterMenuItem::Src => "src",
            ParameterMenuItem::Smpl => "smpl",
            ParameterMenuItem::Fltr => "fltr",
            ParameterMenuItem::Amp => "amp",
            ParameterMenuItem::Lfo => "lfo",
        }
    }
}

impl TryFrom<u8> for ParameterMenuItem {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::Trig),
            1 => Ok(Self::Src),
            2 => Ok(Self::Smpl),
            3 => Ok(Self::Fltr),
            4 => Ok(Self::Amp),
            5 => Ok(Self::Lfo),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "ParameterMenuItem".into(),
            }),
        }
    }
}

impl From<ParameterMenuItem> for u8 {
    fn from(parameter_menu_item: ParameterMenuItem) -> Self {
        match parameter_menu_item {
            ParameterMenuItem::Trig => 0,
            ParameterMenuItem::Src => 1,
            ParameterMenuItem::Smpl => 2,
            ParameterMenuItem::Fltr => 3,
            ParameterMenuItem::Amp => 4,
            ParameterMenuItem::Lfo => 5,
        }
    }
}

/// The six sequential square buttons on the right side of the Analog Rytm MKII. Fx mode on.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum FxParameterMenuItem {
    Trig,
    #[default]
    Delay,
    Reverb,
    Dist,
    Comp,
    Lfo,
}

impl TryFrom<&str> for FxParameterMenuItem {
    type Error = ConversionError;
    fn try_from(fx_parameter_menu_item: &str) -> Result<Self, Self::Error> {
        match fx_parameter_menu_item {
            "trig" => Ok(Self::Trig),
            "delay" => Ok(Self::Delay),
            "reverb" => Ok(Self::Reverb),
            "dist" => Ok(Self::Dist),
            "comp" => Ok(Self::Comp),
            "lfo" => Ok(Self::Lfo),
            _ => Err(ConversionError::Range {
                value: fx_parameter_menu_item.to_string(),
                type_name: "FxParameterMenuItem".into(),
            }),
        }
    }
}

impl From<FxParameterMenuItem> for &str {
    fn from(fx_parameter_menu_item: FxParameterMenuItem) -> Self {
        match fx_parameter_menu_item {
            FxParameterMenuItem::Trig => "trig",
            FxParameterMenuItem::Delay => "delay",
            FxParameterMenuItem::Reverb => "reverb",
            FxParameterMenuItem::Dist => "dist",
            FxParameterMenuItem::Comp => "comp",
            FxParameterMenuItem::Lfo => "lfo",
        }
    }
}

impl TryFrom<u8> for FxParameterMenuItem {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::Trig),
            1 => Ok(Self::Delay),
            2 => Ok(Self::Reverb),
            3 => Ok(Self::Dist),
            4 => Ok(Self::Comp),
            5 => Ok(Self::Lfo),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "FxParameterMenuItem".into(),
            }),
        }
    }
}

impl From<FxParameterMenuItem> for u8 {
    fn from(fx_parameter_menu_item: FxParameterMenuItem) -> Self {
        match fx_parameter_menu_item {
            FxParameterMenuItem::Trig => 0,
            FxParameterMenuItem::Delay => 1,
            FxParameterMenuItem::Reverb => 2,
            FxParameterMenuItem::Dist => 3,
            FxParameterMenuItem::Comp => 4,
            FxParameterMenuItem::Lfo => 5,
        }
    }
}

/// - Normal operation mode is the default mode. In this mode, the sequencer plays the selected pattern in a loop.
/// - Chain mode is used to chain patterns together into a chain. The chain is played in a loop.
/// - Song mode is used to chain patterns together into a song. The song is played once from start to finish.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum SequencerMode {
    #[default]
    Normal,
    Chain,
    Song,
}

impl TryFrom<&str> for SequencerMode {
    type Error = ConversionError;
    fn try_from(sequencer_mode: &str) -> Result<Self, Self::Error> {
        match sequencer_mode {
            "normal" => Ok(Self::Normal),
            "chain" => Ok(Self::Chain),
            "song" => Ok(Self::Song),
            _ => Err(ConversionError::Range {
                value: sequencer_mode.to_string(),
                type_name: "SequencerMode".into(),
            }),
        }
    }
}

impl From<SequencerMode> for &str {
    fn from(sequencer_mode: SequencerMode) -> Self {
        match sequencer_mode {
            SequencerMode::Normal => "normal",
            SequencerMode::Chain => "chain",
            SequencerMode::Song => "song",
        }
    }
}

impl TryFrom<u8> for SequencerMode {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::Normal),
            1 => Ok(Self::Chain),
            2 => Ok(Self::Song),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "SequencerMode".into(),
            }),
        }
    }
}

impl From<SequencerMode> for u8 {
    fn from(sequencer_mode: SequencerMode) -> Self {
        match sequencer_mode {
            SequencerMode::Normal => 0,
            SequencerMode::Chain => 1,
            SequencerMode::Song => 2,
        }
    }
}

/// # Excerpt from the manual
///
/// When changing patterns, different modes affecting the way the active pattern will be changed exist.
///
/// Press `[FUNC]` + `[BANK A–D]` to select PATTERN mode. The <PATTERN MODE> LEDs indicate which mode is
/// selected.
///
/// There are four PATTERN modes.
///
/// - SEQUENTIAL changes patterns after the currently playing pattern reaches its end. This mode is the default mode.
/// - DIRECT START immediately changes patterns. The new pattern will start playing from the beginning.
/// - DIRECT JUMP immediately changes patterns. The new pattern will start playing from the position where the previous pattern left off.
/// - TEMP JUMP works a little bit differently from the other PATTERN modes. It works like this:
///
/// 1. Press `[FUNC]` + `[BANK D]` to arm TEMP JUMP PATTERN mode. The Temp Jump LED starts to flash (if the sequencer is running) to indicate that Temp Jump mode is armed.
/// 2. Select a new pattern. The Temp Jump LED is now firmly lit to indicate that Temp Jump mode is active
///     The pattern changes immediately and the new pattern starts playing from the position where the previous
///     pattern left off. It plays the new pattern once to the end and then return to the pattern that was
///     playing before the change. Once the sequencer has returned to the earlier pattern, then TEMP JUMP
///     mode is no longer active.
///
/// You can also use TEMP JUMP mode when you are in CHAIN mode, but then the pattern you change to
/// instead replaces the current pattern in the chain. For example, say that you have a chain set up like this:
/// A01 > A03 > A04 > A02. When the chain is playing, and you are in TEMP JUMP mode, change pattern to
/// A16 while pattern A03 is playing. The pattern will immediately change to A16 and once A16 has ended
/// then the chain will continue to play from pattern A04.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum PatternMode {
    #[default]
    Sequential,
    DirectStart,
    DirectJump,
    TempJump,
}

impl TryFrom<&str> for PatternMode {
    type Error = ConversionError;
    fn try_from(pattern_mode: &str) -> Result<Self, Self::Error> {
        match pattern_mode {
            "sequential" => Ok(Self::Sequential),
            "directstart" => Ok(Self::DirectStart),
            "directjump" => Ok(Self::DirectJump),
            "tempjump" => Ok(Self::TempJump),
            _ => Err(ConversionError::Range {
                value: pattern_mode.to_string(),
                type_name: "PatternMode".into(),
            }),
        }
    }
}

impl From<PatternMode> for &str {
    fn from(pattern_mode: PatternMode) -> Self {
        match pattern_mode {
            PatternMode::Sequential => "sequential",
            PatternMode::DirectStart => "directstart",
            PatternMode::DirectJump => "directjump",
            PatternMode::TempJump => "tempjump",
        }
    }
}

impl TryFrom<u8> for PatternMode {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::Sequential),
            1 => Ok(Self::DirectStart),
            2 => Ok(Self::DirectJump),
            3 => Ok(Self::TempJump),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "PatternMode".into(),
            }),
        }
    }
}

impl From<PatternMode> for u8 {
    fn from(pattern_mode: PatternMode) -> Self {
        match pattern_mode {
            PatternMode::Sequential => 0,
            PatternMode::DirectStart => 1,
            PatternMode::DirectJump => 2,
            PatternMode::TempJump => 3,
        }
    }
}

/// # Excerpt from the manual
///
/// Source selects between different audio sources to sample from.
/// - AUD L+R sets the input source to sample external audio through the AUDIO IN L+R inputs. The
///     audio is summed together to mono.
/// - AUD L sets the input source to AUDIO IN L.
/// - AUD R sets the input source to AUDIO IN R.
/// - BD, SD, RS/CP, BT, LT, MT/HT, CH/OH, CY/CB sets the input source to the internal audio from the
///     separate drum tracks.
/// - MAIN sets the input source to the internal MAIN L+R channels. The audio is summed together to
///     mono.
/// - USB L+R sets the input source to sample external audio (from both left and right channel) through
///     the USB input. The audio is summed together to mono.
/// - USB L sets the input source to sample external audio from only the left channel of the incoming
///     audio from the USB input.
/// - USB R sets the input source to sample external audio from only the right channel of the incoming
///     audio from the USB input.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum SampleRecorderSource {
    #[default]
    AudLPlusR,
    AudL,
    AudR,
    Bd,
    Sd,
    RsCp,
    Bt,
    Lt,
    MtHt,
    ChOh,
    CyCb,
    Main,
    UsbL,
    UsbR,
    UsbLPlusR,
}

impl TryFrom<&str> for SampleRecorderSource {
    type Error = ConversionError;
    fn try_from(sample_recorder_source: &str) -> Result<Self, Self::Error> {
        match sample_recorder_source {
            "audl+r" => Ok(Self::AudLPlusR),
            "audl" => Ok(Self::AudL),
            "audr" => Ok(Self::AudR),
            "bd" => Ok(Self::Bd),
            "sd" => Ok(Self::Sd),
            "rs/cp" => Ok(Self::RsCp),
            "bt" => Ok(Self::Bt),
            "lt" => Ok(Self::Lt),
            "mt/ht" => Ok(Self::MtHt),
            "ch/oh" => Ok(Self::ChOh),
            "cy/cb" => Ok(Self::CyCb),
            "main" => Ok(Self::Main),
            "usbl" => Ok(Self::UsbL),
            "usbr" => Ok(Self::UsbR),
            "usbl+r" => Ok(Self::UsbLPlusR),
            _ => Err(ConversionError::Range {
                value: sample_recorder_source.to_string(),
                type_name: "SampleRecorderSource".into(),
            }),
        }
    }
}

impl From<SampleRecorderSource> for &str {
    fn from(sample_recorder_source: SampleRecorderSource) -> Self {
        match sample_recorder_source {
            SampleRecorderSource::AudLPlusR => "audl+r",
            SampleRecorderSource::AudL => "audl",
            SampleRecorderSource::AudR => "audr",
            SampleRecorderSource::Bd => "bd",
            SampleRecorderSource::Sd => "sd",
            SampleRecorderSource::RsCp => "rs/cp",
            SampleRecorderSource::Bt => "bt",
            SampleRecorderSource::Lt => "lt",
            SampleRecorderSource::MtHt => "mt/ht",
            SampleRecorderSource::ChOh => "ch/oh",
            SampleRecorderSource::CyCb => "cy/cb",
            SampleRecorderSource::Main => "main",
            SampleRecorderSource::UsbL => "usbl",
            SampleRecorderSource::UsbR => "usbr",
            SampleRecorderSource::UsbLPlusR => "usbl+r",
        }
    }
}

impl TryFrom<u8> for SampleRecorderSource {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::AudLPlusR),
            1 => Ok(Self::AudL),
            2 => Ok(Self::AudR),
            3 => Ok(Self::Bd),
            4 => Ok(Self::Sd),
            5 => Ok(Self::RsCp),
            6 => Ok(Self::Bt),
            7 => Ok(Self::Lt),
            8 => Ok(Self::MtHt),
            9 => Ok(Self::ChOh),
            10 => Ok(Self::CyCb),
            11 => Ok(Self::Main),
            12 => Ok(Self::UsbL),
            13 => Ok(Self::UsbR),
            14 => Ok(Self::UsbLPlusR),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "SampleRecorderSource".into(),
            }),
        }
    }
}

impl From<SampleRecorderSource> for u8 {
    fn from(sample_recorder_source: SampleRecorderSource) -> Self {
        match sample_recorder_source {
            SampleRecorderSource::AudLPlusR => 0,
            SampleRecorderSource::AudL => 1,
            SampleRecorderSource::AudR => 2,
            SampleRecorderSource::Bd => 3,
            SampleRecorderSource::Sd => 4,
            SampleRecorderSource::RsCp => 5,
            SampleRecorderSource::Bt => 6,
            SampleRecorderSource::Lt => 7,
            SampleRecorderSource::MtHt => 8,
            SampleRecorderSource::ChOh => 9,
            SampleRecorderSource::CyCb => 10,
            SampleRecorderSource::Main => 11,
            SampleRecorderSource::UsbL => 12,
            SampleRecorderSource::UsbR => 13,
            SampleRecorderSource::UsbLPlusR => 14,
        }
    }
}

/// # Excerpt from the manual
///
/// Record Length sets the length of the sampling. With a setting of 1–128 steps, the sampling length is
/// decided by the time that it takes the sequencer to advance the set number of steps at the current BPM.
/// With the MAX setting, the sampling continues until max sampling time (33 seconds) is reached or until
/// you press `[YES]` to stop sampling.
///
/// With a BPM set lower than 59, recording the complete 128 steps is not possible because
/// it will take longer than the maximum sampling time. If the device cannot record the entire
/// set length, this is shown by two exclamation marks next to the sample memory time on the
/// screen.
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub enum SampleRecorderRecordingLength {
    _1Step,
    _2Steps,
    _4Steps,
    _8Steps,
    _16Steps,
    _32Steps,
    _64Steps,
    _128Steps,
    #[default]
    Max,
}

impl TryFrom<&str> for SampleRecorderRecordingLength {
    type Error = ConversionError;
    fn try_from(sample_recorder_recording_length: &str) -> Result<Self, Self::Error> {
        match sample_recorder_recording_length {
            "1step" => Ok(Self::_1Step),
            "2steps" => Ok(Self::_2Steps),
            "4steps" => Ok(Self::_4Steps),
            "8steps" => Ok(Self::_8Steps),
            "16steps" => Ok(Self::_16Steps),
            "32steps" => Ok(Self::_32Steps),
            "64steps" => Ok(Self::_64Steps),
            "128steps" => Ok(Self::_128Steps),
            "max" => Ok(Self::Max),
            _ => Err(ConversionError::Range {
                value: sample_recorder_recording_length.to_string(),
                type_name: "SampleRecorderRecordingLength".into(),
            }),
        }
    }
}

impl From<SampleRecorderRecordingLength> for &str {
    fn from(sample_recorder_recording_length: SampleRecorderRecordingLength) -> Self {
        match sample_recorder_recording_length {
            SampleRecorderRecordingLength::_1Step => "1step",
            SampleRecorderRecordingLength::_2Steps => "2steps",
            SampleRecorderRecordingLength::_4Steps => "4steps",
            SampleRecorderRecordingLength::_8Steps => "8steps",
            SampleRecorderRecordingLength::_16Steps => "16steps",
            SampleRecorderRecordingLength::_32Steps => "32steps",
            SampleRecorderRecordingLength::_64Steps => "64steps",
            SampleRecorderRecordingLength::_128Steps => "128steps",
            SampleRecorderRecordingLength::Max => "max",
        }
    }
}

impl TryFrom<u8> for SampleRecorderRecordingLength {
    type Error = ConversionError;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::_1Step),
            1 => Ok(Self::_2Steps),
            2 => Ok(Self::_4Steps),
            3 => Ok(Self::_8Steps),
            4 => Ok(Self::_16Steps),
            5 => Ok(Self::_32Steps),
            6 => Ok(Self::_64Steps),
            7 => Ok(Self::_128Steps),
            8 => Ok(Self::Max),
            _ => Err(ConversionError::Range {
                value: value.to_string(),
                type_name: "SampleRecorderRecordingLength".into(),
            }),
        }
    }
}

impl From<SampleRecorderRecordingLength> for u8 {
    fn from(sample_recorder_recording_length: SampleRecorderRecordingLength) -> Self {
        match sample_recorder_recording_length {
            SampleRecorderRecordingLength::_1Step => 0,
            SampleRecorderRecordingLength::_2Steps => 1,
            SampleRecorderRecordingLength::_4Steps => 2,
            SampleRecorderRecordingLength::_8Steps => 3,
            SampleRecorderRecordingLength::_16Steps => 4,
            SampleRecorderRecordingLength::_32Steps => 5,
            SampleRecorderRecordingLength::_64Steps => 6,
            SampleRecorderRecordingLength::_128Steps => 7,
            SampleRecorderRecordingLength::Max => 8,
        }
    }
}