1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-14 09:03:54 +01:00
This commit is contained in:
Paul Licameli
2020-01-31 23:44:00 -05:00
parent 229e2673c7
commit 4d43967add
22 changed files with 794 additions and 546 deletions

View File

@@ -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;

View File

@@ -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 &)