cwPresetSel.h/cpp : Added multiPresetA/N to fragment.

Removed 'fragN' from stored fragment data structure.
Commented out translate_frags() because it is obsolete.
This commit is contained in:
kevin 2024-01-13 10:12:49 -05:00
parent 293629831c
commit 5611b28c6b
2 changed files with 47 additions and 9 deletions

View File

@ -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; i<p->presetLabelN; ++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; i<fragN; ++i)
for(unsigned i=0; i<fragL_obj->child_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<flow::preset_order_t>(multiPresetN);
f->multiPresetN = multiPresetN;
for(unsigned i=0,j=1; i<presetN; ++i)
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; } );
}
}
}
@ -1711,7 +1739,14 @@ cw::rc_t cw::preset_sel::report_presets( handle_t h )
return rc;
}
cw::rc_t cw::preset_sel::translate_frags( const object_t* cfg )
{
return cwLogError(kNotImplementedRC,"translate_frags() is not implemented.");
}
#undef NOT_DEF
#ifdef NOT_DEF
cw::rc_t cw::preset_sel::translate_frags( const object_t* cfg )
{
rc_t rc = kOkRC;
@ -1938,4 +1973,4 @@ cw::rc_t cw::preset_sel::translate_frags( const object_t* cfg )
return rc;
}
#endif

View File

@ -35,6 +35,9 @@ namespace cw
preset_t* presetA; // presetA[ presetN ] - status of each preset
unsigned presetN;
flow::preset_order_t* multiPresetA; // array of active presets in this frag. sequenced by ascending 'order'.
unsigned multiPresetN;
unsigned* altPresetIdxA; // altPresetIdxA[ alt_count() ] selected preset idx for each alt.
bool uiSelectFl;