From f0e00c3d37a50a679a08a33912d58eeabb049fbf Mon Sep 17 00:00:00 2001 From: kpl Date: Mon, 26 Nov 2012 23:07:22 -0800 Subject: [PATCH] cmDspKr.h/c Added Score Object added Time-line cursor. --- cmMsgProtocol.h | 1 + dsp/cmDspClass.h | 3 +- dsp/cmDspKr.c | 142 ++++++++++++++++++++++++++++++++++++++++++----- dsp/cmDspKr.h | 1 + dsp/cmDspUi.c | 24 +++++++- 5 files changed, 155 insertions(+), 16 deletions(-) diff --git a/cmMsgProtocol.h b/cmMsgProtocol.h index b0ad922..f72d988 100644 --- a/cmMsgProtocol.h +++ b/cmMsgProtocol.h @@ -31,6 +31,7 @@ extern "C" { kCheckDuiId, // ui<--eng create a check box control kLabelDuiId, // ui<--end create a label control kTimeLineDuiId,// ui<--end create a time-line control + kScoreDuiId, // ui<--end create a score control kNumberDuiId, // ui<--eng create a number box kTextDuiId, // ui<--eng create a text entry control kFnameDuiId, // ui<--eng create a file/directory picker control diff --git a/dsp/cmDspClass.h b/dsp/cmDspClass.h index a0f7fff..e4843ff 100644 --- a/dsp/cmDspClass.h +++ b/dsp/cmDspClass.h @@ -392,7 +392,8 @@ extern "C" { cmDspRC_t cmDspUiMeterCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned minVarId, unsigned maxVarId, unsigned valVarId, unsigned lblVarId ); cmDspRC_t cmDspUiButtonCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned typeDuiId, unsigned outVarId, unsigned lblVarId ); cmDspRC_t cmDspUiLabelCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned lblVarId, unsigned alignVarId ); - cmDspRC_t cmDspUiTimeLineCreate(cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned tlFileVarId, unsigned audPathVarId, unsigned selVarId ); + cmDspRC_t cmDspUiTimeLineCreate(cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned tlFileVarId, unsigned audPathVarId, unsigned selVarId, unsigned cursVarId ); + cmDspRC_t cmDspUiScoreCreate( cmDspCtx_t* ctx,cmDspInst_t* inst, unsigned scFileVarId, unsigned selVarId ); cmDspRC_t cmDspUiNewColumn( cmDspCtx_t* ctx, unsigned colW ); cmDspRC_t cmDspUiInsertHorzBorder( cmDspCtx_t* ctx ); diff --git a/dsp/cmDspKr.c b/dsp/cmDspKr.c index fdbc6f6..5096ab1 100644 --- a/dsp/cmDspKr.c +++ b/dsp/cmDspKr.c @@ -21,7 +21,6 @@ #include "cmDspCtx.h" #include "cmDspClass.h" #include "cmDspUi.h" -#include "cmOp.h" #include "cmMath.h" @@ -163,7 +162,7 @@ cmDspRC_t _cmDspKrExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt cmSpecDistExec(p->sdp,ip,iSmpCnt); if((sp = cmSpecDistOut(p->sdp)) != NULL ) - vs_Copy(op,sp,oSmpCnt); + cmVOS_Copy(op,oSmpCnt,sp); return rc; } @@ -241,13 +240,14 @@ enum kTlFileTlId, kAudPathTlId, kSelTlId, + kCursTlId, + kResetTlId, kAudFnTlId, kMidiFnTlId, kBegAudSmpIdxTlId, kEndAudSmpIdxTlId, kBegMidiSmpIdxTlId, kEndMidiSmpIdxTlId - }; cmDspClass_t _cmTimeLineDC; @@ -256,27 +256,31 @@ typedef struct { cmDspInst_t inst; cmTlH_t tlH; + unsigned afIdx; } 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[] = { - { "tlfile", kTlFileTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Time line file." }, - { "path", kAudPathTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Audio path" }, - { "sel", kSelTlId, 0, 0, kInDsvFl | kInDsvFl | kOutDsvFl | kUIntDsvFl, "Selected marker id."}, - { "afn", kAudFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected Audio file." }, - { "mfn", kMidiFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected MIDI file." }, - { "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."}, + { "tlfile", kTlFileTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Time line file." }, + { "path", kAudPathTlId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Audio path" }, + { "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." }, + { "mfn", kMidiFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected MIDI file." }, + { "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."}, { NULL, 0, 0, 0, 0 } }; cmDspTimeLine_t* p = cmDspInstAlloc(cmDspTimeLine_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl); cmDspSetDefaultUInt( ctx, &p->inst, kSelTlId, 0, cmInvalidId); + cmDspSetDefaultUInt( ctx, &p->inst, kCursTlId, 0, 0); cmDspSetDefaultStrcz(ctx, &p->inst, kAudFnTlId, NULL, ""); cmDspSetDefaultStrcz(ctx, &p->inst, kMidiFnTlId, NULL, ""); cmDspSetDefaultInt( ctx, &p->inst, kBegAudSmpIdxTlId, 0, cmInvalidIdx); @@ -285,7 +289,7 @@ cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig cmDspSetDefaultInt( ctx, &p->inst, kEndMidiSmpIdxTlId, 0, cmInvalidIdx); // create the UI control - cmDspUiTimeLineCreate(ctx,&p->inst,kTlFileTlId,kAudPathTlId,kSelTlId); + cmDspUiTimeLineCreate(ctx,&p->inst,kTlFileTlId,kAudPathTlId,kSelTlId,kCursTlId); p->tlH = cmTimeLineNullHandle; @@ -325,6 +329,11 @@ cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_ switch( evt->dstVarId ) { + case kCursTlId: + cmDspSetEvent(ctx,inst,evt); + break; + + case kResetTlId: case kSelTlId: { unsigned markerId; @@ -339,6 +348,8 @@ cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_ { assert(op->typeId == kMarkerTlId); + p->afIdx = op->begSmpIdx; + cmDspSetInt(ctx, inst, kBegAudSmpIdxTlId, op->begSmpIdx ); cmDspSetInt(ctx, inst, kEndAudSmpIdxTlId, op->begSmpIdx + op->durSmpCnt ); @@ -386,6 +397,111 @@ struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx ) return &_cmTimeLineDC; } +//========================================================================================================================================== +// Score UI Object + +enum +{ + kFnScId, + kSelScId, + kSendScId +}; + +cmDspClass_t _cmScoreDC; + +typedef struct +{ + cmDspInst_t inst; + cmScH_t scH; +} 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[] = + { + { "fn", kFnScId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Score file." }, + { "sel", kSelScId, 0, 0, kInDsvFl | kOutDsvFl | kUIntDsvFl, "Selected score element index."}, + { "send", kSendScId, 0, 0, kInDsvFl | kTypeDsvMask, "Resend last selected score element."}, + { 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 + cmDspUiScoreCreate(ctx,&p->inst,kFnScId,kSelScId); + + 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; +} + + +cmDspRC_t _cmDspScoreReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt ) +{ + cmDspRC_t rc = kOkDspRC; + cmDspScore_t* p = (cmDspScore_t*)inst; + + cmDspApplyAllDefaults(ctx,inst); + + const cmChar_t* tlFn; + if((tlFn = cmDspStrcz(inst, kFnScId )) != NULL ) + if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, NULL, NULL ) != kOkTlRC ) + rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Score file open failed."); + + return rc; +} + +cmDspRC_t _cmDspScoreRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt ) +{ + switch( evt->dstVarId ) + { + case kSelScId: + cmDspSetEvent(ctx,inst,evt); + break; + + case kSendScId: + { + unsigned selIdx; + if((selIdx = cmDspUInt(inst,kSelScId)) != cmInvalidIdx ) + cmDspSetUInt(ctx,inst,kSelScId, selIdx ); + } + break; + + default: + {assert(0);} + } + + 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; +} + //========================================================================================================================================== // MIDI File Player diff --git a/dsp/cmDspKr.h b/dsp/cmDspKr.h index 09d372a..ee6853d 100644 --- a/dsp/cmDspKr.h +++ b/dsp/cmDspKr.h @@ -7,6 +7,7 @@ extern "C" { struct cmDspClass_str* cmKrClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx ); + struct cmDspClass_str* cmScoreClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmMidiFilePlayClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmScFolClassCons( cmDspCtx_t* ctx ); diff --git a/dsp/cmDspUi.c b/dsp/cmDspUi.c index 714365c..2d97fb9 100644 --- a/dsp/cmDspUi.c +++ b/dsp/cmDspUi.c @@ -361,10 +361,10 @@ cmDspRC_t cmDspUiLabelCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned lbl return rc; } -cmDspRC_t cmDspUiTimeLineCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned tlFileVarId, unsigned audPathVarId, unsigned selVarId ) +cmDspRC_t cmDspUiTimeLineCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned tlFileVarId, unsigned audPathVarId, unsigned selVarId, unsigned cursVarId ) { cmDspRC_t rc; - unsigned arr[] = { tlFileVarId, audPathVarId, selVarId }; + unsigned arr[] = { tlFileVarId, audPathVarId, selVarId, cursVarId }; cmDspValue_t v; unsigned vn = sizeof(arr)/sizeof(arr[0]); cmDsvSetUIntMtx(&v,arr,vn,1); @@ -382,6 +382,26 @@ cmDspRC_t cmDspUiTimeLineCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned cmDspInstVarSetFlags( ctx, inst, tlFileVarId, kUiDsvFl ); cmDspInstVarSetFlags( ctx, inst, audPathVarId, kUiDsvFl ); cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl ); + cmDspInstVarSetFlags( ctx, inst, cursVarId, kUiDsvFl ); + return rc; +} + +cmDspRC_t cmDspUiScoreCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFileVarId, unsigned selVarId ) +{ + cmDspRC_t rc; + unsigned arr[] = { scFileVarId, selVarId }; + cmDspValue_t v; + unsigned vn = sizeof(arr)/sizeof(arr[0]); + cmDsvSetUIntMtx(&v,arr,vn,1); + + // tell the UI to create a score control + if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kScoreDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC ) + return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Score UI element create failed."); + + // Set the kUiDsvFl on the variables used for the min/max/def/val for this scalar + // Setting this flag will cause their values to be sent to the UI whenever they change. + cmDspInstVarSetFlags( ctx, inst, scFileVarId, kUiDsvFl ); + cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl ); return rc; }