1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +02:00

Break dependency cycle introduced at a69fba9

This commit is contained in:
Paul Licameli 2020-01-19 14:20:44 -05:00
parent f2ed21f9e5
commit 2ec2ad378d
9 changed files with 89 additions and 79 deletions

View File

@ -280,7 +280,7 @@ static const EnumValueSymbol kZoomTypeStrings[nZoomTypes] =
static EnumValueSymbols DiscoverSubViewTypes()
{
const auto &types = WaveTrackSubView::AllTypes();
const auto &types = WaveTrackSubViewType::All();
return transform_container< EnumValueSymbols >(
types, std::mem_fn( &WaveTrackSubView::Type::name ) );
}
@ -360,7 +360,7 @@ bool SetTrackVisualsCommand::ApplyInner(const CommandContext & context, Track *
if( wt && bHasDisplayType )
WaveTrackView::Get( *wt ).SetDisplay(
WaveTrackSubView::AllTypes()[ mDisplayType ].id );
WaveTrackSubViewType::All()[ mDisplayType ].id );
if( wt && bHasScaleType )
wt->GetIndependentWaveformSettings().scaleType =
(mScaleType==kLinear) ?

View File

@ -27,7 +27,7 @@
#include "../Prefs.h"
#include "../ShuttleGui.h"
#include "../tracks/playabletrack/wavetrack/ui/WaveTrackView.h"
#include "../tracks/playabletrack/wavetrack/ui/WaveTrackViewConstants.h"
int TracksPrefs::iPreferencePinned = -1;
@ -149,11 +149,11 @@ static TracksViewModeEnumSetting viewModeSetting()
{
// Do a delayed computation, so that registration of sub-view types completes
// first
const auto &types = WaveTrackSubView::AllTypes();
const auto &types = WaveTrackSubViewType::All();
auto symbols = transform_container< EnumValueSymbols >(
types, std::mem_fn( &WaveTrackSubView::Type::name ) );
auto ids = transform_container< std::vector< WaveTrackSubView::Display > >(
types, std::mem_fn( &WaveTrackSubView::Type::id ) );
types, std::mem_fn( &WaveTrackSubViewType::name ) );
auto ids = transform_container< std::vector< WaveTrackSubViewType::Display > >(
types, std::mem_fn( &WaveTrackSubViewType::id ) );
return {
key3,
symbols,

View File

@ -35,7 +35,7 @@ static WaveTrackSubView::Type sType{
{ wxT("Spectrogram"), XO("&Spectrogram") }
};
static WaveTrackSubView::RegisteredType reg{ sType };
static WaveTrackSubViewType::RegisteredType reg{ sType };
SpectrumView::~SpectrumView() = default;

View File

@ -623,9 +623,9 @@ void WaveTrackMenuTable::InitUserData(void *pUserData)
mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
}
static WaveTrackSubView::Types AllTypes()
static std::vector<WaveTrackSubViewType> AllTypes()
{
auto result = WaveTrackSubView::AllTypes();
auto result = WaveTrackSubViewType::All();
if ( result.size() > reserveDisplays ) {
wxASSERT( false );
result.resize( reserveDisplays );

View File

@ -40,53 +40,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../ui/ButtonHandle.h"
#include "../../../../TrackInfo.h"
namespace {
class Registry {
public:
using Type = WaveTrackSubView::Type;
using Types = std::vector< Type >;
void Append( Type type )
{
types.emplace_back( std::move( type ) );
sorted = false;
}
Types &Get()
{
if ( !sorted ) {
auto begin = types.begin(), end = types.end();
std::sort( begin, end );
// We don't want duplicate ids!
wxASSERT( end == std::adjacent_find( begin, end ) );
sorted = true;
}
return types;
}
private:
Types types;
bool sorted = false;
};
Registry &GetRegistry()
{
static Registry result;
return result;
}
}
WaveTrackSubView::RegisteredType::RegisteredType( Type type )
{
GetRegistry().Append( std::move( type ) );
}
// static
auto WaveTrackSubView::AllTypes() -> const Types &
{
return GetRegistry().Get();
}
namespace {
using WaveTrackSubViewPtrs = std::vector< std::shared_ptr< WaveTrackSubView > >;

View File

@ -13,8 +13,8 @@ Paul Licameli split from class WaveTrack
#include "../../../ui/CommonTrackView.h"
#include "../../../../ClientData.h"
#include "audacity/ComponentInterface.h"
namespace WaveTrackViewConstants{ enum Display : int; }
struct WaveTrackSubViewType;
class CutlineHandle;
class TranslatableString;
@ -26,26 +26,7 @@ class WaveTrackSubView : public CommonTrackView
public:
using Display = WaveTrackViewConstants::Display;
struct Type {
// Identifies the type session-wide, and determines relative position in
// menus listing all types
Display id;
// The translation is suitable for the track control panel drop-down,
// and it may contain a menu accelerator
EnumValueSymbol name;
bool operator < ( const Type &other ) const { return id < other.id; }
bool operator == ( const Type &other ) const { return id == other.id; }
};
using Types = std::vector< Type >;
// Typically a file scope statically constructed object
struct RegisteredType {
RegisteredType( Type type );
};
// Discover all registered types
static const Types &AllTypes();
using Type = WaveTrackSubViewType;
explicit
WaveTrackSubView( WaveTrackView &waveTrackView );

View File

@ -43,3 +43,51 @@ WaveTrackViewConstants::ConvertLegacyDisplayValue(int oldValue)
}
return newValue;
}
namespace {
class Registry {
public:
using Type = WaveTrackSubViewType;
using Types = std::vector< Type >;
void Append( Type type )
{
types.emplace_back( std::move( type ) );
sorted = false;
}
Types &Get()
{
if ( !sorted ) {
auto begin = types.begin(), end = types.end();
std::sort( begin, end );
// We don't want duplicate ids!
wxASSERT( end == std::adjacent_find( begin, end ) );
sorted = true;
}
return types;
}
private:
Types types;
bool sorted = false;
};
Registry &GetRegistry()
{
static Registry result;
return result;
}
}
WaveTrackSubViewType::RegisteredType::RegisteredType( WaveTrackSubViewType type )
{
GetRegistry().Append( std::move( type ) );
}
// static
auto WaveTrackSubViewType::All()
-> const std::vector<WaveTrackSubViewType> &
{
return GetRegistry().Get();
}

View File

@ -79,4 +79,32 @@ namespace WaveTrackViewConstants
Display ConvertLegacyDisplayValue(int oldValue);
}
#include <vector>
#include "audacity/ComponentInterface.h" // for EnumValueSymbol
struct WaveTrackSubViewType {
using Display = WaveTrackViewConstants::Display;
// Identifies the type session-wide, and determines relative position in
// menus listing all types
Display id;
// The translation is suitable for the track control panel drop-down,
// and it may contain a menu accelerator
EnumValueSymbol name;
bool operator < ( const WaveTrackSubViewType &other ) const
{ return id < other.id; }
bool operator == ( const WaveTrackSubViewType &other ) const
{ return id == other.id; }
// Typically a file scope statically constructed object
struct RegisteredType {
RegisteredType( WaveTrackSubViewType type );
};
// Discover all registered types
static const std::vector<WaveTrackSubViewType> &All();
};
#endif

View File

@ -41,7 +41,7 @@ static WaveTrackSubView::Type sType{
{ wxT("Waveform"), XO("Wa&veform") }
};
static WaveTrackSubView::RegisteredType reg{ sType };
static WaveTrackSubViewType::RegisteredType reg{ sType };
WaveformView::~WaveformView() = default;