Etterna 0.74.4
Loading...
Searching...
No Matches
CJOHASequencing.h
1#pragma once
2
5constexpr float chain_slowdown_scale_threshold = 1.99F;
6
33{
34 int chain_swaps = 0;
35 int not_swaps = 0;
36 int cur_len = 0;
37 int cur_anchor_len = 0;
38 bool chain_swapping = false;
39
40 int max_chain_swaps = 0;
41 int max_not_swaps = 0;
42 int max_total_len = 0;
43 int max_anchor_len = 0;
44 col_type anchor_col = col_init;
45 float last_ms = ms_init;
46
47 void zero()
48 {
49 reset_max_seq();
50 reset_seq();
51 last_ms = ms_init;
52 }
53
54 void reset_seq() {
55 chain_swaps = 0;
56 not_swaps = 0;
57 cur_len = 0;
58 cur_anchor_len = 0;
59
60 chain_swapping = false;
61 anchor_col = col_init;
62 // not resetting ms time here
63 }
64
65 void reset_max_seq() {
66 max_chain_swaps = 0;
67 max_not_swaps = 0;
68 max_total_len = 0;
69 max_anchor_len = 0;
70 }
71
72 void update_max_seq() {
73 max_chain_swaps = get_max_chain_swaps();
74 max_not_swaps = get_max_not_swaps();
75 max_total_len = get_max_total_len();
76 max_anchor_len = get_max_anchor_len();
77 }
78
81 {
82 assert(cur_len >= 0);
83
84 // if a chain swap was in progress
85 // we ended on a jump -- the gap after was too big.
86 // to capture the difficulty of the jump, fail a swap
87 if (chain_swapping) {
89 }
90
91 // remove this check to consider 1111122222 a chain
92 // otherwise, only 11111[12]22222 is a chain
93 // and 11111[12]11111 also qualifies
94 if (chain_swaps != 0 || not_swaps != 0) {
95 update_max_seq();
96 }
97
98 // reset curr chain info
99 reset_seq();
100 }
101
108 {
109 chain_swapping = false;
110 max_anchor_len = get_max_anchor_len();
111 cur_anchor_len = 0;
112 chain_swaps++;
113 }
114
121 {
122 chain_swapping = false;
123 not_swaps++;
124 // anchor continues ...
125 }
126
127 void operator()(const col_type& ct, const base_type& bt, const col_type& last_ct, const float& any_ms)
128 {
129 if (last_ms * chain_slowdown_scale_threshold < any_ms) {
130 // if the taps were too slow, reset
131 complete_seq();
132 }
133 last_ms = any_ms;
134
135 switch (bt) {
136 case base_left_right:
137 case base_right_left:
138 // not a chain ...
139 // not an anchor ...
140 // end it
141 complete_seq();
142 break;
143 case base_jump_jump:
144 // allow [12][12] to continue a chain
145 // anchor_col does not change
146 cur_len++;
147 cur_anchor_len++;
148
149 // starting with jumps? no thanks
150 if (anchor_col != col_init)
151 chain_swapping = true;
152 break;
153 case base_single_single:
154 // consecutive 11 or 22
155 // mid chain or about to chain
156 anchor_col = ct;
157 cur_len++;
158 cur_anchor_len++;
159 break;
160 case base_single_jump:
161 // 1[12] or 2[12]
162 // chain expects a swap in columns
163 // or may complete
164 anchor_col = last_ct; // set to the column we used to be on
165 cur_len++;
166 chain_swapping = true;
167 break;
168 case base_jump_single:
169 // [12]1 or [12]2
170 // chain continuing
171 cur_len++;
172 cur_anchor_len++;
173
174 if ((anchor_col == col_left && ct == col_right) ||
175 (anchor_col == col_right && ct == col_left)) {
176 // valid to swap columns and continue
177
178 // cope with swaps
179 if (chain_swapping) {
180 chain_swap();
181 }
182 } else {
183 // anchor is continuing
184 // jump was just ... a jump
185
186 // was trying to swap but failed
187 if (chain_swapping) {
188 swap_failed();
189 }
190 }
191 // this is currently the anchoring column
192 anchor_col = ct;
193
194 break;
195 case base_type_init:
196 // no info
197 break;
198 default:
199 assert(0);
200 break;
201 }
202
203 }
204
205 int get_max_total_len() {
206 return cur_len > max_total_len ? cur_len : max_total_len;
207 }
208
209 int get_max_anchor_len() {
210 return cur_anchor_len > max_anchor_len ? cur_anchor_len
211 : max_anchor_len;
212 }
213
214 int get_max_chain_swaps() {
215 return chain_swaps > max_chain_swaps ? chain_swaps : max_chain_swaps;
216 }
217
218 int get_max_not_swaps() {
219 return not_swaps > max_not_swaps ? not_swaps : max_not_swaps;
220 }
221};
Definition CJOHASequencing.h:33
void complete_seq()
to reset the current chain and continue a new one
Definition CJOHASequencing.h:80
void swap_failed()
Definition CJOHASequencing.h:120
void chain_swap()
Definition CJOHASequencing.h:107