1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 15:23:48 +01:00

Implementation of Timer Toolbar

PRL:  Rebased onto recent master, fixed compilation and indentation, added new
files to the XCode project, added an EXPERIMENTAL flag
This commit is contained in:
Loss
2019-10-14 14:00:26 -03:00
committed by Paul Licameli
parent f1e5e96480
commit e787694f07
16 changed files with 344 additions and 25 deletions

View File

@@ -0,0 +1,186 @@
/**********************************************************************
Audacity: A Digital Audio Editor
TimerToolBar.cpp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*//*******************************************************************/
#include "../Audacity.h"
#include "SelectionBar.h"
#include "SelectionBarListener.h"
#include "ToolManager.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/setup.h> // for wxUSE_* macros
#ifndef WX_PRECOMP
#include <wx/choice.h>
#include <wx/intl.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/valtext.h>
#include <wx/stattext.h>
#endif
#include <wx/statline.h>
#include "SelectionBarListener.h"
#include "SelectionBar.h"
#include "TimerToolBar.h"
//#include "../widgets/AButton.h"
#include "../AudioIO.h"
#include "../AColor.h"
#include "../KeyboardCapture.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../Snap.h"
#include "../widgets/NumericTextCtrl.h"
#include "../AllThemeResources.h"
#if wxUSE_ACCESSIBILITY
#include "../widgets/WindowAccessible.h"
#endif
IMPLEMENT_CLASS(TimerToolBar, ToolBar);
enum {
TimerToolBarFirstID = 2700,
AudioTimeID,
};
BEGIN_EVENT_TABLE(TimerToolBar, ToolBar)
EVT_SIZE(TimerToolBar::OnSize)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimerToolBar::OnCaptureKey)
END_EVENT_TABLE()
TimerToolBar::TimerToolBar( AudacityProject &project )
: ToolBar(project, TimerBarID, XO("TimerToolBar"), wxT("TimerToolBar"),true),
mListener(NULL), mAudioTime(NULL)
{
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIO::GetOptimalSupportedSampleRate());
}
TimerToolBar::~TimerToolBar()
{
}
TimerToolBar &TimerToolBar::Get( AudacityProject &project )
{
auto &toolManager = ToolManager::Get( project );
return *static_cast<TimerToolBar*>( toolManager.GetToolBar(TimerBarID) );
}
const TimerToolBar &TimerToolBar::Get( const AudacityProject &project )
{
return Get( const_cast<AudacityProject&>( project )) ;
}
void TimerToolBar::Create(wxWindow * parent)
{
ToolBar::Create(parent);
UpdatePrefs();
}
NumericTextCtrl * TimerToolBar::AddTime(
const TranslatableString &Name, int id)
{
auto formatName = mListener ? mListener->AS_GetSelectionFormat()
: NumericFormatSymbol{};
auto pCtrl = safenew NumericTextCtrl(
this, id, NumericConverter::TIME, formatName, 0.0, mRate);
pCtrl->SetName(Name);
return pCtrl;
}
void TimerToolBar::Populate()
{
mAudioTime = AddTime(XO("Audio Position"), AudioTimeID);
Add(mAudioTime, 0, wxALIGN_CENTER);
Layout();
SetMinSize(GetSizer()->GetMinSize());
}
void TimerToolBar::UpdatePrefs()
{
SetLabel(XO("TimerToolBar"));
ToolBar::UpdatePrefs();
}
void TimerToolBar::OnSize(wxSizeEvent & event)
{
event.Skip();
int sh = GetSize().GetHeight() - 10;
if (mAudioTime)
{
mAudioTime->SetDigitSize( sh*.63, sh );
wxSize ms = mAudioTime->GetSize();
//int mw = ms.GetWidth();
//mAudioTime->SetMinSize(GetSizer()->GetMinSize());
//printf("(size) %i %i\n", GetSizer()->GetSize());
}
//SetMinSize( GetSizer()->GetMinSize() );
//Layout();
//Fit();
//Refresh(true);
//evt.Skip();
}
void TimerToolBar::SetTimes(double audio)
{
mAudioTime->SetValue(audio);
}
void TimerToolBar::OnFocus(wxFocusEvent &event)
{
KeyboardCapture::OnFocus(*this, event);
}
void TimerToolBar::OnCaptureKey(wxCommandEvent &event)
{
wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
wxWindow *w = FindFocus();
int keyCode = kevent->GetKeyCode();
// Convert numeric keypad entries.
if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) {
keyCode -= WXK_NUMPAD0 - '0';
}
if (keyCode >= '0' && keyCode <= '9') {
return;
}
event.Skip();
}
void TimerToolBar::SetDocked(ToolDock *dock, bool pushed) {
ToolBar::SetDocked(dock, pushed);
Fit();
}
void TimerToolBar::OnSnapTo(wxCommandEvent & WXUNUSED(event))
{
mListener->AS_SetSnapTo(mSnapTo->GetSelection());
}
static RegisteredToolbarFactory factory{ TimerBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew TimerToolBar{ project } }; }
};

View File

@@ -0,0 +1,63 @@
/**********************************************************************
Audacity: A Digital Audio Editor
TimerToolBar.h
Jonatã Bolzan Loss
**********************************************************************/
#ifndef __AUDACITY_BIG_COUNTER__
#define __AUDACITY_BIG_COUNTER__
#include <wx/defs.h>
#include "ToolBar.h"
#include "ToolManager.h"
class SelectionBarListener;
class NumericTextCtrl;
class TimerToolBar final : public ToolBar {
public:
TimerToolBar(AudacityProject &project);
virtual ~TimerToolBar();
static TimerToolBar &Get(AudacityProject &project);
static const TimerToolBar &Get(const AudacityProject &project);
void Create(wxWindow *parent) override;
void Populate() override;
void Repaint(wxDC * WXUNUSED(dc)) override {};
void EnableDisableButtons() override {};
void UpdatePrefs() override;
void SetTimes(double audio);
void RegenerateTooltips() override {};
private:
NumericTextCtrl * AddTime( const TranslatableString &Name, int id);
void OnFocus(wxFocusEvent &event);
void OnCaptureKey(wxCommandEvent &event);
void OnSize(wxSizeEvent &evt);
void OnSnapTo(wxCommandEvent & event);
virtual void SetDocked(ToolDock *dock, bool pushed) override;
SelectionBarListener * mListener;
double mRate;
double mAudio;
NumericTextCtrl *mAudioTime;
wxChoice *mSnapTo;
public:
DECLARE_CLASS(TimerToolBar)
DECLARE_EVENT_TABLE()
};
#endif

View File

@@ -68,6 +68,7 @@ enum
{
NoBarID = -1,
TransportBarID,
TimerBarID,
ToolsBarID,
MeterBarID,
RecordMeterBarID,

View File

@@ -178,7 +178,7 @@ void ToolFrame::OnPaint( wxPaintEvent & WXUNUSED(event) )
dc.SetPen( theTheme.Colour( clrTrackPanelText) );
#if !defined(__WXMAC__)
wxBrush clearer( theTheme.Colour( clrMedium ));
dc.SetBackground( clearer );
dc.SetBackground( clearer );
dc.Clear();
dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc.DrawRectangle( 0, 0, sz.GetWidth(), sz.GetHeight() );
@@ -563,7 +563,7 @@ void ToolManager::Reset()
}
// Decide which dock.
if (ndx == SelectionBarID
if (ndx == SelectionBarID
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|| ndx == SpectralSelectionBarID
#endif
@@ -631,7 +631,7 @@ void ToolManager::Reset()
// This bar is undocked and invisible.
// We are doing a reset toolbars, so even the invisible undocked bars should
// be moved somewhere sensible. Put bar near center of window.
// If there were multiple hidden toobars the ndx * 10 adjustment means
// If there were multiple hidden toobars the ndx * 10 adjustment means
// they won't overlap too much.
floater->CentreOnParent( );
floater->Move( floater->GetPosition() + wxSize( ndx * 10 - 200, ndx * 10 ));
@@ -721,7 +721,7 @@ void ToolManager::ReadConfig()
{
ToolBar *bar = mBars[ ndx ].get();
//wxPoint Center = mParent->GetPosition() + (mParent->GetSize() * 0.33);
//wxPoint Center(
//wxPoint Center(
// wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) /2 ,
// wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) /2 );
@@ -730,18 +730,20 @@ void ToolManager::ReadConfig()
bool bShownByDefault = true;
int defaultDock = TopDockID;
if( ndx == SelectionBarID )
defaultDock = BotDockID;
if( ndx == MeterBarID )
bShownByDefault = false;
if( ndx == ScrubbingBarID )
bShownByDefault = false;
if( ndx == TimerBarID )
bShownByDefault = false;
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
if( ndx == SpectralSelectionBarID ){
defaultDock = BotDockID;
bShownByDefault = false; // Only show if asked for.
bShownByDefault = false; // Only show if asked for.
}
#endif
@@ -751,13 +753,13 @@ void ToolManager::ReadConfig()
gPrefs->Read( wxT("Dock"), &dock, -1); // legacy version of DockV2
else
gPrefs->Read( wxT("DockV2"), &dock, -1);
const bool found = (dock != -1);
if (found)
someFound = true;
if (!found)
dock = defaultDock;
ToolDock *d;
ToolBarConfiguration::Legacy *pLegacy;
switch(dock)
@@ -833,7 +835,7 @@ void ToolManager::ReadConfig()
#endif
// make a note of docked and hidden toolbars
if (!show[ndx])
dockedAndHidden.push_back(bar);
dockedAndHidden.push_back(bar);
if (!ordered)
{
@@ -955,7 +957,7 @@ void ToolManager::WriteConfig()
// its value is compatible with versions 2.1.3 to 2.2.1 which have this bug.
ToolDock* dock = bar->GetDock(); // dock for both shown and hidden toolbars
gPrefs->Write( wxT("DockV2"), static_cast<int>(dock == mTopDock ? TopDockID : dock == mBotDock ? BotDockID : NoDockID ));
gPrefs->Write( wxT("Dock"), static_cast<int>( to ? TopDockID : bo ? BotDockID : NoDockID));
dock = to ? mTopDock : bo ? mBotDock : nullptr; // dock for shown toolbars
@@ -1184,11 +1186,11 @@ void ToolManager::OnMouse( wxMouseEvent & event )
br.SetPosition( mBotDock->GetParent()->ClientToScreen( br.GetPosition() ) );
// Add half the bar height. We could use the actual bar height, but that would be confusing as a
// Add half the bar height. We could use the actual bar height, but that would be confusing as a
// bar removed at a place might not dock back there if just let go.
// Also add 5 pixels in horizontal direction, so that a click without a move (or a very small move)
// Also add 5 pixels in horizontal direction, so that a click without a move (or a very small move)
// lands back where we started.
pos += wxPoint( 5, 20 );
pos += wxPoint( 5, 20 );
// To find which dock, rather than test against pos, test against the whole dragger rect.