Przeglądaj źródła

cmScore.h/c : Added iniital implementation of cmScoreXXXGraphic() functions.

master
kevin 8 lat temu
rodzic
commit
d25868e474
2 zmienionych plików z 148 dodań i 4 usunięć
  1. 130
    3
      app/cmScore.c
  2. 18
    1
      app/cmScore.h

+ 130
- 3
app/cmScore.c Wyświetl plik

@@ -16,6 +16,7 @@
16 16
 #include "cmAudioFile.h"
17 17
 #include "cmTimeLine.h"
18 18
 #include "cmText.h"
19
+#include "cmFile.h"
19 20
 #include "cmScore.h"
20 21
 #include "cmVectOpsTemplateMain.h"
21 22
 
@@ -2424,6 +2425,134 @@ void cmScorePrint( cmScH_t h, cmRpt_t* rpt )
2424 2425
   }
2425 2426
 }
2426 2427
 
2428
+cmScRC_t cmScoreGraphicAlloc( cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef)
2429
+{
2430
+  cmScRC_t       rc = kOkScRC;
2431
+  cmSc_t*        p  = _cmScHandleToPtr(h);
2432
+  cmScGraphic_t* v  = cmMemAllocZ(cmScGraphic_t,p->cnt);
2433
+  unsigned       i,j,k;
2434
+
2435
+  unsigned       bordH = 5;
2436
+  unsigned       bordW = 5;
2437
+  unsigned       noteW = 100;
2438
+  unsigned       noteH = 100;
2439
+  unsigned       left  = 0;
2440
+  unsigned       top   = 0;
2441
+  unsigned       nextTop = 0;
2442
+  
2443
+  for(i=0,k=0; i<p->locCnt; ++i)
2444
+  {
2445
+    left += noteW + bordW;
2446
+    top   = nextTop + bordH;
2447
+    
2448
+    for(j=0; j<p->loc[i].evtCnt; ++i)
2449
+    {
2450
+      const cmScoreEvt_t* e = p->loc[i].evtArray[j];
2451
+      
2452
+      switch( e->type)
2453
+      {
2454
+        case kBarEvtScId:          
2455
+        case kNonEvtScId:
2456
+          
2457
+          assert( k < p->cnt );
2458
+          
2459
+          v[k].type     = e->type;
2460
+          v[k].scEvtIdx = e->index;
2461
+          v[k].left     = left;
2462
+          v[k].top      = top;
2463
+          v[k].width    = noteW;
2464
+          v[k].height   = noteH;
2465
+          
2466
+          if( e->type == kBarEvtScId )
2467
+            v[k].text = cmTsPrintfP(NULL,"%i",e->barNumb);
2468
+          else
2469
+            v[k].text = cmMemAllocStr( cmMidiToSciPitch( e->pitch, NULL, 0));
2470
+          
2471
+          top += noteH + bordH;
2472
+          
2473
+          if( top > nextTop )
2474
+            nextTop = top;
2475
+          
2476
+          k += 1;
2477
+          
2478
+          break;
2479
+      }
2480
+    }
2481
+  }
2482
+
2483
+  *nRef = k;
2484
+  *vRef = v;
2485
+  
2486
+  return rc;
2487
+}
2488
+
2489
+cmScRC_t cmScoreGraphicRelease( cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef)
2490
+{
2491
+  if( vRef == NULL || nRef==NULL )
2492
+    return kOkScRC;
2493
+  
2494
+  unsigned       i;
2495
+  cmScGraphic_t* v = *vRef;
2496
+  unsigned       n = *nRef;
2497
+  for(i=0; i<n; ++i)
2498
+    cmMemFree((cmChar_t*)v[i].text);
2499
+  cmMemFree(v);
2500
+  *vRef = NULL;
2501
+  *nRef = 0;
2502
+  return kOkScRC;
2503
+}
2504
+
2505
+cmScRC_t      cmScoreGraphicWriteF(  cmScH_t h, const cmChar_t* fn, cmScGraphic_t* v, unsigned n )
2506
+{
2507
+  cmScRC_t  rc = kOkScRC;
2508
+  cmSc_t*   p  = _cmScHandleToPtr(h);
2509
+  cmFileH_t fH = cmFileNullHandle;
2510
+  
2511
+  if( cmFileOpen(&fH,fn,kWriteFileFl,p->err.rpt) != kOkFileRC )
2512
+    return cmErrMsg(&p->err,kFileFailScRC,"Graphic file create failed for '%s'.",cmStringNullGuard(fn));
2513
+
2514
+  cmFilePrint(fH,"<!DOCTYPE html>\n<html>\n<body>\n<svg>\n");
2515
+  
2516
+  if((rc != cmScoreGraphicWrite(h,fH,v,n)) != kOkScRC )
2517
+    goto errLabel;
2518
+
2519
+  cmFilePrint(fH,"</svg>\n</body>\n</html>\n");
2520
+
2521
+ errLabel:
2522
+  cmFileClose(&fH);
2523
+  return rc;
2524
+}
2525
+
2526
+cmScRC_t      cmScoreGraphicWrite(   cmScH_t h, cmFileH_t fH, cmScGraphic_t* v, unsigned n )
2527
+{
2528
+  cmSc_t* p = _cmScHandleToPtr(h);
2529
+  unsigned i;
2530
+  for(i=0; i<n; ++i)
2531
+  {
2532
+    const cmScGraphic_t* g = v + i;
2533
+    
2534
+    if( cmFilePrintf(fH,"<rect x=\"%i\" y=\"%i\" width=\"%i\" height=\"%i\" fill=\"white\"/>\n",g->left,g->top,g->width,g->height) != kOkFileRC )
2535
+      return cmErrMsg(&p->err,kFileFailScRC,"File write failed on graphic file output.");
2536
+
2537
+    if( g->text != NULL )
2538
+    {
2539
+      unsigned tx = g->left + g->width/2;
2540
+      unsigned ty = g->top  + g->height/2;
2541
+    
2542
+      if( cmFilePrintf(fH,"<text x=\"%i\" y=\"%i\" alignment-baseline=\"middle\" text-anchor=\"middle\">%s</text>\n",tx,ty,g->text) != kOkFileRC )
2543
+        return cmErrMsg(&p->err,kFileFailScRC,"File write failed on graphic file output.");
2544
+    }
2545
+    
2546
+    //<rect x="0" y="0" width="200" height="100" stroke="red" stroke-width="3px" fill="white"/>
2547
+    //<text x="50%" y="50%" alignment-baseline="middle" text-anchor="middle">TEXT</text>    
2548
+    
2549
+  }
2550
+
2551
+  return kOkScRC;
2552
+}
2553
+
2554
+
2555
+
2427 2556
 cmScRC_t      cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* scoreFn )
2428 2557
 {
2429 2558
   cmScRC_t      rc  = kOkScRC;
@@ -2466,11 +2595,8 @@ cmScRC_t      cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const c
2466 2595
       cmErrMsg(&err,kCsvFailScRC,"Error inserting column index '%i' label in '%s'.",i,cmStringNullGuard(scoreFn));
2467 2596
       goto errLabel;
2468 2597
     }
2469
-
2470 2598
   }    
2471 2599
 
2472
-
2473
-
2474 2600
   for(i=0; i<msgCnt; ++i)
2475 2601
   {
2476 2602
     const cmMidiTrackMsg_t* tmp    = tmpp[i];
@@ -2632,6 +2758,7 @@ cmScRC_t      cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const c
2632 2758
   return rc;
2633 2759
 }
2634 2760
 
2761
+
2635 2762
 void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn )
2636 2763
 {
2637 2764
   cmScH_t h = cmScNullHandle;

+ 18
- 1
app/cmScore.h Wyświetl plik

@@ -16,7 +16,8 @@ extern "C" {
16 16
     kTimeLineFailScRC,
17 17
     kInvalidDynRefCntScRC,
18 18
     kMidiFileFailScRC,
19
-    kPedalInvalidScRC
19
+    kPedalInvalidScRC,
20
+    kFileFailScRC
20 21
   };
21 22
 
22 23
   enum
@@ -271,6 +272,22 @@ extern "C" {
271 272
 
272 273
   void          cmScorePrint( cmScH_t h, cmRpt_t* rpt );
273 274
 
275
+  typedef struct
276
+  {
277
+    unsigned        type;
278
+    unsigned        scEvtIdx;
279
+    unsigned        left;
280
+    unsigned        top;
281
+    unsigned        width;
282
+    unsigned        height;
283
+    const cmChar_t* text;
284
+  } cmScGraphic_t;
285
+
286
+  cmScRC_t      cmScoreGraphicAlloc(   cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef );
287
+  cmScRC_t      cmScoreGraphicRelease( cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef );
288
+  cmScRC_t      cmScoreGraphicWriteF(  cmScH_t h, const cmChar_t* fn, cmScGraphic_t* v, unsigned n );
289
+  cmScRC_t      cmScoreGraphicWrite(   cmScH_t h, cmFileH_t fH, cmScGraphic_t* v, unsigned n );
290
+  
274 291
   // Generate a new score file from a MIDI file.
275 292
   cmScRC_t      cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* scoreFn );
276 293
 

Ładowanie…
Anuluj
Zapisz