diff --git a/cwPresetSel.cpp b/cwPresetSel.cpp index b49ecd0..02514e9 100644 --- a/cwPresetSel.cpp +++ b/cwPresetSel.cpp @@ -6,6 +6,7 @@ #include "cwObject.h" #include "cwTime.h" #include "cwVectOps.h" +#include "cwFlowDecl.h" #include "cwPresetSel.h" #include "cwFile.h" #include "cwPianoScore.h" @@ -1061,7 +1062,6 @@ cw::rc_t cw::preset_sel::create_fragment( handle_t h, unsigned end_loc, time::sp // set the return value fragIdRef = f->fragId; - // intiialize the preset array elements for(unsigned i=0; ipresetLabelN; ++i) { @@ -1147,6 +1147,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); return kOkRC; @@ -1497,7 +1498,6 @@ cw::rc_t cw::preset_sel::write( handle_t h, const char* fn ) } newPairObject("fragL", fragL_obj, root); - newPairObject("fragN", fragN, root); newPairObject("masterWetInGain", p->master_wet_in_gain, root ); newPairObject("masterWetOutGain", p->master_wet_out_gain, root ); newPairObject("masterDryGain", p->master_dry_gain, root ); @@ -1535,7 +1535,6 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) rc_t rc = kOkRC; preset_sel_t* p = _handleToPtr(h); object_t* root = nullptr; - unsigned fragN = 0; const object_t* fragL_obj = nullptr; // parse the preset file @@ -1549,8 +1548,7 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) _destroy_all_frags(p); // parse the root level - if((rc = root->getv( "fragN", fragN, - "fragL", fragL_obj, + if((rc = root->getv( "fragL", fragL_obj, "masterWetInGain", p->master_wet_in_gain, "masterWetOutGain", p->master_wet_out_gain, "masterDryGain", p->master_dry_gain, @@ -1560,13 +1558,14 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) goto errLabel; } + // for each fragment - for(unsigned i=0; ichild_count(); ++i) { frag_t* f = nullptr; const object_t* r = fragL_obj->child_ele(i); - unsigned fragId=kInvalidId,endLoc=0,presetN=0,begPlayLoc=0,endPlayLoc=0; + unsigned fragId=kInvalidId,endLoc=0,presetN=0,multiPresetN=0,begPlayLoc=0,endPlayLoc=0; double igain=0,ogain=0,wetDryGain=0,fadeOutMs=0; const char* note = nullptr; const object_t* presetL_obj = nullptr; @@ -1647,6 +1646,9 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn ) goto errLabel; } + if( order > 0 || playFl ) + multiPresetN += 1; + f->presetA[ preset_idx ].order = order; f->presetA[ preset_idx ].alt_str = mem::duplStr(alt_str); f->presetA[ preset_idx ].playFl = playFl; @@ -1658,6 +1660,32 @@ 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; + + for(unsigned i=0,j=1; ipresetA[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