Etterna 0.74.4
Loading...
Searching...
No Matches
CJOHAnchor.h
1#pragma once
2#include "../MetaIntervalHandInfo.h"
3#include "../HD_Sequencers/CJOHASequencing.h"
4
10{
11 const CalcPatternMod _pmod = CJOHAnchor;
12 const std::string name = "CJOHAnchorMod";
13
14#pragma region params
15
16 float min_mod = 1.F;
17 float max_mod = 1.1F;
18 float base = .5F;
19
20 float len_scaler = 0.2F;
21 float anchor_len_weight = 1.F;
22 float swap_scaler = 0.10775F;
23 float not_swap_scaler = 0.019F;
24
25 const std::vector<std::pair<std::string, float*>> _params{
26 { "min_mod", &min_mod },
27 { "max_mod", &max_mod },
28 { "base", &base },
29
30 { "len_scaler", &len_scaler },
31 { "anchor_len_weight", &anchor_len_weight },
32 { "swap_scaler", &swap_scaler },
33 { "not_swap_scaler", &not_swap_scaler },
34 };
35#pragma endregion params and param map
36
38 int max_chain_swaps = 0;
39 int max_not_swaps = 0;
40 int max_total_len = 0;
41 int max_anchor_len = 0;
42
43 float pmod = neutral;
44
45#pragma region generic functions
46
47 void full_reset()
48 {
49 chain.zero();
50
51 max_chain_swaps = 0;
52 max_not_swaps = 0;
53 max_total_len = 0;
54 max_anchor_len = 0;
55
56 pmod = neutral;
57 }
58
59#pragma endregion
60
61 void advance_sequencing(const col_type& ct, const base_type& bt, const col_type& last_ct, const float& any_ms)
62 {
63 chain(ct, bt, last_ct, any_ms);
64 }
65
66 void set_pmod(const metaItvHandInfo& mitvhi)
67 {
68 const auto& itvhi = mitvhi._itvhi;
69 const auto& base_types = mitvhi._base_types;
70
71 // if cur > max when we ended the interval, grab it
72 max_chain_swaps = chain.get_max_chain_swaps();
73 max_not_swaps = chain.get_max_not_swaps();
74 max_total_len = chain.get_max_total_len();
75 max_anchor_len = chain.get_max_anchor_len();
76
77 // nothing here
78 if (itvhi.get_taps_nowi() == 0) {
79 pmod = neutral;
80 return;
81 }
82
83 // pmod = base + (sum)
84 // max anchor / total rows * scale
85 // max swaps / total rows * scale
86
87 // an interval with only jacks of 11112222 has no completed seq
88 // the clamp should catch that scenario
89 // otherwise assume conditions which continue chains are in chains
90 auto taps_in_any_sequence = std::clamp(base_types[base_single_single] +
91 base_types[base_single_jump] +
92 base_types[base_jump_single],
93 1,
94 std::max(1, max_total_len));
95 auto tapsF = static_cast<float>(taps_in_any_sequence);
96
97 // 11[12]22
98 auto csF = static_cast<float>(max_chain_swaps);
99 // 11[12]11
100 // auto cnF = static_cast<float>(max_not_swaps);
101 // 111[12]222 = 1[12]2[12]1[12]2
102 auto clF = static_cast<float>(max_total_len);
103 // 1[12]2[12]1[12]2 = small number < 11111111111[12]2222
104 auto caF = static_cast<float>(max_anchor_len);
105
106 // anchor_len_weight should be [0,1]
107 // 1 -> worth = entire chain length
108 // 0 -> worth = longest anchor length
109 auto anchor_len_worth =
110 weighted_average(clF, caF, anchor_len_weight, 1.F);
111
112 auto anchor_worth = fastsqrt(anchor_len_worth / tapsF) * len_scaler;
113 auto swap_worth = fastsqrt(csF / tapsF) * swap_scaler;
114 // auto not_swap_worth = fastsqrt(cnF / tapsF) * not_swap_scaler;
115 pmod = std::clamp(base + anchor_worth + swap_worth + not_swap_scaler, min_mod, max_mod);
116 }
117
118 auto operator()(const metaItvHandInfo& mitvhi) -> float
119 {
120 set_pmod(mitvhi);
121
122 interval_end();
123 return pmod;
124 }
125
126 void interval_end()
127 {
128 // reset any interval stuff here
129 chain.reset_max_seq();
130 max_chain_swaps = 0;
131 max_not_swaps = 0;
132 max_total_len = 0;
133 max_anchor_len = 0;
134 }
135};
Definition CJOHAnchor.h:10
Definition CJOHASequencing.h:33
this may prove to be overkill
Definition MetaIntervalHandInfo.h:6