cwPresetSel.h/cpp : Added new fields to fragment: ogain, begPlayLoc, endPlayLoc, note.

This commit is contained in:
kevin 2021-12-27 20:29:37 -05:00
parent 5e93cb4e03
commit 0f4db7e556
2 changed files with 134 additions and 23 deletions

View File

@ -66,6 +66,7 @@ namespace cw
f0->link = f1->link; f0->link = f1->link;
// release the fragment // release the fragment
mem::release(f1->note);
mem::release(f1->presetA); mem::release(f1->presetA);
mem::release(f1); mem::release(f1);
@ -231,8 +232,12 @@ namespace cw
f->presetA[ presetId ].order = value; f->presetA[ presetId ].order = value;
break; break;
case kGainVarId: case kInGainVarId:
f->gain = value; f->igain = value;
break;
case kOutGainVarId:
f->ogain = value;
break; break;
case kFadeOutMsVarId: case kFadeOutMsVarId:
@ -243,6 +248,17 @@ namespace cw
f->wetDryGain = value; f->wetDryGain = value;
break; break;
case kBegPlayLocVarId:
f->begPlayLoc = value;
break;
case kEndPlayLocVarId:
f->endPlayLoc = value;
break;
case kPlayBtnVarId:
break;
default: default:
rc = cwLogError(kInvalidIdRC,"There is no preset variable with var id:%i.",varId); rc = cwLogError(kInvalidIdRC,"There is no preset variable with var id:%i.",varId);
goto errLabel; goto errLabel;
@ -292,8 +308,12 @@ namespace cw
valueRef = f->presetA[ presetId ].order; valueRef = f->presetA[ presetId ].order;
break; break;
case kGainVarId: case kInGainVarId:
valueRef = f->gain; valueRef = f->igain;
break;
case kOutGainVarId:
valueRef = f->ogain;
break; break;
case kFadeOutMsVarId: case kFadeOutMsVarId:
@ -304,6 +324,17 @@ namespace cw
valueRef = f->wetDryGain; valueRef = f->wetDryGain;
break; break;
case kBegPlayLocVarId:
valueRef = f->begPlayLoc;
break;
case kEndPlayLocVarId:
valueRef = f->endPlayLoc;
break;
case kPlayBtnVarId:
break;
default: default:
rc = cwLogError(kInvalidIdRC,"There is no preset variable with var id:%i.",varId); rc = cwLogError(kInvalidIdRC,"There is no preset variable with var id:%i.",varId);
goto errLabel; goto errLabel;
@ -456,12 +487,16 @@ cw::rc_t cw::preset_sel::create_fragment( handle_t h, unsigned end_loc, time::sp
frag_t* f = mem::allocZ<frag_t>(); frag_t* f = mem::allocZ<frag_t>();
f->endLoc = end_loc; f->endLoc = end_loc;
f->endTimestamp = end_timestamp; f->endTimestamp = end_timestamp;
f->gain = p->defaultGain; f->igain = p->defaultGain;
f->ogain = p->defaultGain;
f->wetDryGain = p->defaultWetDryGain; f->wetDryGain = p->defaultWetDryGain;
f->fadeOutMs = p->defaultFadeOutMs; f->fadeOutMs = p->defaultFadeOutMs;
f->presetA = mem::allocZ<preset_t>(p->presetLabelN); f->presetA = mem::allocZ<preset_t>(p->presetLabelN);
f->presetN = p->presetLabelN; f->presetN = p->presetLabelN;
f->fragId = _generate_unique_frag_id(p); f->fragId = _generate_unique_frag_id(p);
f->begPlayLoc = 0;
f->endPlayLoc = end_loc;
f->note = mem::duplStr("");
// set the return value // set the return value
fragIdRef = f->fragId; fragIdRef = f->fragId;
@ -518,6 +553,9 @@ cw::rc_t cw::preset_sel::create_fragment( handle_t h, unsigned end_loc, time::sp
f0->prev = f; f0->prev = f;
} }
if( f->prev != nullptr )
f->begPlayLoc = f->prev->endLoc + 1;
doneLabel: doneLabel:
return kOkRC; return kOkRC;
} }
@ -590,6 +628,31 @@ cw::rc_t cw::preset_sel::set_value( handle_t h, unsigned fragId, unsigned varId,
cw::rc_t cw::preset_sel::set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double value ) cw::rc_t cw::preset_sel::set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double value )
{ return _set_value(h,fragId,varId,presetId,value); } { return _set_value(h,fragId,varId,presetId,value); }
cw::rc_t cw::preset_sel::set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, const char* value )
{
rc_t rc = kOkRC;
preset_sel_t* p = _handleToPtr(h);
frag_t* f = nullptr;
// locate the requested fragment
if((rc = _find_frag(p,fragId,f)) != kOkRC )
goto errLabel;
switch( varId )
{
case kNoteVarId:
mem::release(f->note);
if( value != nullptr )
f->note = mem::duplStr(value);
break;
default:
rc = cwLogError(kInvalidIdRC,"There is no preset variable of type 'string' with var id:%i.",varId);
}
errLabel:
return rc;
}
cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool& valueRef ) cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool& valueRef )
{ return _get_value(h,fragId,varId,presetId,valueRef); } { return _get_value(h,fragId,varId,presetId,valueRef); }
@ -599,6 +662,30 @@ cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId,
cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double& valueRef ) cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double& valueRef )
{ return _get_value(h,fragId,varId,presetId,valueRef); } { return _get_value(h,fragId,varId,presetId,valueRef); }
cw::rc_t cw::preset_sel::get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, const char*& valueRef )
{
rc_t rc = kOkRC;
preset_sel_t* p = _handleToPtr(h);
frag_t* f = nullptr;
// locate the requested fragment
if((rc = _find_frag(p,fragId,f)) != kOkRC )
goto errLabel;
switch( varId )
{
case kNoteVarId:
valueRef = f->note;
break;
default:
rc = cwLogError(kInvalidIdRC,"There is no preset variable of type 'string' with var id:%i.",varId);
}
errLabel:
return rc;
}
bool cw::preset_sel::track_timestamp( handle_t h, const time::spec_t& ts, const cw::preset_sel::frag_t*& frag_Ref ) bool cw::preset_sel::track_timestamp( handle_t h, const time::spec_t& ts, const cw::preset_sel::frag_t*& frag_Ref )
{ {
preset_sel_t* p = _handleToPtr(h); preset_sel_t* p = _handleToPtr(h);
@ -663,9 +750,13 @@ cw::rc_t cw::preset_sel::write( handle_t h, const char* fn )
newPairObject("endLoc", f->endLoc, frag_obj ); newPairObject("endLoc", f->endLoc, frag_obj );
newPairObject("endTimestamp_sec", f->endTimestamp.tv_sec, frag_obj ); newPairObject("endTimestamp_sec", f->endTimestamp.tv_sec, frag_obj );
newPairObject("endTimestamp_nsec", f->endTimestamp.tv_nsec, frag_obj ); newPairObject("endTimestamp_nsec", f->endTimestamp.tv_nsec, frag_obj );
newPairObject("gain", f->gain, frag_obj ); newPairObject("inGain", f->igain, frag_obj );
newPairObject("outGain", f->ogain, frag_obj );
newPairObject("wetDryGain", f->wetDryGain, frag_obj ); newPairObject("wetDryGain", f->wetDryGain, frag_obj );
newPairObject("fadeOutMs", f->fadeOutMs, frag_obj ); newPairObject("fadeOutMs", f->fadeOutMs, frag_obj );
newPairObject("begPlayLoc", f->begPlayLoc, frag_obj );
newPairObject("endPlayLoc", f->endPlayLoc, frag_obj );
newPairObject("note", f->note, frag_obj );
newPairObject("presetN", f->presetN, frag_obj ); newPairObject("presetN", f->presetN, frag_obj );
// note: newPairObject() return a ptr to the pair value node. // note: newPairObject() return a ptr to the pair value node.
@ -700,6 +791,7 @@ cw::rc_t cw::preset_sel::write( handle_t h, const char* fn )
mem::release(s); mem::release(s);
s = nullptr;
if( actual_byteN < s_byteN ) if( actual_byteN < s_byteN )
break; break;
@ -744,8 +836,9 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn )
frag_t* f = nullptr; frag_t* f = nullptr;
const object_t* r = fragL_obj->child_ele(i); const object_t* r = fragL_obj->child_ele(i);
unsigned fragId=kInvalidId,endLoc=0,presetN=0; unsigned fragId=kInvalidId,endLoc=0,presetN=0,begPlayLoc=0,endPlayLoc=0;
double gain=0,wetDryGain=0,fadeOutMs=0; double igain=0,ogain=0,wetDryGain=0,fadeOutMs=0;
const char* note = nullptr;
const object_t* presetL_obj = nullptr; const object_t* presetL_obj = nullptr;
time::spec_t end_ts; time::spec_t end_ts;
@ -754,9 +847,13 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn )
"endLoc",endLoc, "endLoc",endLoc,
"endTimestamp_sec",end_ts.tv_sec, "endTimestamp_sec",end_ts.tv_sec,
"endTimestamp_nsec",end_ts.tv_nsec, "endTimestamp_nsec",end_ts.tv_nsec,
"gain",gain, "inGain",igain,
"outGain",ogain,
"wetDryGain",wetDryGain, "wetDryGain",wetDryGain,
"fadeOutMs",fadeOutMs, "fadeOutMs",fadeOutMs,
"begPlayLoc",begPlayLoc,
"endPlayLoc",endPlayLoc,
"note",note,
"presetN", presetN, "presetN", presetN,
"presetL", presetL_obj )) != kOkRC ) "presetL", presetL_obj )) != kOkRC )
{ {
@ -773,10 +870,13 @@ cw::rc_t cw::preset_sel::read( handle_t h, const char* fn )
} }
// update the fragment variables // update the fragment variables
set_value( h, fragId, kGainVarId, kInvalidId, gain ); set_value( h, fragId, kInGainVarId, kInvalidId, igain );
set_value( h, fragId, kOutGainVarId, kInvalidId, ogain );
set_value( h, fragId, kFadeOutMsVarId, kInvalidId, fadeOutMs ); set_value( h, fragId, kFadeOutMsVarId, kInvalidId, fadeOutMs );
set_value( h, fragId, kWetGainVarId, kInvalidId, wetDryGain ); set_value( h, fragId, kWetGainVarId, kInvalidId, wetDryGain );
set_value( h, fragId, kBegPlayLocVarId, kInvalidId, begPlayLoc );
set_value( h, fragId, kEndPlayLocVarId, kInvalidId, endPlayLoc );
set_value( h, fragId, kNoteVarId, kInvalidId, note );
// locate the new fragment record // locate the new fragment record
if((f = _find_frag(p, fragId )) == nullptr ) if((f = _find_frag(p, fragId )) == nullptr )

View File

@ -22,9 +22,13 @@ namespace cw
unsigned endLoc; // The endLoc is included in this fragment. The begin loc is f->prev->endLoc+1 unsigned endLoc; // The endLoc is included in this fragment. The begin loc is f->prev->endLoc+1
time::spec_t endTimestamp; time::spec_t endTimestamp;
double gain; double igain;
double ogain;
double wetDryGain; double wetDryGain;
double fadeOutMs; double fadeOutMs;
unsigned begPlayLoc;
unsigned endPlayLoc;
char* note;
preset_t* presetA; preset_t* presetA;
unsigned presetN; unsigned presetN;
@ -40,9 +44,14 @@ namespace cw
kGuiUuIdVarId, kGuiUuIdVarId,
kBegLocVarId, kBegLocVarId,
kEndLocVarId, kEndLocVarId,
kGainVarId, kInGainVarId,
kOutGainVarId,
kFadeOutMsVarId, kFadeOutMsVarId,
kWetGainVarId, kWetGainVarId,
kBegPlayLocVarId,
kEndPlayLocVarId,
kPlayBtnVarId,
kNoteVarId,
kPresetOrderVarId, // preset order value kPresetOrderVarId, // preset order value
kPresetSelectVarId, // select a preset to play kPresetSelectVarId, // select a preset to play
@ -73,13 +82,15 @@ namespace cw
rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool value ); rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool value );
rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, unsigned value ); rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, unsigned value );
rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double value ); rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double value );
rc_t set_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, const char* value );
rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool& valueRef ); rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, bool& valueRef );
rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, unsigned& valueRef ); rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, unsigned& valueRef );
rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double& valueRef ); rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, double& valueRef );
rc_t get_value( handle_t h, unsigned fragId, unsigned varId, unsigned presetId, const char*& valueRef );
// Call this function to determine which fragment the timestamp 'ts' is contained by. // Call this function to determine which fragment the timestamp 'ts' is contained by.
// This call is optimized to be called in time critical functions where 'ts' is expected to be increasing. // This function is optimized to be called in time sensitive functions where 'ts' is expected to be increasing.
// If 'ts' is past the last defined fragment then the last fragment is returned. // If 'ts' is past the last defined fragment then the last fragment is returned.
// If no fragments are defined 'frag_Ref' is set to nullptr. // If no fragments are defined 'frag_Ref' is set to nullptr.
// The return value is true when the value of frag_Ref changes from the previous call. // The return value is true when the value of frag_Ref changes from the previous call.