cwPresetSel.cpp : Added preset selection for playing sequences of presets.

This commit is contained in:
kevin 2022-05-21 11:22:22 -04:00
parent 4fb7d26c48
commit 9c0f34e8a5
2 changed files with 83 additions and 12 deletions

View File

@ -234,7 +234,11 @@ namespace cw
case kPresetSelectVarId:
for(unsigned i=0; i<f->presetN; ++i)
f->presetA[i].playFl = f->presetA[i].preset_idx == presetId ? value : false;
break;
case kPresetSeqSelectVarId:
if((rc = _validate_preset_id(f, presetId )) == kOkRC )
f->presetA[ presetId ].seqFl = value;
break;
case kPresetOrderVarId:
@ -269,6 +273,14 @@ namespace cw
case kPlayBtnVarId:
break;
case kPlaySeqBtnVarId:
f->seqAllFl = false;
break;
case kPlaySeqAllBtnVarId:
f->seqAllFl = true;
break;
case kMasterWetInGainVarId:
p->master_wet_in_gain = value;
break;
@ -329,6 +341,11 @@ namespace cw
valueRef = f->presetA[ presetId ].playFl;
break;
case kPresetSeqSelectVarId:
if((rc = _validate_preset_id(f, presetId )) == kOkRC )
valueRef = f->presetA[ presetId ].seqFl;
break;
case kPresetOrderVarId:
if((rc = _validate_preset_id(f, presetId )) == kOkRC )
valueRef = f->presetA[ presetId ].order;
@ -361,6 +378,13 @@ namespace cw
case kPlayBtnVarId:
break;
case kPlaySeqBtnVarId:
break;
case kPlaySeqAllBtnVarId:
valueRef = f->seqAllFl;
break;
case kMasterWetInGainVarId:
valueRef = p->master_wet_in_gain;
break;
@ -769,8 +793,8 @@ bool cw::preset_sel::track_timestamp( handle_t h, const time::spec_t& ts, const
time::spec_t t0;
time::setZero(t0);
unsigned elapsedMs = time::elapsedMs(t0,ts);
double mins = elapsedMs / 60000.0;
//unsigned elapsedMs = time::elapsedMs(t0,ts);
//double mins = elapsedMs / 60000.0;
// if this is the first call to 'track_timestamp()'.
@ -802,15 +826,54 @@ bool cw::preset_sel::track_timestamp( handle_t h, const time::spec_t& ts, const
return frag_changed_fl;
}
unsigned cw::preset_sel::fragment_play_preset_index( const frag_t* frag )
unsigned cw::preset_sel::fragment_play_preset_index( const frag_t* frag, unsigned preset_seq_idx )
{
unsigned n = 0;
// for each preset
for(unsigned i=0; i<frag->presetN; ++i)
{
// if 'preset_seq_idx' is not valid ...
if( preset_seq_idx==kInvalidIdx )
{
// ...then select the first preset whose 'playFl' is set.
if( frag->presetA[i].playFl )
return frag->presetA[i].preset_idx;
}
else
{
// ... otherwise select the 'nth' preset whose 'seqFl' is set
if( frag->presetA[i].seqFl || frag->seqAllFl )
{
if( n == preset_seq_idx )
return frag->presetA[i].preset_idx;
++n;
}
}
}
return kInvalidIdx;
}
unsigned cw::preset_sel::fragment_seq_count( handle_t h, unsigned fragId )
{
rc_t rc = kOkRC;
preset_sel_t* p = _handleToPtr(h);
frag_t* f = nullptr;
unsigned n = 0;
if((rc = _find_frag(p,fragId,f)) != kOkRC )
return 0;
if( f->seqAllFl )
return f->presetN;
for(unsigned i=0; i<f->presetN; ++i)
if( f->presetA[i].seqFl )
++n;
return n;
}
cw::rc_t cw::preset_sel::write( handle_t h, const char* fn )
{

View File

@ -11,6 +11,7 @@ namespace cw
typedef struct preset_str
{
bool playFl; // play this preset
bool seqFl; // play this preset during sequencing.
unsigned preset_idx; // preset index into preset_labelA[].
unsigned order; //
} preset_t;
@ -34,6 +35,7 @@ namespace cw
unsigned presetN;
bool uiSelectFl;
bool seqAllFl; // Set if all preset.seqFl's should be treated as though they are set to true.
struct frag_str* link;
struct frag_str* prev;
@ -51,10 +53,13 @@ namespace cw
kBegPlayLocVarId,
kEndPlayLocVarId,
kPlayBtnVarId,
kPlaySeqBtnVarId,
kPlaySeqAllBtnVarId,
kNoteVarId,
kPresetOrderVarId, // preset order value
kPresetSelectVarId, // select a preset to play
kPresetSeqSelectVarId, // sequence preset selections to play
kPlayEnableVarId, // include in the segment to play
kDryFlVarId, // play this fragment dry
@ -111,7 +116,10 @@ namespace cw
bool track_timestamp( handle_t h, const time::spec_t& ts, const cw::preset_sel::frag_t*& frag_Ref );
// Return the preset index marked to play on this fragment.
unsigned fragment_play_preset_index( const frag_t* frag );
unsigned fragment_play_preset_index( const frag_t* frag, unsigned preset_seq_idx=kInvalidIdx );
// Return the count of presets whose 'seqFl' is set.
unsigned fragment_seq_count( handle_t h, unsigned fragId );
rc_t write( handle_t h, const char* fn );
rc_t read( handle_t h, const char* fn );