-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoteList_ms4.qml
1038 lines (830 loc) · 37.2 KB
/
NoteList_ms4.qml
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
//=============================================================================
// MuseScore
//
// Note List Plugin
//
// Show and save a note list of the score or a selection
//
// Version 2.4
//
// Copyright (C) 2023 rgos
//=============================================================================
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import Qt.labs.settings 1.0
import QtQuick.Dialogs 1.1
import FileIO 3.0
import MuseScore 3.0
MuseScore {
// For MuseScore 4.0
id: some_id
Component.onCompleted : {
if (mscoreMajorVersion >= 4) {
some_id.title = qsTr("Note List") ;
//some_id.thumbnailName = "thumbnail.png";
//some_id.categoryCode = "some_category";
}
}
/////////////////
menuPath: "Plugins.Note List"
version: "4.0"
description: qsTr("Show and save a note list of the score or a selection")
pluginType: "dialog"
requiresScore: true
/////////////////
// JS global var for access in QML
// Alas QML does not use the variable that JS has changed
// TODO: make QML access a JS var
// YESS: works now!!! Accessible from QML and JS can manipulate the var
property var notelist: ""
property var msg: ""
function saveNotelist() {
// Still can't access notelist of course. Do we really have to rebuild it here?
// No. It works now!!!
var rc = outfile.write(notelist);
if (rc) {
msg = "Note list has been saved in " + outfile.source;
console.log(msg);
//txtSaved.text = msg;
return [true, outfile.source];
// Cannot show message box from JS
//alert("Alert text");
//if (Qt.platform.os=="windows") {
// proc.start("notepad " + outfile.source); // Windows
//}
} else {
msg = "Could not write note list to " + outfile.source;
console.log(msg);
//txtSaved.text = msg;
return [false, outfile.source];
}
}
/////////////////
// TODO: gaat fout met opmaat: er wordt tweemaal measure 1 geteld
// NOTE: let op dat de maatnummering bij een opmaat/pickup telt vanaf de eerste hele maat maar dat Ms
// zelf de opmaat als nummer 1 telt, maar dat was hier niet het issue. Hij deed iets met noOffset en irregular
function buildMeasureMap(score) {
var map = {};
var no = 1;
var cursor = score.newCursor();
cursor.rewind(Cursor.SCORE_START);
while (cursor.measure) {
var m = cursor.measure;
var tick = m.firstSegment.tick;
var tsD = m.timesigActual.denominator;
var tsN = m.timesigActual.numerator;
var ticksB = division * 4.0 / tsD;
var ticksM = ticksB * tsN;
//no += m.noOffset;
var cur = {
"tick": tick,
"tsD": tsD,
"tsN": tsN,
"ticksB": ticksB,
"ticksM": ticksM,
"past" : (tick + ticksM),
"no": no
};
map[cur.tick] = cur;
console.log(tsN + "/" + tsD + " measure " + no +
" at tick " + cur.tick + " length " + ticksM);
//if (!m.irregular)
// ++no;
no++;
cursor.nextMeasure();
}
return map;
}
function showPos(cursor, measureMap) {
var t = cursor.segment.tick;
var m = measureMap[cursor.measure.firstSegment.tick];
var b = "?";
if (m && t >= m.tick && t < m.past) {
b = 1 + (t - m.tick) / m.ticksB;
}
return "St: " + (cursor.staffIdx + 1) +
" Vc: " + (cursor.voice + 1) +
" Ms: " + m.no + " Bt: " + b;
}
////////////////////
onRun: {
if (!curScore) {
console.log(qsTranslate("QMessageBox", "No score open.\nThis plugin requires an open score to run.\n"));
Qt.quit();
}
// TODO: make accessible from QML
//var notelist = '';
// RG: why do we have to start at -3 to get the correct number of measures?
// It is because we loop through segments and we had 4 notes in the first measure
// It only works when measures are empty.
var internalMeasureNumber = 1; //we will use this to track the current measure number
//var currentMeasure = null; //we use this to keep a reference to the actual measure, so we can know when it changes
var chordCount = 0;
var noteCount = 0;
var noteCountC = 0;
var noteLengthC = 0;
var noteCountCis = 0;
var noteLengthCis = 0;
var measureCount = 0;
measureCount = curScore.nmeasures;
var staffCount = 0;
staffCount = curScore.nstaves;
var partCount = 0;
partCount = curScore.parts.length;
// for selection
var measureCount2 = 0;
var staffCount2 = 0;
var partCount2 = 0;
var oldPart = 0;
//get a cursor to be able to run over the score
var cursor = curScore.newCursor();
cursor.rewind(0);
cursor.voice = 0;
cursor.staffIdx = 0;
var measure = 1;
var beat = 1;
//var tickCount = 0;
// find ticks for measure 2
var m2 = cursor.measure.nextMeasure.firstSegment.tick;
console.log('m2: ' + m2);
var nextM = m2;
var measureMap = buildMeasureMap(curScore);
// TODO: loop through all staves
// NOTE: when staves are made invisible they are still counted: check for visibility
// HELL: we can only loop through 2 staves. Why?
// Works OK with Ligeti but not our Test1 file.
// staffCount is OK.
// If we recreate the cursor it will work.
var staffBeg = 0;
var staffEnd = staffCount;
var tickEnd = 0;
var toEOF = true;
// TEST: We have a selection
if (curScore.selection.startSegment) {
console.log('Sel start: ' + curScore.selection.startSegment.tick);
//console.log('Sel end: ' + curScore.selection.endSegment.tick);
cursor.rewind(Cursor.SELECTION_END);
cursor.staffIdx = 0;
cursor.voice = 0;
if (!cursor.tick) {
/*
* This happens when the selection goes to the
* end of the score - rewind() jumps behind the
* last segment, setting tick = 0.
*/
toEOF = true;
} else {
toEOF = false;
tickEnd = cursor.tick;
}
// find staffs of selection
staffBeg = curScore.selection.startStaff;
staffEnd = curScore.selection.endStaff;
console.log('Staff beg: ' + staffBeg);
console.log('Staff end: ' + staffEnd);
// TODO: find the correct number of measures, staves and parts for a selection
staffCount2 = staffEnd - staffBeg;
//var mstart = measureMap[curScore.selection.startSegment.tick];
//var mend = measureMap[curScore.selection.endSegment.tick];
//measureCount = mend.no - mstart.no;
// Jammer: Cannot read property 'no' of undefined
// Als we een een deel van een voorgaande measure selecteren dan staat voor die tick
// de measure niet in de measuremap (die bevat alleen de begin tick van measures).
// Hoe op te lossen?
// We kunnen in de notelist de hoogste en laagste measure vinden en die gebruiken.
// Of zo:
cursor.rewind(Cursor.SELECTION_START);
cursor.staffIdx = curScore.selection.startStaff;
cursor.voice = 0;
// Use measure map
var mstart = measureMap[cursor.measure.firstSegment.tick];
cursor.rewind(Cursor.SELECTION_END);
cursor.staffIdx = curScore.selection.endStaff;
cursor.voice = 0;
// Use measure map
// SHIT: cursor.measure null when select All
// HACK:
if (toEOF) {
measureCount2 = measureCount;
} else {
var mend = measureMap[cursor.measure.firstSegment.tick];
measureCount2 = (mend.no - mstart.no) + 1;
}
}
// loop through all staves
//for (var s = 0; s < staffCount; s++) {
for (var s = staffBeg; s < staffEnd; s++) {
//cursor = curScore.newCursor(); // recreate to be sure
//cursor.rewind(0);
//cursor.staffIdx = s;
//cursor.voice = 0;
// TEST:
if (curScore.selection.startSegment) {
cursor.rewind(Cursor.SELECTION_START);
} else {
cursor.rewind(Cursor.SCORE_START);
}
// HELL: now staff change does not work. Why?
// Cursor rewind is flaky. See: https://musescore.org/en/node/301846
// Looks like cursor does not change to the next staff when there is a selection
// Yep, confirmed: count-note-beats.qml heeft er ook last van: selecteer twee staves
// en de onderste krijgt geen beats.
// YESS: we forgot to add a staff indication in the voice loop after a rewind
// Also, we do not need the rewind here in the staff loop, only the voice loop
// so get rid of all that crap here
// Well, we do need to rewind here or we will not find the last staff when there is
// no selection
//cursor.voice = 0;
cursor.staffIdx = s;
cursor.voice = 0;
//console.log('s: ' + s)
// restart
//measure = 1;
//nextM = m2;
// loop through all voices
for (var v = 0; v < 4; v++) {
//cursor.rewind(0);
// TEST:
//cursor.rewind(Cursor.SELECTION_START); // Fucker does not rewind properly for voice 2 selection!!!
//cursor.rewindToTick(curScore.selection.startSegment.tick); // Hell, still does not rewind
if (curScore.selection.startSegment) {
cursor.rewind(Cursor.SELECTION_START);
} else {
cursor.rewind(Cursor.SCORE_START);
}
//console.log(curScore.selection.startSegment);
//console.log('t: ' + cursor.tick); // we are not getting the right tick here
// NOTE NOTE NOTE: After a rewind we always need a voice AND staff indication!!!!!
cursor.staffIdx = s;
cursor.voice = v;
console.log('s: ' + s);
console.log('v: ' + v);
// TODO:
// * select All gives no output. Probably because of end measure overshoot. Fix it.
// DONE: use toEOF to account for selection to end of score
// * no select does not see all staffs. Fix it.
// DONE: rewind in staff loop
// selection geeft de juiste start en end tick voor voice 2 selection.
// Maar als we rewind doen gaat dat kennelijk op basis van voice 1 en dan wordt niks gevonden
// en pakt ie maar de tick van het eerstvolgende voice 1 segment buiten de selectie.
// En zelfs als we een noot in voice 1 zetten aan begin selectie gaat het ook fout: de cursor
// rewind dan wel correct maar de voice wordt niet opgehoogd.
// Yep, confirmed: als v is opgehoogd zou de cursor naar de volgende voice moeten gaan
// maar hij blijft in voice 1.
// YESS: we must do cursor voice change AFTER rewind
//console.log('v: ' + v)
//console.log( showPos(cursor, measureMap) );
// restart
//measure = 1;
//nextM = m2;
// loop through all segments
// TEST: with selection
//while (cursor.segment) {
while (cursor.segment && (toEOF || cursor.tick < tickEnd)) {
// TEST: selection
// TODO: make it work when only voice 2 notes are selected
// Het lijkt wel alsof Cursor.SELECTION_START niet goed rewind als er slechts
// noten in voice 2 geselecteerd zijn. Pas als er een noot van voice 1 mee is
// geselecteerd krijgen we de juiste tick.
console.log('ts: ' + cursor.segment.tick);
console.log('tickEnd: ' + tickEnd);
//console.log('Sel end: ' + curScore.selection.endSegment.tick);
// if (curScore.selection.startSegment) {
// //if (cursor.segment.tick >= curScore.selection.endSegment.tick) break;
// if (cursor.segment.tick >= tickEnd) break;
// }
// TODO: count correctly when measures are full
// SHIT: why are we getting 4 different pointers to the first measure?
// This causes the 3 times overcount of measures when there are 4 chords in the first measure
//console.log(cursor.measure);
// We should just use:
//measureCount = curScore.nmeasures;
// NONO:
// if (cursor.measure != currentMeasure) {
// //we moved into a new measure
// // NONO: will not work because cursor.measure returns a different pointer for every chord
// // even when in the same measure!!! Sucks!!!
// internalMeasureNumber++;
// currentMeasure = cursor.measure;
//
// // LOOK: how nasty
// console.log(cursor.measure);
//
// // TODO: find a way to count measures correctly in a loop
// }
// TODO: list all notes as in the Musescore status bar:
// Note; Pitch: C6; Duration: Quarter; Voice: 1; Measure: 1; Beat: 1; Staff: 1 (Piano)
// TODO: get instrument name
// MS uses Part.longName in the status bar
//console.log(cursor.part.longName);
// This works but how do we find out how many staves a part has?
// See Staff.part:
// Ms::PluginAPI::Part part
// Part which this staff belongs to
//
// So like this: Score->Stave->Part
//console.log(curScore.parts[0].longName); // works
//console.log(curScore.staves[s].part.longName); // why not?
//console.log(curScore.title);
// staves is niet bereikbaar, fout in API
// Yep: https://musescore.org/en/node/317368
//console.log(curScore.parts.length); // OK
//console.log(curScore.staves.length); // cannot read property of undefined
// YESS: can get staff via element
// cursor.element.staff.part.longName
// TEST: find actual time sig
// YESS: need cursor.measure
//console.log(cursor.measure.timesigActual.numerator + '/' + cursor.measure.timesigActual.denominator);
// TEST:
var m = cursor.measure;
var tsD = m.timesigActual.denominator;
var tsN = m.timesigActual.numerator;
var ticksB = division * 4.0 / tsD;
var ticksM = ticksB * tsN;
//console.log(ticksB + '/' + ticksM);
// we are looping through segments, can we find the proper measure and beat without
// first constructing a measure map?
//var t = cursor.tick;
// YESS: it can be done like this
// TODO: find a way to find the initial nextM
// DONE
// SHIT: things go wrong with voice 2 with empty measures because of firstSegment
// skipping totally empty measures
// NOTE: dit moet dus ook fout gaan in count-note-beats.qml maar daar is het niet
// erg want het measure nummer is niet nodig, alleen de beat. En dat gaat goed.
// TODO: hoe kunnen we juist blijven tellen bij maten die helemaal leeg zijn?
// Hebben we toch een measure map nodig die is gemaakt met voice 1 die nooit helemaal
// lege maten heeft?
// Is waarschijnlijk toch het handigst: je kunt dan voor elk segment met zijn tick
// opzoeken in welke maat het zich bevindt.
// Old method
var t = cursor.segment.tick;
//console.log(t);
// Use measure map
var mm = measureMap[cursor.measure.firstSegment.tick];
measure = mm.no;
beat = 1 + (t - mm.tick) / mm.ticksB;
// TODO: round beat to 5 decimals for triplets
beat = +beat.toFixed(5);
// TEST:
//console.log( showPos(cursor, measureMap) );
// TEST: part count for selection
if (curScore.selection.startSegment) {
if (cursor.element && !cursor.element.staff.part.is(oldPart)) {
partCount2++;
oldPart = cursor.element.staff.part;
}
//console.log('Part: ' + cursor.element.staff.part.is(cursor.element.staff.part));
console.log('Part Count: ' + partCount2);
}
// TEST: count notes
if (cursor.element && cursor.element.type == Element.CHORD) {
chordCount++;
//noteCount += cursor.element.notes.length;
//console.log('Chords: ' + chordCount);
//console.log('Notes: ' + noteCount);
// TEST: print measure number
//console.log( 'Measure: ' + ( Math.floor(cursor.tick/1920) + 1) );
//console.log( 'Beat: ' + (((cursor.tick/480)%4) + 1) );
// TODO: 1920 for measure and 480 for beat are for quarter note
// Make universal and make sure it works with unregular measures
// and pickup measures
// A pickup measure of 1 quarter is measure 1, beat 1 so must use
// Actual measure duration (timesigActual)
// For every measure we are in we need to know the actual time signature
// Use cursor.element.timesigActual
//var measure = Math.floor(cursor.tick/1920) + 1;
//var beat = (cursor.tick/480)%4 + 1;
// get note duration
var duration = cursor.element.duration.str;
// TODO: get all the notes in a chord
// DONE
//console.log(cursor.element.notes.CountFunction);
//console.log( cursor.element.notes.length );
// TODO: loop through all notes in a chord and count the pitches
for (var i = 0; i < cursor.element.notes.length; i++) {
noteCount++;
// TEST:
switch (cursor.element.notes[i].tpc) {
case 14:
case 26:
case 2:
noteCountC++;
noteLengthC += cursor.element.duration.ticks;
// TEST: print note and length and voice
//console.log('Voice: ' + (v+1) + ' Note: C' + ' ' + cursor.element.duration.str);
//console.log('Note; Pitch: C; Duration: ' + duration + '; Voice: ' + (v+1) + '; Measure: ' + measure +'; Beat: ' + beat + '; Staff 1');
break;
case 21:
case 33:
case 9:
noteCountCis++;
noteLengthCis += cursor.element.duration.ticks;
// TEST: print note and length and voice
//console.log('Voice: ' + (v+1) + ' Note: C#/Db' + ' ' + cursor.element.duration.str);
//console.log('Note; Pitch: C#/Db; Duration: ' + duration + '; Voice: ' + (v+1) + '; Measure: ' + measure +'; Beat: ' + beat + '; Staff 1');
break;
}
var pitch = cursor.element.notes[i].pitch;
var tpc = cursor.element.notes[i].tpc1; // use concert pitch always
var octave = Math.floor(pitch/12)-1;
var notename = '';
switch (pitch%12) {
case 0:
if (tpc == 26) notename ='B#';
if (tpc == 14) notename ='C';
if (tpc == 2 ) notename ='Dbb';
break;
case 1:
if (tpc == 33) notename ='B##';
if (tpc == 21) notename ='C#';
if (tpc == 9 ) notename ='Db';
break;
case 2:
if (tpc == 28) notename ='C##';
if (tpc == 16) notename ='D';
if (tpc == 4 ) notename ='Ebb';
break;
case 3:
if (tpc == 23) notename ='D#';
if (tpc == 11) notename ='Eb';
if (tpc == -1) notename ='Fbb';
break;
case 4:
if (tpc == 30) notename ='D##';
if (tpc == 18) notename ='E';
if (tpc == 6 ) notename ='Fb';
break;
case 5:
if (tpc == 25) notename ='E#';
if (tpc == 13) notename ='F';
if (tpc == 1 ) notename ='Gbb';
break;
case 6:
if (tpc == 32) notename ='E##';
if (tpc == 20) notename ='F#';
if (tpc == 8 ) notename ='Gb';
break;
case 7:
if (tpc == 27) notename ='F##';
if (tpc == 15) notename ='G';
if (tpc == 3 ) notename ='Abb';
break;
case 8:
if (tpc == 22) notename ='G#';
//
if (tpc == 10 ) notename ='Ab';
break;
case 9:
if (tpc == 29) notename ='G##';
if (tpc == 17) notename ='A';
if (tpc == 5 ) notename ='Bbb';
break;
case 10:
if (tpc == 24) notename ='A#';
if (tpc == 12) notename ='Bb';
if (tpc == 0 ) notename ='Cbb';
break;
case 11:
if (tpc == 31) notename ='A##';
if (tpc == 19) notename ='B';
if (tpc == 7 ) notename ='Cb';
break;
}
/*
pitch tpc name tpc name tpc name
11 31 A## 19 B 7 Cb
10 24 A# 12 Bb 0 Cbb
9 29 G## 17 A 5 Bbb
8 22 G# 10 Ab
7 27 F## 15 G 3 Abb
6 32 E## 20 F# 8 Gb
5 25 E# 13 F 1 Gbb
4 30 D## 18 E 6 Fb
3 23 D# 11 Eb -1 Fbb
2 28 C## 16 D 4 Ebb
1 33 B## 21 C# 9 Db
0 26 B# 14 C 2 Dbb
*/
// get part
var part = cursor.element.staff.part.longName;
// TODO: print correct notename using tpc and pitch
// DONE
//console.log(notename + octave);
console.log('Note; Pitch: ' + notename + octave + '; Duration: ' + duration + '; Voice: ' + (v+1) + '; Measure: ' + measure + '; Beat: ' + beat + '; Staff: ' + (s+1) + ' (' + part + ')');
tV.append({ number: noteCount,
element: 'Note',
pitch: notename + octave,
duration: duration,
voice: (v+1),
measure: measure,
beat: beat,
staff: (s+1),
part: part});
notelist += (noteCount + '; Note; Pitch: ' + notename + octave + '; Duration: ' + duration + '; Voice: ' + (v+1) + '; Measure: ' + measure + '; Beat: ' + beat + '; Staff: ' + (s+1) + ' (' + part + ')');
notelist += '\n';
} // End note loop
// TEST: get duration of note
//console.log('Length: ' + cursor.element.duration.ticks);
//console.log(noteCount);
} // End chord loop
// step to next segment
cursor.next();
} // End while loop segments
// rewind for next voice (will do at begin)
//cursor.rewind(0);
} // End voice loop
// rewind cursor for next staff (not necessary)
//cursor.rewind(0);
} // End staff loop
// TEST: Count number of measures with cursor loop
// Why does it no longer work since we added voice count?
// DONE: it works again with a new cursor. Why can't we use the old one?
var cursor2 = curScore.newCursor();
cursor2.rewind(0);
cursor2.voice = 0;
cursor2.staffIdx = 0;
while ( cursor2.nextMeasure() ) {
internalMeasureNumber++;
//console.log('M');
}
// NONO: this will overcount when measures contain notes
// DONE: its correct now
console.log('Measures: ' + internalMeasureNumber);
//Qt.quit();
// List counts
if (curScore.selection.startSegment) {
helloQml0.text = 'Selection';
helloQml1.text = 'Found ' + measureCount2 + ' measures.';
helloQml2.text = 'Found ' + noteCount + ' notes.'; // is OK
helloQml3.text = 'Found ' + staffCount2 + ' staves.';
helloQml4.text = 'Found ' + partCount2 + ' parts.';
} else {
helloQml0.text = 'Score';
helloQml1.text = 'Found ' + measureCount + ' measures.';
helloQml2.text = 'Found ' + noteCount + ' notes.';
helloQml3.text = 'Found ' + staffCount + ' staves.';
helloQml4.text = 'Found ' + partCount + ' parts.';
}
// list notes
// helloQmlC.text = '\t' + noteCountC + '\t' + noteLengthC/480;
// helloQmlCis.text = '\t' + noteCountCis + '\t' + noteLengthCis/480;
// TEST: fill table YESS
// tV.append({title: "some value",
// author: "Another value",
// year: "One more value",
// revision: "uno mas"});
// Write note list to home dir
// TODO: we actually want to do this from QML with a button but cannot access the JS variable
// DONE
//var rc = outfile.write(notelist);
}
////////////////////////////////////////////////////
FileIO {
id: outfile
source: homePath() + "/" + curScore.scoreName + "_notelist.csv"
onError: console.log(msg)
}
width: 700
height: 475
Rectangle {
//id: myRect
//color: "blue"
//anchors.fill: parent
//anchors.margins: 10
Label {
id: helloQml0
//anchors.centerIn: parent
x: 20
y: 20
text: qsTr("Hello Qml")
font.bold: true
}
Rectangle {
color: "grey"
//anchors.horizontalCenter: parent.horizontalCenter
height: 1
width: 660
x: 20
y: 40
}
Rectangle {
color: "white"
//anchors.horizontalCenter: parent.horizontalCenter
height: 1
width: 660
x: 20
y: 41
}
Label {
id: helloQml1
//anchors.centerIn: parent
x: 20
y: 50
text: qsTr("Hello Qml")
}
Label {
id: helloQml2
//anchors.centerIn: parent
x: 20
y: 70
text: qsTr("Hello Qml")
}
Label {
id: helloQml3
//anchors.centerIn: parent
x: 20
y: 90
text: qsTr("Hello Qml")
}
Label {
id: helloQml4
//anchors.centerIn: parent
x: 20
y: 110
text: qsTr("Hello Qml")
}
// Rectangle {
// color: "grey"
// //anchors.horizontalCenter: parent.horizontalCenter
// height: 1
// width: 300
// y: 10
// x: 25
// }
//
// Label {
// x: 20
// y: 70
// text: qsTr("C")
// font.bold: true
// }
//
// Label {
// id: helloQmlC
// //anchors.centerIn: parent
// x: 40
// y: 70
// text: qsTr("Hello Qml")
// }
//
// Label {
// x: 20
// y: 90
// text: qsTr("C#/Db")
// font.bold: true
// }
//
// Label {
// id: helloQmlCis
// //anchors.centerIn: parent
// x: 40
// y: 90
// text: qsTr("Hello Qml")
// }
// ListModel {
// ListElement {
// name: "Bill Smith"
// number: "555 3264"
// }
// ListElement {
// name: "John Brown"
// number: "555 8426"
// }
// ListElement {
// name: "Sam Wise"
// number: "555 0473"
// }
// }
TableView {
x: 20
y: 170
width: 660
height: 200
//enabled: enabledCheck.checked
TableViewColumn { role: "number" ; title: "#" ; width: 50 ; resizable: true ; movable: true }
TableViewColumn { role: "element" ; title: "Element" ; width: 70 ; resizable: true ; movable: true }
TableViewColumn { role: "pitch" ; title: "Pitch" ; width: 50 ;resizable: true ; movable: true }
TableViewColumn { role: "duration" ; title: "Duration" ; width: 70 ;resizable: true ; movable: true }
TableViewColumn { role: "voice" ; title: "Voice" ; width: 50 ;resizable: true ; movable: true }
TableViewColumn { role: "measure" ; title: "Measure" ; width: 70 ; resizable: true ; movable: true }
TableViewColumn { role: "beat" ; title: "Beat" ; width: 70 ;resizable: true ; movable: true }
TableViewColumn { role: "staff" ; title: "Staff" ; width: 50 ;resizable: true ; movable: true }
TableViewColumn { role: "part" ; title: "Part" ; width: 120 ;resizable: true ; movable: true }
model: ListModel {
id: tV
}
// TODO: sorting when clicking column headers
//sortingEnabled: true
alternatingRowColors: true
//backgroundVisible: true
//headerVisible: true
// style: TableViewStyle {
// headerDelegate: Rectangle {
// height: textItem.implicitHeight * 1.2
// width: textItem.implicitWidth
// //color: "lightsteelblue"
// Label {
// id: textItem
// anchors.fill: parent
// verticalAlignment: Text.AlignVCenter
// horizontalAlignment: styleData.textAlignment
// anchors.leftMargin: 12
// text: styleData.value
// elide: Text.ElideRight
// color: textColor
// renderType: Text.NativeRendering
// }
// }
// itemDelegate: Item {
// Label {
// //id: textItem
// anchors.fill: parent
// //verticalAlignment: Text.AlignVCenter
// //horizontalAlignment: styleData.textAlignment
// anchors.leftMargin: 5
// text: styleData.value
// //elide: Text.ElideRight
// //color: textColor
// //renderType: Text.NativeRendering
// }
// } // Item
// } // TableViewStyle
}// TableView
// MouseArea {
// anchors.fill: parent
// onClicked: Qt.quit()
// }
MessageDialog {
id: messageDialog
title: "May I have your attention please"
text: "It's so cool that you are using Qt Quick."
//modality: Qt.NonModal
onAccepted: {
console.log("And of course you could only agree.")
txtSaved.text = msg;
//Qt.quit()
}
Component.onCompleted: visible = false
}
Label {
id: txtSaved
//anchors.centerIn: parent
x: 20
y: 440
text: qsTr("")
}
Button {
id: saveButton
//Layout.columnSpan: 3
//anchors.centerIn: parent
// Anchored to 20px off the top right corner of the parent
//anchors.right: parent.right
//anchors.bottom: parent.bottom
//anchors.rightMargin: 20
//anchors.bottomMargin: 20
x: 20
y: 400
text: qsTranslate("PrefsDialogBase", "Save .csv")
onClicked: {
// Save notelist
var ret = saveNotelist()
if ( ret[0] == true ) {
// Show message