-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateBreathMark.plg
101 lines (84 loc) · 3.58 KB
/
CreateBreathMark.plg
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
{
Initialize "() {
// v.1.0.0
AddToPluginsMenu('Create Breath Mark','Run'); }"
Run "() {
selection = Sibelius.ActiveScore.Selection;
textStyle = 'Breath Mark';
if (isSelectionEmpty) {
return false;
}
entries = CreateSparseArray();
for each NoteRest nr in selection {
position = nr.Position;
bar = nr.ParentBar;
entry = CreateDictionary();
if (position = 0) {
prevBar = bar.ParentStaff.NthBar(bar.BarNumber - 1);
entry['bar'] = prevBar;
entry['position'] = prevBar.Length - 1;
entry['text'] = ',';
} else {
entry['bar'] = bar;
entry['position'] = position;
entry['text'] = getBreathText(nr);
}
entries.Push(entry);
}
for each entry in entries {
deleteBarObjects(getTextAtPostionForBar(textStyle, entry.position, entry.bar));
entry.bar.AddText(entry.position, entry.text, textStyle);
}
}"
isSelectionEmpty "(selection) {
for each obj in selection {
if (IsObject(obj)) {
return false;
}
}
return true;}"
getTextAtPostionForBar "(style, pos, bar) {
items = CreateSparseArray();
for each Text text in bar {
if (text.StyleAsText = style and text.Position = pos) {
items.Push(text);
}
}
return items;
}"
deleteBarObjects "(objects) {
for each obj in objects {
obj.Delete();
}
}"
getBreathText "(noteRest) {
result = ',';
maxChars = 0;
entries = CreateSparseArray();
for each note in noteRest {
entry = CreateDictionary();
entry['pitch'] = note.WrittenName;
entry['accStyle'] = note.AccidentalStyle;
entries.Push(entry);
}
for each entry in entries {
pitchLength = Length(entry.pitch) - 1;
switch (entry.accStyle) {
case (BracketedAcc) {
pitchLength = pitchLength + 2;
}
case (CautionaryAcc) {
pitchLength = pitchLength + 1;
}
}
if (pitchLength > maxChars) {
maxChars = pitchLength;
}
}
for i = 0 to maxChars {
result = result & ' ';
}
return result;
}"
}