Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Keep up with Audacity's library separation efforts (part 1) #656

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
37 changes: 0 additions & 37 deletions include/tenacity/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,41 +219,4 @@ typedef const char *constSamplePtr;
// ----------------------------------------------------------------------------
typedef wxString PluginID;

// ----------------------------------------------------------------------------
// Supported channel assignments
// ----------------------------------------------------------------------------

typedef enum
{
// Use to mark end of list
ChannelNameEOL = -1,
// The default channel assignment
ChannelNameMono,
// From this point, the channels follow the 22.2 surround sound format
ChannelNameFrontLeft,
ChannelNameFrontRight,
ChannelNameFrontCenter,
ChannelNameLowFrequency1,
ChannelNameBackLeft,
ChannelNameBackRight,
ChannelNameFrontLeftCenter,
ChannelNameFrontRightCenter,
ChannelNameBackCenter,
ChannelNameLowFrequency2,
ChannelNameSideLeft,
ChannelNameSideRight,
ChannelNameTopFrontLeft,
ChannelNameTopFrontRight,
ChannelNameTopFrontCenter,
ChannelNameTopCenter,
ChannelNameTopBackLeft,
ChannelNameTopBackRight,
ChannelNameTopSideLeft,
ChannelNameTopSideRight,
ChannelNameTopBackCenter,
ChannelNameBottomFrontCenter,
ChannelNameBottomFrontLeft,
ChannelNameBottomFrontRight,
} ChannelName, *ChannelNames;

#endif // __AUDACITY_TYPES_H__
2 changes: 2 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set( LIBRARIES
lib-string-utils
lib-strings
lib-utility
lib-components
lib-basic-ui
)

foreach( LIBRARY ${LIBRARIES} )
Expand Down
66 changes: 66 additions & 0 deletions libraries/lib-basic-ui/BasicUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*!********************************************************************

Audacity: A Digital Audio Editor

@file BasicUI.cpp

Paul Licameli

**********************************************************************/
#include "BasicUI.h"

#include <mutex>
#include <vector>

namespace BasicUI {
WindowPlacement::~WindowPlacement() = default;

Services::~Services() = default;

static Services *theInstance = nullptr;

Services *Get() { return theInstance; }

Services *Install(Services *pInstance)
{
auto result = theInstance;
theInstance = pInstance;
return result;
}

static std::recursive_mutex sActionsMutex;
static std::vector<Action> sActions;

void CallAfter(Action action)
{
if (auto p = Get())
p->DoCallAfter(action);
else {
// No services yet -- but don't lose the action. Put it in a queue
auto guard = std::lock_guard{ sActionsMutex };
sActions.emplace_back(std::move(action));
}
}

void Yield()
{
do {
// Dispatch anything in the queue, added while there were no Services
{
auto guard = std::lock_guard{ sActionsMutex };
std::vector<Action> actions;
actions.swap(sActions);
for (auto &action : actions)
action();
}

// Dispatch according to Services, if present
if (auto p = Get())
p->DoYield();
}
// Re-test for more actions that might have been enqueued by actions just
// dispatched
while ( !sActions.empty() );
}

}
82 changes: 82 additions & 0 deletions libraries/lib-basic-ui/BasicUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*!********************************************************************

Audacity: A Digital Audio Editor

@file BasicUI.h
@brief Toolkit-neutral facade for basic user interface services

Paul Licameli

**********************************************************************/
#ifndef __TENACITY_BASIC_UI__
#define __TENACITY_BASIC_UI__

#include <functional>

namespace BasicUI {

//! @name Types used in the Services interface
//! @{

using Action = std::function<void()>;

//! Subclasses may hold information such as a parent window pointer for a dialog.
/*! The default-constructed empty value of this base class must be accepted by overrides of methods of
Services */
class BASIC_UI_API WindowPlacement {
public:
WindowPlacement() = default;

//! Don't slice
WindowPlacement( const WindowPlacement& ) PROHIBITED;
//! Don't slice
WindowPlacement &operator=( const WindowPlacement& ) PROHIBITED;
virtual ~WindowPlacement();
};

//! @}

//! Abstract class defines a few user interface services, not mentioning particular toolkits
/*! The intention is that the application supplies a concrete implementation at
startup. Most code will not use this class directly, but call the inline
functions that follow. */
class BASIC_UI_API Services {
public:
virtual ~Services();
virtual void DoCallAfter(const Action &action) = 0;
virtual void DoYield() = 0;
};

//! Fetch the global instance, or nullptr if none is yet installed
BASIC_UI_API Services *Get();

//! Install an implementation; return the previously installed instance
BASIC_UI_API Services *Install(Services *pInstance);

/*! @name Functions that invoke global Services
These dispatch to the global Services, if supplied. If none was supplied,
they are mostly no-ops, with exceptions as noted. All should be called on
the main thread only, except as noted.
*/
//! @{

//! Schedule an action to be done later, and in the main thread
/*! This function may be called in other threads than the main. If no Services
are yet installed, the action is not lost, but may be dispatched by Yield().
The action may itself invoke CallAfter to enqueue other actions.
*/
void CallAfter(Action action);

//! Dispatch waiting events, including actions enqueued by CallAfter
/*! This function must be called by the main thread. Actions enqueued by
CallAfter before Services were installed will be dispatched in the sequence
they were enqueued, unless an exception thrown by one of them stops the
dispatching.
*/
void Yield();

//! @}
}


#endif
29 changes: 29 additions & 0 deletions libraries/lib-basic-ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[[
This library defines a facade interface, BasicUI::Services, for a few basic
interactions with the user, such as showing simple dialog boxes, and for
enqueuing actions to the event loop, and yielding to to the event dispatcher.

The interface makes no mention of classes in wxWidgets. Using this library
instead of making direct use of wxWidgets enlarges the parts of the program
that are toolkit neutral.

There is a global pointer to an instance of Services, and the main program is
expected, at startup, to create a static instance of a subclass of Services and
set the pointer. If it does not, then calls to the non-member functions in
namespace BasicUI are no-ops.
]]#

set( SOURCES
BasicUI.cpp
BasicUI.h
)

set( LIBRARIES
lib-strings-interface
PRIVATE
wxWidgets::wxWidgets
)

audacity_library( lib-basic-ui "${SOURCES}" "${LIBRARIES}"
"" ""
)
30 changes: 30 additions & 0 deletions libraries/lib-components/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[[
Various abstract base classes related to modules and plugins.

ComponentInterfaceSymbol, which pairs an internal identifier string (suitable
for storing as a configuration file value) with a user-visible translatable
string. It serves to "name" various things.

CommandParameters, for write and reading key-value pairs to and from strings.
]]#

list( APPEND SOURCES
ComponentInterface.cpp
ComponentInterface.h
ComponentInterfaceSymbol.h
ConfigInterface.cpp
ConfigInterface.h
EffectAutomationParameters.cpp
EffectAutomationParameters.h
EffectInterface.cpp
EffectInterface.h
ModuleInterface.cpp
ModuleInterface.h
PluginInterface.cpp
PluginInterface.h
)

audacity_library( lib-components "${SOURCES}"
"lib-strings-interface;PRIVATE;wxWidgets::wxWidgets"
"" ""
)
10 changes: 10 additions & 0 deletions libraries/lib-components/ComponentInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**********************************************************************

Tenacity

@file ComponentInterface.cpp

**********************************************************************/
#include "ComponentInterface.h"

ComponentInterface::~ComponentInterface() = default;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**********************************************************************

Audacity: A Digital Audio Editor
Tenacity

ComponentInterface.h

Expand Down Expand Up @@ -43,7 +43,7 @@
#define __AUDACITY_COMPONENT_INTERFACE_H__

#include "Identifier.h"
#include "tenacity/Types.h"
#include "Internat.h"
#include <wx/string.h> // member variables

class ComponentInterfaceSymbol;
Expand All @@ -58,10 +58,10 @@ plugins. It is what makes a class a plug-in. Additionally it provides an
optional parameter definitions function, for those components such as commands,
effects and (soon) preference pagess that define parameters.
********************************************************************************/
class TENACITY_DLL_API ComponentInterface /* not final */
class COMPONENTS_API ComponentInterface /* not final */
{
public:
virtual ~ComponentInterface() {};
virtual ~ComponentInterface();

// These should return an untranslated value
virtual PluginPath GetPath() = 0;
Expand Down
10 changes: 10 additions & 0 deletions libraries/lib-components/ConfigInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**********************************************************************

Tenacity

@file ConfigInterface.cpp

**********************************************************************/
#include "ConfigInterface.h"

ConfigClientInterface::~ConfigClientInterface() = default;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**********************************************************************

Audacity: A Digital Audio Editor
Tenacity

ConfigInterface.h

Expand Down Expand Up @@ -53,10 +53,10 @@ differentiates between private and shared config. It should probably be replace
with a Shuttle.

*******************************************************************************************/
class TENACITY_DLL_API ConfigClientInterface /* not final */
class COMPONENTS_API ConfigClientInterface /* not final */
{
public:
virtual ~ConfigClientInterface() {};
virtual ~ConfigClientInterface();

virtual bool HasSharedConfigGroup(const RegistryPath & group) = 0;
virtual bool GetSharedConfigSubgroups(const RegistryPath & group, RegistryPaths & subgroups) = 0;
Expand Down
10 changes: 10 additions & 0 deletions libraries/lib-components/EffectAutomationParameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**********************************************************************

Tenacity

@file EffectAutomationParameters.cpp

**********************************************************************/
#include "EffectAutomationParameters.h"

CommandParameters::~CommandParameters() = default;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**********************************************************************

Audacity: A Digital Audio Editor
Tenacity

EffectAutomationParameters.h
(defining CommandParameters)
Expand Down Expand Up @@ -64,7 +64,7 @@ wxWidget validators, and can create default dialogs. However until that convers
done, we need this class, and we use a pointer to one from within a Shuttle when interfacing
with the code that still uses it.
*/
class CommandParameters final : public wxFileConfig
class COMPONENTS_API CommandParameters final : public wxFileConfig
{
public:
CommandParameters(const wxString & parms = {})
Expand All @@ -78,9 +78,7 @@ class CommandParameters final : public wxFileConfig
SetParameters(parms);
}

virtual ~CommandParameters()
{
}
virtual ~CommandParameters();

virtual bool HasGroup(const wxString & strName) const override
{
Expand Down
18 changes: 18 additions & 0 deletions libraries/lib-components/EffectInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**********************************************************************

Tenacity

@file EffectInterface.cpp

**********************************************************************/
#include "EffectInterface.h"

EffectDefinitionInterface::~EffectDefinitionInterface() = default;

EffectHostInterface::~EffectHostInterface() = default;

EffectClientInterface::~EffectClientInterface() = default;

EffectUIHostInterface::~EffectUIHostInterface() = default;

EffectUIClientInterface::~EffectUIClientInterface() = default;