1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

Distinguish the quick-to-compute command flags

This commit is contained in:
Paul Licameli 2019-06-08 20:53:01 -04:00
parent 705b4b28e7
commit 82ea023843
2 changed files with 32 additions and 7 deletions

View File

@ -445,22 +445,30 @@ namespace{
static Predicates thePredicates;
return thePredicates;
}
std::vector< CommandFlagOptions > &Options()
{
static std::vector< CommandFlagOptions > options;
return options;
}
}
ReservedCommandFlag::ReservedCommandFlag( const Predicate &predicate )
ReservedCommandFlag::ReservedCommandFlag(
const Predicate &predicate, const CommandFlagOptions &options )
{
static size_t sNextReservedFlag = 0;
// This will throw std::out_of_range if the constant NCommandFlags is too
// small
set( sNextReservedFlag++ );
RegisteredPredicates().emplace_back( predicate );
Options().emplace_back( options );
}
const ReservedCommandFlag
AudioIONotBusyFlag{
[](const AudacityProject &project ){
return !AudioIOBusyPred( project );
}
},
CommandFlagOptions{}.QuickTest()
},
TimeSelectedFlag{
TimeSelectedPred
@ -568,7 +576,8 @@ const ReservedCommandFlag
}
},
AudioIOBusyFlag{
AudioIOBusyPred
AudioIOBusyPred,
CommandFlagOptions{}.QuickTest()
}, //lll
PlayRegionLockedFlag{
[](const AudacityProject &project){
@ -654,12 +663,14 @@ const ReservedCommandFlag
return (focus &&
!static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
);
}
},
CommandFlagOptions{}.QuickTest()
}, // prl
PausedFlag{
[](const AudacityProject&){
return AudioIOBase::Get()->IsPaused();
}
},
CommandFlagOptions{}.QuickTest()
},
HasWaveDataFlag{
[](const AudacityProject &project){

View File

@ -13,6 +13,7 @@
#include <bitset>
#include <functional>
#include <utility>
class AudacityProject;
@ -32,13 +33,26 @@ constexpr CommandFlag
AlwaysEnabledFlag{}, // all zeroes
NoFlagsSpecified{ ~0ULL }; // all ones
struct CommandFlagOptions{
CommandFlagOptions() = default;
CommandFlagOptions && QuickTest() &&
{ quickTest = true; return std::move( *this ); }
// If true, assume this is a cheap test to be done always. If false, the
// test may be skipped and the condition assumed to be unchanged since the
// last more comprehensive testing
bool quickTest = false;
};
// Construct one statically to register (and reserve) a bit position in the set
// an associate it with a test function
// an associate it with a test function; those with quickTest = true are cheap
// to compute and always checked
class ReservedCommandFlag : public CommandFlag
{
public:
using Predicate = std::function< bool( const AudacityProject& ) >;
ReservedCommandFlag( const Predicate & );
ReservedCommandFlag( const Predicate &predicate,
const CommandFlagOptions &options = {} );
};
// Widely used command flags, but this list need not be exhaustive. It may be