Skip to content

Commit

Permalink
vaguely functional and horribly tuned nkey calc | 514
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Sep 25, 2024
1 parent 359eb0a commit 969196d
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 68 deletions.
46 changes: 13 additions & 33 deletions src/Etterna/MinaCalc/Dependent/HD_PatternMods/GenericBracketing.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ struct GBracketingMod
{ "total_prop_max", &total_prop_max },
{ "total_prop_base", &total_prop_base },

{ "split_hand_pool", &split_hand_pool },
{ "split_hand_min", &split_hand_min },
{ "split_hand_max", &split_hand_max },
{ "split_hand_scaler", &split_hand_scaler },

{ "jack_pool", &jack_pool },
{ "jack_min", &jack_min },
{ "jack_max", &jack_max },
{ "jack_scaler", &jack_scaler },

{ "decay_factor", &decay_factor },
};
#pragma endregion params and param map
Expand All @@ -67,6 +57,7 @@ struct GBracketingMod
float last_mod = min_mod;
float pmod = min_mod;
float t_taps = 0.F;
float bracket_taps = 0.F;

void full_reset()
{
Expand All @@ -79,43 +70,32 @@ struct GBracketingMod
last_mod = pmod;
}

auto operator()(const metaItvInfo& mitvi, const metaItvGenericHandInfo& mitvghi) -> float
auto operator()(const metaItvGenericHandInfo& mitvghi) -> float
{
const auto& itvi = mitvi._itvi;

// empty interval, don't decay mod or update last_mod
if (itvi.total_taps == 0) {
if (mitvghi.total_taps == 0) {
return neutral;
}

// look ma no hands
if (itvi.taps_by_size.at(min_tap_size) == 0) {
// definitely no brackets, decay
if (mitvghi.taps_bracketing == 0) {
decay_mod();
return pmod;
}

t_taps = static_cast<float>(itvi.total_taps);
t_taps = static_cast<float>(mitvghi.total_taps);
bracket_taps = static_cast<float>(mitvghi.taps_bracketing);

// when bark of dog into canyon scream at you
total_prop = total_prop_base +
(static_cast<float>((itvi.taps_by_size.at(min_tap_size)) +
prop_buffer) /
(t_taps - prop_buffer) * total_prop_scaler);
total_prop =
total_prop_base + ((bracket_taps + prop_buffer) /
(t_taps - prop_buffer) * total_prop_scaler);
total_prop =
std::clamp(fastsqrt(total_prop), total_prop_min, total_prop_max);

// downscale by jack density rather than upscale, like cj does
jack_prop = std::clamp(
jack_pool - (static_cast<float>(mitvi.actual_jacks) / t_taps),
jack_min,
jack_max);

pmod =
std::clamp(total_prop * jumptrill_prop * jack_prop, min_mod, max_mod);
// limits
pmod = std::clamp(total_prop, min_mod, max_mod);

// set last mod, we're using it to create a decaying mod that won't
// result in extreme spikiness if files alternate between js and
// hs/stream
// for decay
last_mod = pmod;

return pmod;
Expand Down
36 changes: 8 additions & 28 deletions src/Etterna/MinaCalc/Dependent/HD_PatternMods/GenericStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ struct GStreamMod
{ "max_mod", &max_mod },
{ "prop_buffer", &prop_buffer },
{ "prop_scaler", &prop_scaler },

{ "jack_pool", &jack_pool },
{ "jack_comp_min", &jack_comp_min },
{ "jack_comp_max", &jack_comp_max },

{ "vibro_flag", &vibro_flag },
};
#pragma endregion params and param map

Expand All @@ -54,42 +48,28 @@ struct GStreamMod

}

auto operator()(const metaItvInfo& mitvi, const metaItvGenericHandInfo& mitvghi) -> float
auto operator()(const metaItvGenericHandInfo& mitvghi) -> float
{
const auto& itvi = mitvi._itvi;

// 1 tap is by definition a single tap
if (itvi.total_taps < 2) {
// it needs more taps to bracket
if (mitvghi.total_taps < 2) {
return neutral;
}

if (itvi.taps_by_size.at(_tap_size) == 0) {
// it's all chords
if (mitvghi.taps_by_size.at(_tap_size) == 0) {
return min_mod;
}

prop_component =
static_cast<float>(itvi.taps_by_size.at(_tap_size) + prop_buffer) /
static_cast<float>(static_cast<float>(itvi.total_taps) -
static_cast<float>(mitvghi.taps_by_size.at(_tap_size) + prop_buffer) /
static_cast<float>(static_cast<float>(mitvghi.total_taps) -
prop_buffer) *
prop_scaler;

// allow for a mini/triple jack in streams.. but not more than that
jack_component = std::clamp(
jack_pool - mitvi.actual_jacks, jack_comp_min, jack_comp_max);
pmod = fastsqrt(prop_component * jack_component);
pmod = fastsqrt(prop_component);

pmod = std::clamp(base + pmod, min_mod, max_mod);

if (mitvi.basically_vibro) {
if (mitvi.num_var == 1) {
pmod *= 0.5F * vibro_flag;
} else if (mitvi.num_var == 2) {
pmod *= 0.9F * vibro_flag;
} else if (mitvi.num_var == 3) {
pmod *= 0.95F * vibro_flag;
}
}

// actual mod
return pmod;
}
Expand Down
90 changes: 89 additions & 1 deletion src/Etterna/MinaCalc/Dependent/MetaIntervalGenericHandInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,37 +113,125 @@ determine_generic_base_pattern_type(const unsigned& notes_now,
}
}

inline auto
is_bracket(const unsigned& notes_row,
const unsigned& last_notes,
const unsigned& lastlast_notes) -> bool
{
// firstsec and secthird rows must form some trill
// firstthird rows must "jack" if put next to each other
return (notes_row ^ last_notes) > 0 && (last_notes ^ lastlast_notes) > 0 &&
(notes_row & lastlast_notes) > 0;
}

inline auto
basetype_stops_bracket(const generic_base_type& bt)
{
switch(bt) {
case gbase_single_single:
case gbase_chord_chord_jack:
case gbase_single_chord_jack:
case gbase_easy_trill:
case gbase_chord_weird:
return true;
default:
return false;
}
}

/// tracks hand movements within an interval generically
/// in other words, tracks trills, jacks, chords on a hand
struct metaItvGenericHandInfo
{
unsigned lastlast_row = 0u;
unsigned last_row = 0u;
generic_base_type last_type = gbase_type_init;

int total_taps = 0;
int chord_taps = 0;

// total number of taps involved in a bracket
// classically, a bracket is something like [13]2[13]2
// a chord trilling into something that splits it
int taps_bracketing = 0;
bool bracketing = false;

/// handle end of interval
void interval_end()
{
_base_types.fill(0);
taps_by_size.fill(0);
total_taps = 0;
chord_taps = 0;
taps_bracketing = 0;
bracketing = false;
last_type = gbase_type_init;
}

/// zero everything out for end of hand loop so the trailing values from the
/// left hand don't end up in the start of the right
void zero()
{
_base_types.fill(0);
taps_by_size.fill(0);
total_taps = 0;
chord_taps = 0;
taps_bracketing = 0;
bracketing = false;
last_type = gbase_type_init;
}

void handle_row(const unsigned& new_row, const unsigned& hand_mask){
auto pattern_type = determine_generic_base_pattern_type(
new_row, last_row, hand_mask);
last_row = new_row;

const auto taps_in_row = std::popcount(new_row);
total_taps += taps_in_row;
if (taps_in_row > 1) {
chord_taps += taps_in_row;
}

if (pattern_type >= num_gbase_types) {
lastlast_row = last_row;
last_row = new_row;
return;
}

// stop the bracketing
if (basetype_stops_bracket(pattern_type)) {
bracketing = false;
}

// we might be able to start bracketing
else if (!basetype_stops_bracket(last_type)) {
if (is_bracket(new_row, last_row, lastlast_row)) {
if (bracketing) {
taps_bracketing += taps_in_row;
} else {
bracketing = true;
taps_bracketing += taps_in_row + std::popcount(last_row) +
std::popcount(lastlast_row);
}
}
}

lastlast_row = last_row;
last_row = new_row;
last_type = pattern_type;
_base_types[pattern_type]++;
taps_by_size[taps_in_row - 1] += taps_in_row;
}

int possible_brackets() const
{
return _base_types[gbase_hard_trill] +
_base_types[gbase_single_chord_trill] +
_base_types[gbase_chord_chord_trill];
}

std::array<int, num_gbase_types> _base_types = { 0, 0, 0, 0, 0, 0, 0, 0 };
std::array<int, num_tap_size> taps_by_size = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };

};

2 changes: 1 addition & 1 deletion src/Etterna/MinaCalc/MinaCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ MinaSDCalcDebug(
#endif
}

int mina_calc_version = 513;
int mina_calc_version = 514;
auto
GetCalcVersion() -> int
{
Expand Down
11 changes: 6 additions & 5 deletions src/Etterna/MinaCalc/UlbuBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,26 @@ struct Bazoinkazoink

virtual void set_dependent_pmods(const int& itv) {
PatternMods::set_dependent(
hand, _gstream._pmod, _gstream(_mitvi, _mitvghi), itv, _calc);
hand, _gstream._pmod, _gstream(_mitvghi), itv, _calc);
PatternMods::set_dependent(
hand, _gbracketing._pmod, _gbracketing(_mitvi, _mitvghi), itv, _calc);
hand, _gbracketing._pmod, _gbracketing(_mitvghi), itv, _calc);
}

virtual void full_hand_reset() {
lazy_jacks.init(_calc.keycount);
_mitvghi.zero();

_gstream.full_reset();
_gbracketing.full_reset();

_mitvghi.zero();
}

virtual void handle_dependent_interval_end(const int& itv) {
_mitvghi.interval_end();

set_dependent_pmods(itv);

set_sequenced_base_diffs(itv);

_mitvghi.interval_end();
}

virtual void set_sequenced_base_diffs(const int& itv) const {
Expand Down

0 comments on commit 969196d

Please sign in to comment.