From 0f41dfbcbd6ed67373a44f1a6c96fd3ed5ae57a9 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 29 Apr 2024 09:47:35 -0400 Subject: [PATCH] cwPresetSel.h/cpp : cwIoPresetSel.cpp : Applied multi-preset now includes state of fragment based on current GUI settings. --- cwIoPresetSelApp.cpp | 29 ++++++++++----- cwPresetSel.cpp | 87 +++++++++++++++++++++++++++++++++----------- cwPresetSel.h | 10 +++-- 3 files changed, 91 insertions(+), 35 deletions(-) diff --git a/cwIoPresetSelApp.cpp b/cwIoPresetSelApp.cpp index 54c9e7a..35b907f 100644 --- a/cwIoPresetSelApp.cpp +++ b/cwIoPresetSelApp.cpp @@ -922,25 +922,31 @@ namespace cw } // 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 coeffN = sizeof(coeffV)/sizeof(coeffV[0]); - + unsigned multiPresetN = 0; + + bool allowAnyFl = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) && cwIsFlag(app->multiPresetFlags,flow::kPriPresetProbFl); + flow::multi_preset_selector_t mp_sel = { .flags = app->multiPresetFlags, .coeffV = score_evt->featV, .coeffMinV = score_evt->featMinV, .coeffMaxV = score_evt->featMaxV, .coeffN = perf_meas::kValCnt, - .presetA = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) ? preset_order_array(app->psH) : frag->multiPresetA, - .presetN = cwIsFlag(app->multiPresetFlags,flow::kAllowAllPresetFl) ? preset_count(app->psH) : frag->multiPresetN + .presetA = allowAnyFl ? preset_order_array(app->psH) : fragment_active_presets(app->psH,frag,multiPresetN), + .presetN = allowAnyFl ? preset_count(app->psH) : multiPresetN }; - - if( app->ioFlowH.isValid() ) - 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; + 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() ) + apply_rc = io_flow::apply_preset( app->ioFlowH, flow_cross::kNextDestId, mp_sel ); + } + + preset_label = "(multi)"; preset_type_label = "multi"; @@ -1130,6 +1136,7 @@ namespace cw 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 ); if( f != nullptr ) @@ -1956,6 +1963,8 @@ rc_t _on_ui_play_loc(app_t* app, unsigned appId, unsigned loc); // the fragments are loaded enable the 'load' and 'alt' menu io::uiSetEnable( app->ioH, io::uiFindElementUuId( app->ioH, kPerfSelId ), 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)); io::uiRealTimeReport(app->ioH); diff --git a/cwPresetSel.cpp b/cwPresetSel.cpp index 0324269..28865f8 100644 --- a/cwPresetSel.cpp +++ b/cwPresetSel.cpp @@ -40,6 +40,7 @@ namespace cw unsigned presetLabelN; flow::preset_order_t* presetOrderA; // presetOrderA[ presetLabelN ] + flow::preset_order_t* multiPresetA; // activePresetA[ presetLabelN ] alt_label_t* altLabelA; unsigned altLabelN; @@ -148,6 +149,7 @@ namespace cw mem::release( p->presetLabelA[i].label ); mem::release( p->presetLabelA ); mem::release( p->presetOrderA ); + mem::release( p->multiPresetA ); for(unsigned i=0; ialtLabelN; ++i) mem::release( p->altLabelA[i].label ); @@ -826,6 +828,48 @@ namespace cw errLabel: 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; ipresetN; ++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.ordermultiPresetA : p->multiPresetA+1; + } } } @@ -864,7 +908,8 @@ cw::rc_t cw::preset_sel::create( handle_t& hRef, const object_t* cfg ) p->presetLabelN = preset_labelL->child_count(); p->presetLabelA = mem::allocZ(p->presetLabelN); p->presetOrderA = mem::allocZ(p->presetLabelN); - + p->multiPresetA = mem::allocZ(p->presetLabelN); + // get the preset labels for(unsigned i=0; ipresetLabelN; ++i) { @@ -1165,7 +1210,7 @@ cw::rc_t cw::preset_sel::delete_fragment( handle_t h, unsigned fragId ) // release the fragment mem::release(f->presetA); - mem::release(f->multiPresetA); + //mem::release(f->multiPresetA); mem::release(f); 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 ) { rc_t rc = kOkRC; @@ -1548,6 +1604,7 @@ cw::rc_t cw::preset_sel::write( handle_t h, const char* fn ) return rc; } + cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) { rc_t rc = kOkRC; @@ -1678,32 +1735,18 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) } + /* // create the multiPresetA[] if( multiPresetN>0 ) { - f->multiPresetA = mem::allocZ(multiPresetN); - f->multiPresetN = multiPresetN; + // make multiPresetA as large as possible + f->multiPresetA = mem::allocZ(p->presetLabelN); - for(unsigned i=0,j=1; ipresetA[i].order > 0 || f->presetA[i].playFl ) - { - unsigned out_idx = f->presetA[i].playFl ? 0 : j++; + _load_multi_preset_array(p,f); - 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