mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-12 06:01:13 +02:00
TransportMenus not link dependent on SelectMenus or Scrubbing
This commit is contained in:
parent
09356f7fe7
commit
ffe101f9a2
@ -984,6 +984,7 @@ void InitializeMenuOrdering()
|
||||
)},
|
||||
{wxT("/View/Windows"), wxT("UndoHistory,Karaoke,MixerBoard")},
|
||||
{wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
|
||||
{wxT("/Transport/Basic"),wxT("Play,Record,Scrubbing,Cursor")},
|
||||
};
|
||||
|
||||
bool doFlush = false;
|
||||
|
@ -1188,8 +1188,8 @@ AttachedItem sAttachment2{
|
||||
};
|
||||
}
|
||||
|
||||
// Under /MenuBar/Transport
|
||||
MenuTable::BaseItemSharedPtr CursorMenu()
|
||||
namespace {
|
||||
BaseItemSharedPtr CursorMenu()
|
||||
{
|
||||
using Options = CommandManager::Options;
|
||||
static const auto CanStopFlags = AudioIONotBusyFlag() | CanStopAudioStreamFlag();
|
||||
@ -1231,7 +1231,11 @@ MenuTable::BaseItemSharedPtr CursorMenu()
|
||||
return menu;
|
||||
}
|
||||
|
||||
namespace {
|
||||
AttachedItem sAttachment0{
|
||||
wxT("Transport/Basic"),
|
||||
Shared( CursorMenu() )
|
||||
};
|
||||
|
||||
BaseItemSharedPtr ExtraCursorMenu()
|
||||
{
|
||||
static BaseItemSharedPtr menu{
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "../commands/CommandManager.h"
|
||||
#include "../toolbars/ControlToolBar.h"
|
||||
#include "../toolbars/TranscriptionToolBar.h"
|
||||
#include "../tracks/ui/Scrubbing.h"
|
||||
#include "../widgets/AudacityMessageBox.h"
|
||||
#include "../widgets/ErrorDialog.h"
|
||||
|
||||
@ -190,57 +189,6 @@ void DoMoveToLabel(AudacityProject &project, bool next)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DoKeyboardScrub(AudacityProject& project, bool backwards, bool keyUp)
|
||||
{
|
||||
static double initT0 = 0;
|
||||
static double initT1 = 0;
|
||||
|
||||
if (keyUp) {
|
||||
auto &scrubber = Scrubber::Get(project);
|
||||
if (scrubber.IsKeyboardScrubbing() && scrubber.IsBackwards() == backwards) {
|
||||
auto gAudioIO = AudioIOBase::Get();
|
||||
auto time = gAudioIO->GetStreamTime();
|
||||
auto &viewInfo = ViewInfo::Get(project);
|
||||
auto &selection = viewInfo.selectedRegion;
|
||||
|
||||
// If the time selection has not changed during scrubbing
|
||||
// set the cursor position
|
||||
if (selection.t0() == initT0 && selection.t1() == initT1) {
|
||||
double endTime = TrackList::Get(project).GetEndTime();
|
||||
time = std::min(time, endTime);
|
||||
time = std::max(time, 0.0);
|
||||
selection.setTimes(time, time);
|
||||
ProjectHistory::Get(project).ModifyState(false);
|
||||
}
|
||||
|
||||
scrubber.Cancel();
|
||||
ProjectAudioManager::Get(project).Stop();
|
||||
}
|
||||
}
|
||||
else { // KeyDown
|
||||
auto gAudioIO = AudioIOBase::Get();
|
||||
auto &scrubber = Scrubber::Get(project);
|
||||
if (scrubber.IsKeyboardScrubbing() && scrubber.IsBackwards() != backwards) {
|
||||
// change direction
|
||||
scrubber.SetBackwards(backwards);
|
||||
}
|
||||
else if (!gAudioIO->IsBusy() && !scrubber.HasMark()) {
|
||||
auto &viewInfo = ViewInfo::Get(project);
|
||||
auto &selection = viewInfo.selectedRegion;
|
||||
double endTime = TrackList::Get(project).GetEndTime();
|
||||
double t0 = selection.t0();
|
||||
|
||||
if ((!backwards && t0 >= 0 && t0 < endTime) ||
|
||||
(backwards && t0 > 0 && t0 <= endTime)) {
|
||||
initT0 = t0;
|
||||
initT1 = selection.t1();
|
||||
scrubber.StartKeyboardScrubbing(t0, backwards);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Menu handler functions
|
||||
@ -837,32 +785,6 @@ void OnPlayCutPreview(const CommandContext &context)
|
||||
);
|
||||
}
|
||||
|
||||
void OnKeyboardScrubBackwards(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
auto evt = context.pEvt;
|
||||
if (evt)
|
||||
DoKeyboardScrub(project, true, evt->GetEventType() == wxEVT_KEY_UP);
|
||||
else { // called from menu, so simulate keydown and keyup
|
||||
DoKeyboardScrub(project, true, false);
|
||||
DoKeyboardScrub(project, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnKeyboardScrubForwards(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
auto evt = context.pEvt;
|
||||
if (evt)
|
||||
DoKeyboardScrub(project, false, evt->GetEventType() == wxEVT_KEY_UP);
|
||||
else { // called from menu, so simulate keydown and keyup
|
||||
DoKeyboardScrub(project, false, false);
|
||||
DoKeyboardScrub(project, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnPlayAtSpeed(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
@ -968,8 +890,6 @@ static CommandHandlerObject &findCommandHandler(AudacityProject &) {
|
||||
|
||||
#define FN(X) (& TransportActions::Handler :: X)
|
||||
|
||||
MenuTable::BaseItemSharedPtr CursorMenu();
|
||||
|
||||
// Under /MenuBar
|
||||
namespace {
|
||||
using namespace MenuTable;
|
||||
@ -1037,12 +957,7 @@ BaseItemSharedPtr TransportMenu()
|
||||
// PRL: caution, this is a duplicated command name!
|
||||
Command( wxT("Pause"), XXO("&Pause"), FN(OnPause),
|
||||
CanStopAudioStreamFlag(), wxT("P") )
|
||||
),
|
||||
|
||||
// Scrubbing sub-menu
|
||||
Scrubber::Menu(),
|
||||
|
||||
CursorMenu()
|
||||
)
|
||||
),
|
||||
|
||||
Section( "Other",
|
||||
@ -1143,13 +1058,7 @@ BaseItemSharedPtr ExtraTransportMenu()
|
||||
wxT("Ctrl+Shift+F7") ),
|
||||
Command( wxT("PlayCutPreview"), XXO("Play C&ut Preview"),
|
||||
FN(OnPlayCutPreview),
|
||||
CaptureNotBusyFlag(), wxT("C") ),
|
||||
Command(wxT("KeyboardScrubBackwards"), XXO("Scrub Bac&kwards"),
|
||||
FN(OnKeyboardScrubBackwards),
|
||||
CaptureNotBusyFlag() | CanStopAudioStreamFlag(), wxT("U\twantKeyup")),
|
||||
Command(wxT("KeyboardScrubForwards"), XXO("Scrub For&wards"),
|
||||
FN(OnKeyboardScrubForwards),
|
||||
CaptureNotBusyFlag() | CanStopAudioStreamFlag(), wxT("I\twantKeyup"))
|
||||
CaptureNotBusyFlag(), wxT("C") )
|
||||
) ) };
|
||||
return menu;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../Project.h"
|
||||
#include "../../ProjectAudioIO.h"
|
||||
#include "../../ProjectAudioManager.h"
|
||||
#include "../../ProjectHistory.h"
|
||||
#include "../../ProjectSettings.h"
|
||||
#include "../../ProjectStatus.h"
|
||||
#include "../../Track.h"
|
||||
@ -1127,21 +1128,99 @@ bool Scrubber::CanScrub() const
|
||||
HasWaveDataPred( *mProject );
|
||||
}
|
||||
|
||||
MenuTable::BaseItemSharedPtr Scrubber::Menu()
|
||||
void Scrubber::DoKeyboardScrub(bool backwards, bool keyUp)
|
||||
{
|
||||
auto &project = *mProject;
|
||||
|
||||
static double initT0 = 0;
|
||||
static double initT1 = 0;
|
||||
|
||||
if (keyUp) {
|
||||
auto &scrubber = Scrubber::Get(project);
|
||||
if (scrubber.IsKeyboardScrubbing() && scrubber.IsBackwards() == backwards) {
|
||||
auto gAudioIO = AudioIOBase::Get();
|
||||
auto time = gAudioIO->GetStreamTime();
|
||||
auto &viewInfo = ViewInfo::Get(project);
|
||||
auto &selection = viewInfo.selectedRegion;
|
||||
|
||||
// If the time selection has not changed during scrubbing
|
||||
// set the cursor position
|
||||
if (selection.t0() == initT0 && selection.t1() == initT1) {
|
||||
double endTime = TrackList::Get(project).GetEndTime();
|
||||
time = std::min(time, endTime);
|
||||
time = std::max(time, 0.0);
|
||||
selection.setTimes(time, time);
|
||||
ProjectHistory::Get(project).ModifyState(false);
|
||||
}
|
||||
|
||||
scrubber.Cancel();
|
||||
ProjectAudioManager::Get(project).Stop();
|
||||
}
|
||||
}
|
||||
else { // KeyDown
|
||||
auto gAudioIO = AudioIOBase::Get();
|
||||
auto &scrubber = Scrubber::Get(project);
|
||||
if (scrubber.IsKeyboardScrubbing() && scrubber.IsBackwards() != backwards) {
|
||||
// change direction
|
||||
scrubber.SetBackwards(backwards);
|
||||
}
|
||||
else if (!gAudioIO->IsBusy() && !scrubber.HasMark()) {
|
||||
auto &viewInfo = ViewInfo::Get(project);
|
||||
auto &selection = viewInfo.selectedRegion;
|
||||
double endTime = TrackList::Get(project).GetEndTime();
|
||||
double t0 = selection.t0();
|
||||
|
||||
if ((!backwards && t0 >= 0 && t0 < endTime) ||
|
||||
(backwards && t0 > 0 && t0 <= endTime)) {
|
||||
initT0 = t0;
|
||||
initT1 = selection.t1();
|
||||
scrubber.StartKeyboardScrubbing(t0, backwards);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scrubber::OnKeyboardScrubBackwards(const CommandContext &context)
|
||||
{
|
||||
auto evt = context.pEvt;
|
||||
if (evt)
|
||||
DoKeyboardScrub(true, evt->GetEventType() == wxEVT_KEY_UP);
|
||||
else { // called from menu, so simulate keydown and keyup
|
||||
DoKeyboardScrub(true, false);
|
||||
DoKeyboardScrub(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Scrubber::OnKeyboardScrubForwards(const CommandContext &context)
|
||||
{
|
||||
auto evt = context.pEvt;
|
||||
if (evt)
|
||||
DoKeyboardScrub(false, evt->GetEventType() == wxEVT_KEY_UP);
|
||||
else { // called from menu, so simulate keydown and keyup
|
||||
DoKeyboardScrub(false, false);
|
||||
DoKeyboardScrub(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
static const auto finder =
|
||||
[](AudacityProject &project) -> CommandHandlerObject&
|
||||
{ return Scrubber::Get( project ); };
|
||||
|
||||
using namespace MenuTable;
|
||||
BaseItemSharedPtr ToolbarMenu()
|
||||
{
|
||||
using namespace MenuTable;
|
||||
using Options = CommandManager::Options;
|
||||
|
||||
static BaseItemSharedPtr menu { (
|
||||
FinderScope{
|
||||
[](AudacityProject &project) -> CommandHandlerObject&
|
||||
{ return Scrubber::Get( project ); } },
|
||||
MenuTable::Menu( wxT("Scrubbing"),
|
||||
FinderScope{ finder },
|
||||
Menu( wxT("Scrubbing"),
|
||||
XO("Scru&bbing"),
|
||||
[]{
|
||||
BaseItemPtrs ptrs;
|
||||
for (const auto &item : menuItems()) {
|
||||
ptrs.push_back( MenuTable::Command( item.name, item.label,
|
||||
ptrs.push_back( Command( item.name, item.label,
|
||||
item.memFn,
|
||||
item.flags,
|
||||
item.StatusTest
|
||||
@ -1160,6 +1239,35 @@ MenuTable::BaseItemSharedPtr Scrubber::Menu()
|
||||
return menu;
|
||||
}
|
||||
|
||||
AttachedItem sAttachment{
|
||||
wxT("Transport/Basic"),
|
||||
Shared( ToolbarMenu() )
|
||||
};
|
||||
|
||||
BaseItemSharedPtr KeyboardScrubbingItems()
|
||||
{
|
||||
using Options = CommandManager::Options;
|
||||
|
||||
static BaseItemSharedPtr items{
|
||||
( FinderScope{ finder },
|
||||
Items( wxT("KeyboardScrubbing"),
|
||||
Command(wxT("KeyboardScrubBackwards"), XXO("Scrub Bac&kwards"),
|
||||
&Scrubber::OnKeyboardScrubBackwards,
|
||||
CaptureNotBusyFlag() | CanStopAudioStreamFlag(), wxT("U\twantKeyup")),
|
||||
Command(wxT("KeyboardScrubForwards"), XXO("Scrub For&wards"),
|
||||
&Scrubber::OnKeyboardScrubForwards,
|
||||
CaptureNotBusyFlag() | CanStopAudioStreamFlag(), wxT("I\twantKeyup"))
|
||||
) ) };
|
||||
return items;
|
||||
}
|
||||
|
||||
AttachedItem sAttachment2{
|
||||
wxT("Optional/Extra/Part1/Transport"),
|
||||
Shared( KeyboardScrubbingItems() )
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void Scrubber::PopulatePopupMenu(wxMenu &menu)
|
||||
{
|
||||
int id = CMD_ID;
|
||||
|
@ -117,8 +117,6 @@ public:
|
||||
// This returns the same as the enabled state of the menu items:
|
||||
bool CanScrub() const;
|
||||
|
||||
// For the toolbar
|
||||
static MenuTable::BaseItemSharedPtr Menu();
|
||||
// For popup
|
||||
void PopulatePopupMenu(wxMenu &menu);
|
||||
|
||||
@ -127,6 +125,10 @@ public:
|
||||
void OnSeek(const CommandContext&);
|
||||
void OnToggleScrubRuler(const CommandContext&);
|
||||
|
||||
void OnKeyboardScrubBackwards(const CommandContext&);
|
||||
void OnKeyboardScrubForwards(const CommandContext&);
|
||||
void DoKeyboardScrub(bool backwards, bool keyUp);
|
||||
|
||||
// Convenience wrapper for the above
|
||||
template<void (Scrubber::*pfn)(const CommandContext&)>
|
||||
void Thunk(wxCommandEvent &)
|
||||
|
Loading…
x
Reference in New Issue
Block a user