From c9e0fbfbc83f470df87ca1009b6596c3f45e9e0b Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Tue, 12 Mar 2024 23:03:28 +0100 Subject: [PATCH] Remove extension API v1 compatibility Legacy compatibility is much more work than to upgrade an extension --- lib/sibmei4_legacy_extension_api_v1_test.plg | 78 ------------- src/Extensions.mss | 116 ++----------------- test/sib-test/Run.mss | 15 --- 3 files changed, 11 insertions(+), 198 deletions(-) delete mode 100644 lib/sibmei4_legacy_extension_api_v1_test.plg diff --git a/lib/sibmei4_legacy_extension_api_v1_test.plg b/lib/sibmei4_legacy_extension_api_v1_test.plg deleted file mode 100644 index 9acd48b..0000000 --- a/lib/sibmei4_legacy_extension_api_v1_test.plg +++ /dev/null @@ -1,78 +0,0 @@ -{ - SibmeiExtensionAPIVersion "1.2.0" - - Initialize "() { - AddToPluginsMenu('Sibmei extension test for legacy API v1', '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:api = api; - Self._property:libmei = api.libmei; - - Self._property:MySymbolTemplate = CreateSparseArray('Symbol', CreateDictionary( - 'fontfam', 'myCustomFont', - 'glyph.name', 'mySymbolGlyph' - )); - - Self._property:MyLineTemplate = CreateSparseArray( - 'Line', CreateDictionary('type', 'myline', 'endid') - ); - - api.RegisterSymbolHandlers(CreateDictionary( - 'Name', CreateDictionary( - 'My symbol', 'HandleMySymbol' - ) - ), Self); - - api.RegisterTextHandlers(CreateDictionary( - 'StyleAsText', CreateDictionary( - 'XPath test', 'HandleXPathTest', - 'My text', 'HandleMyText' - ) - ), Self); - - api.RegisterLineHandlers(CreateDictionary( - 'StyleAsText', CreateDictionary( - 'My line', CreateSparseArray( - 'Line', CreateDictionary('type', 'myline', 'endid') - ) - ) - ), Self); - }" - - HandleMySymbol "(this, obj) { - symbolElement = api.HandleControlEvent(obj, MySymbolTemplate); - if (obj.ColorRed = 255) { - libmei.AddAttribute(symbolElement, 'type', 'myRedType'); - } - }" - - HandleMyText "(this, textObj) { - textElement = api.GenerateControlEvent(textObj, 'AnchoredText'); - api.AddFormattedText(textElement, textObj); - return textElement; - }" - - HandleXPathTest "(this, textObj) { - annotElement = api.GenerateControlEvent(textObj, 'Annot'); - 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 about if - // is additional whitespace in XPath expressions. - textWithFormatting[i] = ''; - } - } - libmei.SetText(annotElement, JoinStrings(textWithFormatting, '')); - return annotElement; - }" -} diff --git a/src/Extensions.mss b/src/Extensions.mss index 6c1a46d..44f24fd 100644 --- a/src/Extensions.mss +++ b/src/Extensions.mss @@ -37,10 +37,6 @@ function RegisterAvailableExtensions (availableExtensions, extensionsInfo, plugi { error = null; } - case (extensionSemver[0] = '1') { - // It's O.K., we're giving it a legacy version of the API - error = null; - } case ( (apiSemver[0] < extensionSemver[0]) or (apiSemver[0] = extensionSemver[0] and apiSemver[1] < extensionSemver[1]) @@ -184,40 +180,20 @@ function CreateApiObject (extensionInfo) { 'LyricText', LyricText ); - switch (extensionInfo.apiVersion) + if (extensionInfo.apiVersion != 2) { - case (2) - { - // Current version - apiObject.SetMethod('RegisterSymbolHandlers', Self, 'ExtensionAPI_RegisterSymbolHandlers'); - apiObject.SetMethod('RegisterTextHandlers', Self, 'ExtensionAPI_RegisterTextHandlers'); - apiObject.SetMethod('RegisterLineHandlers', Self, 'ExtensionAPI_RegisterLineHandlers'); - apiObject.SetMethod('RegisterLyricHandlers', Self, 'ExtensionAPI_RegisterLyricHandlers'); - apiObject.SetMethod('MeiFactory', Self, 'ExtensionAPI_MeiFactory'); - apiObject.SetMethod('AddFormattedText', Self, 'AddFormattedText'); - apiObject.SetMethod('GenerateControlEvent', Self, 'ExtensionAPI_GenerateControlEvent'); - apiObject.SetMethod('GenerateModifier', Self, 'ExtensionAPI_GenerateModifier'); - apiObject.SetMethod('AsModifier', Self, 'ExtensionAPI_AsModifier'); - } - case (1) { - // Legacy version - apiObject.SetMethod('RegisterSymbolHandlers', Self, 'LegacyExtensionAPIv1_RegisterSymbolHandlers'); - apiObject.SetMethod('RegisterTextHandlers', Self, 'LegacyExtensionAPIv1_RegisterTextHandlers'); - apiObject.SetMethod('RegisterLineHandlers', Self, 'LegacyExtensionAPIv1_RegisterLineHandlers'); - apiObject.SetMethod('HandleControlEvent', Self, 'LegacyExtensionAPIv1_HandleControlEvent'); - apiObject.SetMethod('HandleModifier', Self, 'LegacyExtensionAPIv1_HandleModifier'); - apiObject.SetMethod('AddFormattedText', Self, 'AddFormattedText'); - apiObject.SetMethod('GenerateControlEvent', Self, 'LegacyExtensionAPIv1_GenerateControlEvent'); - apiObject.SetMethod('AddControlEventAttributes', Self, 'LegacyExtensionAPIv1_AddControlEventAttributes'); - apiObject.SetMethod('HandleLineTemplate', Self, 'LegacyExtensionAPIv1_HandleLineTemplate'); - apiObject.SetMethod('MeiFactory', Self, 'LegacyExtensionAPIv1_MeiFactory'); - } - default - { - StopPlugin('Unsupported extension API version: ' & apiVersion); - } + StopPlugin('Unsupported extension API version: ' & extensionInfo.apiVersion); } + apiObject.SetMethod('RegisterSymbolHandlers', Self, 'ExtensionAPI_RegisterSymbolHandlers'); + apiObject.SetMethod('RegisterTextHandlers', Self, 'ExtensionAPI_RegisterTextHandlers'); + apiObject.SetMethod('RegisterLineHandlers', Self, 'ExtensionAPI_RegisterLineHandlers'); + apiObject.SetMethod('RegisterLyricHandlers', Self, 'ExtensionAPI_RegisterLyricHandlers'); + apiObject.SetMethod('MeiFactory', Self, 'ExtensionAPI_MeiFactory'); + apiObject.SetMethod('AddFormattedText', Self, 'AddFormattedText'); + apiObject.SetMethod('GenerateControlEvent', Self, 'ExtensionAPI_GenerateControlEvent'); + apiObject.SetMethod('GenerateModifier', Self, 'ExtensionAPI_GenerateModifier'); + return apiObject; } //$end @@ -253,73 +229,3 @@ function ExtensionAPI_GenerateControlEvent (this, bobj, element) { function ExtensionAPI_GenerateModifier (this, bobj, element) { GenerateModifier(bobj, element); } //$end - -function ExtensionAPI_AsModifier (this, templateObject) { - return AsModifier(templateObject); -} //$end - - - -///// Legacy methods - -function LegacyExtensionAPIv1_RegisterHandlers (pluginInfo, handlers, handlerDict) { - for each Name idProperty in symbolHandlerDict - { - handlersById = symbolHandlerDict[idProperty]; - for each Name id in handlersById - { - if (IsObject(handlersById[id])) - { - handlerMethod = handlersById[id]; - template = null; - } - else - { - handlerMethod = defaultHandlerMethod; - template = handlersById[id]; - } - - RegisterHandlers(this, handlers, idProperty, handlerMethod, CreateDictionary( - id, template - )); - } - } -} //$end - - -function LegacyExtensionAPIv1_RegisterSymbolHandlers (this, symbolHandlerDict, plugin) { - LegacyExtensionAPIv1_RegisterHandlers(this, SymbolHandlers, symbolHandlerDict); -} //$end - -function LegacyExtensionAPIv1_RegisterTextHandlers (this, textHandlerDict, plugin) { - LegacyExtensionAPIv1_RegisterHandlers(this, TextHandlers, symbolHandlerDict); -} //$end - -function LegacyExtensionAPIv1_RegisterLineHandlers (this, lineHandlerDict, plugin) { - LegacyExtensionAPIv1_RegisterHandlers(this, LineHandlers, symbolHandlerDict); -} //$end - - -function LegacyExtensionAPIv1_HandleControlEvent (this, bobj, template) { - return GenerateControlEvent(bobj, MeiFactory(template)); -} //$end - -function LegacyEtensionAPIv1_HandleModifier (this, bobj, template) { - return GenerateModifier(bobj, MeiFactory(template)); -} //$end - -function LegacyExtensionAPIv1_GenerateControlEvent (this, bobj, elementName) { - return AddControlEventAttributes(bobj, libmei.@elementName()); -} //$end - -function LegacyExtensionAPIv1_AddControlEventAttributes (this, bobj, element) { - return AddControlEventAttributes(bobj, element); -} //$end - -function LegacyExtensionAPIv1_HandleLineTemplate (this, lobj, template) { - return GenerateControlEvent(lobj, MeiFactory(template)); -} //$end - -function LegacyExtensionAPIv1_MeiFactory (this, templateObject, bobj) { - return MeiFactory(templateObject, bobj); -} //$end diff --git a/test/sib-test/Run.mss b/test/sib-test/Run.mss index 8e1ac0a..72fab7d 100644 --- a/test/sib-test/Run.mss +++ b/test/sib-test/Run.mss @@ -41,21 +41,6 @@ function Run() { CloseAllWindows(); - // Export with legacy API before batch exporting all the test files because - // batch export shows a dialog, and we'd rather have that dialog pop up - // when everything is finished. - sibmei4.InitGlobals(CreateSparseArray('sibmei4_legacy_extension_api_v1_test')); - score = sibmei4.GetScore(_SibTestFileDirectory & 'extensions.sib'); - sibmei4.DoExport(score, _SibTestFileDirectory & 'legacy_extensions_api_v1.mei'); - - testFolder = Sibelius.GetFolder(_SibTestFileDirectory); - testFiles = CreateSparseArray(); - for each SIB file in testFolder - { - testFiles.Push(file); - } - sibmei4.ExportBatch(testFiles, CreateSparseArray('sibmei4_extension_test')); - if (Sibelius.PathSeparator = '/') { mochaScript = pluginDir & 'test.sh'; } else {