forked from music-encoding/sibmei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sibmei4_extension_test.plg
63 lines (55 loc) · 2.14 KB
/
sibmei4_extension_test.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
{
SibmeiExtensionAPIVersion "2.0.0"
Initialize "() {
AddToPluginsMenu('Sibmei extension test', 'Run');
}"
Run "() {
// The plugin will be listed in the menu, but it is not runnable. Give some
// instructions instead of showing no response when users try to run it.
Sibelius.MessageBox(
'This plug-in is an extension of the sibmei MEI export plug-in. To use it, run MEI export.'
);
}"
InitSibmeiExtension "(api) {
Self._property:MySymbolTemplate = CreateSparseArray('Symbol', CreateDictionary(
'fontfam', 'myCustomFont',
'glyph.name', 'mySymbolGlyph'
));
api.RegisterSymbolHandlers('Name', CreateDictionary(
'My symbol', 'HandleMySymbol'
), Self);
api.RegisterTextHandlers('StyleAsText', CreateDictionary(
// Example of a text generated by means of a custom text handler
'XPath test', 'HandleXPathTest',
// Example of a text generated by template
'My text', CreateSparseArray('AnchoredText', CreateDictionary(), api.FormattedText)
), Self);
api.RegisterLineHandlers('StyleAsText', CreateDictionary(
'My line', CreateSparseArray(
'Line', CreateDictionary('type', 'myline', 'endid', 'PreciseMatch')
)
), Self);
}"
HandleMySymbol "(api, obj) {
symbolElement = api.GenerateControlEvent(obj, api.MeiFactory(MySymbolTemplate, obj));
if (obj.ColorRed = 255) {
api.libmei.AddAttribute(symbolElement, 'type', 'myRedType');
}
return symbolElement;
}"
HandleXPathTest "(api, textObj) {
// This text style is used by the sibmei test suite
annotElement = api.GenerateControlEvent(textObj, api.libmei.Annot());
api.libmei.AddAttribute(annotElement, 'type', 'xpath-test');
textWithFormatting = textObj.TextWithFormatting;
for i = 0 to textWithFormatting.NumChildren {
if (CharAt(textWithFormatting[i], 0) = '\\') {
// Remove formatting and newlines. fontoxpath will complain if there is
// additional whitespace in XPath expressions.
textWithFormatting[i] = '';
}
}
api.libmei.SetText(annotElement, JoinStrings(textWithFormatting, ''));
return annotElement;
}"
}