cwPresetSel.h/cpp : cwIoPresetSel.cpp : Applied multi-preset now includes state of fragment based on current GUI settings.

This commit is contained in:
kevin 2024-04-29 09:47:35 -04:00
parent 52409219a2
commit 0f41dfbcbd
3 changed files with 91 additions and 35 deletions

View File

@ -922,10 +922,11 @@ namespace cw
} }
// if we are not automatically sequencing through the presets and a score event was given // if we are not automatically sequencing through the presets and a score event was given
if( seq_idx_n == kInvalidIdx && score_evt != nullptr && frag->multiPresetN>0 ) if( seq_idx_n == kInvalidIdx && score_evt != nullptr )
{ {
//double coeffV[] = { score_evt->even, score_evt->dyn, score_evt->tempo, score_evt->cost }; unsigned multiPresetN = 0;
//unsigned coeffN = sizeof(coeffV)/sizeof(coeffV[0]);
bool allowAnyFl = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) && cwIsFlag(app->multiPresetFlags,flow::kPriPresetProbFl);
flow::multi_preset_selector_t mp_sel = flow::multi_preset_selector_t mp_sel =
{ .flags = app->multiPresetFlags, { .flags = app->multiPresetFlags,
@ -933,14 +934,19 @@ namespace cw
.coeffMinV = score_evt->featMinV, .coeffMinV = score_evt->featMinV,
.coeffMaxV = score_evt->featMaxV, .coeffMaxV = score_evt->featMaxV,
.coeffN = perf_meas::kValCnt, .coeffN = perf_meas::kValCnt,
.presetA = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) ? preset_order_array(app->psH) : frag->multiPresetA, .presetA = allowAnyFl ? preset_order_array(app->psH) : fragment_active_presets(app->psH,frag,multiPresetN),
.presetN = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) ? preset_count(app->psH) : frag->multiPresetN .presetN = allowAnyFl ? preset_count(app->psH) : multiPresetN
}; };
if( mp_sel.presetA == nullptr || mp_sel.presetN == 0 )
cwLogWarning("No active presets were found for loc:%i at end loc:%i.",loc,frag->endLoc);
else
{
if( app->ioFlowH.isValid() ) if( app->ioFlowH.isValid() )
apply_rc = io_flow::apply_preset( app->ioFlowH, flow_cross::kNextDestId, mp_sel ); apply_rc = io_flow::apply_preset( app->ioFlowH, flow_cross::kNextDestId, mp_sel );
}
preset_label = "(multi)"; //mp_sel.presetN>0 && mp_sel.presetA[0].preset_label!=nullptr ? mp_sel.presetA[0].preset_label : nullptr; preset_label = "(multi)";
preset_type_label = "multi"; preset_type_label = "multi";
@ -1130,6 +1136,7 @@ namespace cw
if( preset_sel::track_loc( app->psH, loc, f ) ) if( preset_sel::track_loc( app->psH, loc, f ) )
{ {
printf("Loc:%i\n",loc);
_apply_preset( app, loc, (const perf_score::event_t*)msg_arg, f ); _apply_preset( app, loc, (const perf_score::event_t*)msg_arg, f );
if( f != nullptr ) if( f != nullptr )
@ -1957,6 +1964,8 @@ rc_t _on_ui_play_loc(app_t* app, unsigned appId, unsigned loc);
io::uiSetEnable( app->ioH, io::uiFindElementUuId( app->ioH, kPerfSelId ), true ); io::uiSetEnable( app->ioH, io::uiFindElementUuId( app->ioH, kPerfSelId ), true );
io::uiSetEnable( app->ioH, io::uiFindElementUuId( app->ioH, kAltSelId ), true ); io::uiSetEnable( app->ioH, io::uiFindElementUuId( app->ioH, kAltSelId ), true );
_set_status(app,"Load complete.");
cwLogInfo("Fragment restore complete: elapsed secs:%f",time::elapsedSecs(app->psLoadT0)); cwLogInfo("Fragment restore complete: elapsed secs:%f",time::elapsedSecs(app->psLoadT0));
io::uiRealTimeReport(app->ioH); io::uiRealTimeReport(app->ioH);

View File

@ -40,6 +40,7 @@ namespace cw
unsigned presetLabelN; unsigned presetLabelN;
flow::preset_order_t* presetOrderA; // presetOrderA[ presetLabelN ] flow::preset_order_t* presetOrderA; // presetOrderA[ presetLabelN ]
flow::preset_order_t* multiPresetA; // activePresetA[ presetLabelN ]
alt_label_t* altLabelA; alt_label_t* altLabelA;
unsigned altLabelN; unsigned altLabelN;
@ -148,6 +149,7 @@ namespace cw
mem::release( p->presetLabelA[i].label ); mem::release( p->presetLabelA[i].label );
mem::release( p->presetLabelA ); mem::release( p->presetLabelA );
mem::release( p->presetOrderA ); mem::release( p->presetOrderA );
mem::release( p->multiPresetA );
for(unsigned i=0; i<p->altLabelN; ++i) for(unsigned i=0; i<p->altLabelN; ++i)
mem::release( p->altLabelA[i].label ); mem::release( p->altLabelA[i].label );
@ -827,6 +829,48 @@ namespace cw
return e; return e;
} }
const flow::preset_order_t* _load_active_multi_preset_array( preset_sel_t* p, const frag_t* f, unsigned& cnt_ref )
{
bool has_zero_fl = false;
cnt_ref = 0;
for(unsigned i=0,j=1; i<f->presetN; ++i)
{
if( f->presetA[i].order > 0 || f->presetA[i].playFl )
{
unsigned out_idx;
// Exactly one preset can have the 'playFl' set.
// This is the highest priority preset.
// It is always placed in the first slot.
if( !f->presetA[i].playFl )
out_idx = j++;
else
{
out_idx = 0;
has_zero_fl = true;
}
assert( out_idx < p->presetLabelN );
p->multiPresetA[out_idx].preset_label = _preset_label( p, f->presetA[i].preset_idx );
p->multiPresetA[out_idx].order = f->presetA[i].order;
++cnt_ref;
}
}
// sort the presets on 'order' - being careful to not move the zeroth preset (if it exists)
if( (has_zero_fl && cnt_ref > 2) || (!has_zero_fl && cnt_ref>1) )
{
std::sort(p->multiPresetA+1,
p->multiPresetA+(cnt_ref-1),
[](const flow::preset_order_t& a,const flow::preset_order_t& b){ return a.order<b.order; } );
}
return has_zero_fl ? p->multiPresetA : p->multiPresetA+1;
}
} }
} }
@ -864,6 +908,7 @@ cw::rc_t cw::preset_sel::create( handle_t& hRef, const object_t* cfg )
p->presetLabelN = preset_labelL->child_count(); p->presetLabelN = preset_labelL->child_count();
p->presetLabelA = mem::allocZ<preset_label_t>(p->presetLabelN); p->presetLabelA = mem::allocZ<preset_label_t>(p->presetLabelN);
p->presetOrderA = mem::allocZ<flow::preset_order_t>(p->presetLabelN); p->presetOrderA = mem::allocZ<flow::preset_order_t>(p->presetLabelN);
p->multiPresetA = mem::allocZ<flow::preset_order_t>(p->presetLabelN);
// get the preset labels // get the preset labels
for(unsigned i=0; i<p->presetLabelN; ++i) for(unsigned i=0; i<p->presetLabelN; ++i)
@ -1165,7 +1210,7 @@ cw::rc_t cw::preset_sel::delete_fragment( handle_t h, unsigned fragId )
// release the fragment // release the fragment
mem::release(f->presetA); mem::release(f->presetA);
mem::release(f->multiPresetA); //mem::release(f->multiPresetA);
mem::release(f); mem::release(f);
return kOkRC; return kOkRC;
@ -1471,6 +1516,17 @@ unsigned cw::preset_sel::fragment_seq_count( handle_t h, unsigned fragId )
} }
const cw::flow::preset_order_t* cw::preset_sel::fragment_active_presets( handle_t h, const frag_t* f, unsigned& count_ref )
{
preset_sel_t* p = _handleToPtr(h);
count_ref = 0;
return _load_active_multi_preset_array(p,f,count_ref);
}
cw::rc_t cw::preset_sel::write( handle_t h, const char* fn ) cw::rc_t cw::preset_sel::write( handle_t h, const char* fn )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -1548,6 +1604,7 @@ cw::rc_t cw::preset_sel::write( handle_t h, const char* fn )
return rc; return rc;
} }
cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) cw::rc_t cw::preset_sel::read( handle_t h, const char* fn )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -1678,31 +1735,17 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn )
} }
/*
// create the multiPresetA[] // create the multiPresetA[]
if( multiPresetN>0 ) if( multiPresetN>0 )
{ {
f->multiPresetA = mem::allocZ<flow::preset_order_t>(multiPresetN); // make multiPresetA as large as possible
f->multiPresetN = multiPresetN; f->multiPresetA = mem::allocZ<flow::preset_order_t>(p->presetLabelN);
for(unsigned i=0,j=1; i<presetN; ++i) _load_multi_preset_array(p,f);
if( f->presetA[i].order > 0 || f->presetA[i].playFl )
{
unsigned out_idx = f->presetA[i].playFl ? 0 : j++;
assert( out_idx < multiPresetN );
f->multiPresetA[out_idx].preset_label = _preset_label( p, f->presetA[i].preset_idx );
f->multiPresetA[out_idx].order = f->presetA[i].order;
}
// sort
if( multiPresetN > 1 )
{
std::sort(f->multiPresetA+1,
f->multiPresetA+f->multiPresetN-1,
[](const flow::preset_order_t& a,const flow::preset_order_t& b){ return a.order<b.order; } );
}
} }
*/
} }

View File

@ -35,10 +35,12 @@ namespace cw
preset_t* presetA; // presetA[ presetN ] - status of each preset preset_t* presetA; // presetA[ presetN ] - status of each preset
unsigned presetN; unsigned presetN;
flow::preset_order_t* multiPresetA; // array of active presets in this frag. sequenced by ascending 'order'. // array of stored presets in this frag. sequenced by ascending 'order'.
unsigned multiPresetN; //flow::preset_order_t* multiPresetA;
//unsigned multiPresetN;
unsigned* altPresetIdxA; // altPresetIdxA[ alt_count() ] selected preset idx for each alt. // altPresetIdxA[ alt_count() ] selected preset idx for each alt.
unsigned* altPresetIdxA;
bool uiSelectFl; bool uiSelectFl;
bool seqAllFl; // Set if all preset.seqFl's should be treated as though they are set to true. bool seqAllFl; // Set if all preset.seqFl's should be treated as though they are set to true.
@ -139,6 +141,8 @@ namespace cw
// Return the count of presets whose 'seqFl' is set. // Return the count of presets whose 'seqFl' is set.
unsigned fragment_seq_count( handle_t h, unsigned fragId ); unsigned fragment_seq_count( handle_t h, unsigned fragId );
const flow::preset_order_t* fragment_active_presets( handle_t h, const frag_t* f, unsigned& count_ref );
rc_t write( handle_t h, const char* fn ); rc_t write( handle_t h, const char* fn );
rc_t read( handle_t h, const char* fn ); rc_t read( handle_t h, const char* fn );
rc_t report( handle_t h ); rc_t report( handle_t h );