Browse Source

cmXScore.h/c,Makefile.am : Initial commit.

master
Kevin Larke 8 years ago
parent
commit
1fc5183394
3 changed files with 394 additions and 2 deletions
  1. 75
    2
      Makefile.am
  2. 276
    0
      app/cmXScore.c
  3. 43
    0
      app/cmXScore.h

+ 75
- 2
Makefile.am View File

@@ -75,7 +75,80 @@ cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/
75 75
 
76 76
 
77 77
 cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h 
78
-cmSRC += src/libcm/app/cmOnset.c src/libcm/app/cmTimeLine.c src/libcm/app/cmScore.c src/libcm/app/cmScoreProc.c 
78
+
79
+cmHDR += src/libcm/cmErr.h src/libcm/cmCtx.h src/libcm/cmRpt.h src/libcm/cmGlobal.h src/libcm/cmComplexTypes.h src/libcm/cmFloatTypes.h src/libcm/cmPrefix.h
80
+cmSRC += src/libcm/cmErr.c src/libcm/cmCtx.c src/libcm/cmRpt.c src/libcm/cmGlobal.c src/libcm/cmComplexTypes.c
81
+
82
+cmHDR += src/libcm/cmSerialize.h src/libcm/cmSymTbl.h src/libcm/cmHashTbl.h src/libcm/cmFileSys.h src/libcm/cmFile.h 
83
+cmSRC += src/libcm/cmSerialize.c src/libcm/cmSymTbl.c src/libcm/cmHashTbl.c src/libcm/cmFileSys.c src/libcm/cmFile.c 
84
+
85
+cmHDR += src/libcm/cmMem.h src/libcm/cmTime.h src/libcm/cmExec.h src/libcm/cmPgmOpts.h
86
+cmSRC += src/libcm/cmMem.c src/libcm/cmTime.c src/libcm/cmExec.c src/libcm/cmPgmOpts.c
87
+
88
+cmHDR += src/libcm/cmData.h src/libcm/cmLib.h src/libcm/cmText.h src/libcm/cmTextTemplate.h
89
+cmSRC += src/libcm/cmData.c src/libcm/cmLib.c src/libcm/cmText.c src/libcm/cmTextTemplate.c
90
+
91
+cmHDR += src/libcm/cmMath.h src/libcm/cmGnuPlot.h src/libcm/cmKeyboard.h  src/libcm/cmStrStream.h
92
+cmSRC += src/libcm/cmMath.c src/libcm/cmGnuPlot.c src/libcm/cmKeyboard.c  src/libcm/cmStrStream.c
93
+
94
+cmHDR += src/libcm/cmLinkedHeap.h src/libcm/cmMallocDebug.h src/libcm/cmLex.h src/libcm/cmJson.h src/libcm/cmXml.h src/libcm/cmPrefs.h src/libcm/cmStack.h src/libcm/cmArray.h
95
+cmSRC += src/libcm/cmLinkedHeap.c src/libcm/cmMallocDebug.c src/libcm/cmLex.c src/libcm/cmJson.c src/libcm/cmXml.c src/libcm/cmPrefs.c src/libcm/cmStack.c src/libcm/cmArray.c
96
+
97
+cmHDR += src/libcm/cmUdpPort.h src/libcm/cmUdpNet.h src/libcm/cmVirtNet.h
98
+cmSRC += src/libcm/cmUdpPort.c src/libcm/cmUdpNet.c src/libcm/cmVirtNet.c
99
+
100
+cmHDR += src/libcm/cmAudioPort.h src/libcm/cmApBuf.h src/libcm/cmAudioAggDev.h src/libcm/cmAudioNrtDev.h src/libcm/cmThread.h	
101
+cmSRC += src/libcm/cmAudioPort.c src/libcm/cmApBuf.c src/libcm/cmAudioAggDev.c src/libcm/cmAudioNrtDev.c src/libcm/cmThread.c
102
+
103
+cmHDR += src/libcm/cmMidiFilePlay.h src/libcm/cmMidiPort.h src/libcm/cmMidiFile.h src/libcm/cmMidi.h 
104
+cmSRC += src/libcm/cmMidiFilePlay.c src/libcm/cmMidiPort.c src/libcm/cmMidiFile.c src/libcm/cmMidi.c 
105
+
106
+cmHDR += src/libcm/cmAudioFile.h src/libcm/cmAudioFileMgr.h src/libcm/cmMsgProtocol.h src/libcm/cmAudioSys.h src/libcm/cmAudioPortFile.h src/libcm/cmAudioFileDev.h 
107
+cmSRC += src/libcm/cmAudioFile.c src/libcm/cmAudioFileMgr.c src/libcm/cmMsgProtocol.c src/libcm/cmAudioSys.c src/libcm/cmAudioPortFile.c src/libcm/cmAudioFileDev.c
108
+
109
+cmHDR += src/libcm/cmRtSys.h src/libcm/cmRtNet.h src/libcm/cmUiRtSysMstr.h src/libcm/cmRtSysMsg.h 
110
+cmSRC += src/libcm/cmRtSys.c src/libcm/cmRtNet.c src/libcm/cmUiRtSysMstr.c
111
+
112
+cmHDR += src/libcm/cmDevCfg.h src/libcm/cmUi.h src/libcm/cmUiDrvr.h 
113
+cmSRC += src/libcm/cmDevCfg.c src/libcm/cmUi.c src/libcm/cmUiDrvr.c
114
+
115
+cmHDR += src/libcm/cmFrameFile.h src/libcm/cmFeatFile.h src/libcm/cmCsv.h src/libcm/cmAudLabelFile.h src/libcm/cmTagFile.h
116
+cmSRC += src/libcm/cmFrameFile.c src/libcm/cmFeatFile.c src/libcm/cmCsv.c src/libcm/cmAudLabelFile.c src/libcm/cmTagFile.c
117
+
118
+cmSRC += src/libcm/cmGr.c src/libcm/cmGrDevCtx.c src/libcm/cmGrPage.c src/libcm/cmGrPlot.c src/libcm/cmGrPlotAudio.c
119
+cmHDR += src/libcm/cmGr.h src/libcm/cmGrDevCtx.h src/libcm/cmGrPage.h src/libcm/cmGrPlot.h src/libcm/cmGrPlotAudio.h
120
+
121
+cmHDR +=  src/libcm/dsp/cmDspSys.h src/libcm/dsp/cmDspClass.h src/libcm/dsp/cmDspValue.h src/libcm/dsp/cmDspUi.h src/libcm/dsp/cmDspPreset.h src/libcm/dsp/cmDspNet.h
122
+cmSRC +=  src/libcm/dsp/cmDspSys.c src/libcm/dsp/cmDspClass.c src/libcm/dsp/cmDspValue.c src/libcm/dsp/cmDspUi.c src/libcm/dsp/cmDspPreset.c src/libcm/dsp/cmDspNet.c
123
+
124
+cmHDR += src/libcm/dsp/cmDspStore.h src/libcm/dsp/cmDspBuiltIn.h  src/libcm/dsp/cmDspFx.h 
125
+cmSRC += src/libcm/dsp/cmDspStore.c src/libcm/dsp/cmDspBuiltIn.c  src/libcm/dsp/cmDspFx.c 
126
+
127
+cmHDR += src/libcm/dsp/cmDspPgm.h src/libcm/dsp/cmDspPgmPP.h src/libcm/dsp/cmDspPgmPPMain.h
128
+cmSRC += src/libcm/dsp/cmDspPgm.c src/libcm/dsp/cmDspPgmPP.c src/libcm/dsp/cmDspPgmPPMain.c
129
+
130
+cmHDR +=  src/libcm/dsp/cmDspKr.h src/libcm/dsp/cmDspPgmKr.h
131
+cmSRC +=  src/libcm/dsp/cmDspKr.c src/libcm/dsp/cmDspPgmKr.c
132
+
133
+cmHDR += src/libcm/cmAudDsp.h src/libcm/cmAudDspIF.h src/libcm/cmAudDspLocal.h
134
+cmSRC += src/libcm/cmAudDsp.c src/libcm/cmAudDspIF.c src/libcm/cmAudDspLocal.c
135
+
136
+cmHDR += src/libcm/vop/cmVectOpsTemplateUndef.h src/libcm/vop/cmVectOpsTemplateHdr.h src/libcm/vop/cmVectOpsTemplateCode.h src/libcm/vop/cmVectOpsTemplateMain.h
137
+cmHDR += src/libcm/vop/cmVectOpsRIHdr.h src/libcm/vop/cmVectOpsRICode.h 
138
+cmHDR += src/libcm/vop/cmProcTemplateUndef.h src/libcm/vop/cmProcTemplateHdr.h src/libcm/vop/cmProcTemplateCode.h src/libcm/vop/cmProcTemplateMain.h
139
+cmHDR += src/libcm/vop/cmVectOps.h src/libcm/vop/cmProcTemplate.h
140
+
141
+cmSRC += src/libcm/vop/cmVectOps.c src/libcm/vop/cmProcTemplate.c
142
+
143
+cmSRC += src/libcm/cmDList.c
144
+cmHDR += src/libcm/cmDList.h src/libcm/cmDListTpl.h
145
+
146
+cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/cmProc3.h src/libcm/cmProc4.h src/libcm/cmProc5.h src/libcm/cmProcTest.h
147
+cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProc5.c src/libcm/cmProcTest.c
148
+
149
+
150
+cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h src/libcm/app/cmXScore.h 
151
+cmSRC += src/libcm/app/cmOnset.c src/libcm/app/cmTimeLine.c src/libcm/app/cmScore.c src/libcm/app/cmScoreProc.c src/libcm/app/cmXScore.c
79 152
 
80 153
 cmHDR += src/libcm/app/cmSdb.h  src/libcm/app/cmTakeSeqBldr.h  src/libcm/app/cmDspPgmJsonToDot.h
81 154
 cmSRC += src/libcm/app/cmSdb.c  src/libcm/app/cmTakeSeqBldr.c  src/libcm/app/cmDspPgmJsonToDot.c
@@ -83,7 +156,7 @@ cmSRC += src/libcm/app/cmSdb.c  src/libcm/app/cmTakeSeqBldr.c  src/libcm/app/cmD
83 156
 cmHDR += src/libcm/app/cmPickup.h src/libcm/cmRbm.h src/libcm/cmTaskMgr.h  src/libcm/cmSyncRecd.h
84 157
 cmSRC += src/libcm/app/cmPickup.c src/libcm/cmRbm.c src/libcm/cmTaskMgr.c  src/libcm/cmSyncRecd.c
85 158
 
86
-cmHDR += src/libcm/sa/cmSaProc.h  
159
+cmHDR += src/libcm/sa/cmSaProc.h 
87 160
 cmSRC += src/libcm/sa/cmSaProc.c
88 161
 
89 162
 if INC_SONICART

+ 276
- 0
app/cmXScore.c View File

@@ -0,0 +1,276 @@
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 "cmXml.h"
11
+#include "cmText.h"
12
+#include "cmXScore.h"
13
+
14
+cmXsH_t cmXsNullHandle = cmSTATIC_NULL_HANDLE;
15
+
16
+typedef struct cmXsNote_str
17
+{
18
+} cmXsNote_t;
19
+
20
+typedef struct cmXsVoice_str
21
+{
22
+  unsigned              id;    // Voice id
23
+  cmXsNote_t*           noteL; // List of notes in this voice 
24
+  struct cmXsVoice_str* link;  // Link to other voices in this measure
25
+} cmXsVoice_t;
26
+
27
+typedef struct cmXsMeas_str
28
+{
29
+  unsigned             number;  // Measure number
30
+  
31
+  unsigned             divisions; 
32
+  unsigned             beats;
33
+  unsigned             beat_type;
34
+  
35
+  cmXsVoice_t*         voiceL;  // List of voices in this measure   
36
+  
37
+  struct cmXsMeas_str* link;    // Link to other measures in this part.
38
+} cmXsMeas_t;
39
+
40
+typedef struct cmXsPart_str
41
+{
42
+  const cmChar_t*      idStr;   // Id of this part
43
+  cmXsMeas_t*          measL;   // List of measures in this part.
44
+  struct cmXsPart_str* link;    // Link to other parts in this score
45
+} cmXsPart_t;
46
+
47
+typedef struct
48
+{
49
+  cmErr_t              err;
50
+  cmXmlH_t             xmlH;
51
+  cmLHeapH_t           lhH;
52
+  cmXsPart_t*          partL;
53
+} cmXScore_t;
54
+
55
+cmXScore_t* _cmXScoreHandleToPtr( cmXsH_t h )
56
+{
57
+  cmXScore_t* p = (cmXScore_t*)h.h;
58
+  assert( p != NULL );
59
+  return p;
60
+}
61
+
62
+cmXsRC_t _cmXScoreFinalize( cmXScore_t* p )
63
+{
64
+  cmXsRC_t rc = kOkXsRC;
65
+
66
+  // release the XML file
67
+  if( cmXmlIsValid(p->xmlH) )
68
+    cmXmlFree( &p->xmlH );
69
+
70
+  // release the local linked heap memory
71
+  if( cmLHeapIsValid(p->lhH) )
72
+    cmLHeapDestroy(&p->lhH);
73
+  
74
+  cmMemFree(p);
75
+  
76
+  return rc;
77
+}
78
+
79
+cmXsRC_t _cmXScoreMissingNode( cmXScore_t* p, const cmChar_t* label, const cmXmlAttr_t* attr )
80
+{
81
+  if( attr == NULL )
82
+    return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Missing XML node '%s'.",label);
83
+
84
+  return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Missing XML node '%s' - Attribute:%s=%s",label,attr->label,attr->value);
85
+}
86
+
87
+cmXsRC_t _cmXScoreMissingAttribute( cmXScore_t* p, const cmXmlNode_t* np, const cmChar_t* attrLabel )
88
+{
89
+  return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Missing XML attribute '%s' from node '%s'.",attrLabel,np->label);
90
+}
91
+
92
+cmXsRC_t _cmXScoreParsePartList( cmXScore_t* p )
93
+{
94
+  cmXsRC_t           rc          = kOkXsRC;
95
+  cmXsPart_t*        lastPartPtr = NULL;
96
+  const cmXmlNode_t* xnp;
97
+
98
+  // find the 'part-list'
99
+  if((xnp = cmXmlSearch( cmXmlRoot(p->xmlH), "part-list", NULL, 0)) == NULL )
100
+    return _cmXScoreMissingNode(p,"part-list",NULL);
101
+  
102
+  const cmXmlNode_t* cnp = xnp->children;
103
+
104
+  // for each child of the 'part-list'
105
+  for(; cnp!=NULL; cnp=cnp->sibling)
106
+    if( cmTextCmp( cnp->label, "score-part" ) == 0 )
107
+    {
108
+      const cmXmlAttr_t* a;
109
+
110
+      // find the 'score-part' id
111
+      if((a = cmXmlFindAttrib(cnp,"id")) == NULL )
112
+        return _cmXScoreMissingAttribute(p,cnp,"id");
113
+
114
+      // allocate a new part record
115
+      cmXsPart_t* pp = cmLhAllocZ(p->lhH,cmXsPart_t,1);
116
+
117
+      pp->idStr = a->value;  // set the part id
118
+
119
+      // link the new part record to the end of the part list
120
+      if(lastPartPtr == NULL)
121
+        p->partL = pp;
122
+      else
123
+        lastPartPtr->link = pp;
124
+
125
+      lastPartPtr = pp;      
126
+    }
127
+
128
+  return rc;
129
+}
130
+
131
+
132
+cmXsRC_t _cmXScoreParseMeasure(cmXScore_t* p, cmXsPart_t* pp, const cmXmlNode_t* mnp )
133
+{
134
+  cmXsRC_t rc = kOkXsRC;
135
+
136
+  cmXsMeas_t* meas = cmLhAllocZ(p->lhH,cmXsMeas_t,1);
137
+  const cmXmlNode_t* np;
138
+
139
+  // get measure number
140
+  if( cmXmlAttrUInt(mnp,"number", &meas->number) != kOkXmlRC )
141
+    return _cmXScoreMissingAttribute(p,mnp,"number");
142
+
143
+  if( pp->measL == NULL )
144
+    pp->measL = meas;
145
+  else
146
+  {
147
+    cmXsMeas_t* m = pp->measL;
148
+    while( m->link != NULL )
149
+      m = m->link;
150
+    m->link = meas;
151
+  }
152
+  
153
+  // get measure attributes node
154
+  if((np = cmXmlSearch(mnp,"attributes",NULL,0)) == NULL)
155
+    return rc; // (this measure does not have any attributes)
156
+
157
+  cmXmlNodeUInt(np,&meas->divisions,"divisions",NULL);
158
+  cmXmlNodeUInt(np,&meas->beats,"time","beats",NULL);
159
+  cmXmlNodeUInt(np,&meas->beat_type,"time","beat-type",NULL);
160
+  
161
+  return rc;
162
+}
163
+
164
+cmXsRC_t _cmXScoreParsePart( cmXScore_t* p, cmXsPart_t* pp )
165
+{
166
+  cmXsRC_t           rc       = kOkXsRC;
167
+  const cmXmlNode_t* xnp;
168
+  cmXmlAttr_t        partAttr = { "id", pp->idStr };
169
+  
170
+  // find the 'part'
171
+  if((xnp = cmXmlSearch( cmXmlRoot(p->xmlH), "part", &partAttr, 1)) == NULL )
172
+    return _cmXScoreMissingNode(p,"part",&partAttr);
173
+
174
+  // for each child of this part - find each measure
175
+  const cmXmlNode_t* cnp = xnp->children;
176
+  for(; cnp!=NULL; cnp=cnp->sibling)
177
+    if( cmTextCmp(cnp->label,"measure") == 0 )
178
+      if((rc = _cmXScoreParseMeasure(p,pp,cnp)) != kOkXsRC )
179
+        return rc;
180
+  
181
+  return rc;
182
+}
183
+
184
+cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn )
185
+{
186
+  cmXsRC_t rc = kOkXsRC;
187
+
188
+  if((rc = cmXScoreFinalize(hp)) != kOkXsRC )
189
+    return rc;
190
+
191
+  cmXScore_t* p = cmMemAllocZ(cmXScore_t,1);
192
+
193
+  cmErrSetup(&p->err,&ctx->rpt,"XScore");
194
+
195
+  // create a local linked heap
196
+  if( cmLHeapIsValid( p->lhH = cmLHeapCreate(8196,ctx)) == false )
197
+    return cmErrMsg(&p->err,kLHeapFailXsRC,"Lheap create failed.");
198
+
199
+  // open the music xml file
200
+  if( cmXmlAlloc(ctx, &p->xmlH, xmlFn) != kOkXmlRC )
201
+  {
202
+    rc = cmErrMsg(&p->err,kXmlFailXsRC,"Unable to open the MusicXML file '%s'.",cmStringNullGuard(xmlFn));
203
+    goto errLabel;
204
+  }
205
+
206
+  // parse the part-list
207
+  if((rc = _cmXScoreParsePartList( p )) != kOkXsRC )
208
+    goto errLabel;
209
+
210
+  cmXsPart_t* pp = p->partL;
211
+  for(; pp!=NULL; pp=pp->link)
212
+    if((rc = _cmXScoreParsePart(p,pp)) != kOkXsRC )
213
+      goto errLabel;
214
+
215
+  
216
+ errLabel:
217
+  if( rc != kOkXsRC )
218
+    _cmXScoreFinalize(p);
219
+  else
220
+    hp->h = p;
221
+  
222
+  return rc;
223
+}
224
+
225
+cmXsRC_t cmXScoreFinalize( cmXsH_t* hp )
226
+{
227
+  cmXsRC_t rc = kOkXsRC;
228
+  
229
+  if( hp == NULL || cmXScoreIsValid(*hp)==false )
230
+    return kOkXsRC;
231
+
232
+  cmXScore_t* p = _cmXScoreHandleToPtr(*hp);
233
+
234
+  if((rc = _cmXScoreFinalize(p)) != kOkXsRC )
235
+    return rc;
236
+
237
+  hp->h = NULL;
238
+
239
+  return rc;
240
+  
241
+}
242
+
243
+
244
+bool     cmXScoreIsValid( cmXsH_t h )
245
+{ return h.h != NULL; }
246
+
247
+void     cmXScoreReport( cmXsH_t h, cmRpt_t* rpt )
248
+{
249
+  cmXScore_t* p = _cmXScoreHandleToPtr(h);
250
+
251
+  cmXsPart_t* pp = p->partL;
252
+  for(; pp!=NULL; pp=pp->link)
253
+  {
254
+    cmRptPrintf(rpt,"Part:%s\n",pp->idStr);
255
+
256
+    const cmXsMeas_t* meas = pp->measL;
257
+    for(; meas!=NULL; meas=meas->link)
258
+      cmRptPrintf(rpt,"  %i : div:%i beat:%i beat-type:%i\n",meas->number,meas->divisions,meas->beats,meas->beat_type);
259
+  }
260
+  
261
+}
262
+
263
+
264
+cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* fn )
265
+{
266
+  cmXsRC_t rc;
267
+  cmXsH_t h = cmXsNullHandle;
268
+  
269
+  if((rc = cmXScoreInitialize( ctx, &h, fn)) != kOkXsRC )
270
+    return cmErrMsg(&ctx->err,rc,"XScore alloc failed.");
271
+
272
+  cmXScoreReport(h,&ctx->rpt);
273
+  
274
+  return cmXScoreFinalize(&h);
275
+
276
+}

+ 43
- 0
app/cmXScore.h View File

@@ -0,0 +1,43 @@
1
+#ifndef cmXScore_h
2
+#define cmXScore_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+  enum
9
+  {
10
+  kOkXsRC = cmOkRC,
11
+    kXmlFailXsRC,
12
+    kLHeapFailXsRC,
13
+    kSyntaxErrorXsRC
14
+    };
15
+
16
+  typedef cmRC_t     cmXsRC_t;
17
+  typedef cmHandle_t cmXsH_t;
18
+
19
+  extern cmXsH_t cmXsNullHandle;
20
+
21
+  // Prepare the MusicXML file:
22
+  //
23
+  // 1) Convert XML to UTF-8:
24
+  //       a. Change: encoding='UTF-16' to encoding='UTF-8'
25
+  //       b. Emacs C-x <RET> f utf-8 <RET>
26
+  //
27
+  // 2) Replace "DoletSibelius Unknown Symbol Index" with "DoletSibelius unknownSymIdx"
28
+  
29
+
30
+  cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn );
31
+  cmXsRC_t cmXScoreFinalize( cmXsH_t* hp );
32
+
33
+  bool     cmXScoreIsValid( cmXsH_t h );
34
+
35
+  void     cmXScoreReport( cmXsH_t h, cmRpt_t* rpt );
36
+
37
+  cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* fn );
38
+  
39
+#ifdef __cplusplus
40
+}
41
+#endif
42
+
43
+#endif

Loading…
Cancel
Save