mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-14 09:03:54 +01:00
Revert to a465ce0046
This commit is contained in:
@@ -21,7 +21,6 @@ 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"
|
||||
@@ -1128,99 +1127,21 @@ bool Scrubber::CanScrub() const
|
||||
HasWaveDataPred( *mProject );
|
||||
}
|
||||
|
||||
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()
|
||||
MenuTable::BaseItemSharedPtr Scrubber::Menu()
|
||||
{
|
||||
using namespace MenuTable;
|
||||
using Options = CommandManager::Options;
|
||||
|
||||
static BaseItemSharedPtr menu { (
|
||||
FinderScope{ finder },
|
||||
Menu( wxT("Scrubbing"),
|
||||
FinderScope{
|
||||
[](AudacityProject &project) -> CommandHandlerObject&
|
||||
{ return Scrubber::Get( project ); } },
|
||||
MenuTable::Menu( wxT("Scrubbing"),
|
||||
XO("Scru&bbing"),
|
||||
[]{
|
||||
BaseItemPtrs ptrs;
|
||||
for (const auto &item : menuItems()) {
|
||||
ptrs.push_back( Command( item.name, item.label,
|
||||
ptrs.push_back( MenuTable::Command( item.name, item.label,
|
||||
item.memFn,
|
||||
item.flags,
|
||||
item.StatusTest
|
||||
@@ -1239,35 +1160,6 @@ BaseItemSharedPtr ToolbarMenu()
|
||||
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,6 +117,8 @@ 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);
|
||||
|
||||
@@ -125,10 +127,6 @@ 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 &)
|
||||
|
||||
Reference in New Issue
Block a user