2012-10-30 03:52:39 +00:00
|
|
|
#include "cmPrefix.h"
|
|
|
|
#include "cmGlobal.h"
|
|
|
|
#include "cmFloatTypes.h"
|
|
|
|
#include "cmComplexTypes.h"
|
|
|
|
#include "cmRpt.h"
|
|
|
|
#include "cmErr.h"
|
|
|
|
#include "cmCtx.h"
|
|
|
|
#include "cmMem.h"
|
|
|
|
#include "cmMallocDebug.h"
|
|
|
|
#include "cmLinkedHeap.h"
|
|
|
|
#include "cmFile.h"
|
|
|
|
#include "cmSymTbl.h"
|
|
|
|
#include "cmJson.h"
|
2013-02-09 07:48:54 +00:00
|
|
|
#include "cmText.h"
|
2012-10-30 03:52:39 +00:00
|
|
|
#include "cmPrefs.h"
|
|
|
|
#include "cmDspValue.h"
|
|
|
|
#include "cmMsgProtocol.h"
|
|
|
|
#include "cmThread.h"
|
|
|
|
#include "cmUdpPort.h"
|
|
|
|
#include "cmUdpNet.h"
|
|
|
|
#include "cmAudioSys.h"
|
|
|
|
#include "cmDspCtx.h"
|
|
|
|
#include "cmDspClass.h"
|
2013-03-02 01:40:04 +00:00
|
|
|
#include "cmDspStore.h"
|
2012-10-30 03:52:39 +00:00
|
|
|
#include "cmDspUi.h"
|
2012-12-13 23:38:45 +00:00
|
|
|
#include "cmDspSys.h"
|
2012-10-30 03:52:39 +00:00
|
|
|
#include "cmMath.h"
|
|
|
|
|
2012-11-16 20:13:36 +00:00
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
#include "cmAudioFile.h"
|
|
|
|
#include "cmFileSys.h"
|
|
|
|
#include "cmProcObj.h"
|
|
|
|
#include "cmProcTemplateMain.h"
|
|
|
|
#include "cmProc.h"
|
|
|
|
#include "cmMidi.h"
|
|
|
|
#include "cmProc2.h"
|
|
|
|
#include "cmVectOpsTemplateMain.h"
|
|
|
|
|
2012-11-16 20:13:36 +00:00
|
|
|
#include "cmAudioFile.h"
|
|
|
|
#include "cmMidiFile.h"
|
|
|
|
#include "cmTimeLine.h"
|
2012-11-18 01:33:10 +00:00
|
|
|
#include "cmScore.h"
|
|
|
|
#include "cmProc4.h"
|
2012-11-16 20:13:36 +00:00
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kWndSmpCntKrId,
|
|
|
|
kHopFactKrId,
|
|
|
|
kModeKrId,
|
|
|
|
kThreshKrId,
|
|
|
|
kLwrSlopeKrId,
|
|
|
|
kUprSlopeKrId,
|
|
|
|
kOffsetKrId,
|
|
|
|
kInvertKrId,
|
2013-03-02 01:40:04 +00:00
|
|
|
kBypassKrId,
|
|
|
|
kWetKrId,
|
2012-10-30 03:52:39 +00:00
|
|
|
kAudioInKrId,
|
|
|
|
kAudioOutKrId
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmCtx* ctx;
|
|
|
|
cmSpecDist_t* sdp;
|
|
|
|
} cmDspKr_t;
|
|
|
|
|
|
|
|
cmDspClass_t _cmKrDC;
|
|
|
|
|
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
//==========================================================================================================================================
|
2012-10-30 03:52:39 +00:00
|
|
|
|
|
|
|
cmDspInst_t* _cmDspKrAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
|
|
|
{ "wndn", kWndSmpCntKrId, 0, 0, kInDsvFl | kUIntDsvFl | kReqArgDsvFl, "Window sample count" },
|
|
|
|
{ "hopf", kHopFactKrId, 0, 0, kInDsvFl | kUIntDsvFl | kOptArgDsvFl, "Hop factor" },
|
|
|
|
{ "mode", kModeKrId, 0, 0, kInDsvFl | kUIntDsvFl | kOptArgDsvFl, "Mode 0=bypass 1=basic 2=spec cnt 3=amp env" },
|
|
|
|
{ "thrh", kThreshKrId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Threshold" },
|
|
|
|
{ "lwrs", kLwrSlopeKrId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Lower Slope"},
|
|
|
|
{ "uprs", kUprSlopeKrId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Upper Slope"},
|
|
|
|
{ "offs", kOffsetKrId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Offset"},
|
|
|
|
{ "invt", kInvertKrId, 0, 0, kInDsvFl | kUIntDsvFl | kOptArgDsvFl, "Invert"},
|
2013-03-02 01:40:04 +00:00
|
|
|
{ "bypass", kBypassKrId, 0, 0, kInDsvFl | kBoolDsvFl | kOptArgDsvFl, "Bypass enable flag." },
|
|
|
|
{ "wet", kWetKrId, 0, 0, kInDsvFl | kSampleDsvFl, "Wet mix level."},
|
2012-10-30 03:52:39 +00:00
|
|
|
{ "in", kAudioInKrId, 0, 0, kInDsvFl | kAudioBufDsvFl, "Audio Input" },
|
|
|
|
{ "out", kAudioOutKrId, 0, 1, kOutDsvFl | kAudioBufDsvFl, "Audio Output" },
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspKr_t* p = cmDspInstAlloc(cmDspKr_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
unsigned defWndSmpCnt = cmDspDefaultUInt(&p->inst,kWndSmpCntKrId);
|
|
|
|
unsigned wndSmpCnt = cmNextPowerOfTwo( defWndSmpCnt );
|
|
|
|
|
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst, kWndSmpCntKrId, defWndSmpCnt, wndSmpCnt );
|
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst, kHopFactKrId, 0, 4 );
|
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst, kModeKrId, 0, kBasicModeSdId );
|
|
|
|
cmDspSetDefaultDouble( ctx,&p->inst, kThreshKrId, 0, 60.0 );
|
|
|
|
cmDspSetDefaultDouble( ctx,&p->inst, kLwrSlopeKrId, 0, 2.0 );
|
|
|
|
cmDspSetDefaultDouble( ctx,&p->inst, kUprSlopeKrId, 0, 0.0 );
|
|
|
|
cmDspSetDefaultDouble( ctx,&p->inst, kOffsetKrId, 0, 30.0);
|
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst, kInvertKrId, 0, 0 );
|
2013-03-02 01:40:04 +00:00
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst, kBypassKrId, 0, 0 );
|
|
|
|
cmDspSetDefaultSample( ctx,&p->inst, kWetKrId, 0, 1.0);
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
//_cmDspKrCmInit(ctx,p); // initialize the cm library
|
|
|
|
|
|
|
|
p->ctx = cmCtxAlloc(NULL,ctx->rpt,ctx->lhH,ctx->stH);
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspKrFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspKr_t* p = (cmDspKr_t*)inst;
|
|
|
|
|
|
|
|
cmSpecDistFree(&p->sdp);
|
|
|
|
|
|
|
|
cmCtxFree(&p->ctx);
|
|
|
|
//_cmDspKrCmFinal(ctx,p); // finalize the cm library
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspKrSetup(cmDspCtx_t* ctx, cmDspKr_t* p )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
unsigned wndSmpCnt = cmDspUInt(&p->inst,kWndSmpCntKrId);
|
|
|
|
unsigned hopFact = cmDspUInt(&p->inst,kHopFactKrId);
|
2013-03-02 01:40:04 +00:00
|
|
|
unsigned olaWndTypeId =kHannWndId;
|
2012-10-30 03:52:39 +00:00
|
|
|
|
|
|
|
cmSpecDistFree(&p->sdp);
|
2013-03-02 01:40:04 +00:00
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
p->sdp = cmSpecDistAlloc(p->ctx, NULL, cmDspSamplesPerCycle(ctx), cmDspSampleRate(ctx), wndSmpCnt, hopFact, olaWndTypeId);
|
|
|
|
|
|
|
|
assert(p->sdp != NULL );
|
|
|
|
|
|
|
|
if((rc = cmDspZeroAudioBuf(ctx,&p->inst,kAudioOutKrId)) != kOkDspRC )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspKrReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspKr_t* p = (cmDspKr_t*)inst;
|
|
|
|
cmDspRC_t rc;
|
|
|
|
|
|
|
|
if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return _cmDspKrSetup(ctx,p);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspKrExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspKr_t* p = (cmDspKr_t*)inst;
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
|
|
|
|
unsigned iChIdx = 0;
|
|
|
|
const cmSample_t* ip = cmDspAudioBuf(ctx,inst,kAudioInKrId,iChIdx);
|
|
|
|
unsigned iSmpCnt = cmDspVarRows(inst,kAudioInKrId);
|
2013-02-09 07:48:54 +00:00
|
|
|
|
|
|
|
// if no connected
|
|
|
|
if( iSmpCnt == 0 )
|
|
|
|
return rc;
|
2012-10-30 03:52:39 +00:00
|
|
|
|
|
|
|
unsigned oChIdx = 0;
|
|
|
|
cmSample_t* op = cmDspAudioBuf(ctx,inst,kAudioOutKrId,oChIdx);
|
|
|
|
unsigned oSmpCnt = cmDspVarRows(inst,kAudioOutKrId);
|
|
|
|
const cmSample_t* sp;
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
cmSample_t wet = cmDspSample(inst,kWetKrId);
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
cmSpecDistExec(p->sdp,ip,iSmpCnt);
|
|
|
|
|
|
|
|
if((sp = cmSpecDistOut(p->sdp)) != NULL )
|
2013-03-02 01:40:04 +00:00
|
|
|
{
|
|
|
|
cmVOS_MultVVS(op,oSmpCnt,sp,wet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wet<1.0 )
|
|
|
|
cmVOS_MultSumVVS(op,oSmpCnt,ip,1.0-wet);
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspKrRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspKr_t* p = (cmDspKr_t*)inst;
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
|
|
|
case kWndSmpCntKrId:
|
|
|
|
case kHopFactKrId:
|
|
|
|
_cmDspKrSetup(ctx,p);
|
2013-03-02 01:40:04 +00:00
|
|
|
|
|
|
|
// THIS IS A HACK
|
|
|
|
// WHEN WND OR HOP CHANGE THE RESULTING CHANGES
|
|
|
|
// SHOULD BE ISOLATED IN cmSpecDist() AND THE
|
|
|
|
// CURRENT STATE OF THE PARAMETERS SHOULD NOT BE
|
|
|
|
// LOST - IF THE CHANGES WERE ISOLATED WITHIN PVANL
|
|
|
|
// AND PVSYN IT MIGHT BE POSSIBLE TO DO WITH
|
|
|
|
// MINIMAL AUDIO INTERUPTION.
|
|
|
|
|
|
|
|
p->sdp->mode = cmDspUInt(inst,kModeKrId);
|
|
|
|
p->sdp->thresh = cmDspDouble(inst,kThreshKrId);
|
|
|
|
p->sdp->uprSlope = cmDspDouble(inst,kUprSlopeKrId);
|
|
|
|
p->sdp->lwrSlope = cmDspDouble(inst,kLwrSlopeKrId);
|
|
|
|
p->sdp->offset = cmDspDouble(inst,kOffsetKrId);
|
|
|
|
p->sdp->invertFl = cmDspUInt(inst,kInvertKrId)!=0;
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
printf("wsn:%i hsn:%i\n",p->sdp->wndSmpCnt,p->sdp->hopSmpCnt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kModeKrId:
|
|
|
|
p->sdp->mode = cmDspUInt(inst,kModeKrId);
|
|
|
|
printf("mode:%i\n",p->sdp->mode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kThreshKrId:
|
|
|
|
p->sdp->thresh = cmDspDouble(inst,kThreshKrId);
|
2013-03-02 01:40:04 +00:00
|
|
|
//printf("thr:p:%p sdp:%p %f\n",p,p->sdp,p->sdp->thresh);
|
2012-10-30 03:52:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kUprSlopeKrId:
|
|
|
|
p->sdp->uprSlope = cmDspDouble(inst,kUprSlopeKrId);
|
2013-03-02 01:40:04 +00:00
|
|
|
//printf("upr slope:%f\n",p->sdp->uprSlope);
|
2012-10-30 03:52:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kLwrSlopeKrId:
|
|
|
|
p->sdp->lwrSlope = cmDspDouble(inst,kLwrSlopeKrId);
|
2013-03-02 01:40:04 +00:00
|
|
|
//printf("upr slope:%f\n",p->sdp->lwrSlope);
|
2012-10-30 03:52:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kOffsetKrId:
|
|
|
|
p->sdp->offset = cmDspDouble(inst,kOffsetKrId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kInvertKrId:
|
|
|
|
p->sdp->invertFl = cmDspUInt(inst,kInvertKrId)!=0;
|
|
|
|
break;
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
case kWetKrId:
|
|
|
|
break;
|
|
|
|
|
2012-10-30 03:52:39 +00:00
|
|
|
default:
|
|
|
|
{ assert(0); }
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmKrClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmKrDC,ctx,"Kr",
|
|
|
|
NULL,
|
|
|
|
_cmDspKrAlloc,
|
|
|
|
_cmDspKrFree,
|
|
|
|
_cmDspKrReset,
|
|
|
|
_cmDspKrExec,
|
|
|
|
_cmDspKrRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Fourier based non-linear transformer.");
|
|
|
|
|
|
|
|
return &_cmKrDC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
//==========================================================================================================================================
|
2012-11-18 01:33:10 +00:00
|
|
|
// Time Line UI Object
|
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
enum
|
|
|
|
{
|
2012-11-16 18:01:57 +00:00
|
|
|
kTlFileTlId,
|
2013-08-12 07:11:59 +00:00
|
|
|
kPrefixPathTlId,
|
2012-11-16 20:13:36 +00:00
|
|
|
kSelTlId,
|
2012-11-27 07:07:22 +00:00
|
|
|
kCursTlId,
|
|
|
|
kResetTlId,
|
2012-11-16 20:13:36 +00:00
|
|
|
kAudFnTlId,
|
2013-09-26 06:46:11 +00:00
|
|
|
kAudLblTlId,
|
2012-11-17 06:07:46 +00:00
|
|
|
kMidiFnTlId,
|
2013-09-26 06:46:11 +00:00
|
|
|
kMidiLblTlId,
|
2012-11-18 01:33:10 +00:00
|
|
|
kBegAudSmpIdxTlId,
|
|
|
|
kEndAudSmpIdxTlId,
|
|
|
|
kBegMidiSmpIdxTlId,
|
|
|
|
kEndMidiSmpIdxTlId
|
2012-11-16 01:42:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmTimeLineDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
2012-11-16 20:13:36 +00:00
|
|
|
cmTlH_t tlH;
|
2012-11-27 07:07:22 +00:00
|
|
|
unsigned afIdx;
|
2012-11-16 01:42:29 +00:00
|
|
|
} cmDspTimeLine_t;
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2012-11-27 07:07:22 +00:00
|
|
|
{ "tlfile", kTlFileTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Time line file." },
|
2013-08-12 07:11:59 +00:00
|
|
|
{ "path", kPrefixPathTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Time line data file prefix path" },
|
2012-11-27 07:07:22 +00:00
|
|
|
{ "sel", kSelTlId, 0, 0, kInDsvFl | kOutDsvFl | kUIntDsvFl, "Selected marker id."},
|
|
|
|
{ "curs", kCursTlId, 0, 0, kInDsvFl | kUIntDsvFl, "Current audio file index."},
|
|
|
|
{ "reset", kResetTlId, 0, 0, kInDsvFl | kSymDsvFl, "Resend all outputs." },
|
|
|
|
{ "afn", kAudFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected Audio file." },
|
2013-09-26 06:46:11 +00:00
|
|
|
{ "albl", kAudLblTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Select Audio file time line label."},
|
2012-11-27 07:07:22 +00:00
|
|
|
{ "mfn", kMidiFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected MIDI file." },
|
2013-09-26 06:46:11 +00:00
|
|
|
{ "mlbl", kMidiLblTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Select MIDI file time line label."},
|
2012-11-27 07:07:22 +00:00
|
|
|
{ "absi", kBegAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin audio sample index."},
|
|
|
|
{ "aesi", kEndAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "End audio sample index."},
|
|
|
|
{ "mbsi", kBegMidiSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin MIDI sample index."},
|
|
|
|
{ "mesi", kEndMidiSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "End MIDI sample index."},
|
2012-11-16 01:42:29 +00:00
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspTimeLine_t* p = cmDspInstAlloc(cmDspTimeLine_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
2012-11-16 20:13:36 +00:00
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kSelTlId, 0, cmInvalidId);
|
2012-11-27 07:07:22 +00:00
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kCursTlId, 0, 0);
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetDefaultStrcz(ctx, &p->inst, kAudFnTlId, NULL, "");
|
2013-09-26 06:46:11 +00:00
|
|
|
cmDspSetDefaultStrcz(ctx, &p->inst, kAudLblTlId, NULL, "");
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetDefaultStrcz(ctx, &p->inst, kMidiFnTlId, NULL, "");
|
2013-09-26 06:46:11 +00:00
|
|
|
cmDspSetDefaultStrcz(ctx, &p->inst, kMidiLblTlId, NULL, "");
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kBegAudSmpIdxTlId, 0, cmInvalidIdx);
|
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kEndAudSmpIdxTlId, 0, cmInvalidIdx);
|
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kBegMidiSmpIdxTlId, 0, cmInvalidIdx);
|
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kEndMidiSmpIdxTlId, 0, cmInvalidIdx);
|
2012-11-16 01:42:29 +00:00
|
|
|
|
|
|
|
// create the UI control
|
2013-08-12 07:11:59 +00:00
|
|
|
cmDspUiTimeLineCreate(ctx,&p->inst,kTlFileTlId,kPrefixPathTlId,kSelTlId,kCursTlId);
|
2012-11-16 20:13:36 +00:00
|
|
|
|
|
|
|
p->tlH = cmTimeLineNullHandle;
|
2012-11-16 01:42:29 +00:00
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
2012-11-16 20:13:36 +00:00
|
|
|
cmDspRC_t _cmDspTimeLineFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
|
|
|
|
|
|
|
if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
|
|
|
|
return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "Time-line finalize failed.");
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
cmDspRC_t _cmDspTimeLineReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2012-11-16 20:13:36 +00:00
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
2012-11-16 20:13:36 +00:00
|
|
|
|
|
|
|
const cmChar_t* tlFn;
|
2013-08-12 07:11:59 +00:00
|
|
|
|
|
|
|
const cmChar_t* tlPrePath = cmDspStrcz(inst,kPrefixPathTlId);
|
|
|
|
|
2012-11-16 20:13:36 +00:00
|
|
|
if((tlFn = cmDspStrcz(inst, kTlFileTlId )) != NULL )
|
2013-08-12 07:11:59 +00:00
|
|
|
if( cmTimeLineInitializeFromFile(ctx->cmCtx, &p->tlH, NULL, NULL, tlFn, tlPrePath ) != kOkTlRC )
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Time-line file open failed.");
|
2012-11-16 20:13:36 +00:00
|
|
|
|
|
|
|
return rc;
|
2012-11-16 01:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2012-11-17 06:07:46 +00:00
|
|
|
cmDspTimeLine_t* p = (cmDspTimeLine_t*)inst;
|
2012-11-16 01:42:29 +00:00
|
|
|
|
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
2013-08-12 07:11:59 +00:00
|
|
|
case kPrefixPathTlId:
|
2013-05-22 22:13:41 +00:00
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
break;
|
|
|
|
|
2012-11-27 07:07:22 +00:00
|
|
|
case kCursTlId:
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kResetTlId:
|
2012-11-16 20:13:36 +00:00
|
|
|
case kSelTlId:
|
2012-11-17 06:07:46 +00:00
|
|
|
{
|
|
|
|
unsigned markerId;
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
// get the id of the selected marker
|
|
|
|
if((markerId = cmDspUInt(inst,kSelTlId)) != cmInvalidId )
|
|
|
|
{
|
|
|
|
// get the marker object
|
|
|
|
cmTlObj_t* op;
|
|
|
|
if((op = cmTimeLineIdToObj(p->tlH, cmInvalidId, markerId )) != NULL )
|
|
|
|
{
|
|
|
|
assert(op->typeId == kMarkerTlId);
|
|
|
|
|
2012-11-27 07:07:22 +00:00
|
|
|
p->afIdx = op->begSmpIdx;
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetInt(ctx, inst, kBegAudSmpIdxTlId, op->begSmpIdx );
|
|
|
|
cmDspSetInt(ctx, inst, kEndAudSmpIdxTlId, op->begSmpIdx + op->durSmpCnt );
|
2012-11-17 06:07:46 +00:00
|
|
|
|
|
|
|
// locate the audio file assoc'd with the marker
|
|
|
|
cmTlAudioFile_t* afp;
|
|
|
|
if((afp = cmTimeLineAudioFileAtTime(p->tlH,op->seqId,op->seqSmpIdx)) != NULL)
|
2013-09-26 06:46:11 +00:00
|
|
|
{
|
2012-11-17 06:07:46 +00:00
|
|
|
cmDspSetStrcz(ctx, inst, kAudFnTlId, afp->fn );
|
2013-09-26 06:46:11 +00:00
|
|
|
cmDspSetStrcz(ctx, inst, kAudLblTlId, afp->obj.name );
|
|
|
|
}
|
2012-11-17 06:07:46 +00:00
|
|
|
|
|
|
|
// locate the midi file assoc'd with the marker
|
|
|
|
cmTlMidiFile_t* mfp;
|
|
|
|
if((mfp = cmTimeLineMidiFileAtTime(p->tlH,op->seqId,op->seqSmpIdx)) != NULL )
|
2012-11-18 01:33:10 +00:00
|
|
|
{
|
|
|
|
cmDspSetInt(ctx, inst, kBegMidiSmpIdxTlId, op->seqSmpIdx - mfp->obj.seqSmpIdx );
|
|
|
|
cmDspSetInt(ctx, inst, kEndMidiSmpIdxTlId, op->seqSmpIdx + op->durSmpCnt - mfp->obj.seqSmpIdx );
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
cmDspSetStrcz(ctx, inst, kMidiFnTlId, mfp->fn );
|
2013-09-26 06:46:11 +00:00
|
|
|
cmDspSetStrcz(ctx, inst, kMidiLblTlId,mfp->obj.name );
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
2012-11-17 06:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-11-16 20:13:36 +00:00
|
|
|
|
2012-11-16 01:42:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{assert(0);}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmTimeLineDC,ctx,"TimeLine",
|
|
|
|
NULL,
|
|
|
|
_cmDspTimeLineAlloc,
|
2012-11-16 20:13:36 +00:00
|
|
|
_cmDspTimeLineFree,
|
2012-11-16 01:42:29 +00:00
|
|
|
_cmDspTimeLineReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspTimeLineRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Time Line control.");
|
|
|
|
|
|
|
|
return &_cmTimeLineDC;
|
|
|
|
}
|
|
|
|
|
2012-11-27 07:07:22 +00:00
|
|
|
//==========================================================================================================================================
|
|
|
|
// Score UI Object
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kFnScId,
|
|
|
|
kSelScId,
|
2012-12-13 23:38:45 +00:00
|
|
|
kSendScId,
|
|
|
|
kStatusScId,
|
|
|
|
kD0ScId,
|
|
|
|
kD1ScId,
|
|
|
|
kSmpIdxScId,
|
|
|
|
kLocIdxScId,
|
|
|
|
kEvtIdxScId,
|
|
|
|
kDynScId,
|
|
|
|
kValTypeScId,
|
|
|
|
kValueScId
|
2012-11-27 07:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmScoreDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmScH_t scH;
|
2012-12-13 23:38:45 +00:00
|
|
|
cmDspCtx_t* ctx; // temporary ctx ptr used during cmScore callback in _cmDspScoreRecv()
|
2012-11-27 07:07:22 +00:00
|
|
|
} cmDspScore_t;
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspScoreAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2012-12-13 23:38:45 +00:00
|
|
|
{ "fn", kFnScId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Score file." },
|
|
|
|
{ "sel", kSelScId, 0, 0, kInDsvFl | kOutDsvFl | kUIntDsvFl, "Selected score element index input."},
|
|
|
|
{ "send", kSendScId, 0, 0, kInDsvFl | kTypeDsvMask, "Resend last selected score element."},
|
|
|
|
{ "status", kStatusScId, 0, 0, kInDsvFl | kIntDsvFl, "Performed MIDI status value output" },
|
|
|
|
{ "d0", kD0ScId, 0, 0, kInDsvFl | kUIntDsvFl, "Performed MIDI msg data byte 0" },
|
|
|
|
{ "d1", kD1ScId, 0, 0, kInDsvFl | kUIntDsvFl, "Performed MIDI msg data byte 1" },
|
|
|
|
{ "smpidx", kSmpIdxScId, 0, 0, kInDsvFl | kUIntDsvFl, "Performed MIDi msg time tag as a sample index." },
|
|
|
|
{ "loc", kLocIdxScId, 0, 0, kInDsvFl | kUIntDsvFl, "Performance score location."},
|
|
|
|
{ "evtidx", kEvtIdxScId, 0, 0, kOutDsvFl | kUIntDsvFl, "Performed event index of following dynamcis level."},
|
|
|
|
{ "dyn", kDynScId, 0, 0, kOutDsvFl | kUIntDsvFl, "Dynamic level of previous event index."},
|
|
|
|
{ "type", kValTypeScId,0, 0, kOutDsvFl | kUIntDsvFl, "Output variable type."},
|
|
|
|
{ "value", kValueScId, 0, 0, kOutDsvFl | kDoubleDsvFl, "Output variable value."},
|
2012-11-27 07:07:22 +00:00
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspScore_t* p = cmDspInstAlloc(cmDspScore_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kSelScId, 0, cmInvalidId);
|
|
|
|
|
|
|
|
// create the UI control
|
2012-12-13 23:38:45 +00:00
|
|
|
cmDspUiScoreCreate(ctx,&p->inst,kFnScId,kSelScId,kSmpIdxScId,kD0ScId,kD1ScId,kLocIdxScId,kEvtIdxScId,kDynScId,kValTypeScId,kValueScId);
|
2012-11-27 07:07:22 +00:00
|
|
|
|
|
|
|
p->scH = cmScNullHandle;
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScoreFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScore_t* p = (cmDspScore_t*)inst;
|
|
|
|
|
|
|
|
if( cmScoreFinalize(&p->scH) != kOkTlRC )
|
|
|
|
return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "Score finalize failed.");
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
// Callback from cmScore triggered from _cmDspScoreRecv() during call to cmScoreSetPerfEvent().
|
|
|
|
void _cmDspScoreCb( void* arg, const void* data, unsigned byteCnt )
|
|
|
|
{
|
|
|
|
cmDspInst_t* inst = (cmDspInst_t*)arg;
|
|
|
|
cmDspScore_t* p = (cmDspScore_t*)inst;
|
|
|
|
cmScMsg_t m;
|
|
|
|
if( cmScoreDecode(data,byteCnt,&m) == kOkScRC )
|
|
|
|
{
|
|
|
|
switch( m.typeId )
|
|
|
|
{
|
|
|
|
case kDynMsgScId:
|
|
|
|
cmDspSetUInt( p->ctx,inst, kEvtIdxScId, m.u.dyn.evtIdx );
|
|
|
|
cmDspSetUInt( p->ctx,inst, kDynScId, m.u.dyn.dynLvl );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVarMsgScId:
|
|
|
|
cmDspSetUInt( p->ctx,inst, kValTypeScId, m.u.meas.varId);
|
|
|
|
cmDspSetDouble(p->ctx,inst, kValueScId, m.u.meas.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{ assert(0); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-27 07:07:22 +00:00
|
|
|
|
|
|
|
cmDspRC_t _cmDspScoreReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2012-12-13 23:38:45 +00:00
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScore_t* p = (cmDspScore_t*)inst;
|
|
|
|
const cmChar_t* tlFn = NULL;
|
|
|
|
unsigned* dynRefArray = NULL;
|
|
|
|
unsigned dynRefCnt = 0;
|
2012-11-27 07:07:22 +00:00
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
|
|
|
|
if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
|
|
|
|
{
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
2012-11-27 07:07:22 +00:00
|
|
|
if((tlFn = cmDspStrcz(inst, kFnScId )) != NULL )
|
2013-03-02 01:40:04 +00:00
|
|
|
if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, cmDspSampleRate(ctx), dynRefArray, dynRefCnt, _cmDspScoreCb, p, cmSymTblNullHandle ) != kOkTlRC )
|
2012-11-27 07:07:22 +00:00
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Score file open failed.");
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
errLabel:
|
2012-11-27 07:07:22 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScoreRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2012-12-13 23:38:45 +00:00
|
|
|
cmDspScore_t* p = (cmDspScore_t*)inst;
|
|
|
|
|
|
|
|
if( evt->dstVarId == kSendScId )
|
|
|
|
{
|
|
|
|
unsigned selIdx;
|
|
|
|
if((selIdx = cmDspUInt(inst,kSelScId)) != cmInvalidIdx )
|
|
|
|
{
|
|
|
|
cmDspSetUInt(ctx,inst,kSelScId, selIdx );
|
|
|
|
cmScoreClearPerfInfo(p->scH);
|
|
|
|
}
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
2012-11-27 07:07:22 +00:00
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
|
|
|
case kSelScId:
|
2012-12-13 23:38:45 +00:00
|
|
|
cmScoreClearPerfInfo(p->scH);
|
2012-11-27 07:07:22 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
case kStatusScId:
|
|
|
|
//printf("st:%x\n",cmDspUInt(inst,kStatusScId));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kLocIdxScId:
|
2012-11-27 07:07:22 +00:00
|
|
|
{
|
2012-12-13 23:38:45 +00:00
|
|
|
assert( cmDspUInt(inst,kStatusScId ) == kNoteOnMdId );
|
|
|
|
p->ctx = ctx; // setup p->ctx for use in _cmDspScoreCb()
|
|
|
|
|
|
|
|
// this call may result in callbacks to _cmDspScoreCb()
|
|
|
|
cmScoreExecPerfEvent(p->scH, cmDspUInt(inst,kLocIdxScId), cmDspUInt(inst,kSmpIdxScId), cmDspUInt(inst,kD0ScId), cmDspUInt(inst,kD1ScId) );
|
2012-11-27 07:07:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmScoreClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmScoreDC,ctx,"Score",
|
|
|
|
NULL,
|
|
|
|
_cmDspScoreAlloc,
|
|
|
|
_cmDspScoreFree,
|
|
|
|
_cmDspScoreReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspScoreRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Score control.");
|
|
|
|
|
|
|
|
return &_cmScoreDC;
|
|
|
|
}
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
//==========================================================================================================================================
|
2012-11-18 01:33:10 +00:00
|
|
|
// MIDI File Player
|
2012-11-17 06:07:46 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kFnMfId,
|
|
|
|
kSelMfId,
|
|
|
|
kBsiMfId,
|
|
|
|
kEsiMfId,
|
|
|
|
kStatusMfId,
|
|
|
|
kD0MfId,
|
2012-12-04 01:12:09 +00:00
|
|
|
kD1MfId,
|
2013-09-26 06:46:11 +00:00
|
|
|
kSmpIdxMfId,
|
|
|
|
kIdMfId
|
2012-11-17 06:07:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmMidiFilePlayDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmMidiFileH_t mfH;
|
2012-11-18 01:33:10 +00:00
|
|
|
unsigned curMsgIdx; // current midi file msg index
|
|
|
|
int csi; // current sample index
|
|
|
|
int bsi; // starting sample index
|
|
|
|
int esi; // ending sample index
|
2012-11-17 06:07:46 +00:00
|
|
|
unsigned startSymId;
|
|
|
|
unsigned stopSymId;
|
|
|
|
unsigned contSymId;
|
2012-12-17 20:53:41 +00:00
|
|
|
bool errFl;
|
2012-11-17 06:07:46 +00:00
|
|
|
} cmDspMidiFilePlay_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
'bsi' and 'esi' give the starting and ending sample for MIDI file playback.
|
|
|
|
These indexes are relative to the start of the file.
|
|
|
|
When the player recieves a 'start' msg it sets the current sample index
|
|
|
|
'si' to 'bsi' and begins scanning for the next note to play.
|
|
|
|
On each call to the _cmDspMidiFilePlayExec() msgs that fall in the interval
|
|
|
|
si:si+sPc-1 will be transmitted. (where sPc are the number of samples per DSP cycle).
|
|
|
|
*/
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspMidiFilePlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2012-11-18 01:33:10 +00:00
|
|
|
{ "fn", kFnMfId, 0, 0, kInDsvFl | kStrzDsvFl, "File name"},
|
2012-11-17 06:07:46 +00:00
|
|
|
{ "sel", kSelMfId, 0, 0, kInDsvFl | kSymDsvFl, "start | stop | continue" },
|
2012-12-04 01:12:09 +00:00
|
|
|
{ "bsi", kBsiMfId, 0, 0, kInDsvFl | kIntDsvFl, "Starting sample." },
|
|
|
|
{ "esi", kEsiMfId, 0, 0, kInDsvFl | kIntDsvFl, "Ending sample."},
|
|
|
|
{ "status", kStatusMfId, 0, 0, kOutDsvFl | kIntDsvFl, "Status value output" },
|
2012-11-17 06:07:46 +00:00
|
|
|
{ "d0", kD0MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 0" },
|
|
|
|
{ "d1", kD1MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 1" },
|
2013-09-26 06:46:11 +00:00
|
|
|
{ "smpidx", kSmpIdxMfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Msg time tag as a sample index." },
|
|
|
|
{ "id", kIdMfId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI file msg unique id."},
|
2012-11-17 06:07:46 +00:00
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspMidiFilePlay_t* p = cmDspInstAlloc(cmDspMidiFilePlay_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
p->startSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"start");
|
|
|
|
p->stopSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"stop");
|
|
|
|
p->contSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"continue");
|
|
|
|
p->mfH = cmMidiFileNullHandle;
|
2012-11-18 01:33:10 +00:00
|
|
|
|
|
|
|
cmDspSetDefaultStrcz( ctx, &p->inst, kFnMfId, NULL, "");
|
|
|
|
cmDspSetDefaultSymbol(ctx, &p->inst, kSelMfId, p->stopSymId);
|
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kBsiMfId, 0, 0);
|
|
|
|
cmDspSetDefaultInt( ctx, &p->inst, kEsiMfId, 0, 0);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kStatusMfId, 0, 0);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kD0MfId, 0, 0);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kD1MfId, 0, 0);
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspMidiFilePlayFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
|
|
if( cmMidiFileClose(&p->mfH) )
|
|
|
|
return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "MIDI file close failed.");
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the index of the msg following smpIdx
|
2012-12-17 20:53:41 +00:00
|
|
|
unsigned _cmDspMidiFilePlaySeekMsgIdx( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned smpIdx )
|
2012-11-17 06:07:46 +00:00
|
|
|
{
|
2012-12-17 20:53:41 +00:00
|
|
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
|
|
|
|
|
|
if( cmMidiFileIsValid(p->mfH) == false )
|
|
|
|
{
|
|
|
|
cmErrMsg(&inst->classPtr->err, kInvalidStateDspRC,"The MIDI file player has not been given a valid MIDI file.");
|
|
|
|
return cmInvalidIdx;
|
|
|
|
}
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned n = cmMidiFileMsgCount(p->mfH);
|
|
|
|
const cmMidiTrackMsg_t** a = cmMidiFileMsgArray(p->mfH);
|
|
|
|
|
|
|
|
for(i=0; i<n; ++i)
|
2012-11-18 01:33:10 +00:00
|
|
|
if( a[i]->dtick > smpIdx )
|
2012-11-17 06:07:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
return i==n ? cmInvalidIdx : i;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
|
|
|
|
{
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
const cmChar_t* fn = cmDspStrcz(inst,kFnMfId);
|
2012-11-17 06:07:46 +00:00
|
|
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
|
|
|
2012-12-17 20:53:41 +00:00
|
|
|
p->errFl = false;
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
if( fn==NULL || strlen(fn)==0 )
|
|
|
|
return rc;
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
if( cmMidiFileOpen( fn, &p->mfH, ctx->cmCtx ) != kOkFileRC )
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "MIDI file open failed.");
|
|
|
|
else
|
|
|
|
{
|
2012-11-18 01:33:10 +00:00
|
|
|
p->curMsgIdx = 0;
|
|
|
|
p->bsi = cmDspInt(inst,kBsiMfId);
|
|
|
|
p->esi = cmDspInt(inst,kEsiMfId);
|
|
|
|
p->csi = 0;
|
2012-12-17 20:53:41 +00:00
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
// force the first msg to occurr one quarter note into the file
|
|
|
|
cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
|
|
|
|
|
|
|
|
// convert midi msg times to absolute time in samples
|
|
|
|
cmMidiFileTickToSamples(p->mfH,cmDspSampleRate(ctx),true);
|
2012-12-13 23:38:45 +00:00
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspMidiFilePlayReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
return _cmDspMidiFilePlayOpen(ctx,inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspMidiFilePlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
|
|
unsigned sPc = cmDspSamplesPerCycle(ctx);
|
2012-11-17 06:07:46 +00:00
|
|
|
|
2012-12-17 20:53:41 +00:00
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
if( cmDspSymbol(inst,kSelMfId) != p->stopSymId )
|
|
|
|
{
|
2012-12-17 20:53:41 +00:00
|
|
|
if( cmMidiFileIsValid(p->mfH) == false )
|
|
|
|
{
|
|
|
|
if( p->errFl==false )
|
|
|
|
{
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kInvalidStateDspRC,"The MIDI file player has not been given a valid MIDI file.");
|
|
|
|
p->errFl = true;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
const cmMidiTrackMsg_t** mpp = cmMidiFileMsgArray(p->mfH);
|
|
|
|
unsigned msgN = cmMidiFileMsgCount(p->mfH);
|
2012-11-17 06:07:46 +00:00
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
for(; p->curMsgIdx < msgN && p->csi <= mpp[p->curMsgIdx]->dtick && mpp[p->curMsgIdx]->dtick < (p->csi + sPc); ++p->curMsgIdx )
|
|
|
|
{
|
|
|
|
const cmMidiTrackMsg_t* mp = mpp[p->curMsgIdx];
|
|
|
|
switch( mp->status )
|
|
|
|
{
|
|
|
|
case kNoteOnMdId:
|
|
|
|
case kCtlMdId:
|
2012-12-04 01:12:09 +00:00
|
|
|
cmDspSetUInt(ctx,inst, kSmpIdxMfId, mp->dtick);
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspSetUInt(ctx,inst, kD1MfId, mp->u.chMsgPtr->d1);
|
|
|
|
cmDspSetUInt(ctx,inst, kD0MfId, mp->u.chMsgPtr->d0);
|
|
|
|
cmDspSetUInt(ctx,inst, kStatusMfId, mp->status);
|
2013-09-26 06:46:11 +00:00
|
|
|
cmDspSetUInt(ctx,inst, kIdMfId, mp->uid);
|
2012-11-18 01:33:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-17 06:07:46 +00:00
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
p->csi += sPc;
|
|
|
|
|
2012-11-17 06:07:46 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspMidiFilePlayRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
|
|
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
switch(evt->dstVarId)
|
|
|
|
{
|
|
|
|
case kFnMfId:
|
|
|
|
_cmDspMidiFilePlayOpen(ctx, inst );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kSelMfId:
|
|
|
|
{
|
|
|
|
if( cmDspSymbol(inst,kSelMfId)==p->startSymId )
|
|
|
|
{
|
2012-11-18 01:33:10 +00:00
|
|
|
p->csi = cmDspInt(inst,kBsiMfId);
|
2012-12-17 20:53:41 +00:00
|
|
|
p->curMsgIdx = _cmDspMidiFilePlaySeekMsgIdx(ctx, inst, p->csi );
|
2012-11-17 06:07:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
2012-11-17 06:07:46 +00:00
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmMidiFilePlayClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmMidiFilePlayDC,ctx,"MidiFilePlay",
|
|
|
|
NULL,
|
|
|
|
_cmDspMidiFilePlayAlloc,
|
|
|
|
_cmDspMidiFilePlayFree,
|
|
|
|
_cmDspMidiFilePlayReset,
|
|
|
|
_cmDspMidiFilePlayExec,
|
|
|
|
_cmDspMidiFilePlayRecv,
|
|
|
|
NULL,NULL,
|
2013-09-26 06:46:11 +00:00
|
|
|
"MIDI file player.");
|
2012-11-17 06:07:46 +00:00
|
|
|
|
|
|
|
return &_cmMidiFilePlayDC;
|
|
|
|
}
|
2012-11-18 01:33:10 +00:00
|
|
|
|
|
|
|
//==========================================================================================================================================
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kFnSfId,
|
2012-11-27 22:20:54 +00:00
|
|
|
kBufCntSfId,
|
2012-12-04 01:12:09 +00:00
|
|
|
kMinLkAhdSfId,
|
|
|
|
kMaxWndCntSfId,
|
|
|
|
kMinVelSfId,
|
2012-11-18 01:33:10 +00:00
|
|
|
kIndexSfId,
|
|
|
|
kStatusSfId,
|
|
|
|
kD0SfId,
|
|
|
|
kD1SfId,
|
2012-12-04 01:12:09 +00:00
|
|
|
kSmpIdxSfId,
|
2012-12-13 23:38:45 +00:00
|
|
|
kCmdSfId,
|
2013-01-31 01:37:23 +00:00
|
|
|
kOutSfId,
|
|
|
|
kDynSfId,
|
|
|
|
kEvenSfId,
|
2013-03-02 01:40:04 +00:00
|
|
|
kTempoSfId,
|
|
|
|
kCostSfId,
|
|
|
|
kSymSfId
|
2012-11-18 01:33:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmScFolDC;
|
2013-01-31 01:37:23 +00:00
|
|
|
struct cmDspScFol_str;
|
2012-11-18 01:33:10 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-01-31 01:37:23 +00:00
|
|
|
cmDspCtx_t* ctx;
|
|
|
|
struct cmDspScFol_str* sfp;
|
|
|
|
} cmDspScFolCbArg_t;
|
|
|
|
|
|
|
|
typedef struct cmDspScFol_str
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmScMatcher* sfp;
|
|
|
|
cmScMeas* smp;
|
|
|
|
cmScH_t scH;
|
|
|
|
cmDspScFolCbArg_t arg;
|
|
|
|
unsigned printSymId;
|
|
|
|
unsigned quietSymId;
|
2012-11-18 01:33:10 +00:00
|
|
|
} cmDspScFol_t;
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2012-12-04 01:12:09 +00:00
|
|
|
{ "fn", kFnSfId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Score file." },
|
|
|
|
{ "bufcnt",kBufCntSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Event buffer element count." },
|
|
|
|
{ "lkahd", kMinLkAhdSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Minimum window look-ahead."},
|
|
|
|
{ "wndcnt",kMaxWndCntSfId,0, 0, kInDsvFl | kUIntDsvFl, "Maximum window length."},
|
|
|
|
{ "minvel",kMinVelSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Minimum velocity."},
|
|
|
|
{ "index", kIndexSfId, 0, 0, kInDsvFl | kUIntDsvFl, "Tracking start location."},
|
|
|
|
{ "status",kStatusSfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI status byte"},
|
|
|
|
{ "d0", kD0SfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI data byte 0"},
|
|
|
|
{ "d1", kD1SfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI data byte 1"},
|
|
|
|
{ "smpidx",kSmpIdxSfId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI time tag as a sample index"},
|
2012-12-13 23:38:45 +00:00
|
|
|
{ "cmd", kCmdSfId, 0, 0, kInDsvFl | kSymDsvFl, "Command input: print | quiet"},
|
2013-07-10 21:19:33 +00:00
|
|
|
{ "out", kOutSfId, 0, 0, kOutDsvFl| kUIntDsvFl, "Current score location index."},
|
2013-01-31 01:37:23 +00:00
|
|
|
{ "dyn", kDynSfId, 0, 0, kOutDsvFl| kDoubleDsvFl, "Dynamic value."},
|
|
|
|
{ "even", kEvenSfId, 0, 0, kOutDsvFl| kDoubleDsvFl, "Evenness value."},
|
|
|
|
{ "tempo", kTempoSfId, 0, 0, kOutDsvFl| kDoubleDsvFl, "Tempo value."},
|
2013-03-02 01:40:04 +00:00
|
|
|
{ "cost", kCostSfId, 0, 0, kOutDsvFl| kDoubleDsvFl, "Match cost value."},
|
|
|
|
{ "sym", kSymSfId, 0, 0, kOutDsvFl| kSymDsvFl, "Symbol associated with a global variable which has changed value."},
|
2012-12-04 01:12:09 +00:00
|
|
|
{ NULL, 0, 0, 0, 0, NULL }
|
2012-11-18 01:33:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspScFol_t* p;
|
|
|
|
|
|
|
|
if((p = cmDspInstAlloc(cmDspScFol_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl)) == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
p->sfp = cmScMatcherAlloc(ctx->cmProcCtx, NULL, 0, cmScNullHandle, 0, 0, NULL, NULL );
|
|
|
|
p->smp = cmScMeasAlloc( ctx->cmProcCtx, NULL, cmScNullHandle, 0, NULL, 0 );
|
2012-12-13 23:38:45 +00:00
|
|
|
p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"print");
|
|
|
|
p->quietSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"quiet");
|
2012-11-18 01:33:10 +00:00
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kBufCntSfId, 0, 7);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kMaxWndCntSfId, 0, 10);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kMinLkAhdSfId, 0, 3);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kMinVelSfId, 0, 5);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kIndexSfId, 0, 0);
|
|
|
|
cmDspSetDefaultUInt( ctx, &p->inst, kOutSfId, 0, 0);
|
|
|
|
cmDspSetDefaultDouble( ctx, &p->inst, kDynSfId, 0, 0);
|
|
|
|
cmDspSetDefaultDouble( ctx, &p->inst, kEvenSfId, 0, 0);
|
|
|
|
cmDspSetDefaultDouble( ctx, &p->inst, kTempoSfId, 0, 0);
|
2013-03-02 01:40:04 +00:00
|
|
|
cmDspSetDefaultDouble( ctx, &p->inst, kCostSfId, 0, 0);
|
2013-01-31 01:37:23 +00:00
|
|
|
|
|
|
|
cmDspSetDefaultSymbol(ctx,&p->inst, kCmdSfId, p->quietSymId );
|
2012-11-18 01:33:10 +00:00
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScFolFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
2013-01-31 01:37:23 +00:00
|
|
|
cmScMatcherFree(&p->sfp);
|
|
|
|
cmScMeasFree(&p->smp);
|
2012-11-18 01:33:10 +00:00
|
|
|
cmScoreFinalize(&p->scH);
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
// This is a callback function from cmScMatcherExec() which is called when
|
|
|
|
// this cmDspFol object receives a new score location index.
|
2013-01-31 01:37:23 +00:00
|
|
|
void _cmScFolMatcherCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
|
|
|
{
|
|
|
|
cmDspScFolCbArg_t* ap = (cmDspScFolCbArg_t*)arg;
|
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
if( cmScMeasExec(ap->sfp->smp, rp->mni, rp->locIdx, rp->scEvtIdx, rp->flags, rp->smpIdx, rp->pitch, rp->vel ) == cmOkRC )
|
|
|
|
{
|
2013-02-09 07:48:54 +00:00
|
|
|
cmDspInst_t* inst = &(ap->sfp->inst);
|
2013-01-31 01:37:23 +00:00
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
// send 'set' values that were calculated on the previous call to cmScMeasExec()
|
2013-01-31 01:37:23 +00:00
|
|
|
unsigned i;
|
2013-02-09 07:48:54 +00:00
|
|
|
for(i=ap->sfp->smp->vsi; i<ap->sfp->smp->nsi; ++i)
|
2013-05-26 16:34:40 +00:00
|
|
|
if(ap->sfp->smp->set[i].value != DBL_MAX )
|
2013-01-31 01:37:23 +00:00
|
|
|
{
|
2013-03-02 01:40:04 +00:00
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
switch( ap->sfp->smp->set[i].sp->varId )
|
|
|
|
{
|
|
|
|
case kEvenVarScId:
|
|
|
|
cmDspSetDouble(ap->ctx,inst,kEvenSfId,ap->sfp->smp->set[i].value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kDynVarScId:
|
|
|
|
cmDspSetDouble(ap->ctx,inst,kDynSfId,ap->sfp->smp->set[i].value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kTempoVarScId:
|
|
|
|
cmDspSetDouble(ap->ctx,inst,kTempoSfId,ap->sfp->smp->set[i].value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{ assert(0); }
|
|
|
|
}
|
2013-03-02 01:40:04 +00:00
|
|
|
|
|
|
|
cmDspSetDouble(ap->ctx,inst,kCostSfId,ap->sfp->smp->set[i].match_cost);
|
|
|
|
|
|
|
|
|
|
|
|
// Set the values in the global variable storage
|
|
|
|
cmDspValue_t vv,cv;
|
|
|
|
unsigned j;
|
|
|
|
cmDsvSetDouble(&vv,ap->sfp->smp->set[i].value);
|
|
|
|
cmDsvSetDouble(&cv,ap->sfp->smp->set[i].match_cost);
|
|
|
|
|
|
|
|
for(j=0; j<ap->sfp->smp->set[i].sp->sectCnt; ++j)
|
|
|
|
{
|
|
|
|
cmDspStoreSetValueViaSym(ap->ctx->dsH, ap->sfp->smp->set[i].sp->symArray[j], &vv );
|
|
|
|
cmDspStoreSetValueViaSym(ap->ctx->dsH, ap->sfp->smp->set[i].sp->costSymArray[j], &cv );
|
|
|
|
|
|
|
|
cmDspSetSymbol(ap->ctx,inst,kSymSfId,ap->sfp->smp->set[i].sp->symArray[j]);
|
|
|
|
cmDspSetSymbol(ap->ctx,inst,kSymSfId,ap->sfp->smp->set[i].sp->costSymArray[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
}
|
2013-02-09 07:48:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
// trigger 'section' starts
|
|
|
|
for(i=ap->sfp->smp->vsli; i<ap->sfp->smp->nsli; ++i)
|
|
|
|
{
|
|
|
|
const cmScoreLoc_t* locPtr = cmScoreLoc(ap->sfp->smp->mp->scH,i);
|
|
|
|
if( locPtr->begSectPtr != NULL )
|
|
|
|
cmDspSetUInt(ap->ctx,inst,kSectIndexSfId,locPtr->begSectPtr->index);
|
|
|
|
}
|
|
|
|
*/
|
2013-01-31 01:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-18 01:33:10 +00:00
|
|
|
cmDspRC_t _cmDspScFolOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
|
|
|
|
{
|
2013-01-31 01:37:23 +00:00
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
2012-11-18 01:33:10 +00:00
|
|
|
const cmChar_t* fn;
|
|
|
|
|
|
|
|
if((fn = cmDspStrcz(inst,kFnSfId)) == NULL || strlen(fn)==0 )
|
|
|
|
return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL, ctx->stH ) != kOkScRC )
|
2012-11-18 01:33:10 +00:00
|
|
|
return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
|
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
if( cmScoreIsValid(p->scH) )
|
|
|
|
{
|
|
|
|
unsigned* dynRefArray = NULL;
|
|
|
|
unsigned dynRefCnt = 0;
|
|
|
|
|
|
|
|
// initialize the cmScMatcher
|
|
|
|
if( cmScMatcherInit(p->sfp, cmDspSampleRate(ctx), p->scH, cmDspUInt(inst,kMaxWndCntSfId), cmDspUInt(inst,kBufCntSfId), _cmScFolMatcherCb, p->smp ) != cmOkRC )
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal score follower allocation failed.");
|
|
|
|
|
|
|
|
// read the dynamics reference array
|
|
|
|
if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
|
|
|
|
{
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize the cmScMeas object.
|
|
|
|
if( cmScMeasInit(p->smp, p->scH, cmDspSampleRate(ctx), dynRefArray, dynRefCnt ) != cmOkRC )
|
|
|
|
rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal scMeas object initialization failed.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-13 23:38:45 +00:00
|
|
|
errLabel:
|
|
|
|
return rc;
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2013-01-31 01:37:23 +00:00
|
|
|
cmDspRC_t rc;
|
|
|
|
if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
|
2012-11-18 01:33:10 +00:00
|
|
|
return rc;
|
|
|
|
|
2013-01-31 01:37:23 +00:00
|
|
|
return _cmDspScFolOpenScore(ctx,inst);
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScFolRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScFol_t* p = (cmDspScFol_t*)inst;
|
|
|
|
|
|
|
|
if((rc = cmDspSetEvent(ctx,inst,evt)) == kOkDspRC && p->sfp != NULL )
|
|
|
|
{
|
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
|
|
|
case kIndexSfId:
|
2012-11-19 06:41:27 +00:00
|
|
|
if( cmScoreIsValid(p->scH) )
|
2013-01-31 01:37:23 +00:00
|
|
|
{
|
|
|
|
if( cmScMeasReset( p->smp ) != cmOkRC )
|
|
|
|
cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score measure unit reset to score index '%i' failed.");
|
|
|
|
|
|
|
|
if( cmScMatcherReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
|
2012-11-19 06:41:27 +00:00
|
|
|
cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score follower reset to score index '%i' failed.");
|
2013-01-31 01:37:23 +00:00
|
|
|
}
|
2012-11-18 01:33:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kStatusSfId:
|
2012-11-19 06:41:27 +00:00
|
|
|
if( cmScoreIsValid(p->scH))
|
2012-11-18 01:33:10 +00:00
|
|
|
{
|
2013-01-31 01:37:23 +00:00
|
|
|
unsigned scLocIdx = cmInvalidIdx;
|
|
|
|
|
|
|
|
// setup the cmScMeas() callback arg.
|
|
|
|
p->arg.ctx = ctx;
|
|
|
|
p->arg.sfp = p;
|
|
|
|
p->sfp->cbArg = &p->arg;
|
|
|
|
|
|
|
|
// this call may result in a callback to _cmScFolMatcherCb()
|
|
|
|
if( cmScMatcherExec(p->sfp, cmDspUInt(inst,kSmpIdxSfId), cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId), &scLocIdx) == cmOkRC )
|
|
|
|
if( scLocIdx != cmInvalidIdx )
|
|
|
|
cmDspSetUInt(ctx,inst,kOutSfId,scLocIdx);
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFnSfId:
|
|
|
|
_cmDspScFolOpenScore(ctx,inst);
|
|
|
|
break;
|
2012-12-13 23:38:45 +00:00
|
|
|
|
|
|
|
case kCmdSfId:
|
|
|
|
if( cmDspSymbol(inst,kCmdSfId) == p->printSymId )
|
|
|
|
p->sfp->printFl = true;
|
|
|
|
else
|
|
|
|
if( cmDspSymbol(inst,kCmdSfId) == p->quietSymId )
|
|
|
|
p->sfp->printFl = false;
|
|
|
|
|
|
|
|
break;
|
2012-11-18 01:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmScFolClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmScFolDC,ctx,"ScFol",
|
|
|
|
NULL,
|
|
|
|
_cmDspScFolAlloc,
|
|
|
|
_cmDspScFolFree,
|
|
|
|
_cmDspScFolReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspScFolRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Score Follower");
|
|
|
|
|
|
|
|
return &_cmScFolDC;
|
|
|
|
}
|
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
//==========================================================================================================================================
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2013-03-02 01:40:04 +00:00
|
|
|
kScLocIdxMdId,
|
|
|
|
kResetIdxMdId,
|
|
|
|
kCmdMdId
|
2013-02-09 07:48:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmModulatorDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmScModulator* mp;
|
|
|
|
cmDspCtx_t* tmp_ctx; // used to temporarily hold the current cmDspCtx during callback
|
2013-03-02 01:40:04 +00:00
|
|
|
cmChar_t* fn;
|
|
|
|
cmChar_t* modLabel;
|
|
|
|
unsigned onSymId;
|
|
|
|
unsigned offSymId;
|
2013-02-09 07:48:54 +00:00
|
|
|
} cmDspScMod_t;
|
|
|
|
|
|
|
|
void _cmDspScModCb( void* arg, unsigned varSymId, double value )
|
|
|
|
{
|
|
|
|
cmDspScMod_t* p = (cmDspScMod_t*)arg;
|
|
|
|
|
|
|
|
cmDspVar_t* varPtr;
|
|
|
|
if((varPtr = cmDspVarSymbolToPtr( p->tmp_ctx, &p->inst, varSymId, 0 )) == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmDspSetDouble(p->tmp_ctx,&p->inst,varPtr->constId,value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspScModAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
va_list vl1;
|
|
|
|
va_copy(vl1,vl);
|
|
|
|
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2013-03-02 01:40:04 +00:00
|
|
|
{ "index", kScLocIdxMdId, 0,0, kInDsvFl | kUIntDsvFl, "Score follower index input."},
|
|
|
|
{ "reset", kResetIdxMdId, 0,0, kInDsvFl | kUIntDsvFl | kOptArgDsvFl, "Reset the modulator and go to the score index."},
|
|
|
|
{ "cmd", kCmdMdId, 0,0, kInDsvFl | kSymDsvFl | kOptArgDsvFl, "on | off."},
|
2013-02-09 07:48:54 +00:00
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// validate the argument count
|
|
|
|
if( va_cnt != 2 )
|
|
|
|
{
|
|
|
|
cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The Modulator requires at least two arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the modulator file and label strings
|
|
|
|
const cmChar_t* fn = va_arg(vl1,const cmChar_t*);
|
|
|
|
const cmChar_t* modLabel = va_arg(vl1,const cmChar_t*);
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
va_end(vl1);
|
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
// validate the file
|
|
|
|
if( fn==NULL || cmFsIsFile(fn)==false )
|
|
|
|
{
|
|
|
|
cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The Modulator file '%s' is not valid.",cmStringNullGuard(fn));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate the internal modulator object
|
|
|
|
cmScModulator* mp = cmScModulatorAlloc(ctx->cmProcCtx, NULL, ctx->cmCtx, ctx->stH, cmDspSampleRate(ctx), cmDspSamplesPerCycle(ctx), fn, modLabel, _cmDspScModCb, NULL );
|
|
|
|
|
|
|
|
if(mp == NULL )
|
|
|
|
{
|
|
|
|
cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The internal modulator object initialization failed.");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-02 01:40:04 +00:00
|
|
|
unsigned fixArgCnt = sizeof(args)/sizeof(args[0]) - 1;
|
|
|
|
unsigned argCnt = fixArgCnt + cmScModulatorOutVarCount(mp);
|
2013-02-09 07:48:54 +00:00
|
|
|
cmDspVarArg_t a[ argCnt+1 ];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
cmDspArgCopy( a, argCnt, 0, args, fixArgCnt );
|
|
|
|
|
|
|
|
for(i=fixArgCnt; i<argCnt; ++i)
|
|
|
|
{
|
|
|
|
unsigned varIdx = i - fixArgCnt;
|
2013-03-02 01:40:04 +00:00
|
|
|
const cmScModVar_t* vp = cmScModulatorOutVar(mp,varIdx);
|
2013-02-09 07:48:54 +00:00
|
|
|
const cmChar_t* label = cmSymTblLabel( ctx->stH, vp->varSymId );
|
|
|
|
const cmChar_t* docStr = cmTsPrintfS("Variable output for %s",label);
|
|
|
|
|
|
|
|
cmDspArgSetup(ctx, a + i, label, cmInvalidId, i, 0, 0, kOutDsvFl | kDoubleDsvFl, docStr );
|
|
|
|
}
|
|
|
|
cmDspArgSetupNull(a+argCnt); // set terminating arg. flags
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
cmDspScMod_t* p = cmDspInstAlloc(cmDspScMod_t,ctx,classPtr,a,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
|
|
|
|
p->fn = cmMemAllocStr(fn);
|
|
|
|
p->modLabel = cmMemAllocStr(modLabel);
|
|
|
|
p->mp = mp;
|
|
|
|
p->onSymId = cmSymTblId(ctx->stH,"on");
|
|
|
|
p->offSymId = cmSymTblId(ctx->stH,"off");
|
2013-02-09 07:48:54 +00:00
|
|
|
|
|
|
|
mp->cbArg = p; // set the modulator callback arg
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
cmDspSetDefaultUInt(ctx,&p->inst,kScLocIdxMdId,0,0);
|
|
|
|
cmDspSetDefaultSymbol(ctx,&p->inst,kCmdMdId,p->offSymId);
|
2013-02-09 07:48:54 +00:00
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScModFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScMod_t* p = (cmDspScMod_t*)inst;
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
if( cmScModulatorFree(&p->mp) != kOkTlRC )
|
|
|
|
return cmErrMsg(&inst->classPtr->err, kInstFinalFailDspRC, "Modulator release failed.");
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
cmMemFree(p->fn);
|
|
|
|
cmMemFree(p->modLabel);
|
2013-02-09 07:48:54 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScModReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScModRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
2013-03-02 01:40:04 +00:00
|
|
|
cmDspScMod_t* p = (cmDspScMod_t*)inst;
|
2013-02-09 07:48:54 +00:00
|
|
|
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
2013-03-02 01:40:04 +00:00
|
|
|
|
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
|
|
|
case kResetIdxMdId:
|
|
|
|
cmDspSetUInt(ctx,inst,kScLocIdxMdId,cmDspUInt(inst,kResetIdxMdId));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kCmdMdId:
|
|
|
|
{
|
|
|
|
unsigned symId = cmDspSymbol(inst,kCmdMdId);
|
|
|
|
if( symId == p->onSymId )
|
|
|
|
cmScModulatorReset(p->mp, ctx->cmCtx, cmDspUInt(inst,kScLocIdxMdId));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2013-02-09 07:48:54 +00:00
|
|
|
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScModExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspScMod_t* p = (cmDspScMod_t*)inst;
|
|
|
|
|
2013-03-02 01:40:04 +00:00
|
|
|
if( cmDspSymbol(inst,kCmdMdId) != p->offSymId )
|
|
|
|
{
|
|
|
|
p->tmp_ctx = ctx;
|
|
|
|
cmScModulatorExec(p->mp,cmDspUInt(inst,kScLocIdxMdId));
|
|
|
|
}
|
|
|
|
|
2013-02-09 07:48:54 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmScModClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmModulatorDC,ctx,"ScMod",
|
|
|
|
NULL,
|
|
|
|
_cmDspScModAlloc,
|
|
|
|
_cmDspScModFree,
|
|
|
|
_cmDspScModReset,
|
|
|
|
_cmDspScModExec,
|
|
|
|
_cmDspScModRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Score Driven Variable Modulator.");
|
|
|
|
|
|
|
|
return &_cmModulatorDC;
|
|
|
|
}
|
2013-03-02 01:40:04 +00:00
|
|
|
|
|
|
|
//==========================================================================================================================================
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kInChCntGsId,
|
|
|
|
kOutGroupCntGsId,
|
|
|
|
kGroupSelIdxGsId,
|
|
|
|
kBaseInFloatGsId
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmGSwitchDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
|
|
|
|
unsigned iChCnt;
|
|
|
|
unsigned oGroupCnt;
|
|
|
|
|
|
|
|
unsigned baseInFloatGsId;
|
|
|
|
unsigned baseInSymGsId;
|
|
|
|
unsigned baseInBoolGsId;
|
|
|
|
|
|
|
|
unsigned baseOutFloatGsId;
|
|
|
|
unsigned baseOutSymGsId;
|
|
|
|
unsigned baseOutBoolGsId;
|
|
|
|
|
|
|
|
} cmDspGSwitch_t;
|
|
|
|
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspGSwitchAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
va_list vl1;
|
|
|
|
va_copy(vl1,vl);
|
|
|
|
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
|
|
|
{ "ichs", kInChCntGsId, 0,0, kUIntDsvFl | kReqArgDsvFl, "Input channel count."},
|
|
|
|
{ "ochs", kOutGroupCntGsId, 0,0, kUIntDsvFl | kReqArgDsvFl, "Output group count."},
|
|
|
|
{ "sel", kGroupSelIdxGsId, 0,0, kInDsvFl | kUIntDsvFl, "Group select index."},
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// validate the argument count
|
|
|
|
if( va_cnt != 2 )
|
|
|
|
{
|
|
|
|
cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The GSwitch requires at least two arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the input ch and output group count
|
|
|
|
unsigned iChCnt = va_arg(vl1,unsigned);
|
|
|
|
unsigned oGroupCnt = va_arg(vl1,unsigned);
|
|
|
|
|
|
|
|
va_end(vl1);
|
|
|
|
|
|
|
|
// validate the channel counts
|
|
|
|
if( iChCnt == 0 || oGroupCnt==0 )
|
|
|
|
{
|
|
|
|
cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The GSwitch input channel count and group count must be greater than zero.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned typeCnt = 3; // i.e. float,sym,bool
|
|
|
|
unsigned baseInFloatGsId = kBaseInFloatGsId;
|
|
|
|
unsigned baseInSymGsId = baseInFloatGsId + iChCnt;
|
|
|
|
unsigned baseInBoolGsId = baseInSymGsId + iChCnt;
|
|
|
|
unsigned baseOutFloatGsId = baseInBoolGsId + iChCnt;
|
|
|
|
unsigned baseOutSymGsId = baseOutFloatGsId + (iChCnt * oGroupCnt);
|
|
|
|
unsigned baseOutBoolGsId = baseOutSymGsId + (iChCnt * oGroupCnt);
|
|
|
|
|
|
|
|
unsigned fixArgCnt = 3;
|
|
|
|
unsigned varArgCnt = (iChCnt * typeCnt) + (iChCnt * typeCnt * oGroupCnt);
|
|
|
|
unsigned argCnt = fixArgCnt + varArgCnt;
|
|
|
|
cmDspVarArg_t a[ argCnt+1 ];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
cmDspArgCopy( a, argCnt, 0, args, fixArgCnt );
|
|
|
|
cmDspArgSetupN( ctx, a, argCnt, baseInFloatGsId, iChCnt, "f-in", baseInFloatGsId, 0, 0, kInDsvFl | kDoubleDsvFl, "Float input");
|
|
|
|
cmDspArgSetupN( ctx, a, argCnt, baseInSymGsId, iChCnt, "s-in", baseInSymGsId, 0, 0, kInDsvFl | kSymDsvFl, "Symbol input");
|
|
|
|
cmDspArgSetupN( ctx, a, argCnt, baseInBoolGsId, iChCnt, "b-in", baseInBoolGsId, 0, 0, kInDsvFl | kBoolDsvFl, "Bool input");
|
|
|
|
|
|
|
|
unsigned labelCharCnt = 63;
|
|
|
|
cmChar_t label[labelCharCnt+1];
|
|
|
|
label[labelCharCnt] = 0;
|
|
|
|
|
|
|
|
unsigned gsid = baseOutFloatGsId;
|
|
|
|
for(i=0; i<oGroupCnt; ++i, gsid+=iChCnt)
|
|
|
|
{
|
|
|
|
snprintf(label,labelCharCnt,"f-out-%i",i);
|
|
|
|
cmDspArgSetupN( ctx, a, argCnt, gsid, iChCnt, label, gsid, 0, 0, kInDsvFl | kDoubleDsvFl, "Float output");
|
|
|
|
}
|
|
|
|
|
|
|
|
gsid = baseOutSymGsId;
|
|
|
|
for(i=0; i<oGroupCnt; ++i, gsid+=iChCnt)
|
|
|
|
{
|
|
|
|
snprintf(label,labelCharCnt,"s-out-%i",i);
|
|
|
|
cmDspArgSetupN( ctx, a, argCnt, gsid, iChCnt, label, gsid, 0, 0, kInDsvFl | kSymDsvFl, "Symbol output");
|
|
|
|
}
|
|
|
|
|
|
|
|
gsid = baseOutBoolGsId;
|
|
|
|
for(i=0; i<oGroupCnt; ++i, gsid+=iChCnt)
|
|
|
|
{
|
|
|
|
snprintf(label,labelCharCnt,"b-out-%i",i);
|
|
|
|
cmDspArgSetupN( ctx,a, argCnt, gsid, iChCnt, label, gsid, 0, 0, kInDsvFl | kBoolDsvFl, "Bool output");
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspArgSetupNull(a+argCnt); // set terminating arg. flags
|
|
|
|
|
|
|
|
cmDspGSwitch_t* p = cmDspInstAlloc(cmDspGSwitch_t,ctx,classPtr,a,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
p->iChCnt = iChCnt;
|
|
|
|
p->oGroupCnt = oGroupCnt;
|
|
|
|
p->baseInFloatGsId = baseInFloatGsId;
|
|
|
|
p->baseInSymGsId = baseInSymGsId;
|
|
|
|
p->baseInBoolGsId = baseInBoolGsId;
|
|
|
|
p->baseOutFloatGsId = baseOutFloatGsId;
|
|
|
|
p->baseOutSymGsId = baseOutSymGsId;
|
|
|
|
p->baseOutBoolGsId = baseOutBoolGsId;
|
|
|
|
|
|
|
|
cmDspSetDefaultUInt(ctx,&p->inst,kGroupSelIdxGsId,0,0);
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspGSwitchReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspGSwitchRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspGSwitch_t* p = (cmDspGSwitch_t*)inst;
|
|
|
|
|
|
|
|
// if this is the group selector
|
|
|
|
if( evt->dstVarId == kGroupSelIdxGsId )
|
|
|
|
{
|
|
|
|
unsigned idx;
|
|
|
|
if( (idx = cmDsvGetUInt(evt->valuePtr)) > p->oGroupCnt )
|
|
|
|
cmDspInstErr(ctx,inst,kInvalidArgDspRC,"The GSwitch group select index %i is out of range %i.",idx,p->oGroupCnt);
|
|
|
|
else
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the group selector
|
|
|
|
unsigned groupIdx = cmDspUInt(inst,kGroupSelIdxGsId);
|
|
|
|
assert( groupIdx < p->oGroupCnt);
|
|
|
|
|
|
|
|
|
|
|
|
// if this is a float input
|
|
|
|
if( p->baseInFloatGsId <= evt->dstVarId && evt->dstVarId < p->baseInFloatGsId + p->iChCnt )
|
|
|
|
{
|
|
|
|
unsigned outVarId = p->baseOutFloatGsId + (groupIdx * p->iChCnt) + (evt->dstVarId - p->baseInFloatGsId);
|
|
|
|
cmDspValueSet(ctx, inst, outVarId, evt->valuePtr, 0 );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this is a symbol input
|
|
|
|
if( p->baseInSymGsId <= evt->dstVarId && evt->dstVarId < p->baseInSymGsId + p->iChCnt )
|
|
|
|
{
|
|
|
|
unsigned outVarId = p->baseOutSymGsId + (groupIdx * p->iChCnt) + (evt->dstVarId - p->baseInSymGsId);
|
|
|
|
cmDspValueSet(ctx, inst, outVarId, evt->valuePtr, 0 );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this is a bool input
|
|
|
|
if( p->baseInBoolGsId <= evt->dstVarId && evt->dstVarId < p->baseInBoolGsId + p->iChCnt )
|
|
|
|
{
|
|
|
|
unsigned outVarId = p->baseOutBoolGsId + (groupIdx * p->iChCnt) + (evt->dstVarId - p->baseInBoolGsId);
|
|
|
|
cmDspValueSet(ctx, inst, outVarId, evt->valuePtr, 0 );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmGSwitchClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmGSwitchDC,ctx,"GSwitch",
|
|
|
|
NULL,
|
|
|
|
_cmDspGSwitchAlloc,
|
|
|
|
NULL,
|
|
|
|
_cmDspGSwitchReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspGSwitchRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Ganged switch.");
|
|
|
|
|
|
|
|
return &_cmGSwitchDC;
|
|
|
|
}
|
2013-04-20 17:37:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================================================================================
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kMinInSrId,
|
|
|
|
kMaxInSrId,
|
|
|
|
kMinOutSrId,
|
|
|
|
kMaxOutSrId,
|
|
|
|
kValInSrId,
|
|
|
|
kValOutSrId,
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmScaleRangeDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
|
|
|
|
} cmDspScaleRange_t;
|
|
|
|
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspScaleRangeAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
va_list vl1;
|
|
|
|
va_copy(vl1,vl);
|
|
|
|
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
|
|
|
{ "min_in", kMinInSrId, 0,0, kInDsvFl | kDoubleDsvFl , "Min Input value."},
|
|
|
|
{ "max_in", kMaxInSrId, 0,0, kInDsvFl | kDoubleDsvFl , "Min Input value."},
|
|
|
|
{ "min_out", kMinOutSrId, 0,0, kInDsvFl | kDoubleDsvFl , "Min Input value."},
|
|
|
|
{ "max_out", kMaxOutSrId, 0,0, kInDsvFl | kDoubleDsvFl , "Min Input value."},
|
|
|
|
{ "val_in", kValInSrId, 0,0, kInDsvFl | kDoubleDsvFl, "Input value."},
|
|
|
|
{ "val_out", kValOutSrId, 0,0, kOutDsvFl | kDoubleDsvFl, "Output value"},
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspScaleRange_t* p = cmDspInstAlloc(cmDspScaleRange_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kMinInSrId,0,0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kMaxInSrId,0,1.0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kMinOutSrId,0,0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kMaxOutSrId,0,1.0);
|
|
|
|
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScaleRangeReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspScaleRangeRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
2013-05-01 22:09:46 +00:00
|
|
|
//cmDspScaleRange_t* p = (cmDspScaleRange_t*)inst;
|
2013-04-20 17:37:20 +00:00
|
|
|
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
if( evt->dstVarId == kValInSrId )
|
|
|
|
{
|
|
|
|
double val = cmDspDouble(inst,kValInSrId);
|
|
|
|
double min_in = cmDspDouble(inst,kMinInSrId);
|
|
|
|
double max_in = cmDspDouble(inst,kMaxInSrId);
|
|
|
|
double min_out = cmDspDouble(inst,kMinOutSrId);
|
|
|
|
double max_out = cmDspDouble(inst,kMaxOutSrId);
|
|
|
|
|
|
|
|
double x = cmMax(min_in,cmMin(max_in,val));
|
|
|
|
|
|
|
|
x = (x - min_in)/(max_in - min_in);
|
|
|
|
|
|
|
|
x = min_out + x * (max_out - min_out);
|
|
|
|
|
|
|
|
cmDspSetDouble(ctx,inst,kValOutSrId, x );
|
|
|
|
//printf("%f (%f %f) : (%f %f) %f\n",val,min_in,max_in,min_out,max_out,x);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmScaleRangeClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmScaleRangeDC,ctx,"ScaleRange",
|
|
|
|
NULL,
|
|
|
|
_cmDspScaleRangeAlloc,
|
|
|
|
NULL,
|
|
|
|
_cmDspScaleRangeReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspScaleRangeRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Scale a value inside an input range to a value in the output range.");
|
|
|
|
|
|
|
|
return &_cmScaleRangeDC;
|
|
|
|
}
|
2013-07-10 19:24:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================================================================================
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kCntAmId,
|
|
|
|
kSflocAmId,
|
|
|
|
kLocAmId,
|
|
|
|
kTypeAmId,
|
|
|
|
kValueAmId,
|
|
|
|
kCstAmId,
|
|
|
|
kCmdAmId,
|
2013-08-12 07:11:59 +00:00
|
|
|
kScLocAmId,
|
2013-07-10 19:24:08 +00:00
|
|
|
kEvenAmId,
|
|
|
|
kDynAmId,
|
|
|
|
kTempoAmId,
|
|
|
|
kCostAmId
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmActiveMeasDC;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned loc;
|
|
|
|
unsigned type;
|
|
|
|
double value;
|
|
|
|
double cost;
|
|
|
|
} cmDspActiveMeasRecd_t;
|
|
|
|
|
|
|
|
int cmDspActiveMeasRecdCompare(const void * p0, const void * p1)
|
|
|
|
{
|
|
|
|
return ((int)((cmDspActiveMeasRecd_t*)p0)->loc) - (int)(((cmDspActiveMeasRecd_t*)p1)->loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
unsigned addSymId;
|
|
|
|
unsigned clearSymId;
|
2013-07-10 21:19:33 +00:00
|
|
|
unsigned printSymId;
|
|
|
|
unsigned rewindSymId;
|
2013-07-10 19:24:08 +00:00
|
|
|
cmDspActiveMeasRecd_t* array; // array[cnt]
|
|
|
|
unsigned cnt;
|
|
|
|
unsigned nextEmptyIdx;
|
|
|
|
unsigned nextFullIdx;
|
|
|
|
} cmDspActiveMeas_t;
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspActiveMeasAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
|
|
|
{ "cnt", kCntAmId, 0,0, kInDsvFl | kUIntDsvFl, "Maximum count of active measurements."},
|
|
|
|
{ "sfloc", kSflocAmId, 0,0, kInDsvFl | kUIntDsvFl, "Score follower location input." },
|
|
|
|
{ "loc", kLocAmId, 0,0, kInDsvFl | kUIntDsvFl, "Meas. location." },
|
|
|
|
{ "type", kTypeAmId, 0,0, kInDsvFl | kUIntDsvFl, "Meas. Type." },
|
|
|
|
{ "val", kValueAmId, 0,0, kInDsvFl | kDoubleDsvFl, "Meas. Value."},
|
|
|
|
{ "cst", kCstAmId, 0,0, kInDsvFl | kDoubleDsvFl, "Meas. Cost."},
|
2013-07-10 21:19:33 +00:00
|
|
|
{ "cmd", kCmdAmId, 0,0, kInDsvFl | kSymDsvFl, "Commands:add | clear | dump | rewind"},
|
2013-08-12 07:11:59 +00:00
|
|
|
{ "scloc", kScLocAmId, 0,0, kOutDsvFl | kUIntDsvFl, "Score location"},
|
2013-07-10 19:24:08 +00:00
|
|
|
{ "even", kEvenAmId, 0,0, kOutDsvFl | kDoubleDsvFl, "Even out"},
|
|
|
|
{ "dyn", kDynAmId, 0,0, kOutDsvFl | kDoubleDsvFl, "Dyn out"},
|
|
|
|
{ "tempo", kTempoAmId, 0,0, kOutDsvFl | kDoubleDsvFl, "Tempo out"},
|
|
|
|
{ "cost", kCostAmId, 0,0, kOutDsvFl | kDoubleDsvFl, "Cost out"},
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmDspActiveMeas_t* p = cmDspInstAlloc(cmDspActiveMeas_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
p->addSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"add");
|
|
|
|
p->clearSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"clear");
|
2013-07-10 21:19:33 +00:00
|
|
|
p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"dump");
|
|
|
|
p->rewindSymId= cmSymTblRegisterStaticSymbol(ctx->stH,"rewind");
|
2013-07-10 19:24:08 +00:00
|
|
|
|
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst,kCntAmId, 0,100);
|
2013-08-12 07:11:59 +00:00
|
|
|
cmDspSetDefaultUInt( ctx,&p->inst,kScLocAmId,0,0);
|
2013-07-10 19:24:08 +00:00
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kEvenAmId, 0,0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kDynAmId, 0,0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
|
|
|
|
cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
|
|
|
|
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspActiveMeasPrint(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for(i=0; i<p->nextEmptyIdx; ++i)
|
|
|
|
{
|
|
|
|
const cmChar_t* label = "<null>";
|
|
|
|
switch( p->array[i].type )
|
|
|
|
{
|
|
|
|
case kEvenVarScId: label="even "; break;
|
|
|
|
case kDynVarScId: label="dyn "; break;
|
|
|
|
case kTempoVarScId: label="tempo"; break;
|
|
|
|
default:
|
|
|
|
{ assert(0); }
|
|
|
|
}
|
|
|
|
|
|
|
|
cmRptPrintf(ctx->rpt,"loc:%i %s %f %f\n",p->array[i].loc,label,p->array[i].value,p->array[i].cost);
|
|
|
|
}
|
|
|
|
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspActiveMeasClear(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
|
|
|
{
|
|
|
|
p->nextEmptyIdx = 0;
|
|
|
|
p->nextFullIdx = cmInvalidIdx;
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspActiveMeasFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspActiveMeas_t* p = (cmDspActiveMeas_t*)inst;
|
|
|
|
_cmDspActiveMeasClear(ctx,p);
|
|
|
|
cmMemPtrFree(&p->array);
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspActiveMeasReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspActiveMeas_t* p = (cmDspActiveMeas_t*)inst;
|
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
unsigned cnt = cmMax(100,cmDspUInt(inst,kCntAmId));
|
|
|
|
_cmDspActiveMeasFree(ctx,inst,evt);
|
|
|
|
p->array = cmMemAllocZ(cmDspActiveMeasRecd_t,cnt);
|
|
|
|
p->cnt = cnt;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspActiveMeasRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspActiveMeas_t* p = (cmDspActiveMeas_t*)inst;
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
switch( evt->dstVarId )
|
|
|
|
{
|
|
|
|
case kSflocAmId:
|
|
|
|
if( p->nextFullIdx != cmInvalidIdx )
|
|
|
|
{
|
2013-08-12 07:11:59 +00:00
|
|
|
// get the recv'd score location
|
2013-07-10 19:24:08 +00:00
|
|
|
unsigned sflocIdx = cmDspUInt(inst,kSflocAmId);
|
2013-08-12 07:11:59 +00:00
|
|
|
|
|
|
|
unsigned prvLoc = cmInvalidIdx;
|
|
|
|
|
|
|
|
// for each remaining avail record
|
2013-07-10 19:24:08 +00:00
|
|
|
for(; p->nextFullIdx < p->nextEmptyIdx; p->nextFullIdx++)
|
|
|
|
{
|
|
|
|
cmDspActiveMeasRecd_t* r = p->array + p->nextFullIdx;
|
2013-08-12 07:11:59 +00:00
|
|
|
|
|
|
|
// if this records score location is after the recv'd score loc then we're done
|
2013-07-10 19:24:08 +00:00
|
|
|
if( r->loc > sflocIdx )
|
|
|
|
break;
|
|
|
|
|
2013-08-12 07:11:59 +00:00
|
|
|
// deterimine the records type
|
2013-07-10 19:24:08 +00:00
|
|
|
unsigned varId = cmInvalidId;
|
|
|
|
switch( r->type )
|
|
|
|
{
|
|
|
|
case kEvenVarScId: varId = kEvenAmId; break;
|
|
|
|
case kDynVarScId: varId = kDynAmId; break;
|
|
|
|
case kTempoVarScId: varId = kTempoAmId; break;
|
|
|
|
default:
|
|
|
|
{ assert(0); }
|
|
|
|
}
|
|
|
|
|
2013-08-12 07:11:59 +00:00
|
|
|
// if this score location has not yet been sent then send it now
|
|
|
|
if( prvLoc != r->loc )
|
|
|
|
cmDspSetUInt(ctx,inst,kScLocAmId,r->loc);
|
|
|
|
|
|
|
|
// transmit the records value and cost
|
2013-07-10 19:24:08 +00:00
|
|
|
cmDspSetDouble(ctx,inst,varId,r->value);
|
|
|
|
cmDspSetDouble(ctx,inst,kCostAmId,r->value);
|
2013-08-12 07:11:59 +00:00
|
|
|
|
|
|
|
prvLoc = r->loc;
|
2013-07-10 19:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kCmdAmId:
|
|
|
|
{
|
|
|
|
unsigned cmdSymId = cmDspSymbol(inst,kCmdAmId);
|
|
|
|
|
|
|
|
if( cmdSymId == p->addSymId )
|
|
|
|
{
|
|
|
|
if( p->nextEmptyIdx >= p->cnt )
|
|
|
|
cmDspInstErr(ctx,inst,kProcFailDspRC,"The active measurement list is full cnt=%i.",p->cnt);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmDspActiveMeasRecd_t* r = p->array + p->nextEmptyIdx;
|
|
|
|
r->loc = cmDspUInt( inst,kLocAmId);
|
|
|
|
r->type = cmDspUInt( inst,kTypeAmId);
|
|
|
|
r->value = cmDspDouble(inst,kValueAmId);
|
|
|
|
r->cost = cmDspDouble(inst,kCstAmId);
|
|
|
|
p->nextEmptyIdx += 1;
|
|
|
|
|
|
|
|
qsort(p->array,p->nextEmptyIdx,sizeof(p->array[0]),cmDspActiveMeasRecdCompare);
|
|
|
|
|
|
|
|
if( p->nextEmptyIdx == 1 && p->nextFullIdx == cmInvalidIdx )
|
|
|
|
p->nextFullIdx = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cmdSymId == p->clearSymId )
|
|
|
|
rc = _cmDspActiveMeasClear(ctx,p);
|
|
|
|
else
|
|
|
|
if( cmdSymId == p->printSymId )
|
|
|
|
rc = _cmDspActiveMeasPrint(ctx,p);
|
2013-07-10 21:19:33 +00:00
|
|
|
else
|
|
|
|
if(cmdSymId == p->rewindSymId )
|
|
|
|
p->nextFullIdx = 0;
|
2013-07-10 19:24:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmActiveMeasClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmActiveMeasDC,ctx,"ActiveMeas",
|
|
|
|
NULL,
|
|
|
|
_cmDspActiveMeasAlloc,
|
|
|
|
_cmDspActiveMeasFree,
|
|
|
|
_cmDspActiveMeasReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspActiveMeasRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Scale a value inside an input range to a value in the output range.");
|
|
|
|
|
|
|
|
return &_cmActiveMeasDC;
|
|
|
|
}
|
|
|
|
|
2013-09-26 06:46:11 +00:00
|
|
|
//==========================================================================================================================================
|
|
|
|
// Audio MIDI Sync
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kSelAmId,
|
|
|
|
kAFnAmId,
|
|
|
|
kASmpAmId,
|
|
|
|
kMFnAmId,
|
|
|
|
kMIdAmId,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kAfnAmFl = 0x01,
|
|
|
|
kMfnAmFl = 0x02,
|
|
|
|
kAsmpAmFl = 0x04,
|
|
|
|
kMidAmFl = 0x08,
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspClass_t _cmAmSyncDC;
|
|
|
|
|
|
|
|
typedef struct cmDspAmSyncEntry_str
|
|
|
|
{
|
|
|
|
const cmChar_t* afn;
|
|
|
|
const cmChar_t* mfn;
|
|
|
|
unsigned asmp; // Audio sample index to sync to MIDI event
|
|
|
|
unsigned mid; // MIDI event unique id (cmMidiTrackMsg_t.uid)
|
|
|
|
int afi;
|
|
|
|
int mfi;
|
|
|
|
unsigned state;
|
|
|
|
} cmDspAmSyncEntry_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cmDspInst_t inst;
|
|
|
|
cmDspAmSyncEntry_t* array;
|
|
|
|
unsigned arrayCnt;
|
|
|
|
cmDspAmSyncEntry_t* acur;
|
|
|
|
cmDspAmSyncEntry_t* mcur;
|
|
|
|
} cmDspAmSync_t;
|
|
|
|
|
|
|
|
cmDspInst_t* _cmDspAmSyncAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
|
|
{
|
|
|
|
cmDspVarArg_t args[] =
|
|
|
|
{
|
2013-09-26 19:48:55 +00:00
|
|
|
{ "sel", kSelAmId, 0, 0, kInDsvFl | kTypeDsvMask, "Print and reset" },
|
2013-09-26 06:46:11 +00:00
|
|
|
{ "afn", kAFnAmId, 0, 0, kInDsvFl | kStrzDsvFl, "Audio File name"},
|
|
|
|
{ "asmp", kASmpAmId, 0, 0, kInDsvFl | kIntDsvFl, "Audio sample index"},
|
|
|
|
{ "mfn", kMFnAmId, 0, 0, kInDsvFl | kStrzDsvFl, "MIDI File name"},
|
|
|
|
{ "mid", kMIdAmId, 0, 0, kInDsvFl | kIntDsvFl, "MIDI Event Unique Id"},
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
cmDspAmSync_t* p = cmDspInstAlloc(cmDspAmSync_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
|
|
|
|
|
|
return &p->inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspAmSyncFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
|
|
|
|
|
|
cmMemFree(p->array);
|
|
|
|
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspAmSyncReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspRC_t rc = kOkDspRC;
|
|
|
|
cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
|
|
|
|
|
|
cmDspApplyAllDefaults(ctx,inst);
|
|
|
|
|
|
|
|
cmJsonH_t jsH = cmDspSysPgmRsrcHandle(ctx->dspH);
|
|
|
|
cmJsonNode_t* np;
|
|
|
|
const cmChar_t* errLabelPtr;
|
|
|
|
unsigned i;
|
|
|
|
cmJsRC_t jsRC;
|
|
|
|
|
|
|
|
if((np = cmJsonFindValue(jsH, "amSync", NULL, kArrayTId)) == NULL )
|
|
|
|
{
|
|
|
|
rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The AUDIO MIDI Sync cfg. record was not found.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->arrayCnt = cmJsonChildCount(np);
|
|
|
|
|
|
|
|
p->array = cmMemResizeZ(cmDspAmSyncEntry_t,p->array,p->arrayCnt);
|
|
|
|
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
{
|
|
|
|
cmJsonNode_t* anp = cmJsonArrayElement(np,i);
|
|
|
|
|
|
|
|
cmDspAmSyncEntry_t* r = p->array + i;
|
|
|
|
if( (jsRC = cmJsonMemberValues(anp,&errLabelPtr,
|
|
|
|
"af", kStringTId,&r->afn,
|
|
|
|
"asmp",kIntTId, &r->asmp,
|
|
|
|
"mf", kStringTId,&r->mfn,
|
|
|
|
"mid", kIntTId, &r->mid,
|
|
|
|
NULL)) != kOkJsRC )
|
|
|
|
{
|
|
|
|
if( jsRC == kNodeNotFoundJsRC )
|
|
|
|
rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The Audio-MIDI Sync cfg. field '%s' was missing in the cfg. record at index %i.",errLabelPtr,i);
|
|
|
|
else
|
|
|
|
rc = cmDspInstErr(ctx,inst,kInvalidArgDspRC,"The AUDIO MIDI Sync cfg. parse failed on the record at index %i.",i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
r->afi = cmInvalidIdx;
|
|
|
|
r->mfi = cmInvalidIdx;
|
|
|
|
r->state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errLabel:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmDspRC_t _cmDspAmSyncRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
|
|
{
|
|
|
|
cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if( evt->dstVarId != kSelAmId )
|
|
|
|
cmDspSetEvent(ctx,inst,evt);
|
|
|
|
|
|
|
|
switch(evt->dstVarId)
|
|
|
|
{
|
|
|
|
case kSelAmId:
|
|
|
|
{
|
2013-09-26 15:56:14 +00:00
|
|
|
double srate = cmDspSysSampleRate(ctx->dspH);
|
|
|
|
int fpc = cmDspSamplesPerCycle(ctx);
|
|
|
|
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
{
|
2013-09-26 19:48:55 +00:00
|
|
|
cmDspAmSyncEntry_t* r = p->array + i;
|
2013-09-26 15:56:14 +00:00
|
|
|
|
|
|
|
int dframes = r->mfi-r->afi;
|
|
|
|
cmRptPrintf(ctx->rpt,"0x%x : %s %i %i - %s %i %i : frm:%i smp:%i sec:%f\n",
|
|
|
|
r->state,r->afn,r->asmp,r->afi,r->mfn,r->mid,r->mfi,dframes,dframes*fpc,dframes*fpc/srate);
|
2013-09-26 19:48:55 +00:00
|
|
|
|
|
|
|
r->afi = cmInvalidIdx;
|
|
|
|
r->mfi = cmInvalidIdx;
|
|
|
|
r->state = 0;
|
|
|
|
|
2013-09-26 15:56:14 +00:00
|
|
|
}
|
2013-09-26 19:48:55 +00:00
|
|
|
p->acur = NULL;
|
|
|
|
p->mcur = NULL;
|
2013-09-26 15:56:14 +00:00
|
|
|
}
|
2013-09-26 06:46:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kAFnAmId:
|
|
|
|
{
|
|
|
|
const cmChar_t* fn = cmDspStrcz(inst, kAFnAmId );
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
if( strcmp(fn,p->array[i].afn) == 0 )
|
|
|
|
{
|
|
|
|
p->array[i].state = cmSetFlag(p->array[i].state,kAfnAmFl);
|
2013-09-26 19:48:55 +00:00
|
|
|
p->acur = p->array + i;
|
2013-09-26 06:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kMFnAmId:
|
|
|
|
{
|
|
|
|
const cmChar_t* fn = cmDspStrcz(inst, kMFnAmId );
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
if( strcmp(fn,p->array[i].mfn) == 0 )
|
|
|
|
{
|
|
|
|
p->array[i].state = cmSetFlag(p->array[i].state,kMfnAmFl);
|
2013-09-26 19:48:55 +00:00
|
|
|
p->mcur = p->array + i;
|
2013-09-26 06:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kASmpAmId:
|
|
|
|
{
|
2013-09-26 19:48:55 +00:00
|
|
|
int v = cmDspInt(inst,kASmpAmId);
|
|
|
|
|
|
|
|
if( p->acur != NULL )
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
{
|
|
|
|
cmDspAmSyncEntry_t* r = p->array + i;
|
|
|
|
if( cmIsNotFlag(r->state,kAsmpAmFl) && r->asmp <= v && strcmp(p->acur->afn,r->afn)==0 )
|
|
|
|
{
|
|
|
|
r->afi = ctx->cycleCnt;
|
|
|
|
r->state = cmSetFlag(r->state,kAsmpAmFl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 06:46:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kMIdAmId:
|
|
|
|
{
|
|
|
|
int v = cmDspInt(inst,kMIdAmId);
|
2013-09-26 19:48:55 +00:00
|
|
|
if( p->mcur != NULL )
|
|
|
|
for(i=0; i<p->arrayCnt; ++i)
|
|
|
|
{
|
|
|
|
cmDspAmSyncEntry_t* r = p->array + i;
|
|
|
|
if( cmIsNotFlag(r->state,kMidAmFl) && r->mid == v && strcmp(p->mcur->mfn,r->mfn)==0 )
|
|
|
|
{
|
|
|
|
r->mfi = ctx->cycleCnt;
|
|
|
|
r->state = cmSetFlag(r->state,kMidAmFl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 06:46:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return kOkDspRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmDspClass_str* cmAmSyncClassCons( cmDspCtx_t* ctx )
|
|
|
|
{
|
|
|
|
cmDspClassSetup(&_cmAmSyncDC,ctx,"AmSync",
|
|
|
|
NULL,
|
|
|
|
_cmDspAmSyncAlloc,
|
|
|
|
_cmDspAmSyncFree,
|
|
|
|
_cmDspAmSyncReset,
|
|
|
|
NULL,
|
|
|
|
_cmDspAmSyncRecv,
|
|
|
|
NULL,NULL,
|
|
|
|
"Audio - MIDI Sync Object.");
|
|
|
|
|
|
|
|
return &_cmAmSyncDC;
|
|
|
|
}
|
|
|
|
|