Skip to content

Commit fd1ec25

Browse files
author
laurent
committed
Corrected the "reverse/invert" mode
1 parent 13d1c73 commit fd1ec25

File tree

1 file changed

+57
-52
lines changed

1 file changed

+57
-52
lines changed

workoutbuilder.qml

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -636,25 +636,15 @@ MuseScore {
636636

637637
var notes = [];
638638

639-
if (!chkInvert.checked || ((r % 2) == 0)) {
640-
console.log("-- => normal");
641-
for (var j = 0; j < basesteps.length; j++) {
642-
console.log(">>> Looking at note " + j + ": " + basesteps[j].note);
643-
//notes.push(root + basesteps[j]);
644-
var _n=(basesteps[j].note!==null)?(root + basesteps[j].note):null;
645-
// var _n=(basesteps[j].note!==null)?root + basesteps[j].note:0;
646-
notes.push({"note" : _n, "duration": basesteps[j].duration });
647-
}
648-
} else {
649-
console.log("-- => reverse");
650-
for (var j = basesteps.length - 1; j >= 0; j--) {
651-
console.log(">>> Looking at note " + j + ": " + basesteps[j].note);
652-
// notes.push(root + basesteps[j]);
653-
var _n=(basesteps[j].note!==null)?(root + basesteps[j].note):null;
654-
// var _n=(basesteps[j].note!==null)?root + basesteps[j].note:0;
655-
notes.push({"note" : _n, "duration": basesteps[basesteps.length - 1 - j].duration });
639+
var p=(!chkInvert.checked || ((r % 2) == 0))?basesteps:reversePattern(basesteps);
640+
for (var j = 0; j < p.length; j++) {
641+
console.log(">>> Looking at note " + j + ": " + p[j].note);
642+
//notes.push(root + p[j]);
643+
var _n=(p[j].note!==null)?(root + p[j].note):null;
644+
// var _n=(p[j].note!==null)?root + p[j].note:0;
645+
notes.push({"note" : _n, "duration": p[j].duration });
656646
}
657-
}
647+
658648

659649
debugO("pushing to pages (effective_chord): ", effective_chord, ["scale"]);
660650

@@ -706,7 +696,7 @@ MuseScore {
706696

707697
// 1.2) Completing the pattern to have a round duration
708698
var total=p.map(function(e) {return e.duration}).reduce(function(t,n) { return t+n; });
709-
if (total<Math.ceil(total)) {
699+
if ((chkAdaptativeMeasure.checked && chkStrictLayout.checked) && total<Math.ceil(total)) {
710700
var inc=Math.ceil(total)-total;
711701
console.log("adding a rest of "+inc);
712702
p.push({"note": null, "duration": inc});
@@ -731,6 +721,8 @@ MuseScore {
731721
} else {
732722
cText = m3 ? "m" : "M";
733723
}
724+
725+
console.log("No Chord Text => will use "+cText+" (because notes are: "+JSON.stringify(nn));
734726

735727
}
736728
var cSymb = _chordTypes[cText];
@@ -807,22 +799,15 @@ MuseScore {
807799

808800
var notes = [];
809801

810-
if (!chkInvert.checked || ((r % 2) == 0)) {
811-
console.log("-- => normal");
812-
for (var j = 0; j < basesteps.length; j++) {
813-
var _n=(basesteps[j].note!==null)?(root + basesteps[j].note):null;
814-
// var _n=(basesteps[j].note!==null)?root + basesteps[j].note:0;
815-
notes.push({"note" : _n, "duration": basesteps[j].duration });
816-
}
817-
} else {
818-
console.log("-- => reverse");
819-
for (var j = basesteps.length - 1; j >= 0; j--) {
820-
// notes.push(root + basesteps[j]);
821-
var _n=(basesteps[j].note!==null)?(root + basesteps[j].note):null;
822-
// var _n=(basesteps[j].note!==null)?root + basesteps[j].note:0;
823-
notes.push({"note" : _n, "duration": basesteps[basesteps.length - 1 - j].duration });
824-
}
825-
}
802+
var p=(!chkInvert.checked || ((r % 2) == 0))?basesteps:reversePattern(basesteps);
803+
for (var j = 0; j < p.length; j++) {
804+
console.log(">>> Looking at note " + j + ": " + p[j].note);
805+
//notes.push(root + p[j]);
806+
var _n=(p[j].note!==null)?(root + p[j].note):null;
807+
// var _n=(p[j].note!==null)?root + p[j].note:0;
808+
notes.push({"note" : _n, "duration": p[j].duration });
809+
}
810+
826811

827812
pages[page].push({
828813
"root": root,
@@ -1127,7 +1112,7 @@ MuseScore {
11271112
var target = {
11281113
"pitch": pitch,
11291114
"concertPitch": false,
1130-
"sha;rp_mode": f
1115+
"sharp_mode": f
11311116
};
11321117

11331118
//cur_time = note.parent.tick; // getting note's segment's tick
@@ -1375,14 +1360,7 @@ MuseScore {
13751360
} else
13761361
extpattern["subpatterns"].push(basesteps);
13771362

1378-
// var reversed = [].concat(basesteps); // clone the basesteps
1379-
var reversed=JSON.parse(JSON.stringify(basesteps)); // clone the steps with a deep copy !! ( [].concat(xxx) is a *shallow* copy)
1380-
reversed.reverse();
1381-
1382-
// and we reset the right durations
1383-
for(var j=0;j<basesteps.length;j++) {
1384-
reversed[j].duration=basesteps[j].duration;
1385-
}
1363+
var reversed=reversePattern(basesteps);
13861364

13871365
if (lastrest) {
13881366
reversed.push(lastrest);
@@ -1458,6 +1436,33 @@ MuseScore {
14581436
return extpattern;
14591437

14601438
}
1439+
1440+
function reversePattern(pattern) {
1441+
var reduced = pattern.filter(function (e) {
1442+
return e.note !== null
1443+
}).map(function (e) {
1444+
return e.note
1445+
});
1446+
1447+
reduced = reduced.reverse();
1448+
1449+
var p = [];
1450+
1451+
// reinserting the rests and the durations
1452+
var p = [];
1453+
for (var j = 0; j < pattern.length; j++) {
1454+
var _b = pattern[j];
1455+
if (_b.note === null) {
1456+
reduced.splice(j, 0, null);
1457+
}
1458+
p.push({
1459+
note: reduced[j],
1460+
duration: pattern[j].duration
1461+
});
1462+
}
1463+
return p;
1464+
1465+
}
14611466

14621467
function shiftPattern(pattern, scale, step) {
14631468
var pdia = [];
@@ -2609,10 +2614,10 @@ MuseScore {
26092614
}
26102615

26112616
implicitHeight: 30
2612-
implicitWidth: 60
2617+
implicitWidth: 70
26132618

26142619
font.family: 'MScore Text'
2615-
font.pointSize: 8
2620+
font.pointSize: 9
26162621

26172622
delegate: ItemDelegate {
26182623
contentItem: Text {
@@ -2638,8 +2643,8 @@ MuseScore {
26382643

26392644
model: steps
26402645

2641-
Row {
2642-
// StackLayout {
2646+
// Row {
2647+
StackLayout {
26432648

26442649
width: parent.width
26452650
property var stepIndex: index
@@ -2650,12 +2655,12 @@ MuseScore {
26502655
Layout.preferredHeight: 30
26512656
Layout.preferredWidth: 50
26522657

2653-
spacing: 2
2658+
// spacing: 2 // specific to "Row"
26542659

2655-
StackLayout {
2660+
// StackLayout {
2661+
// width: 60
26562662

26572663
currentIndex: modeIndex()
2658-
width: 60
26592664
// implicitWidth: 60
26602665

26612666

@@ -2743,7 +2748,7 @@ MuseScore {
27432748
}
27442749
27452750
}*/
2746-
}
2751+
// }
27472752
}
27482753
}
27492754

0 commit comments

Comments
 (0)