|
@@ -286,7 +286,9 @@ enum
|
286
|
286
|
kCursTlId,
|
287
|
287
|
kResetTlId,
|
288
|
288
|
kAudFnTlId,
|
|
289
|
+ kAudLblTlId,
|
289
|
290
|
kMidiFnTlId,
|
|
291
|
+ kMidiLblTlId,
|
290
|
292
|
kBegAudSmpIdxTlId,
|
291
|
293
|
kEndAudSmpIdxTlId,
|
292
|
294
|
kBegMidiSmpIdxTlId,
|
|
@@ -312,7 +314,9 @@ cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
|
312
|
314
|
{ "curs", kCursTlId, 0, 0, kInDsvFl | kUIntDsvFl, "Current audio file index."},
|
313
|
315
|
{ "reset", kResetTlId, 0, 0, kInDsvFl | kSymDsvFl, "Resend all outputs." },
|
314
|
316
|
{ "afn", kAudFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected Audio file." },
|
|
317
|
+ { "albl", kAudLblTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Select Audio file time line label."},
|
315
|
318
|
{ "mfn", kMidiFnTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Selected MIDI file." },
|
|
319
|
+ { "mlbl", kMidiLblTlId, 0, 0, kOutDsvFl | kStrzDsvFl, "Select MIDI file time line label."},
|
316
|
320
|
{ "absi", kBegAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin audio sample index."},
|
317
|
321
|
{ "aesi", kEndAudSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "End audio sample index."},
|
318
|
322
|
{ "mbsi", kBegMidiSmpIdxTlId, 0, 0, kOutDsvFl | kIntDsvFl, "Begin MIDI sample index."},
|
|
@@ -325,7 +329,9 @@ cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
|
325
|
329
|
cmDspSetDefaultUInt( ctx, &p->inst, kSelTlId, 0, cmInvalidId);
|
326
|
330
|
cmDspSetDefaultUInt( ctx, &p->inst, kCursTlId, 0, 0);
|
327
|
331
|
cmDspSetDefaultStrcz(ctx, &p->inst, kAudFnTlId, NULL, "");
|
|
332
|
+ cmDspSetDefaultStrcz(ctx, &p->inst, kAudLblTlId, NULL, "");
|
328
|
333
|
cmDspSetDefaultStrcz(ctx, &p->inst, kMidiFnTlId, NULL, "");
|
|
334
|
+ cmDspSetDefaultStrcz(ctx, &p->inst, kMidiLblTlId, NULL, "");
|
329
|
335
|
cmDspSetDefaultInt( ctx, &p->inst, kBegAudSmpIdxTlId, 0, cmInvalidIdx);
|
330
|
336
|
cmDspSetDefaultInt( ctx, &p->inst, kEndAudSmpIdxTlId, 0, cmInvalidIdx);
|
331
|
337
|
cmDspSetDefaultInt( ctx, &p->inst, kBegMidiSmpIdxTlId, 0, cmInvalidIdx);
|
|
@@ -406,7 +412,10 @@ cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
|
406
|
412
|
// locate the audio file assoc'd with the marker
|
407
|
413
|
cmTlAudioFile_t* afp;
|
408
|
414
|
if((afp = cmTimeLineAudioFileAtTime(p->tlH,op->seqId,op->seqSmpIdx)) != NULL)
|
|
415
|
+ {
|
409
|
416
|
cmDspSetStrcz(ctx, inst, kAudFnTlId, afp->fn );
|
|
417
|
+ cmDspSetStrcz(ctx, inst, kAudLblTlId, afp->obj.name );
|
|
418
|
+ }
|
410
|
419
|
|
411
|
420
|
// locate the midi file assoc'd with the marker
|
412
|
421
|
cmTlMidiFile_t* mfp;
|
|
@@ -416,6 +425,8 @@ cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
|
416
|
425
|
cmDspSetInt(ctx, inst, kEndMidiSmpIdxTlId, op->seqSmpIdx + op->durSmpCnt - mfp->obj.seqSmpIdx );
|
417
|
426
|
|
418
|
427
|
cmDspSetStrcz(ctx, inst, kMidiFnTlId, mfp->fn );
|
|
428
|
+ cmDspSetStrcz(ctx, inst, kMidiLblTlId,mfp->obj.name );
|
|
429
|
+
|
419
|
430
|
}
|
420
|
431
|
}
|
421
|
432
|
|
|
@@ -637,7 +648,8 @@ enum
|
637
|
648
|
kStatusMfId,
|
638
|
649
|
kD0MfId,
|
639
|
650
|
kD1MfId,
|
640
|
|
- kSmpIdxMfId
|
|
651
|
+ kSmpIdxMfId,
|
|
652
|
+ kIdMfId
|
641
|
653
|
};
|
642
|
654
|
|
643
|
655
|
cmDspClass_t _cmMidiFilePlayDC;
|
|
@@ -676,7 +688,8 @@ cmDspInst_t* _cmDspMidiFilePlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, u
|
676
|
688
|
{ "status", kStatusMfId, 0, 0, kOutDsvFl | kIntDsvFl, "Status value output" },
|
677
|
689
|
{ "d0", kD0MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 0" },
|
678
|
690
|
{ "d1", kD1MfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Data byte 1" },
|
679
|
|
- { "smpidx", kSmpIdxMfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Msg time tag as a sample index." },
|
|
691
|
+ { "smpidx", kSmpIdxMfId, 0, 0, kOutDsvFl | kUIntDsvFl, "Msg time tag as a sample index." },
|
|
692
|
+ { "id", kIdMfId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI file msg unique id."},
|
680
|
693
|
{ NULL, 0, 0, 0, 0 }
|
681
|
694
|
};
|
682
|
695
|
|
|
@@ -798,6 +811,7 @@ cmDspRC_t _cmDspMidiFilePlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
|
798
|
811
|
cmDspSetUInt(ctx,inst, kD1MfId, mp->u.chMsgPtr->d1);
|
799
|
812
|
cmDspSetUInt(ctx,inst, kD0MfId, mp->u.chMsgPtr->d0);
|
800
|
813
|
cmDspSetUInt(ctx,inst, kStatusMfId, mp->status);
|
|
814
|
+ cmDspSetUInt(ctx,inst, kIdMfId, mp->uid);
|
801
|
815
|
break;
|
802
|
816
|
}
|
803
|
817
|
}
|
|
@@ -844,7 +858,7 @@ struct cmDspClass_str* cmMidiFilePlayClassCons( cmDspCtx_t* ctx )
|
844
|
858
|
_cmDspMidiFilePlayExec,
|
845
|
859
|
_cmDspMidiFilePlayRecv,
|
846
|
860
|
NULL,NULL,
|
847
|
|
- "Time tagged text file.");
|
|
861
|
+ "MIDI file player.");
|
848
|
862
|
|
849
|
863
|
return &_cmMidiFilePlayDC;
|
850
|
864
|
}
|
|
@@ -1869,3 +1883,209 @@ struct cmDspClass_str* cmActiveMeasClassCons( cmDspCtx_t* ctx )
|
1869
|
1883
|
return &_cmActiveMeasDC;
|
1870
|
1884
|
}
|
1871
|
1885
|
|
|
1886
|
+//==========================================================================================================================================
|
|
1887
|
+// Audio MIDI Sync
|
|
1888
|
+
|
|
1889
|
+enum
|
|
1890
|
+{
|
|
1891
|
+ kSelAmId,
|
|
1892
|
+ kAFnAmId,
|
|
1893
|
+ kASmpAmId,
|
|
1894
|
+ kMFnAmId,
|
|
1895
|
+ kMIdAmId,
|
|
1896
|
+};
|
|
1897
|
+
|
|
1898
|
+enum
|
|
1899
|
+{
|
|
1900
|
+ kAfnAmFl = 0x01,
|
|
1901
|
+ kMfnAmFl = 0x02,
|
|
1902
|
+ kAsmpAmFl = 0x04,
|
|
1903
|
+ kMidAmFl = 0x08,
|
|
1904
|
+};
|
|
1905
|
+
|
|
1906
|
+cmDspClass_t _cmAmSyncDC;
|
|
1907
|
+
|
|
1908
|
+typedef struct cmDspAmSyncEntry_str
|
|
1909
|
+{
|
|
1910
|
+ const cmChar_t* afn;
|
|
1911
|
+ const cmChar_t* mfn;
|
|
1912
|
+ unsigned asmp; // Audio sample index to sync to MIDI event
|
|
1913
|
+ unsigned mid; // MIDI event unique id (cmMidiTrackMsg_t.uid)
|
|
1914
|
+ int afi;
|
|
1915
|
+ int mfi;
|
|
1916
|
+ unsigned state;
|
|
1917
|
+} cmDspAmSyncEntry_t;
|
|
1918
|
+
|
|
1919
|
+typedef struct
|
|
1920
|
+{
|
|
1921
|
+ cmDspInst_t inst;
|
|
1922
|
+ cmDspAmSyncEntry_t* array;
|
|
1923
|
+ unsigned arrayCnt;
|
|
1924
|
+ cmDspAmSyncEntry_t* acur;
|
|
1925
|
+ cmDspAmSyncEntry_t* mcur;
|
|
1926
|
+} cmDspAmSync_t;
|
|
1927
|
+
|
|
1928
|
+cmDspInst_t* _cmDspAmSyncAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
1929
|
+{
|
|
1930
|
+ cmDspVarArg_t args[] =
|
|
1931
|
+ {
|
|
1932
|
+ { "sel", kSelAmId, 0, 0, kInDsvFl | kTypeDsvMask, "Any message to print" },
|
|
1933
|
+ { "afn", kAFnAmId, 0, 0, kInDsvFl | kStrzDsvFl, "Audio File name"},
|
|
1934
|
+ { "asmp", kASmpAmId, 0, 0, kInDsvFl | kIntDsvFl, "Audio sample index"},
|
|
1935
|
+ { "mfn", kMFnAmId, 0, 0, kInDsvFl | kStrzDsvFl, "MIDI File name"},
|
|
1936
|
+ { "mid", kMIdAmId, 0, 0, kInDsvFl | kIntDsvFl, "MIDI Event Unique Id"},
|
|
1937
|
+ { NULL, 0, 0, 0, 0 }
|
|
1938
|
+ };
|
|
1939
|
+
|
|
1940
|
+ cmDspAmSync_t* p = cmDspInstAlloc(cmDspAmSync_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
1941
|
+
|
|
1942
|
+ return &p->inst;
|
|
1943
|
+}
|
|
1944
|
+
|
|
1945
|
+cmDspRC_t _cmDspAmSyncFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
1946
|
+{
|
|
1947
|
+ cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
1948
|
+
|
|
1949
|
+ cmMemFree(p->array);
|
|
1950
|
+
|
|
1951
|
+ return kOkDspRC;
|
|
1952
|
+}
|
|
1953
|
+
|
|
1954
|
+
|
|
1955
|
+cmDspRC_t _cmDspAmSyncReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
1956
|
+{
|
|
1957
|
+ cmDspRC_t rc = kOkDspRC;
|
|
1958
|
+ cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
1959
|
+
|
|
1960
|
+ cmDspApplyAllDefaults(ctx,inst);
|
|
1961
|
+
|
|
1962
|
+ cmJsonH_t jsH = cmDspSysPgmRsrcHandle(ctx->dspH);
|
|
1963
|
+ cmJsonNode_t* np;
|
|
1964
|
+ const cmChar_t* errLabelPtr;
|
|
1965
|
+ unsigned i;
|
|
1966
|
+ cmJsRC_t jsRC;
|
|
1967
|
+
|
|
1968
|
+ if((np = cmJsonFindValue(jsH, "amSync", NULL, kArrayTId)) == NULL )
|
|
1969
|
+ {
|
|
1970
|
+ rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The AUDIO MIDI Sync cfg. record was not found.");
|
|
1971
|
+ goto errLabel;
|
|
1972
|
+ }
|
|
1973
|
+
|
|
1974
|
+ p->arrayCnt = cmJsonChildCount(np);
|
|
1975
|
+
|
|
1976
|
+ p->array = cmMemResizeZ(cmDspAmSyncEntry_t,p->array,p->arrayCnt);
|
|
1977
|
+
|
|
1978
|
+ for(i=0; i<p->arrayCnt; ++i)
|
|
1979
|
+ {
|
|
1980
|
+ cmJsonNode_t* anp = cmJsonArrayElement(np,i);
|
|
1981
|
+
|
|
1982
|
+ cmDspAmSyncEntry_t* r = p->array + i;
|
|
1983
|
+ if( (jsRC = cmJsonMemberValues(anp,&errLabelPtr,
|
|
1984
|
+ "af", kStringTId,&r->afn,
|
|
1985
|
+ "asmp",kIntTId, &r->asmp,
|
|
1986
|
+ "mf", kStringTId,&r->mfn,
|
|
1987
|
+ "mid", kIntTId, &r->mid,
|
|
1988
|
+ NULL)) != kOkJsRC )
|
|
1989
|
+ {
|
|
1990
|
+ if( jsRC == kNodeNotFoundJsRC )
|
|
1991
|
+ rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The Audio-MIDI Sync cfg. field '%s' was missing in the cfg. record at index %i.",errLabelPtr,i);
|
|
1992
|
+ else
|
|
1993
|
+ rc = cmDspInstErr(ctx,inst,kInvalidArgDspRC,"The AUDIO MIDI Sync cfg. parse failed on the record at index %i.",i);
|
|
1994
|
+ break;
|
|
1995
|
+ }
|
|
1996
|
+ r->afi = cmInvalidIdx;
|
|
1997
|
+ r->mfi = cmInvalidIdx;
|
|
1998
|
+ r->state = 0;
|
|
1999
|
+ }
|
|
2000
|
+
|
|
2001
|
+ errLabel:
|
|
2002
|
+ return rc;
|
|
2003
|
+}
|
|
2004
|
+
|
|
2005
|
+
|
|
2006
|
+cmDspRC_t _cmDspAmSyncRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
2007
|
+{
|
|
2008
|
+ cmDspAmSync_t* p = (cmDspAmSync_t*)inst;
|
|
2009
|
+ unsigned i;
|
|
2010
|
+
|
|
2011
|
+ if( evt->dstVarId != kSelAmId )
|
|
2012
|
+ cmDspSetEvent(ctx,inst,evt);
|
|
2013
|
+
|
|
2014
|
+ switch(evt->dstVarId)
|
|
2015
|
+ {
|
|
2016
|
+ case kSelAmId:
|
|
2017
|
+ for(i=0; i<p->arrayCnt; ++i)
|
|
2018
|
+ {
|
|
2019
|
+ const cmDspAmSyncEntry_t* r = p->array + i;
|
|
2020
|
+ cmRptPrintf(ctx->rpt,"0x%x : %s %i %i - %s %i %i : %i\n",
|
|
2021
|
+ r->state,r->afn,r->asmp,r->afi,r->mfn,r->mid,r->mfi,r->afi-r->mfi);
|
|
2022
|
+ }
|
|
2023
|
+ break;
|
|
2024
|
+
|
|
2025
|
+ case kAFnAmId:
|
|
2026
|
+ {
|
|
2027
|
+ const cmChar_t* fn = cmDspStrcz(inst, kAFnAmId );
|
|
2028
|
+ for(i=0; i<p->arrayCnt; ++i)
|
|
2029
|
+ if( strcmp(fn,p->array[i].afn) == 0 )
|
|
2030
|
+ {
|
|
2031
|
+ p->acur = p->array + i;
|
|
2032
|
+ p->array[i].state = cmSetFlag(p->array[i].state,kAfnAmFl);
|
|
2033
|
+ break;
|
|
2034
|
+ }
|
|
2035
|
+ }
|
|
2036
|
+ break;
|
|
2037
|
+
|
|
2038
|
+ case kMFnAmId:
|
|
2039
|
+ {
|
|
2040
|
+ const cmChar_t* fn = cmDspStrcz(inst, kMFnAmId );
|
|
2041
|
+ for(i=0; i<p->arrayCnt; ++i)
|
|
2042
|
+ if( strcmp(fn,p->array[i].mfn) == 0 )
|
|
2043
|
+ {
|
|
2044
|
+ p->mcur = p->array + i;
|
|
2045
|
+ p->array[i].state = cmSetFlag(p->array[i].state,kMfnAmFl);
|
|
2046
|
+ break;
|
|
2047
|
+ }
|
|
2048
|
+ }
|
|
2049
|
+ break;
|
|
2050
|
+
|
|
2051
|
+ case kASmpAmId:
|
|
2052
|
+ {
|
|
2053
|
+ int v = cmDspInt(inst,kASmpAmId);
|
|
2054
|
+ if( p->acur != NULL && p->acur->asmp <= v )
|
|
2055
|
+ {
|
|
2056
|
+ p->acur->afi = ctx->cycleCnt;
|
|
2057
|
+ p->acur->state = cmSetFlag(p->acur->state,kAsmpAmFl);
|
|
2058
|
+ }
|
|
2059
|
+ }
|
|
2060
|
+ break;
|
|
2061
|
+
|
|
2062
|
+ case kMIdAmId:
|
|
2063
|
+ {
|
|
2064
|
+ int v = cmDspInt(inst,kMIdAmId);
|
|
2065
|
+ if( p->mcur != NULL && p->mcur->mid == v )
|
|
2066
|
+ {
|
|
2067
|
+ p->mcur->mfi = ctx->cycleCnt;
|
|
2068
|
+ p->mcur->state = cmSetFlag(p->mcur->state,kMidAmFl);
|
|
2069
|
+ }
|
|
2070
|
+ }
|
|
2071
|
+ break;
|
|
2072
|
+
|
|
2073
|
+ }
|
|
2074
|
+ return kOkDspRC;
|
|
2075
|
+}
|
|
2076
|
+
|
|
2077
|
+struct cmDspClass_str* cmAmSyncClassCons( cmDspCtx_t* ctx )
|
|
2078
|
+{
|
|
2079
|
+ cmDspClassSetup(&_cmAmSyncDC,ctx,"AmSync",
|
|
2080
|
+ NULL,
|
|
2081
|
+ _cmDspAmSyncAlloc,
|
|
2082
|
+ _cmDspAmSyncFree,
|
|
2083
|
+ _cmDspAmSyncReset,
|
|
2084
|
+ NULL,
|
|
2085
|
+ _cmDspAmSyncRecv,
|
|
2086
|
+ NULL,NULL,
|
|
2087
|
+ "Audio - MIDI Sync Object.");
|
|
2088
|
+
|
|
2089
|
+ return &_cmAmSyncDC;
|
|
2090
|
+}
|
|
2091
|
+
|