@@ -43,6 +43,7 @@ const uint32_t kRightKey = stmlib::FourCC<'o', 'v', 'e', 'r'>::value;
43
43
// How long before unpatching an input actually breaks the chain.
44
44
const uint32_t kUnpatchedInputDelay = 2000 ;
45
45
const int32_t kLongPressDuration = 800 ;
46
+ const int32_t kVeryLongPressDuration = 3000 ;
46
47
47
48
void ChainState::Init (SerialLink* left, SerialLink* right) {
48
49
index_ = 0 ;
@@ -298,6 +299,14 @@ void ChainState::Configure(SegmentGenerator* segment_generator) {
298
299
!channel_state_[channel].input_patched ();
299
300
}
300
301
if (dirty || num_segments != segment_generator[i].num_segments ()) {
302
+ // The alt mode is only available for single segments.
303
+ if (num_segments != 1 ) {
304
+ for (int j = 0 ; j < num_segments; ++j) {
305
+ if (configuration[j].type == segment::TYPE_ALT) {
306
+ configuration[j].type = segment::TYPE_RAMP;
307
+ }
308
+ }
309
+ }
301
310
segment_generator[i].Configure (true , configuration, num_segments);
302
311
}
303
312
set_loop_status (i, 0 , last_loop);
@@ -471,16 +480,26 @@ void ChainState::PollSwitches() {
471
480
request_ = MakeLoopChangeRequest (first_pressed, switch_index);
472
481
switch_press_time_[first_pressed] = -1 ;
473
482
switch_press_time_[switch_index] = -1 ;
474
- } else if (switch_press_time_[switch_index] > kLongPressDuration ) {
475
- // Long press on a single button.
483
+ } else if (switch_press_time_[switch_index] == kLongPressDuration ) {
484
+ // Long press on a single button: send the loop change message
485
+ // only once.
476
486
request_ = MakeLoopChangeRequest (switch_index, switch_index);
487
+ } else if (switch_press_time_[switch_index] > kVeryLongPressDuration ) {
488
+ request_ = MakeLoopChangeRequest (switch_index, switch_index);
489
+ const bool valid_loop = request_.request != REQUEST_NONE;
490
+ const bool single_segment = \
491
+ request_.argument [0 ] == request_.argument [3 ] || \
492
+ request_.argument [0 ] == (request_.argument [3 ] - 1 );
493
+ if (valid_loop && single_segment) {
494
+ request_.request = REQUEST_SET_ALT_SEGMENT_TYPE;
495
+ }
477
496
switch_press_time_[switch_index] = -1 ;
478
497
} else {
479
498
first_pressed = switch_index;
480
499
}
481
500
}
482
501
} else {
483
- if (switch_press_time_[switch_index] > 5 ) {
502
+ if (switch_press_time_[switch_index] > 5 && switch_press_time_[switch_index] < kLongPressDuration ) {
484
503
// A button has been released after having been held for a
485
504
// sufficiently long time (5ms), but not for long enough to be
486
505
// detected as a long press.
@@ -509,15 +528,22 @@ void ChainState::HandleRequest(Settings* settings) {
509
528
uint8_t type_bits = s->segment_configuration [i] & 0x3 ;
510
529
uint8_t loop_bit = s->segment_configuration [i] & 0x4 ;
511
530
512
- if (request_.request == REQUEST_SET_SEGMENT_TYPE) {
531
+ if (request_.request == REQUEST_SET_ALT_SEGMENT_TYPE) {
532
+ if (channel == request_.argument [0 ]) {
533
+ type_bits = 0x3 ;
534
+ loop_bit = 0x4 ;
535
+ dirty = true ;
536
+ }
537
+ } else if (request_.request == REQUEST_SET_SEGMENT_TYPE) {
513
538
if (channel == request_.argument [0 ]) {
514
- s-> segment_configuration [i] = ((type_bits + 1 ) % 3 ) | loop_bit ;
539
+ type_bits = ((type_bits + 1 ) % 3 );
515
540
dirty |= true ;
516
541
}
517
542
} else if (request_.request == REQUEST_SET_LOOP) {
518
543
uint8_t new_loop_bit = loop_bit;
519
544
if ((channel >= request_.argument [0 ] && channel < request_.argument [3 ])) {
520
545
new_loop_bit = 0x0 ;
546
+ type_bits = type_bits % 3 ;
521
547
}
522
548
if (channel == request_.argument [1 ] || channel == request_.argument [2 ]) {
523
549
if (request_.argument [1 ] == request_.argument [2 ]) {
@@ -526,9 +552,10 @@ void ChainState::HandleRequest(Settings* settings) {
526
552
new_loop_bit = 0x4 ;
527
553
}
528
554
}
529
- s->segment_configuration [i] = type_bits | new_loop_bit;
530
555
dirty |= new_loop_bit != loop_bit;
556
+ loop_bit = new_loop_bit;
531
557
}
558
+ s->segment_configuration [i] = type_bits | loop_bit;
532
559
}
533
560
534
561
if (dirty) {
0 commit comments