libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmDspPgmKr.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmRpt.h"
  5. #include "cmErr.h"
  6. #include "cmCtx.h"
  7. #include "cmMem.h"
  8. #include "cmMallocDebug.h"
  9. #include "cmLinkedHeap.h"
  10. #include "cmText.h"
  11. #include "cmFileSys.h"
  12. #include "cmSymTbl.h"
  13. #include "cmJson.h"
  14. #include "cmPrefs.h"
  15. #include "cmDspValue.h"
  16. #include "cmMsgProtocol.h"
  17. #include "cmThread.h"
  18. #include "cmUdpPort.h"
  19. #include "cmUdpNet.h"
  20. #include "cmAudioSys.h"
  21. #include "cmProcObj.h"
  22. #include "cmDspCtx.h"
  23. #include "cmDspClass.h"
  24. #include "cmDspSys.h"
  25. #include "cmDspPgm.h"
  26. #include "cmAudioFile.h"
  27. #include "cmProcObj.h"
  28. #include "cmProc.h"
  29. #include "cmProc3.h"
  30. #include "cmVectOpsTemplateMain.h"
  31. #include "cmVectOps.h"
  32. typedef struct
  33. {
  34. const cmChar_t* tlFn;
  35. const cmChar_t* audPath;
  36. const cmChar_t* scFn;
  37. } krRsrc_t;
  38. cmDspRC_t krLoadRsrc(cmDspSysH_t h, cmErr_t* err, krRsrc_t* r)
  39. {
  40. cmDspRC_t rc;
  41. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  42. return rc;
  43. cmDspRsrcString(h,&r->tlFn, "timeLineFn", NULL);
  44. cmDspRsrcString(h,&r->audPath,"tlAudioFilePath", NULL);
  45. cmDspRsrcString(h,&r->scFn, "scoreFn", NULL);
  46. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  47. cmErrMsg(err,rc,"A KR DSP resource load failed.");
  48. return rc;
  49. }
  50. cmDspRC_t _cmDspSysPgm_TimeLine(cmDspSysH_t h, void** userPtrPtr )
  51. {
  52. cmDspRC_t rc = kOkDspRC;
  53. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  54. cmErr_t err;
  55. krRsrc_t r;
  56. unsigned wtLoopCnt = -1; // play once (do not loop)
  57. unsigned wtInitMode = 0; // initial wt mode is 'silence'
  58. unsigned wtSmpCnt = floor(cmDspSysSampleRate(h)); // wt length == srate
  59. memset(&r,0,sizeof(r));
  60. cmErrSetup(&err,&cmCtx->rpt,"Kr Timeline");
  61. if( krLoadRsrc(h,&err,&r) != kOkDspRC )
  62. return rc;
  63. cmDspInst_t* tlp = cmDspSysAllocInst(h,"TimeLine", "tl", 2, r.tlFn, r.audPath );
  64. cmDspInst_t* scp = cmDspSysAllocInst(h,"Score", "sc", 1, r.scFn );
  65. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 1, cmDspSysSampleRate(h) );
  66. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable", NULL, 4, wtSmpCnt, wtInitMode, NULL, wtLoopCnt );
  67. cmDspInst_t* pts = cmDspSysAllocInst(h,"PortToSym", NULL, 2, "on", "off" );
  68. cmDspInst_t* mfp = cmDspSysAllocInst(h,"MidiFilePlay",NULL, 0 );
  69. cmDspInst_t* sfp = cmDspSysAllocInst(h,"ScFol", NULL, 1, r.scFn );
  70. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 0 );
  71. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 1 );
  72. cmDspSysNewPage(h,"Controls");
  73. cmDspInst_t* onb = cmDspSysAllocInst(h,"Button", "start", 2, kButtonDuiId, 1.0 );
  74. cmDspInst_t* offb = cmDspSysAllocInst(h,"Button", "stop", 2, kButtonDuiId, 1.0 );
  75. cmDspInst_t* prtb = cmDspSysAllocInst(h,"Button", "print", 2, kButtonDuiId, 1.0 );
  76. cmDspInst_t* qtb = cmDspSysAllocInst(h,"Button", "quiet", 2, kButtonDuiId, 1.0 );
  77. cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL, 1, ">" );
  78. //cmDspInst_t* prd = cmDspSysAllocInst(h,"Printer", NULL, 1, "DYN:" );
  79. //cmDspInst_t* pre = cmDspSysAllocInst(h,"Printer", NULL, 1, "EVEN:" );
  80. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  81. return rc;
  82. // phasor->wt->aout
  83. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phs -> wt
  84. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wt -> aout0
  85. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" ); // wt -> aout1
  86. cmDspSysInstallCb( h, wtp, "fidx",tlp, "curs", NULL);
  87. // start connections
  88. cmDspSysInstallCb(h, onb, "sym", tlp, "reset", NULL );
  89. cmDspSysInstallCb(h, onb, "sym", scp, "send", NULL );
  90. cmDspSysInstallCb(h, onb, "sym", mfp, "sel", NULL );
  91. cmDspSysInstallCb(h, onb, "sym", pts, "on", NULL );
  92. cmDspSysInstallCb(h, pts, "on", wtp, "cmd", NULL );
  93. // stop connections
  94. cmDspSysInstallCb(h, wtp, "done",offb,"in", NULL ); // 'done' from WT simulates pressing Stop btn.
  95. cmDspSysInstallCb(h, tlp, "mfn", pts, "off", NULL ); // Prevents WT start on new audio file from TL.
  96. cmDspSysInstallCb(h, offb, "sym", mfp, "sel", NULL );
  97. cmDspSysInstallCb(h, offb, "sym", pts, "off", NULL );
  98. cmDspSysInstallCb(h, pts, "off", wtp, "cmd", NULL );
  99. // time-line to wave-table selection
  100. cmDspSysInstallCb(h, tlp, "absi", wtp, "beg", NULL );
  101. cmDspSysInstallCb(h, tlp, "aesi", wtp, "end", NULL );
  102. cmDspSysInstallCb(h, tlp, "afn", wtp, "fn", NULL );
  103. // time-line to MIDI file player selection
  104. cmDspSysInstallCb(h, tlp, "mbsi", mfp, "bsi", NULL );
  105. cmDspSysInstallCb(h, tlp, "mesi", mfp, "esi", NULL );
  106. cmDspSysInstallCb(h, tlp, "mfn", mfp, "fn", NULL );
  107. // score to score follower - to set initial search location
  108. //cmDspSysInstallCb(h, scp, "sel", sfp, "index", NULL );
  109. // MIDI file player to score-follower and score - the order of connections is the same
  110. // as the msg transmision order from MFP
  111. cmDspSysInstallCb(h, mfp, "smpidx", scp, "smpidx", NULL );
  112. cmDspSysInstallCb(h, mfp, "d1", scp, "d1", NULL );
  113. //cmDspSysInstallCb(h, mfp, "d1", sfp, "d1", NULL );
  114. cmDspSysInstallCb(h, mfp, "d0", scp, "d0", NULL );
  115. //cmDspSysInstallCb(h, mfp, "d0", sfp, "d0", NULL );
  116. cmDspSysInstallCb(h, mfp, "status", scp, "status", NULL );
  117. //cmDspSysInstallCb(h, mfp, "status", sfp, "status", NULL );
  118. // score follower to score
  119. //cmDspSysInstallCb(h, sfp, "out", scp, "loc", NULL );
  120. // Printer connections
  121. cmDspSysInstallCb(h, tlp, "afn", prp, "in", NULL );
  122. cmDspSysInstallCb(h, tlp, "mfn", prp, "in", NULL );
  123. cmDspSysInstallCb(h, tlp, "sel", prp, "in", NULL );
  124. //cmDspSysInstallCb(h, sfp, "out", prp, "in", NULL );
  125. //cmDspSysInstallCb(h, scp, "even", pre, "in", NULL );
  126. //cmDspSysInstallCb(h, scp, "dyn", prd, "in", NULL );
  127. cmDspSysInstallCb(h, prtb, "sym", sfp, "cmd", NULL );
  128. cmDspSysInstallCb(h, qtb, "sym", sfp, "cmd", NULL );
  129. return rc;
  130. }