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:
parent
705b4b28e7
commit
82ea023843
@ -445,22 +445,30 @@ namespace{
|
|||||||
static Predicates thePredicates;
|
static Predicates thePredicates;
|
||||||
return 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;
|
static size_t sNextReservedFlag = 0;
|
||||||
// This will throw std::out_of_range if the constant NCommandFlags is too
|
// This will throw std::out_of_range if the constant NCommandFlags is too
|
||||||
// small
|
// small
|
||||||
set( sNextReservedFlag++ );
|
set( sNextReservedFlag++ );
|
||||||
RegisteredPredicates().emplace_back( predicate );
|
RegisteredPredicates().emplace_back( predicate );
|
||||||
|
Options().emplace_back( options );
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReservedCommandFlag
|
const ReservedCommandFlag
|
||||||
AudioIONotBusyFlag{
|
AudioIONotBusyFlag{
|
||||||
[](const AudacityProject &project ){
|
[](const AudacityProject &project ){
|
||||||
return !AudioIOBusyPred( project );
|
return !AudioIOBusyPred( project );
|
||||||
}
|
},
|
||||||
|
CommandFlagOptions{}.QuickTest()
|
||||||
},
|
},
|
||||||
TimeSelectedFlag{
|
TimeSelectedFlag{
|
||||||
TimeSelectedPred
|
TimeSelectedPred
|
||||||
@ -568,7 +576,8 @@ const ReservedCommandFlag
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
AudioIOBusyFlag{
|
AudioIOBusyFlag{
|
||||||
AudioIOBusyPred
|
AudioIOBusyPred,
|
||||||
|
CommandFlagOptions{}.QuickTest()
|
||||||
}, //lll
|
}, //lll
|
||||||
PlayRegionLockedFlag{
|
PlayRegionLockedFlag{
|
||||||
[](const AudacityProject &project){
|
[](const AudacityProject &project){
|
||||||
@ -654,12 +663,14 @@ const ReservedCommandFlag
|
|||||||
return (focus &&
|
return (focus &&
|
||||||
!static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
|
!static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
CommandFlagOptions{}.QuickTest()
|
||||||
}, // prl
|
}, // prl
|
||||||
PausedFlag{
|
PausedFlag{
|
||||||
[](const AudacityProject&){
|
[](const AudacityProject&){
|
||||||
return AudioIOBase::Get()->IsPaused();
|
return AudioIOBase::Get()->IsPaused();
|
||||||
}
|
},
|
||||||
|
CommandFlagOptions{}.QuickTest()
|
||||||
},
|
},
|
||||||
HasWaveDataFlag{
|
HasWaveDataFlag{
|
||||||
[](const AudacityProject &project){
|
[](const AudacityProject &project){
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class AudacityProject;
|
class AudacityProject;
|
||||||
|
|
||||||
@ -32,13 +33,26 @@ constexpr CommandFlag
|
|||||||
AlwaysEnabledFlag{}, // all zeroes
|
AlwaysEnabledFlag{}, // all zeroes
|
||||||
NoFlagsSpecified{ ~0ULL }; // all ones
|
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
|
// 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
|
class ReservedCommandFlag : public CommandFlag
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Predicate = std::function< bool( const AudacityProject& ) >;
|
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
|
// Widely used command flags, but this list need not be exhaustive. It may be
|
||||||
|
Loading…
x
Reference in New Issue
Block a user