Skip to content

Commit

Permalink
Remove extension API v1 compatibility
Browse files Browse the repository at this point in the history
Legacy compatibility is much more work than to upgrade an extension
  • Loading branch information
th-we committed Mar 12, 2024
1 parent 3c3ed49 commit c9e0fbf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 198 deletions.
78 changes: 0 additions & 78 deletions lib/sibmei4_legacy_extension_api_v1_test.plg

This file was deleted.

116 changes: 11 additions & 105 deletions src/Extensions.mss
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
15 changes: 0 additions & 15 deletions test/sib-test/Run.mss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c9e0fbf

Please sign in to comment.