-
Notifications
You must be signed in to change notification settings - Fork 1
/
readScoreTemp.php
1778 lines (1653 loc) · 62.4 KB
/
readScoreTemp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Score Analyzer </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="EditPlus">
<meta name="author" content="Veronique SEBASTIEN">
<meta name="keywords" content="score music analyzer musicxml piano difficulty e-learning">
<meta name="description" content="">
<link rel="stylesheet" media="screen" type="text/css" href="style.css">
</head>
<body>
<div id="content">
<h1>Score Analyzer</h1>
<?php
//tableau des pieces
$pieces = scandir("./pieces");
//piece courante
if (isset($_POST['choixPiece']))
$piece = $_POST['choixPiece'];
else if (isset($_GET['choixPiece']))
$piece = $_GET['choixPiece'];
else if (isset($_POST['choixPiece2']))
$piece = $_POST['choixPiece2'];
else
$piece = "arabesque1";
if (isset($_POST['calculate']))
$calculationAsked = true;
else
$calculationAsked = false;
//repertoire des pieces (xml et images)
$xmlPiecePath = "pieces/";
$imagePiecePath = "images/"; //dans le repertoire de chaque piece
//repertoire de la piece selectionnee
$selectedPiecePath = $piece."/";
//on recupere le numero de la page (par defaut, on arrive sur la page 1 de la partition)
if(isset($_GET["page"])) {
$page=$_GET["page"];
}
else {
$page=1;
}
//fonctions
//pitch2int : convertit la hauteur d'une note (do,re,mi,fa,sol,la,si, avec octave et aleration) en nombre pour des calculs (do milieu = 1).
function pitch2int($pitch,$noteOctave,$alter)
{
$pitchValue = 1;
switch ($pitch) {
case "A":
$pitchValue = 10;
break;
case "B":
$pitchValue = 12;
break;
case "C":
$pitchValue = 1;
break;
case "D":
$pitchValue = 3;
break;
case "E":
$pitchValue = 5;
break;
case "F":
$pitchValue = 6;
break;
case "G":
$pitchValue = 8;
break;
}
if($alter != null)
$pitchValue = $pitchValue + $alter;
switch ($noteOctave) {
case 1:
$pitchValue = $pitchValue - 3*12;
break;
case 2:
$pitchValue = $pitchValue - 2*12;
break;
case 3:
$pitchValue = $pitchValue - 1*12;
break;
case 5:
$pitchValue = $pitchValue + 1*12;
break;
case 6:
$pitchValue = $pitchValue + 2*12;
break;
case 7:
$pitchValue = $pitchValue + 3*12;
break;
case 8:
$pitchValue = $pitchValue + 4*12;
break;
}
return $pitchValue;
}
//semitone2octave : convertit un écartement x en demi-tons (0<x<88) en écartement en octaves. Retourne un couple (nbOctaves,reste)
function semitone2octave($semitoneNum)
{
$nbOctaves = floor($semitoneNum/12);
$reste = $semitoneNum % 12;
return array($nbOctaves,$reste);
}
//atSameTime : renvoie un tableau de notes attaquées en même temps que la note donnée en entrée. Permet de déterminer quelles notes sont pressées en même temps aux deux mains. Pour les notes sur la même portée, il suffit de repérer l'élément <chord/>. On part du principe qu'un changement de portée (staff) induit un retour au premier temps
function atSameTime($note)
{
$result = array();
$measureNodes = $note->xpath('parent::*');
$measureNode = $measureNodes[0];
$theNotes = $measureNode->note;
//$staff = $note->staff;
//notesOnRH = $measureNode->xpath('//note[staff='.$staff.' and chord');
$notesTimecodes = array();
$notesTimecodes[] = array($theNotes[0],0); //la toute première note de la mesure est jouée au timecode 0
$currentTimecode = 0;
$previousNote = $theNotes[0];
$myNoteTimecode = 0;
for($i=1;$i<count($theNotes);$i++){
$currentNote = $theNotes[$i];
if((int)$previousNote->staff != (int)$currentNote->staff){ //changement de portée
$currentTimecode = 0;
}
else if(!($currentNote->chord)){
$currentTimecode = $currentTimecode + $previousNote->duration;
}
$notesTimecodes[] = array($currentNote,$currentTimecode);
$previousNote = $currentNote;
if($currentNote == $note)
$myNoteTimecode = $currentTimecode;
}
for($i=0;$i<count($notesTimecodes);$i++){
$tied = $notesTimecodes[$i][0]->xpath("./notations/tied");
if (count($tied) != 0){
$tied = $tied[0]->attributes();
if($tied != 'stop')
$tied = false;
}
if(($notesTimecodes[$i][0] != $note) && ($notesTimecodes[$i][1] == $myNoteTimecode) && !($notesTimecodes[$i][0]->rest) && !$tied)
$result[] = $notesTimecodes[$i][0];
}
//print "<br/>";
return $result;
//return $notesTimecodes;
}
//getNote : renvoie le nième élément note (hors silences) à la mesure $mes de la portée $staff (=1 ou =2), dans le fichier musicXML $xml. Dans un accord, on respecte l'ordre de lecture solfégique (la première note est celle la plus basse). Retourne null si une telle note n'existe pas
function getNote($xml,$mes,$n,$staff)
{
$theMeasure = $xml->xpath('//measure[@number='.$mes.']');
$theNotes = $theMeasure[0]->xpath('./note[staff='.$staff.' and not(rest)]');
if(count($theNotes) >= $n)
return $theNotes[$n-1];
else
return null;
}
//getMeasure : renvoie l'élément measure de l'élément note passé en argument (retourne son parent donc)
function getMeasure($xml,$note)
{
$measureNodes = $note->xpath('parent::*');
$measureNode = $measureNodes[0];
return $measureNode;
}
//getMeasure : renvoie le numéro de mesure de la note passée en argument (retourne son parent donc)
function getMeasureNumber($xml,$note)
{
$theMeasure = getMeasure($xml,$note);
$measureAttributes = $theMeasure->attributes();
$measureNum = $measureAttributes["number"];
return $measureNum;
}
//getNotePosInMes : renvoie la position $i de la note $note de la mesure $mes sur la portée $staff. Les silences sont comptés comme des notes
function getNotePosInMes($xml,$note)
{
$staff = $note->staff;
$theMeasure = getMeasure($xml,$note);
$theNotes = $theMeasure->xpath('./note[staff='.$staff.']');
$i=0;
$found = false;
while($i < count($theNotes) and !$found){
if($theNotes[$i] == $note)
$found = true;
$i++;
}
if ($found){
//echo "on a trouvé la position ".$i;
return $i;
}
else{
//echo "on a pas trouvé !!!";
return null;
}
}
//getNotePosInMes : renvoie l'élément note précédant la note donnée en argument, qu'il s'agisse d'un silence ou pas. S'il n'existe pas de telle note, il renvoit la note donnée en argument
function getPreviousNoteElement($xml,$note)
{
//echo "ouaix on entre dans la fonction getPreviousNoteElement, on analyse la note ".$note->pitch->step.$note->pitch->octave."<br>";
$previousNoteProv = $note;
$pos = getNotePosInMes($xml,$note); //position de la note actuelle dans la mesure (silence compris)
$staff = $note->staff;
if($pos != null){
if($pos == 1){ //si c'est la première note, la note précédente est à chercher dans la mesure précédente
$mes = getMeasureNumber($xml,$note);
if($mes > 1){
//echo "$mes=".$mes."<br>";
$theMeasure = $xml->xpath('//measure[@number='.($mes-1).']');
$theNotesProv = $theMeasure[0]->xpath('./note[staff='.$staff.']');
if(count($theNotesProv) > 0)
$previousNoteProv = $theNotesProv[count($theNotesProv)-1];
else { //une mesure sans élément note signifie que la melodie de la main droite est écrite sur la portée 2-> on prend alors la dernière note de celle-ci
while(count($theNotesProv) == 0){
//echo "oula y a pas de notes : ".$mes."<br>";
$mes=$mes-1;
$theMeasure = $xml->xpath('//measure[@number='.($mes-1).']');
$theNotesProv = $theMeasure[0]->xpath('./note[staff='.$staff.']');
}
if(count($theNotesProv) > 0)
$previousNoteProv = $theNotesProv[count($theNotesProv)-1];
}
}
}
else{
$mesNode = getMeasure($xml,$note);
$theNotesProv = $mesNode->xpath('./note[staff='.$staff.']'); //silences compris
if(count($theNotesProv) > 0)
$previousNoteProv = $theNotesProv[$pos-2];
}
}
return $previousNoteProv;
}
//evaluateDifficulty : renvoie un score de 1 à 4 évaluant la difficulté du critère $criteria de valeur $value
function evaluateDifficulty($criteria,$value,$valueLH)
{
$result = 0;
$resultLH = 0;
switch ($criteria) {
case "speed":
switch (true) {
case ($value <= 20):
return 1;
break;
case ($value > 20 && $value <= 50):
return 2;
break;
case ($value > 50 && $value <= 80):
return 3;
break;
case ($value > 80):
return 4;
break;
}
break;
case "displacement":
switch (true) {
case ($value <= 5):
$result = 1;
break;
case (($value > 5) && ($value <= 10)):
$result = 2;
break;
case ($value > 10 && $value <= 20):
$result = 3;
break;
case ($value > 20):
$result = 4;
break;
}
switch (true) {
case ($valueLH <= 10):
$resultLH = 1;
break;
case ($valueLH > 10 && $valueLH <=20):
$resultLH = 2;
break;
case ($valueLH > 20 && $valueLH <= 55):
$resultLH = 3;
break;
case ($valueLH > 55):
$resultLH = 4;
break;
}
if($result == 2 && $resultLH == 2)
return 3;
else if ($result == 3 && $resultLH == 3)
return 4;
else
return max($result,$resultLH);
break;
case "chords":
switch (true) {
case ($value <= 10):
$result = 1;
break;
case ($value > 10 && $value <=30):
$result = 2;
break;
case ($value > 30 && $value <= 60):
$result = 3;
break;
case ($value > 60):
$result = 4;
break;
}
switch (true) {
case ($valueLH <= 10):
$resultLH = 1;
break;
case ($valueLH > 10 && $valueLH <=30):
$resultLH = 2;
break;
case ($valueLH > 30 && $valueLH <= 60):
$resultLH = 3;
break;
case ($valueLH > 60):
$resultLH = 4;
break;
}
if($result == 2 && $resultLH == 2)
return 3;
else if ($result == 3 && $resultLH == 3)
return 4;
else
return max($result,$resultLH);
break;
case "harmony":
switch (true) {
case ($value <= 5):
$result = 1;
break;
case ($value > 5 && $value <=20):
$result = 2;
break;
case ($value > 20 && $value <= 30):
$result = 3;
break;
case ($value > 30):
$result = 4;
break;
}
switch (true) {
case ($valueLH <= 5):
$resultLH = 1;
break;
case ($valueLH > 5 && $valueLH <=20):
$resultLH = 2;
break;
case ($valueLH > 20 && $valueLH <= 30):
$resultLH = 3;
break;
case ($valueLH > 30):
$resultLH = 4;
break;
}
if ($result == 3 && $resultLH == 3)
return 4;
else
return max($result,$resultLH);
break;
case "rhythm":
switch (true) {
case ($value == 0):
return 1;
break;
case ($value > 0 && $value <=20):
return 2;
break;
case ($value > 20 && $value <= 60):
return 3;
break;
case ($value > 60):
return 4;
break;
}
break;
case "nbpages":
switch (true) {
case ($value > 0 && $value <=2):
return 1;
break;
case ($value > 2 && $value <= 4):
return 2;
break;
case ($value > 4 && $value <= 6):
return 3;
break;
case ($value > 6):
return 4;
break;
}
break;
case "tonality":
switch (true) {
case ($value >= 0 && $value <=1):
return 1;
break;
case ($value > 1 && $value <= 3):
return 2;
break;
case ($value > 3 && $value <= 5):
return 3;
break;
case ($value > 5):
return 4;
break;
}
break;
}
}
function getDifficultyComment($criteria,$score)
{
switch ($criteria) {
case "speed":
switch ($score) {
case 1:
return "slow";
break;
case 2:
return "moderate";
break;
case 3:
return "fast";
break;
case 4:
return "presto!";
break;
}
break;
case "displacement":
switch ($score) {
case 1:
return "sporadic";
break;
case 2:
return "several";
break;
case 3:
return "many";
break;
case 4:
return "numerous!";
break;
}
break;
case "chords":
switch ($score) {
case 1:
return "sporadic";
break;
case 2:
return "several";
break;
case 3:
return "many";
break;
case 4:
return "numerous!";
break;
}
break;
case "harmony":
switch ($score) {
case 1:
return "easy";
break;
case 2:
return "average";
break;
case 3:
return "difficult";
break;
case 4:
return "indecipherable!";
break;
}
break;
case "rhythm":
switch ($score) {
case 1:
return "easy";
break;
case 2:
return "average";
break;
case 3:
return "difficult";
break;
case 4:
return "awkward!";
break;
}
break;
case "nbpages":
switch ($score) {
case 1:
return "short";
break;
case 2:
return "average";
break;
case 3:
return "long";
break;
case 4:
return "very long!";
break;
}
break;
case "tonality":
switch ($score) {
case 1:
return "easy";
break;
case 2:
return "average";
break;
case 3:
return "complex";
break;
case 4:
return "complex";
break;
}
break;
case "general":
switch (true) {
case ($score < 1.5):
return "beginner";
break;
case ($score >= 1.5 && $score < 2.5):
return "intermediate";
break;
case ($score >= 2.5 && $score < 3.5):
return "advanced";
break;
case ($score >= 3.5):
return "virtuoso";
break;
}
break;
}
}
function getDifficultyImage($value)
{
switch ($value) {
case 1:
return "barEasy.png";
break;
case 2:
return "barIntermediate.png";
break;
case 3:
return "barAdvanced.png";
break;
case 4:
return "barvirtuoso.png";
break;
}
return null;
}
function getDifficultyImageFromComment($comment)
{
switch ($comment) {
case "beginner":
return "barEasy.png";
break;
case "intermediate":
return "barIntermediate.png";
break;
case "advanced":
return "barAdvanced.png";
break;
case "virtuoso":
return "barvirtuoso.png";
break;
}
return null;
}
function getTonality($fifths, $mode)
{
if($mode == "major"){
switch ($fifths) {
case 0:
return "C";
break;
case 1:
return "G";
break;
case 2:
return "D";
break;
case 3:
return "A";
break;
case 4:
return "E";
break;
case 5:
return "B";
break;
case 6:
return "F#";
break;
case 7:
return "C#";
break;
case -1:
return "F";
break;
case -2:
return "Bb";
break;
case -3:
return "Eb";
break;
case -4:
return "Ab";
break;
case -5:
return "Db";
break;
case -6:
return "Gb";
break;
case -7:
return "B";
break;
}
}
else {
switch ($fifths) {
case 0:
return "A";
break;
case 1:
return "E";
break;
case 2:
return "B";
break;
case 3:
return "F#";
break;
case 4:
return "C#";
break;
case 5:
return "G#";
break;
case 6:
return "D#";
break;
case 7:
return "Bb";
break;
case -1:
return "D";
break;
case -2:
return "G";
break;
case -3:
return "C";
break;
case -4:
return "F";
break;
case -5:
return "Bb";
break;
case -6:
return "Eb";
break;
case -7:
return "G#";
break;
}
}
return null;
}
?>
<div id="score">
<FORM method="post" action="./readScoreTemp.php?page=1">
<SELECT name="choixPiece" size="1">
<?php
for($i=2;$i<count($pieces);$i++){
echo "<option";
if($pieces[$i] == $piece)
echo " selected ";
echo ">".$pieces[$i]."</option>";
}
?>
</SELECT>
<input type="submit" value="OK"/>
</FORM>
<FORM method="post" action="./readScoreTemp.php?page=1">
<input name="calculate" type="hidden" value="calculateButton">
<input name="choixPiece2" type="hidden" value="<?php echo $piece; ?>">
<input type="submit" value="recalculate"/>
</FORM>
<?php
//affichage de la partition
$scoreFiles = scandir($xmlPiecePath.$selectedPiecePath.$imagePiecePath); //tableau contenant les fichiers images représentant la partition
//si on n'a qu'un fichier pdf ...
$fileExt = substr($scoreFiles[2],count($scoreFiles[2])-4);
if($fileExt == "pdf"){
?>
<object data="<?php echo "./".$xmlPiecePath.$selectedPiecePath.$imagePiecePath.$scoreFiles[2]; ?>" type="application/pdf" width="600" height="800"></object>
<?php
}
else {
//print_r($scoreFiles);
$nbpages = count($scoreFiles)-2;
?>
<img src="<?php echo "./".$xmlPiecePath.$selectedPiecePath.$imagePiecePath.$scoreFiles[$page+1]; ?>" alt="partition"/>
<!-- navigation pages -->
<div id="navigationPages">
<?php
if ($page > 1){
echo "<a href='readScoreTemp.php?page=".($page-1)."&choixPiece=".$piece."'>< </a>";
}
?>
page <?php echo $page." / ".$nbpages; ?>
<?php
if ($page < $nbpages){
echo "<a href='readScoreTemp.php?page=".($page+1)."&choixPiece=".$piece."'> ></a>";
}
?>
</div> <!-- End navigationPages -->
<?php } ?>
</div> <!-- End score -->
<!-------------------------------------------- Analyse de la partition XML ------------------------------------------------------------->
<?php
//ouverture du fichier xml créé
$xmlFilePathSearch = scandir($xmlPiecePath.$selectedPiecePath);
$i = 0;
while(substr($xmlFilePathSearch[$i],count($xmlFilePathSearch[$i])-4) != "xml" && $i<count($xmlFilePathSearch)){
$i++;
}
$pieceXmlFile = "";
if($i<count($xmlFilePathSearch)){
$pieceXmlFile = $xmlFilePathSearch[$i];
}
else{
echo "error ! no xml score found for this piece";
exit;
}
//vérification que le fichier xml ne soit pas déjà en base : si c'est le cas, il n'est pas nécessaire de faire tous les calculs ci-dessous, on fait juste les requêtes SQL nécessaires
//connection à la bdd
// require_once "bdd-inc.php";
// $query= "SELECT `idPieceScore`, `nbpages` FROM `scores` WHERE `xmlFile` = '".$pieceXmlFile."';";
// $result=mysql_query($query);
$idPiece = "";
// $row = mysql_fetch_array($result, MYSQL_ASSOC);
// if(count($row)>0){
// $idPiece = $row['idPieceScore'];
// $nbpages = $row['nbpages'];
// }
/*while($row = mysql_fetch_array($result, MYSQL_ASSOC) and $idPiece == ""){
if($row['xmlFile'] == $pieceXmlFile){
$idPiece = $row['idPieceScore'];
}
}*/
//echo $idPiece;
$calculated = false; //booléen indiquant si les résultats ont été calculés par la page php, ou bien sont juste chargés depuis la BD
if($idPiece == "" or $calculationAsked) {
if($calculationAsked) {
//on supprime l'entrée déjà en base
$query = "DELETE FROM `pieces` WHERE `pieces`.`idPiece` = ".$idPiece;
$result=mysql_query($query);
$query = "DELETE FROM `scores` WHERE `scores`.`idPieceScore` = ".$idPiece;
$result=mysql_query($query);
$query = "DELETE FROM `criteria` WHERE `criteria`.`idPieceCriteria` = ".$idPiece;
$result=mysql_query($query);
$query = "DELETE FROM `stats` WHERE `stats`.`idPieceStat` = ".$idPiece;
$result=mysql_query($query);
$query = "DELETE FROM `structure` WHERE `structure`.`idPieceStruct` = ".$idPiece;
$result=mysql_query($query);
}
$calculated = true;
//la piecec n'est pas en base, il faut faire tous les calculs
//echo $pieceXmlFile."<br/>";
$xmlFile = $xmlPiecePath.$selectedPiecePath.$pieceXmlFile;
$xml = simplexml_load_file($xmlFile);
//recuperation du titre
//$xml->registerXPathNamespace('mmd', 'http://musicbrainz.org/ns/mmd-1.0#');
$identification = $xml->xpath('//identification');
//calcul nb de pages (tel que déclaré dans le fichier XML, sinon, on compte les fichiers images)
$pages = $xml->xpath('//print[@page-number]');
$numPages = array();
foreach ($pages as $page) {
$pageAttributes = $page->attributes();
$numPages[] = $pageAttributes['page-number'];
}
if (count($numPages) != 0){
$nbpages = count($numPages);
}
else{
$pages = $xml->xpath('//print[@new-page="yes"]');
if (count($pages) != 0)
$nbpages = count($pages)+1;
else
$nbpages = 1;
}
//calcul nb de mesures
$mesures = $xml->xpath('//measure');
$nbMesures = count($mesures);
//calcul de la quantise et de la durée la plus courte (durée de base)
$notes = $xml->xpath('//note[not(rest)]');
$quantise = 4; //ronde
$noteValues = array("whole"=>1,"half"=>2,"quarter"=>4,"eighth"=>8,"16th"=>16,"32nd"=>32,"64th"=>64,"128th"=>128,"256th"=>256);
$noteProportions = array(); // tableau contenant le nombre de notes par valeur (ex : 4->142, 8->57, 16->27, etc) il peut y avoir des valeurs ternaires (ex: 8*2/3 = 5.33 -> c'est la croche ternaire)
$noteCounter = 0; //nbre de notes du morceau, toutes portées confondues
$noteCounterRH = 0; //nbre de notes à la main droite
$noteCounterLH = 0; //nbre de notes à la main gauche
//$baseDurations = $notes[0]->xpath('//duration[not(time-modification)]'); //valeur de durée de base (la plus courte du morceau)
$baseDuration = 10000;
foreach ($notes as $note) {
$noteCounter++;
if($note->voice == 1)
$noteCounterRH++;
else
$noteCounterLH++;
$currentNoteValue = 0;
$noteType = $note->type;
$currentNoteValue = $noteValues[(string)$noteType];
if(count($note->xpath('time-modification')) > 0){
$actualNote = $note->xpath('time-modification/actual-notes');
//echo "actual Note : ".$actualNote[0]."<br>";
$normalNote = $note->xpath('time-modification/normal-notes');
//echo "normal Note : ".$normalNote[0]."<br>";
$currentNoteValue = $currentNoteValue * $actualNote[0] / $normalNote[0]; //on a un rythme ternaire dans du binaire ou vice-versa
//echo "current Note : ".$currentNoteValue."<br>";
}
$k=0;
while(($k<count($noteProportions)) && ($noteProportions[$k][0] != $currentNoteValue)) {
$k++;
}
if($k<count($noteProportions)){
//echo "woo on rajoute pour l'indice ".$k." qui represente la valeur ".$noteProportions[$k][0]."<br>";
$noteProportions[$k][1] = $noteProportions[$k][1] + 1;
}
else {
$noteProportions[] = array($currentNoteValue,1);
}
//$noteProportions[(string)$noteType]++;
/*$measureNode = $note->xpath('parent::*');
$measureAttributes = $measureNode[0]->attributes();
$measure = $measureAttributes["number"];
echo "mesure : ".$measure."<br/>";*/
if(count($note->xpath('time-modification')) == 0) { //on n'utilise pas les valeurs 3 pour 2 comme duration de base
$theNoteDuration = $note->duration;
if($theNoteDuration != ""){
if((int)$theNoteDuration < (int)$baseDuration){
$baseDuration = $note->duration;
}
}
//mise à jour de la quantise (on ne prend pas non plus les valeurs ternaires)
if($currentNoteValue > $quantise)
$quantise = $currentNoteValue;
}
}
//calcul de la tonalité
$tonalityP = $xml->xpath('//key/fifths');
$tonality = $tonalityP[0];
$modeP = $xml->xpath('//key/mode');
$mode = $modeP[0];
$tonalityString = getTonality($tonality,$mode)." ".$mode;
//identification des grandes parties du morceau (une partie est définie par un couple (mes début, mes fin, certitude))
//parcours mesure par mesure
$mesures = $xml->xpath('//measure');
$currentPart = array(1,count($mesures),100); //pour l'instant une seule partie qui fait tout le morceau. On raffine au fur et à mesure du parsing
$parts = array();
$parts[] = $currentPart;
for ($i=1;$i<count($mesures);$i++) {
$newPartScore = 0; //pourcentage de chance pour que la mesure actuelle débute une nouvelle partie, la présence de chaque critère (changement de tempo, tonalité, etc ...) l'incrémente. Seuil à fixer pour assurer le changement de partie
$currentMesure = $mesures[$i]; //on commence à la mesure 2
if($currentMesure->attributes->key){
//on a un changement de tonalité
$newPartScore += 100;
}
if($currentMesure->direction){
if(count($currentMesure->xpath('./direction[@placement="above" and staff=1]')) != 0){
//echo count($currentMesure->xpath('./direction[@placement="above" and staff=1]'))."<br/>";
if(count($currentMesure->xpath('./direction/direction-type/metronome')) != 0){
$newPartScore += 80;
}
/*$words = $currentMesure->xpath('./direction/direction-type/words');
if(count($words) != 0){
if($words[0] != "cresc." && $words[0] != "crescendo" && $words[0] != "decresc." && $words[0] != "decrescendo")
$newPartScore += 60;
}*/
}
}
if(count($currentMesure->xpath('./sound[@tempo]')) != 0){
$newPartScore += 20;
}
$addonemeasure = false;
if(count($currentMesure->xpath('./barline[@location="right"]')) != 0){
//on a un changement de tonalité
$newPartScore += 50;
$addonemeasure = true;
}
//estimation finale
if($newPartScore >= 50){
if($addonemeasure){
$parts[count($parts)-1][1] = $i+1;
$parts[] = array($i+2,count($mesures),floor($newPartScore/260*100)); //la certitude est un pourcentage du score maximal (tous les critères présents)
}
else{
$parts[count($parts)-1][1] = $i;
$parts[] = array($i+1,count($mesures),floor($newPartScore/260*100)); //la certitude est un pourcentage du score maximal (tous les critères présents)
}
}
}
//elimination des parties < 2 mesures
$aeffacer = array();
for ($i=1;$i<count($parts);$i++) {
if($parts[$i][1] - $parts[$i][0] < 2){
$parts[$i-1][1] = $parts[$i][1];
$aeffacer[] = $i;
}
}
for ($i=count($aeffacer)-1;$i>=0;$i--) {
//unset($parts[$aeffacer[$i]]);
array_splice($parts,$aeffacer[$i],1);
}
//------------------estimation de la rapidité du morceau-----------------------------------------------------------------------
$tempoP = $xml->xpath('//@tempo');
$tempo = $tempoP[0];
$beatsP = $xml->xpath('//beats');
$beats = $beatsP[0];
$beatTypeP = $xml->xpath('//beat-type');
$beatType = $beatTypeP[0];
$quickestValue = 1; //la ronde comme point de départ
$quickestValueReal = 1; //y compris les trilles et autres "petites notes rapides"
//echo "zoeifjzoieh ".count($noteProportions)."<br>";
for ($i=0;$i<count($noteProportions);$i++) {
//si il y a un nombre conséquent (>15%) de notes plus rapides dans la pièce, on met à jour la valeur de $quickestValue
$key = $noteProportions[$i][0];
$value = $noteProportions[$i][1];
//echo $key."<br>";
//echo $value."<br><br>";