-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopy Below.qml
109 lines (87 loc) · 3.97 KB
/
Copy Below.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
/*========================================================================
Move Selection
https://github.com/Ash-86/Move-Selection
Copyright (C)2023 Ashraf El Droubi (Ash-86)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=========================================================================*/
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.Move/Duplicate Selection.Duplicate to Staff Below"
description: "Duplicates selection to the staff below."
version: "1.0"
//4.4 title: "Duplicate to Staff Below"
//4.4 thumbnailName: "do.png"
//4.4 categoryCode: "composing-arranging-tools"
Component.onCompleted : {
if (mscoreMajorVersion >= 4) {
title= "Duplicate to Staff Below"
thumbnailName = "do.png"
categoryCode = "composing-arranging-tools"
}
}
onRun: {
///// get start and end tics,staff,and track, for selection
var cursor = curScore.newCursor();
//end
cursor.rewind(2); // go to the end of the selection
var endTick = cursor.tick;
// if (endTick == 0) { // dealing with some bug when selecting to end.
// var endTick = score.lastSegment.tick + 1;
// }
var endStaff = cursor.staffIdx +1;
var endTrack = endStaff * 4;
//start
cursor.rewind(1); // go to the beginning of the selection
// var startSegTick= cursor.segment.tick
var startSegTick= curScore.selection.startSegment.tick;
var startTick = cursor.tick;
var startStaff = cursor.staffIdx;
var startTrack = startStaff * 4;
///////////////////////////////////////////////////////////////
if (endStaff==curScore.nstaves){
return
}else{
curScore.startCmd();
cmd("copy");
////////////////////////////////
var stavesN= endStaff - startStaff
cursor.track=startTrack+stavesN*4; //// set cursor to staff above
cursor.rewindToTick(startSegTick); // go back to beginning of selection
/////// In case the startTick at lower staff falls within the space of an element,
/////// (cursor.tick in this case returns tick of next element)
//////// navigate to previous element and addRest until element tick coincides with startTick.
if (cursor.tick > startSegTick){ /// it seems empty measure have to have special condition to prepare measure
cursor.prev();
cursor.setDuration(1, 4);
cursor.addRest();
cursor.rewindToTick(startSegTick);
}
while(cursor.tick > startSegTick){
cursor.prev();
var n=cursor.element.duration.numerator;
var d=cursor.element.duration.denominator;
cursor.setDuration(n, d*2);
cursor.addRest();
cursor.rewindToTick(startSegTick);
}
///////////////////////////////////////////////
if (cursor.element.type==Element.CHORD){
curScore.selection.select(cursor.element.notes[0])
}else {
curScore.selection.select(cursor.element)
}
cmd("paste");
curScore.endCmd()
}///end else
}///end onRun
}