function audioPluginBlockHelper(varargin)
% audioPluginBlockHelper Helper function for the Audio Plugin block

%   Copyright 2022 The MathWorks, Inc.

if bdIsLibrary(get_param(gcbh,'Parent')) && ~(nargin==1 && strcmp(varargin{1},'delete'))
    error(getString(message('audio:plugin:BlockInLibrary')))
end

dlgObj = get_param(gcbh,'UserData');

if nargin==1 && strcmp(varargin{1},'delete')
    if ~isempty(dlgObj) && isvalid(dlgObj)
        delete(dlgObj)
    end
    return
end

if isempty(dlgObj) || ~isvalid(dlgObj)
    dlgObj = audio.internal.AudioPluginBlockDialog(gcbh);
    if isvalid(dlgObj)
        set_param(gcbh,'UserData',dlgObj)
    end
end

model = bdroot(gcbh);
if isvalid(dlgObj)

    loc = get_param(model, 'Location');
    mdlx = loc(1);
    mdlw = loc(3) - loc(1);
    mdlh = loc(4) - loc(2);

    h =  findall(dlgObj.getWidget(),'type','figure');
    pos = get(h,'Position');

    figx = mdlx + mdlw / 2;
    figw = pos(3);
    figh = pos(4);

    screen = get(0, 'ScreenSize');

    dy = ((screen(4) - mdlh) + mdlh) / 2;

    h.Position = [figx,dy,figw,figh];
    h.Visible = 'on';

end
