From 9c0f34e8a5775b32e94db580587c98fbe4558799 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 21 May 2022 11:22:22 -0400 Subject: [PATCH] cwPresetSel.cpp : Added preset selection for playing sequences of presets. --- cwPresetSel.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++----- cwPresetSel.h | 18 ++++++++---- 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/cwPresetSel.cpp b/cwPresetSel.cpp index cb9c8d2..d5a7b55 100644 --- a/cwPresetSel.cpp +++ b/cwPresetSel.cpp @@ -234,9 +234,13 @@ namespace cw case kPresetSelectVarId: for(unsigned i=0; ipresetN; ++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: if((rc = _validate_preset_id(f, presetId )) == kOkRC ) f->presetA[ presetId ].order = value; @@ -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; @@ -360,6 +377,13 @@ namespace cw case kPlayBtnVarId: break; + + case kPlaySeqBtnVarId: + break; + + case kPlaySeqAllBtnVarId: + valueRef = f->seqAllFl; + break; case kMasterWetInGainVarId: valueRef = p->master_wet_in_gain; @@ -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; ipresetN; ++i) - if( frag->presetA[i].playFl ) - return frag->presetA[i].preset_idx; + { + // 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; ipresetN; ++i) + if( f->presetA[i].seqFl ) + ++n; + + return n; +} + cw::rc_t cw::preset_sel::write( handle_t h, const char* fn ) { diff --git a/cwPresetSel.h b/cwPresetSel.h index a633cdc..c9131b9 100644 --- a/cwPresetSel.h +++ b/cwPresetSel.h @@ -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,12 +53,15 @@ namespace cw kBegPlayLocVarId, kEndPlayLocVarId, kPlayBtnVarId, + kPlaySeqBtnVarId, + kPlaySeqAllBtnVarId, kNoteVarId, - kPresetOrderVarId, // preset order value - kPresetSelectVarId, // select a preset to play - kPlayEnableVarId, // include in the segment to play - kDryFlVarId, // play this fragment dry + 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 kBaseMasterVarId, // All 'master' variables have id's greater than kBaseMasterVarId @@ -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 );