libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cmScoreProc.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "cmGlobal.h"
  2. #include "cmFloatTypes.h"
  3. #include "cmRpt.h"
  4. #include "cmErr.h"
  5. #include "cmCtx.h"
  6. #include "cmMem.h"
  7. #include "cmMallocDebug.h"
  8. #include "cmLinkedHeap.h"
  9. #include "cmSymTbl.h"
  10. #include "cmJson.h"
  11. #include "cmMidi.h"
  12. #include "cmMidiFile.h"
  13. #include "cmAudioFile.h"
  14. #include "cmScore.h"
  15. #include "cmTimeLine.h"
  16. #include "cmScoreProc.h"
  17. enum
  18. {
  19. kOkSpRC,
  20. kJsonFailSpRC,
  21. kScoreFailSpRC,
  22. kTimeLineFailSpRC
  23. };
  24. typedef struct
  25. {
  26. cmErr_t err;
  27. cmScH_t scH;
  28. const cmChar_t* tlFn;
  29. cmTlH_t tlH;
  30. cmJsonH_t jsH;
  31. unsigned* dynArray;
  32. unsigned dynCnt;
  33. double srate;
  34. } cmSp_t;
  35. cmSpRC_t _cmJsonReadDynArray( cmJsonH_t jsH, unsigned** dynArray, unsigned* dynCnt )
  36. {
  37. cmJsonNode_t* np;
  38. int i;
  39. if( cmJsonPathToArray(jsH, NULL, NULL, "dynRef", &np ) != kOkJsRC )
  40. return kJsonFailSpRC;
  41. *dynCnt = cmJsonChildCount(np);
  42. *dynArray = cmMemAllocZ(unsigned,*dynCnt);
  43. for(i=0; i<*dynCnt; ++i)
  44. if( cmJsonUIntValue( cmJsonArrayElement(np,i), (*dynArray)+i ) != kOkJsRC )
  45. return kJsonFailSpRC;
  46. return kOkSpRC;
  47. }
  48. cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
  49. {
  50. cmSpRC_t rc = kOkSpRC;
  51. const cmChar_t* scFn = NULL;
  52. const cmChar_t* tlFn = NULL;
  53. p->srate = 96000;
  54. cmErrSetup(&p->err,&ctx->rpt,"ScoreProc");
  55. // open the resource file
  56. if( cmJsonInitializeFromFile( &p->jsH, rsrcFn, ctx ) != kOkJsRC )
  57. {
  58. rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to load the main resource file:%s.",cmStringNullGuard(rsrcFn));
  59. goto errLabel;
  60. }
  61. // get the time line fn
  62. if( cmJsonPathToString( p->jsH, NULL, NULL, "timeLineFn", &tlFn ) != kOkJsRC )
  63. {
  64. rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the time line file name in the main resource file:%s",cmStringNullGuard(rsrcFn));
  65. goto errLabel;
  66. }
  67. // get the score file name
  68. if( cmJsonPathToString( p->jsH, NULL, NULL, "scoreFn", &scFn ) != kOkJsRC )
  69. {
  70. rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the score file name in the main resource file:%s",cmStringNullGuard(rsrcFn));
  71. goto errLabel;
  72. }
  73. // read the dynamics reference array
  74. if((rc = _cmJsonReadDynArray( p->jsH, &p->dynArray, &p->dynCnt )) != kOkSpRC )
  75. {
  76. rc = cmErrMsg(&p->err,rc,"Unable to read dynamics reference array resource from the main resource file:%s",cmStringNullGuard(rsrcFn));
  77. goto errLabel;
  78. }
  79. // load the score file
  80. if( cmScoreInitialize(ctx, &p->scH, scFn, p->srate, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC )
  81. {
  82. rc = cmErrMsg(&p->err,kScoreFailSpRC,"Score load failed for score file:%s.",cmStringNullGuard(scFn));
  83. goto errLabel;
  84. }
  85. if( cmTimeLineInitialize(ctx, &p->tlH, NULL, NULL ) != kOkTlRC )
  86. {
  87. rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn));
  88. goto errLabel;
  89. }
  90. errLabel:
  91. return rc;
  92. }
  93. cmSpRC_t _cmScoreProcFinal( cmSp_t* p )
  94. {
  95. cmSpRC_t rc = kOkSpRC;
  96. if( cmScoreFinalize(&p->scH) != kOkScRC )
  97. cmErrMsg(&p->err,kScoreFailSpRC,"Score finalize failed.");
  98. if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
  99. cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line finalize failed.");
  100. if( cmJsonFinalize(&p->jsH) != kOkJsRC )
  101. cmErrMsg(&p->err,kJsonFailSpRC,"JSON finalize failed.");
  102. cmMemFree(p->dynArray);
  103. return rc;
  104. }
  105. unsigned cmScoreProc(cmCtx_t* ctx)
  106. {
  107. cmSpRC_t rc = kOkSpRC;
  108. const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js";
  109. cmSp_t sp;
  110. memset(&sp,0,sizeof(sp));
  111. cmRptPrintf(&ctx->rpt,"Score Proc Start\n");
  112. if((rc = _cmScoreProcInit(ctx,&sp,rsrcFn)) != kOkSpRC )
  113. goto errLabel;
  114. errLabel:
  115. _cmScoreProcFinal(&sp);
  116. cmRptPrintf(&ctx->rpt,"Score Proc End\n");
  117. return rc;
  118. }