Audacity  2.2.2
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
LabelTrack Class Referencefinal

A LabelTrack is a Track that holds labels (LabelStruct). More...

#include <LabelTrack.h>

Inheritance diagram for LabelTrack:
Track CommonTrackPanelCell XMLTagHandler TrackPanelCell

Classes

struct  Flags
 

Public Types

using Holder = std::unique_ptr< LabelTrack >
 
- Public Types inherited from Track
enum  { LeftChannel = 0, RightChannel = 1, MonoChannel = 2 }
 
enum  TrackKindEnum {
  None, Wave, Label, Time,
  All
}
 
enum  : unsigned { DefaultHeight = 150 }
 
using Holder = std::unique_ptr< Track >
 

Public Member Functions

bool IsGoodLabelFirstKey (const wxKeyEvent &evt)
 Returns true for keys we capture to start a label. More...
 
bool IsGoodLabelEditKey (const wxKeyEvent &evt)
 This returns true for keys we capture for label editing. More...
 
bool IsTextSelected ()
 
void CreateCustomGlyphs ()
 
 LabelTrack (const std::shared_ptr< DirManager > &projDirManager)
 
 LabelTrack (const LabelTrack &orig)
 
virtual ~LabelTrack ()
 
std::vector< UIHandlePtrDetailedHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool) override
 
bool DoCaptureKey (wxKeyEvent &event)
 
unsigned CaptureKey (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent) override
 
unsigned KeyDown (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent) override
 
unsigned Char (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent) override
 
void SetOffset (double dOffset) override
 
void Draw (TrackPanelDrawingContext &context, const wxRect &r, const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo) const
 
int getSelectedIndex () const
 
int GetKind () const override
 
double GetOffset () const override
 
double GetStartTime () const override
 
double GetEndTime () const override
 
Track::Holder Duplicate () const override
 
void SetSelected (bool s) override
 
bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
XMLTagHandlerHandleXMLChild (const wxChar *tag) override
 
void WriteXML (XMLWriter &xmlFile) const override
 
Track::Holder Cut (double t0, double t1) override
 
Track::Holder Copy (double t0, double t1, bool forClipboard=true) const override
 
void Clear (double t0, double t1) override
 
void Paste (double t, const Track *src) override
 
bool Repeat (double t0, double t1, int n)
 
void Silence (double t0, double t1) override
 
void InsertSilence (double t, double len) override
 
void OverGlyph (LabelTrackHit &hit, int x, int y) const
 
void ResetFlags ()
 
Flags SaveFlags () const
 
void RestoreFlags (const Flags &flags)
 
int OverATextBox (int xx, int yy) const
 
bool OverTextBox (const LabelStruct *pLabel, int x, int y) const
 
bool CutSelectedText ()
 
bool CopySelectedText ()
 
bool PasteSelectedText (double sel0, double sel1)
 
void HandleGlyphClick (LabelTrackHit &hit, const wxMouseEvent &evt, const wxRect &r, const ZoomInfo &zoomInfo, SelectedRegion *newSel)
 
void HandleTextClick (const wxMouseEvent &evt, const wxRect &r, const ZoomInfo &zoomInfo, SelectedRegion *newSel)
 
bool HandleGlyphDragRelease (LabelTrackHit &hit, const wxMouseEvent &evt, wxRect &r, const ZoomInfo &zoomInfo, SelectedRegion *newSel)
 
void HandleTextDragRelease (const wxMouseEvent &evt)
 
bool OnKeyDown (SelectedRegion &sel, wxKeyEvent &event)
 KeyEvent is called for every keypress when over the label track. More...
 
bool OnChar (SelectedRegion &sel, wxKeyEvent &event)
 
void Import (wxTextFile &f)
 Import labels, handling files with or without end-times. More...
 
void Export (wxTextFile &f) const
 Export labels including label start and end-times. More...
 
void Unselect ()
 
bool IsSelected () const
 
int GetNumLabels () const
 
const LabelStructGetLabel (int index) const
 
int AddLabel (const SelectedRegion &region, const wxString &title=wxT(""), int restoreFocus=-1)
 
int GetLabelIndex (double t, double t1)
 
void DeleteLabel (int index)
 
bool CalcCursorX (int *x) const
 
void CalcHighlightXs (int *x1, int *x2) const
 
void MayAdjustLabel (LabelTrackHit &hit, int iLabel, int iEdge, bool bAllowSwapping, double fNewTime)
 
void MayMoveLabel (int iLabel, int iEdge, double fNewTime)
 
bool PasteOver (double t, const Track *src)
 
void ShiftLabelsOnInsert (double length, double pt)
 
void ChangeLabelsOnReverse (double b, double e)
 
void ScaleLabels (double b, double e, double change)
 
double AdjustTimeStampOnScale (double t, double b, double e, double change)
 
void WarpLabels (const TimeWarper &warper)
 
wxString GetTextOfLabels (double t0, double t1) const
 
int FindNextLabel (const SelectedRegion &currentSelection)
 
int FindPrevLabel (const SelectedRegion &currentSelection)
 
void SortLabels (LabelTrackHit *pHit=nullptr)
 
int FindCurrentCursorPosition (int xPos)
 
void SetCurrentCursorPosition (int xPos)
 Set the cursor position according to x position of mouse. More...
 
- Public Member Functions inherited from Track
TrackId GetId () const
 
std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &, const AudacityProject *pProject) finaloverride
 
std::shared_ptr< TrackPanelCellGetTrackControl ()
 
std::shared_ptr< TrackPanelCellGetVRulerControl ()
 
std::shared_ptr< TrackPanelCellGetResizer ()
 
virtual int GetMinimizedHeight () const
 
int GetActualHeight () const
 
int GetIndex () const
 
void SetIndex (int index)
 
int GetY () const
 
int GetHeight () const
 
void SetHeight (int h)
 
bool GetMinimized () const
 
void SetMinimized (bool isMinimized)
 
TrackGetLink () const
 
 Track (const std::shared_ptr< DirManager > &projDirManager)
 
 Track (const Track &orig)
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual void Merge (const Track &orig)
 
wxString GetName () const
 
void SetName (const wxString &n)
 
wxString GetDefaultName () const
 
void SetDefaultName (const wxString &n)
 
bool GetSelected () const
 
bool GetLinked () const
 
void SetLinked (bool l)
 
virtual int GetChannel () const
 
void Offset (double t)
 
void SetChannel (int c)
 
virtual void SetPan (float)
 
virtual void SetPanFromChannelType ()
 
const std::shared_ptr
< DirManager > & 
GetDirManager () const
 
virtual Holder Cut (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual Holder Copy (double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard=true) const =0
 
virtual void Clear (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual void Paste (double WXUNUSED(t), const Track *WXUNUSED(src))=0
 
virtual void SyncLockAdjust (double oldT1, double newT1)
 
virtual void Silence (double WXUNUSED(t0), double WXUNUSED(t1))=0
 
virtual void InsertSilence (double WXUNUSED(t), double WXUNUSED(len))=0
 
virtual bool GetErrorOpening ()
 
bool IsSyncLockSelected () const
 
- Public Member Functions inherited from CommonTrackPanelCell
 CommonTrackPanelCell ()
 
virtual ~CommonTrackPanelCell ()=0
 
- Public Member Functions inherited from TrackPanelCell
virtual ~TrackPanelCell ()=0
 
virtual unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, wxPoint *pPosition)
 
virtual unsigned KeyUp (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent)
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Static Public Member Functions

static wxFont GetFont (const wxString &faceName, int size=DefaultFontSize)
 
static void ResetFont ()
 
static wxBitmap & GetGlyph (int i)
 
static bool IsTextClipSupported ()
 
- Static Public Member Functions inherited from Track
template<typename Subclass = Track>
static std::shared_ptr< Subclass > Pointer (Track *t)
 
template<typename Subclass = const Track>
static std::shared_ptr< Subclass > Pointer (const Track *t)
 

Static Public Attributes

static const int DefaultFontSize = 12
 

Protected Member Functions

std::shared_ptr< TrackControlsGetControls () override
 
std::shared_ptr
< TrackVRulerControls
GetVRulerControls () override
 
- Protected Member Functions inherited from Track
virtual void DoSetHeight (int h)
 
virtual void DoSetMinimized (bool isMinimized)
 
std::shared_ptr< TrackFindTrack () override
 
- Protected Member Functions inherited from CommonTrackPanelCell
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 

Private Member Functions

void ShowContextMenu ()
 
void OnContextMenu (wxCommandEvent &evt)
 
void ComputeLayout (const wxRect &r, const ZoomInfo &zoomInfo) const
 
void ComputeTextPosition (const wxRect &r, int index) const
 
void calculateFontHeight (wxDC &dc) const
 
void RemoveSelectedText ()
 

Private Attributes

int mSelIndex
 
int mxMouseDisplacement
 Keeps track of the currently selected label. More...
 
LabelArray mLabels
 Displacement of mouse cursor from the centre being dragged. More...
 
int mCurrentCursorPos
 
int mInitialCursorPos
 current cursor position More...
 
bool mRightDragging
 initial cursor position More...
 
bool mDrawCursor
 flag to tell if it's a valid dragging More...
 
int mRestoreFocus
 cursor or not More...
 
double mClipLen
 when done editing More...
 
int miLastLabel
 
std::weak_ptr< LabelGlyphHandlemGlyphHandle
 
std::weak_ptr< LabelTextHandlemTextHandle
 

Static Private Attributes

static int mIconHeight
 
static int mIconWidth
 
static int mTextHeight
 
static bool mbGlyphsReady =false
 
static wxBitmap mBoundaryGlyphs [NUM_GLYPH_CONFIGS *NUM_GLYPH_HIGHLIGHTS]
 
static int mFontHeight =-1
 
static wxFont msFont
 

Friends

class LabelStruct
 
class GetInfoCommand
 
class SetLabelCommand
 

Additional Inherited Members

- Public Attributes inherited from Track
wxSize vrulerSize
 
- Protected Attributes inherited from Track
std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 
int mIndex
 
int mY
 
int mHeight
 
wxString mName
 
wxString mDefaultName
 
bool mSelected
 
bool mLinked
 
bool mMinimized
 
int mChannel
 
double mOffset
 
std::shared_ptr< DirManagermDirManager
 
std::shared_ptr< TrackControlsmpControls
 
std::shared_ptr
< TrackVRulerControls
mpVRulerContols
 
std::shared_ptr
< TrackPanelResizerCell
mpResizer
 
std::weak_ptr< SelectHandlemSelectHandle
 
std::weak_ptr< TimeShiftHandlemTimeShiftHandle
 

Detailed Description

A LabelTrack is a Track that holds labels (LabelStruct).

These are used to annotate a waveform. Each label has a start time and an end time. The text of the labels is editable and the positions of the end points are draggable.

Definition at line 113 of file LabelTrack.h.

Member Typedef Documentation

using LabelTrack::Holder = std::unique_ptr<LabelTrack>

Definition at line 162 of file LabelTrack.h.

Constructor & Destructor Documentation

LabelTrack::LabelTrack ( const std::shared_ptr< DirManager > &  projDirManager)

Definition at line 104 of file LabelTrack.cpp.

References _(), CreateCustomGlyphs(), Track::GetDefaultName(), ResetFlags(), ResetFont(), Track::SetDefaultName(), Track::SetHeight(), and Track::SetName().

104  :
105  Track(projDirManager),
106  mSelIndex(-1),
107  mRestoreFocus(-1),
108  mClipLen(0.0),
109  miLastLabel(-1)
110 {
111  SetDefaultName(_("Label Track"));
113 
114  // Label tracks are narrow
115  // Default is to allow two rows so that NEW users get the
116  // idea that labels can 'stack' when they would overlap.
117  SetHeight(73);
118 
119  ResetFont();
121 
122  // reset flags
123  ResetFlags();
124 }
void SetHeight(int h)
Definition: Track.cpp:189
int miLastLabel
Definition: LabelTrack.h:303
static void ResetFont()
Definition: LabelTrack.cpp:296
wxString GetDefaultName() const
Definition: Track.h:273
double mClipLen
when done editing
Definition: LabelTrack.h:301
int mSelIndex
Definition: LabelTrack.h:280
int mRestoreFocus
cursor or not
Definition: LabelTrack.h:297
void SetDefaultName(const wxString &n)
Definition: Track.h:274
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Track(const std::shared_ptr< DirManager > &projDirManager)
Definition: Track.cpp:55
void SetName(const wxString &n)
Definition: Track.h:272
void CreateCustomGlyphs()
void ResetFlags()
Definition: LabelTrack.cpp:268
LabelTrack::LabelTrack ( const LabelTrack orig)

Definition at line 126 of file LabelTrack.cpp.

References mLabels, mSelIndex, ResetFlags(), and LabelStruct::selectedRegion.

126  :
127  Track(orig),
128  mSelIndex(-1),
129  mClipLen(0.0)
130 {
131  for (auto &original: orig.mLabels) {
132  LabelStruct l { original.selectedRegion, original.title };
133  mLabels.push_back(l);
134  }
135  mSelIndex = orig.mSelIndex;
136 
137  // reset flags
138  ResetFlags();
139 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
double mClipLen
when done editing
Definition: LabelTrack.h:301
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
int mSelIndex
Definition: LabelTrack.h:280
Track(const std::shared_ptr< DirManager > &projDirManager)
Definition: Track.cpp:55
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
void ResetFlags()
Definition: LabelTrack.cpp:268
LabelTrack::~LabelTrack ( )
virtual

Definition at line 141 of file LabelTrack.cpp.

142 {
143 }

Member Function Documentation

int LabelTrack::AddLabel ( const SelectedRegion region,
const wxString &  title = wxT(""),
int  restoreFocus = -1 
)

Definition at line 2734 of file LabelTrack.cpp.

References mCurrentCursorPos, mDrawCursor, mInitialCursorPos, mRestoreFocus, mSelIndex, and SelectedRegion::t0().

Referenced by AudacityProject::DoAddLabel(), OnChar(), AudacityProject::OnPasteNewLabel(), PasteSelectedText(), EffectFindClipping::ProcessOne(), and NyquistEffect::ProcessOne().

2736 {
2737  LabelStruct l { selectedRegion, title };
2738  mInitialCursorPos = mCurrentCursorPos = title.length();
2739 
2740  int len = mLabels.size();
2741  int pos = 0;
2742 
2743  while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
2744  pos++;
2745 
2746  mLabels.insert(mLabels.begin() + pos, l);
2747 
2748  // restoreFocus is -2 e.g. from Nyquist label creation, when we should not
2749  // even lose the focus and open the label to edit in the first place.
2750  // -1 means we don't need to restore it to anywhere.
2751  // 0 or above is the track to restore to afetr editing the label is complete.
2752  if( restoreFocus >= -1 )
2753  mSelIndex = pos;
2754 
2755  // Make sure the caret is visible
2756  //
2757  // LLL: The cursor will not be drawn when the first label
2758  // is added since mDrawCursor will be false. Presumably,
2759  // if the user adds a label, then a cursor should be drawn
2760  // to indicate that typing is expected.
2761  //
2762  // If the label is added during actions like import, then the
2763  // mDrawCursor flag will be reset once the action is complete.
2764  mDrawCursor = true;
2765 
2766  mRestoreFocus = restoreFocus;
2767 
2768  return pos;
2769 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
int mSelIndex
Definition: LabelTrack.h:280
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
int mRestoreFocus
cursor or not
Definition: LabelTrack.h:297
double LabelTrack::AdjustTimeStampOnScale ( double  t,
double  b,
double  e,
double  change 
)

Definition at line 237 of file LabelTrack.cpp.

Referenced by ScaleLabels().

238 {
239 //t is the time stamp we'll be changing
240 //b and e are the selection start and end
241 
242  if (t < b){
243  return t;
244  }else if (t > e){
245  double shift = (e-b)*change - (e-b);
246  return t + shift;
247  }else{
248  double shift = (t-b)*change - (t-b);
249  return t + shift;
250  }
251 }
bool LabelTrack::CalcCursorX ( int *  x) const

Definition at line 723 of file LabelTrack.cpp.

References mCurrentCursorPos, mIconWidth, mLabels, mSelIndex, and msFont.

Referenced by AudacityProject::HandlePasteText(), KeyDown(), and ShowContextMenu().

724 {
725  if (mSelIndex >= 0) {
726  wxMemoryDC dc;
727 
728  if (msFont.Ok()) {
729  dc.SetFont(msFont);
730  }
731 
732  mLabels[mSelIndex].getXPos(dc, x, mCurrentCursorPos);
733  *x += LabelTrack::mIconWidth / 2;
734  return true;
735  }
736 
737  return false;
738 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
static int mIconWidth
Definition: LabelTrack.h:285
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
static wxFont msFont
Definition: LabelTrack.h:316
void LabelTrack::CalcHighlightXs ( int *  x1,
int *  x2 
) const

Definition at line 740 of file LabelTrack.cpp.

References mCurrentCursorPos, mInitialCursorPos, mLabels, mSelIndex, and msFont.

Referenced by HandleTextClick().

741 {
742  wxMemoryDC dc;
743 
744  if (msFont.Ok()) {
745  dc.SetFont(msFont);
746  }
747 
748  int pos1 = mInitialCursorPos, pos2 = mCurrentCursorPos;
749  if (pos1 > pos2)
750  std::swap(pos1, pos2);
751 
752  const auto &labelStruct = mLabels[mSelIndex];
753 
754  // find the left X pos of highlighted area
755  labelStruct.getXPos(dc, x1, pos1);
756  // find the right X pos of highlighted area
757  labelStruct.getXPos(dc, x2, pos2);
758 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
static wxFont msFont
Definition: LabelTrack.h:316
void LabelTrack::calculateFontHeight ( wxDC &  dc) const
private

Definition at line 964 of file LabelTrack.cpp.

References mFontHeight.

965 {
966  int charDescent;
967  int charLeading;
968 
969  // Calculate the width of the substring and add it to Xpos
970  dc.GetTextExtent(wxT("(Test String)|[yp]"), NULL, &mFontHeight, &charDescent, &charLeading);
971 
972  // The cursor will have height charHeight. We don't include the descender as
973  // part of the height because for phonetic fonts this leads to cursors which are
974  // too tall. We don't include leading either - it is usually 0.
975  // To make up for ignoring the descender height, we add one pixel above and below
976  // using CursorExtraHeight so that the cursor is just a little taller than the
977  // body of the characters.
978  const int CursorExtraHeight=2;
979  mFontHeight += CursorExtraHeight - (charLeading+charDescent);
980 }
static int mFontHeight
Definition: LabelTrack.h:290
unsigned LabelTrack::CaptureKey ( wxKeyEvent &  event,
ViewInfo viewInfo,
wxWindow *  pParent 
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 1779 of file LabelTrack.cpp.

References DoCaptureKey(), and RefreshCode::RefreshNone.

1780 {
1781  event.Skip(!DoCaptureKey(event));
1782  return RefreshCode::RefreshNone;
1783 }
bool DoCaptureKey(wxKeyEvent &event)
void LabelTrack::ChangeLabelsOnReverse ( double  b,
double  e 
)

Definition at line 213 of file LabelTrack.cpp.

References mLabels, SortLabels(), and LabelStruct::SURROUNDS_LABEL.

Referenced by EffectReverse::Process().

214 {
215  for (auto &labelStruct: mLabels) {
216  if (labelStruct.RegionRelation(b, e, this) ==
218  {
219  double aux = b + (e - labelStruct.getT1());
220  labelStruct.selectedRegion.setTimes(
221  aux,
222  e - (labelStruct.getT0() - b));
223  }
224  }
225  SortLabels();
226 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void SortLabels(LabelTrackHit *pHit=nullptr)
unsigned LabelTrack::Char ( wxKeyEvent &  event,
ViewInfo viewInfo,
wxWindow *  pParent 
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 1817 of file LabelTrack.cpp.

References _(), CONSOLIDATE, GetActiveProject(), OnChar(), AudacityProject::PushState(), RefreshCode::RefreshAll, RefreshCode::RefreshCell, RefreshCode::RefreshNone, ViewInfo::selectedRegion, SelectedRegion::t0(), and SelectedRegion::t1().

1818 {
1819  double bkpSel0 = viewInfo.selectedRegion.t0(),
1820  bkpSel1 = viewInfo.selectedRegion.t1();
1821  // Pass keystroke to labeltrack's handler and add to history if any
1822  // updates were done
1823 
1824  AudacityProject *const pProj = GetActiveProject();
1825 
1826  if (OnChar(viewInfo.selectedRegion, event))
1827  pProj->PushState(_("Modified Label"),
1828  _("Label Edit"),
1830 
1831  // If selection modified, refresh
1832  // Otherwise, refresh track display if the keystroke was handled
1833  if (bkpSel0 != viewInfo.selectedRegion.t0() ||
1834  bkpSel1 != viewInfo.selectedRegion.t1())
1835  return RefreshCode::RefreshAll;
1836  else if (!event.GetSkipped())
1837  return RefreshCode::RefreshCell;
1838 
1839  return RefreshCode::RefreshNone;
1840 }
bool OnChar(SelectedRegion &sel, wxKeyEvent &event)
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
double t1() const
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void LabelTrack::Clear ( double  t0,
double  t1 
)
override

Definition at line 151 of file LabelTrack.cpp.

References LabelStruct::BEFORE_LABEL, LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, mLabels, LabelStruct::SURROUNDS_LABEL, and LabelStruct::WITHIN_LABEL.

Referenced by Cut().

152 {
153  // May DELETE labels, so use subscripts to iterate
154  for (size_t i = 0; i < mLabels.size(); ++i) {
155  auto &labelStruct = mLabels[i];
156  LabelStruct::TimeRelations relation =
157  labelStruct.RegionRelation(b, e, this);
158  if (relation == LabelStruct::BEFORE_LABEL)
159  labelStruct.selectedRegion.move(- (e-b));
160  else if (relation == LabelStruct::SURROUNDS_LABEL) {
161  DeleteLabel( i );
162  --i;
163  }
164  else if (relation == LabelStruct::ENDS_IN_LABEL)
165  labelStruct.selectedRegion.setTimes(
166  b,
167  labelStruct.getT1() - (e - b));
168  else if (relation == LabelStruct::BEGINS_IN_LABEL)
169  labelStruct.selectedRegion.setT1(b);
170  else if (relation == LabelStruct::WITHIN_LABEL)
171  labelStruct.selectedRegion.moveT1( - (e-b));
172  }
173 }
void DeleteLabel(int index)
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:73
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void LabelTrack::ComputeLayout ( const wxRect &  r,
const ZoomInfo zoomInfo 
) const
private

ComputeLayout determines which row each label should be placed on, and reserves space for it. Function assumes that the labels are sorted.

Definition at line 461 of file LabelTrack.cpp.

References ComputeTextPosition(), MAX_NUM_ROWS, mIconHeight, mIconWidth, mLabels, mTextHeight, and ZoomInfo::TimeToPosition().

462 {
463  int xUsed[MAX_NUM_ROWS];
464 
465  int iRow;
466  // Rows are the 'same' height as icons or as the text,
467  // whichever is taller.
468  const int yRowHeight = wxMax(mTextHeight,mIconHeight)+3;// pixels.
469  // Extra space at end of rows.
470  // We allow space for one half icon at the start and two
471  // half icon widths for extra x for the text frame.
472  // [we don't allow half a width space for the end icon since it is
473  // allowed to be obscured by the text].
474  const int xExtra= (3 * mIconWidth)/2;
475 
476  const int nRows = wxMin((r.height / yRowHeight) + 1, MAX_NUM_ROWS);
477  // Initially none of the rows have been used.
478  // So set a value that is less than any valid value.
479  {
480  // Bug 502: With dragging left of zeros, labels can be in
481  // negative space. So set least possible value as starting point.
482  const int xStart = INT_MIN;
483  for (auto &x : xUsed)
484  x = xStart;
485  }
486  int nRowsUsed=0;
487 
488  { int i = -1; for (auto &labelStruct : mLabels) { ++i;
489  const int x = zoomInfo.TimeToPosition(labelStruct.getT0(), r.x);
490  const int x1 = zoomInfo.TimeToPosition(labelStruct.getT1(), r.x);
491  int y = r.y;
492 
493  labelStruct.x=x;
494  labelStruct.x1=x1;
495  labelStruct.y=-1;// -ve indicates nothing doing.
496  iRow=0;
497  // Our first preference is a row that ends where we start.
498  // (This is to encourage merging of adjacent label boundaries).
499  while( (iRow<nRowsUsed) && (xUsed[iRow] != x ))
500  iRow++;
501  // IF we didn't find one THEN
502  // find any row that can take a span starting at x.
503  if( iRow >= nRowsUsed )
504  {
505  iRow=0;
506  while( (iRow<nRows) && (xUsed[iRow] > x ))
507  iRow++;
508  }
509  // IF we found such a row THEN record a valid position.
510  if( iRow<nRows )
511  {
512  // Possibly update the number of rows actually used.
513  if( iRow >= nRowsUsed )
514  nRowsUsed=iRow+1;
515  // Record the position for this label
516  y= r.y + iRow * yRowHeight +(yRowHeight/2)+1;
517  labelStruct.y=y;
518  // On this row we have used up to max of end marker and width.
519  // Plus also allow space to show the start icon and
520  // some space for the text frame.
521  xUsed[iRow]=x+labelStruct.width+xExtra;
522  if( xUsed[iRow] < x1 ) xUsed[iRow]=x1;
523  ComputeTextPosition( r, i );
524  }
525  }}
526 }
static int mIconHeight
Definition: LabelTrack.h:284
const int MAX_NUM_ROWS
Definition: LabelTrack.h:108
static int mIconWidth
Definition: LabelTrack.h:285
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void ComputeTextPosition(const wxRect &r, int index) const
Definition: LabelTrack.cpp:317
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ViewInfo.cpp:59
static int mTextHeight
Definition: LabelTrack.h:286
void LabelTrack::ComputeTextPosition ( const wxRect &  r,
int  index 
) const
private

ComputeTextPosition is 'smart' about where to display the label text.

The text must be displayed between its endpoints x and x1 We'd also like it centered between them, and we'd like it on screen. It isn't always possible to achieve all of this, so we do the best we can.

This function has a number of tests and adjustments to the text start position. The tests later in the function will take priority over the ones earlier, so because centering is the first thing we do, it's the first thing we lose if we can't do everything we want to.

Definition at line 317 of file LabelTrack.cpp.

References mIconWidth, and mLabels.

Referenced by ComputeLayout().

318 {
319  auto &labelStruct = mLabels[index];
320 
321  // xExtra is extra space
322  // between the text and the endpoints.
323  const int xExtra=mIconWidth;
324  int x = labelStruct.x; // left endpoint
325  int x1 = labelStruct.x1; // right endpoint.
326  int width = labelStruct.width;
327 
328  int xText; // This is where the text will end up.
329 
330  // Will the text all fit at this zoom?
331  bool bTooWideForScreen = width > (r.width-2*xExtra);
332 // bool bSimpleCentering = !bTooWideForScreen;
333  bool bSimpleCentering = false;
334 
335  //TODO (possibly):
336  // Add configurable options as to when to use simple
337  // and when complex centering.
338  //
339  // Simple centering does its best to keep the text
340  // centered between the label limits.
341  //
342  // Complex centering positions the text proportionally
343  // to how far we are through the label.
344  //
345  // If we add preferences for this, we want to be able to
346  // choose separately whether:
347  // a) Wide text labels centered simple/complex.
348  // b) Other text labels centered simple/complex.
349  //
350 
351  if( bSimpleCentering )
352  {
353  // Center text between the two end points.
354  xText = (x+x1-width)/2;
355  }
356  else
357  {
358  // Calculate xText position to make text line
359  // scroll sideways evenly as r moves right.
360 
361  // xText is a linear function of r.x.
362  // These variables are used to compute that function.
363  int rx0,rx1,xText0,xText1;
364 
365  // Since we will be using a linear function,
366  // we should blend smoothly between left and right
367  // aligned text as r, the 'viewport' moves.
368  if( bTooWideForScreen )
369  {
370  rx0=x; // when viewport at label start.
371  xText0=x+xExtra; // text aligned left.
372  rx1=x1-r.width; // when viewport end at label end
373  xText1=x1-(width+xExtra); // text aligned right.
374  }
375  else
376  {
377  // when label start + width + extra spacing at viewport end..
378  rx0=x-r.width+width+2*xExtra;
379  // ..text aligned left.
380  xText0=x+xExtra;
381  // when viewport start + width + extra spacing at label end..
382  rx1=x1-(width+2*xExtra);
383  // ..text aligned right.
384  xText1=x1-(width+xExtra);
385  }
386 
387  if( rx1 > rx0 ) // Avoid divide by zero case.
388  {
389  // Compute the blend between left and right aligned.
390 
391  // Don't use:
392  //
393  // xText = xText0 + ((xText1-xText0)*(r.x-rx0))/(rx1-rx0);
394  //
395  // The problem with the above is that it integer-oveflows at
396  // high zoom.
397 
398  // Instead use:
399  xText = xText0 + (int)((xText1-xText0)*(((float)(r.x-rx0))/(rx1-rx0)));
400  }
401  else
402  {
403  // Avoid divide by zero by reverting to
404  // simple centering.
405  //
406  // We could also fall into this case if x and x1
407  // are swapped, in which case we'll end up
408  // left aligned anyway because code later on
409  // will catch that.
410  xText = (x+x1-width)/2;
411  }
412  }
413 
414  // Is the text now appearing partly outside r?
415  bool bOffLeft = xText < r.x+xExtra;
416  bool bOffRight = xText > r.x+r.width-width-xExtra;
417 
418  // IF any part of the text is offscreen
419  // THEN we may bring it back.
420  if( bOffLeft == bOffRight )
421  {
422  //IF both sides on screen, THEN nothing to do.
423  //IF both sides off screen THEN don't do
424  //anything about it.
425  //(because if we did, you'd never get to read
426  //all the text by scrolling).
427  }
428  else if( bOffLeft != bTooWideForScreen)
429  {
430  // IF we're off on the left, OR we're
431  // too wide for the screen and off on the right
432  // (only) THEN align left.
433  xText = r.x+xExtra;
434  }
435  else
436  {
437  // We're off on the right, OR we're
438  // too wide and off on the left (only)
439  // SO align right.
440  xText =r.x+r.width-width-xExtra;
441  }
442 
443  // But if we've taken the text out from its endpoints
444  // we must move it back so that it's between the endpoints.
445 
446  // We test the left end point last because the
447  // text might not even fit between the endpoints (at this
448  // zoom factor), and in that case we'd like to position
449  // the text at the left end point.
450  if( xText > (x1-width-xExtra))
451  xText=(x1-width-xExtra);
452  if( xText < x+xExtra )
453  xText=x+xExtra;
454 
455  labelStruct.xText = xText;
456 }
static int mIconWidth
Definition: LabelTrack.h:285
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
Track::Holder LabelTrack::Copy ( double  t0,
double  t1,
bool  forClipboard = true 
) const
override

Definition at line 2496 of file LabelTrack.cpp.

References LabelStruct::BEGINS_IN_LABEL, LabelStruct::ENDS_IN_LABEL, Track::GetDirManager(), LabelStruct::selectedRegion, LabelStruct::SURROUNDS_LABEL, and LabelStruct::WITHIN_LABEL.

Referenced by Cut(), and Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack().

2497 {
2498  auto tmp = std::make_unique<LabelTrack>(GetDirManager());
2499  const auto lt = static_cast<LabelTrack*>(tmp.get());
2500 
2501  for (auto &labelStruct: mLabels) {
2502  LabelStruct::TimeRelations relation =
2503  labelStruct.RegionRelation(t0, t1, this);
2504  if (relation == LabelStruct::SURROUNDS_LABEL) {
2505  LabelStruct l {
2506  labelStruct.selectedRegion,
2507  labelStruct.getT0() - t0,
2508  labelStruct.getT1() - t0,
2509  labelStruct.title
2510  };
2511  lt->mLabels.push_back(l);
2512  }
2513  else if (relation == LabelStruct::WITHIN_LABEL) {
2514  LabelStruct l {
2515  labelStruct.selectedRegion,
2516  0,
2517  t1-t0,
2518  labelStruct.title
2519  };
2520  lt->mLabels.push_back(l);
2521  }
2522  else if (relation == LabelStruct::BEGINS_IN_LABEL) {
2523  LabelStruct l {
2524  labelStruct.selectedRegion,
2525  0,
2526  labelStruct.getT1() - t0,
2527  labelStruct.title
2528  };
2529  lt->mLabels.push_back(l);
2530  }
2531  else if (relation == LabelStruct::ENDS_IN_LABEL) {
2532  LabelStruct l {
2533  labelStruct.selectedRegion,
2534  labelStruct.getT0() - t0,
2535  t1 - t0,
2536  labelStruct.title
2537  };
2538  lt->mLabels.push_back(l);
2539  }
2540  }
2541  lt->mClipLen = (t1 - t0);
2542 
2543  // This std::move is needed to "upcast" the pointer type
2544  return std::move(tmp);
2545 }
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:73
const std::shared_ptr< DirManager > & GetDirManager() const
Definition: Track.h:300
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
bool LabelTrack::CopySelectedText ( )

Copy the selected text in the text box

Returns
true if text is selected in text box, false otherwise

Definition at line 1035 of file LabelTrack.cpp.

References mCurrentCursorPos, mInitialCursorPos, mLabels, mSelIndex, and safenew.

Referenced by HandleTextDragRelease(), and OnContextMenu().

1036 {
1037  if (mSelIndex == -1)
1038  return false;
1039 
1040  const auto &labelStruct = mLabels[mSelIndex];
1041 
1042  int init = mInitialCursorPos;
1043  int cur = mCurrentCursorPos;
1044  if (init > cur)
1045  std::swap(init, cur);
1046 
1047  if (init == cur)
1048  return false;
1049 
1050  // data for copying
1051  wxString data = labelStruct.title.Mid(init, cur-init);
1052 
1053  // copy the data on clipboard
1054  if (wxTheClipboard->Open()) {
1055  // Clipboard owns the data you give it
1056  wxTheClipboard->SetData(safenew wxTextDataObject(data));
1057  wxTheClipboard->Close();
1058  }
1059 
1060  return true;
1061 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
#define safenew
Definition: Audacity.h:230
int mSelIndex
Definition: LabelTrack.h:280
void LabelTrack::CreateCustomGlyphs ( )

CreateCustomGlyphs() creates the mBoundaryGlyph array. It's a bit like painting by numbers!

Schematically the glyphs we want will 'look like': <O, O> and <O> for a left boundary to a label, a right boundary and both. we're creating all three glyphs using the one Xpm Spec.

When we hover over a glyph we highlight the inside of either the '<', the 'O' or the '>' or none, giving 3 x 4 = 12 combinations.

Two of those combinations aren't used, but treating them specially would make other code more complicated.

Definition at line 2850 of file LabelTrack.cpp.

References GlyphXpmRegionSpec, mbGlyphsReady, mBoundaryGlyphs, mIconHeight, mIconWidth, mTextHeight, NUM_GLYPH_CONFIGS, NUM_GLYPH_HIGHLIGHTS, and safenew.

Referenced by LabelTrack().

2851 {
2852  int iConfig;
2853  int iHighlight;
2854  int index;
2855  const int nSpecRows =
2856  sizeof( GlyphXpmRegionSpec )/sizeof( GlyphXpmRegionSpec[0]);
2857  const char *XmpBmp[nSpecRows];
2858 
2859  // The glyphs are declared static wxIcon; so we only need
2860  // to create them once, no matter how many LabelTracks.
2861  if( mbGlyphsReady )
2862  return;
2863 
2864  // We're about to tweak the basic color spec to get 12 variations.
2865  for( iConfig=0;iConfig<NUM_GLYPH_CONFIGS;iConfig++)
2866  {
2867  for( iHighlight=0;iHighlight<NUM_GLYPH_HIGHLIGHTS;iHighlight++)
2868  {
2869  index = iConfig + NUM_GLYPH_CONFIGS * iHighlight;
2870  // Copy the basic spec...
2871  memcpy( XmpBmp, GlyphXpmRegionSpec, sizeof( GlyphXpmRegionSpec ));
2872  // The higlighted region (if any) is white...
2873  if( iHighlight==1 ) XmpBmp[5]="5 c #FFFFFF";
2874  if( iHighlight==2 ) XmpBmp[6]="6 c #FFFFFF";
2875  if( iHighlight==3 ) XmpBmp[7]="7 c #FFFFFF";
2876  // For left or right arrow the other side of the glyph
2877  // is the transparent color.
2878  if( iConfig==0) { XmpBmp[3]="3 c none"; XmpBmp[5]="5 c none"; }
2879  if( iConfig==1) { XmpBmp[4]="4 c none"; XmpBmp[7]="7 c none"; }
2880  // Create the icon from the tweaked spec.
2881  mBoundaryGlyphs[index] = wxBitmap(XmpBmp);
2882  // Create the mask
2883  // SetMask takes ownership
2884  mBoundaryGlyphs[index].SetMask(safenew wxMask(mBoundaryGlyphs[index], wxColour(192, 192, 192)));
2885  }
2886  }
2887 
2888  mIconWidth = mBoundaryGlyphs[0].GetWidth();
2889  mIconHeight = mBoundaryGlyphs[0].GetHeight();
2890  mTextHeight = mIconHeight; // until proved otherwise...
2891  // The icon should have an odd width so that the
2892  // line goes exactly down the middle.
2893  wxASSERT( (mIconWidth %2)==1);
2894 
2895  mbGlyphsReady=true;
2896 }
static int mIconHeight
Definition: LabelTrack.h:284
static int mIconWidth
Definition: LabelTrack.h:285
#define safenew
Definition: Audacity.h:230
static const char *const GlyphXpmRegionSpec[]
const int NUM_GLYPH_CONFIGS
Definition: LabelTrack.h:106
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS *NUM_GLYPH_HIGHLIGHTS]
Definition: LabelTrack.h:288
static bool mbGlyphsReady
Definition: LabelTrack.h:287
const int NUM_GLYPH_HIGHLIGHTS
Definition: LabelTrack.h:107
static int mTextHeight
Definition: LabelTrack.h:286
Track::Holder LabelTrack::Cut ( double  t0,
double  t1 
)
override

Definition at line 2473 of file LabelTrack.cpp.

References Clear(), and Copy().

2474 {
2475  auto tmp = Copy(t0, t1);
2476 
2477  Clear(t0, t1);
2478 
2479  return tmp;
2480 }
void Clear(double t0, double t1) override
Definition: LabelTrack.cpp:151
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
bool LabelTrack::CutSelectedText ( )

Cut the selected text in the text box

Returns
true if text is selected in text box, false otherwise

Definition at line 993 of file LabelTrack.cpp.

References IsTextSelected(), mCurrentCursorPos, mInitialCursorPos, mLabels, mSelIndex, and safenew.

Referenced by OnContextMenu().

994 {
995  if (!IsTextSelected())
996  return false;
997 
998  wxString left, right;
999  auto &labelStruct = mLabels[mSelIndex];
1000  auto &text = labelStruct.title;
1001 
1002  int init = mInitialCursorPos;
1003  int cur = mCurrentCursorPos;
1004  if (init > cur)
1005  std::swap(init, cur);
1006 
1007  // data for cutting
1008  wxString data = text.Mid(init, cur - init);
1009 
1010  // get left-remaining text
1011  if (init > 0)
1012  left = text.Left(init);
1013 
1014  // get right-remaining text
1015  if (cur < (int)text.Length())
1016  right = text.Mid(cur);
1017 
1018  // set title to the combination of the two remainders
1019  text = left + right;
1020 
1021  // copy data onto clipboard
1022  if (wxTheClipboard->Open()) {
1023  // Clipboard owns the data you give it
1024  wxTheClipboard->SetData(safenew wxTextDataObject(data));
1025  wxTheClipboard->Close();
1026  }
1027 
1028  // set cursor positions
1029  mInitialCursorPos = mCurrentCursorPos = left.Length();
1030  return true;
1031 }
bool IsTextSelected()
Definition: LabelTrack.cpp:982
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
#define safenew
Definition: Audacity.h:230
int mSelIndex
Definition: LabelTrack.h:280
void LabelTrack::DeleteLabel ( int  index)

Definition at line 2771 of file LabelTrack.cpp.

References mCurrentCursorPos, and mSelIndex.

Referenced by Clear(), OnContextMenu(), OnKeyDown(), Silence(), and LabelDialog::TransferDataFromWindow().

2772 {
2773  wxASSERT((index < (int)mLabels.size()));
2774  mLabels.erase(mLabels.begin() + index);
2775  // IF we've deleted the selected label
2776  // THEN set no label selected.
2777  if( mSelIndex== index )
2778  {
2779  mSelIndex = -1;
2780  mCurrentCursorPos = 1;
2781  }
2782  // IF we removed a label before the selected label
2783  // THEN the NEW selected label number is one less.
2784  else if( index < mSelIndex )
2785  {
2786  mSelIndex--;
2787  }
2788 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
std::vector< UIHandlePtr > LabelTrack::DetailedHitTest ( const TrackPanelMouseState state,
const AudacityProject pProject,
int  currentTool,
bool  bMultiTool 
)
overridevirtual

Implements Track.

Definition at line 25 of file LabelTrackUI.cpp.

References LabelTextHandle::HitTest(), LabelGlyphHandle::HitTest(), TrackPanelMouseState::rect, and TrackPanelMouseState::state.

27 {
28  UIHandlePtr result;
29  std::vector<UIHandlePtr> results;
30  const wxMouseState &state = st.state;
31 
33  mGlyphHandle, state, Pointer<LabelTrack>(this), st.rect);
34  if (result)
35  results.push_back(result);
36 
37  result = LabelTextHandle::HitTest(
38  mTextHandle, state, Pointer<LabelTrack>(this));
39  if (result)
40  results.push_back(result);
41 
42  return results;
43 }
static UIHandlePtr HitTest(std::weak_ptr< LabelGlyphHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT, const wxRect &rect)
std::weak_ptr< LabelTextHandle > mTextHandle
Definition: LabelTrack.h:319
std::weak_ptr< LabelGlyphHandle > mGlyphHandle
Definition: LabelTrack.h:318
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
static UIHandlePtr HitTest(std::weak_ptr< LabelTextHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT)
bool LabelTrack::DoCaptureKey ( wxKeyEvent &  event)

Definition at line 1721 of file LabelTrack.cpp.

References gAudioIO, GetActiveProject(), AudacityProject::GetAudioIOToken(), GetLabelIndex(), AudacityProject::GetPlayRegion(), gPrefs, IsGoodLabelEditKey(), IsGoodLabelFirstKey(), AudioIO::IsStreamActive(), mLabels, mSelIndex, AudacityProject::mViewInfo, ViewInfo::selectedRegion, SelectedRegion::t0(), and SelectedRegion::t1().

Referenced by CaptureKey().

1722 {
1723  // Check for modifiers and only allow shift
1724  int mods = event.GetModifiers();
1725  if (mods != wxMOD_NONE && mods != wxMOD_SHIFT) {
1726  return false;
1727  }
1728 
1729  // Always capture the navigation keys, if we have any labels
1730  auto code = event.GetKeyCode();
1731  if ((code == WXK_TAB || code == WXK_NUMPAD_TAB) &&
1732  !mLabels.empty())
1733  return true;
1734 
1735  if (mSelIndex >= 0) {
1736  if (IsGoodLabelEditKey(event)) {
1737  return true;
1738  }
1739  }
1740  else {
1741  bool typeToCreateLabel;
1742  gPrefs->Read(wxT("/GUI/TypeToCreateLabel"), &typeToCreateLabel, true);
1743  if (IsGoodLabelFirstKey(event) && typeToCreateLabel) {
1744  AudacityProject * pProj = GetActiveProject();
1745 
1746 
1747 // The commented out code can prevent label creation, causing bug 1551
1748 // We should only be in DoCaptureKey IF this label track has focus,
1749 // and in that case creating a Label is the expected/intended thing.
1750 #if 0
1751  // If we're playing, don't capture if the selection is the same as the
1752  // playback region (this helps prevent label track creation from
1753  // stealing unmodified kbd. shortcuts)
1754  if (pProj->GetAudioIOToken() > 0 &&
1756  {
1757  double t0, t1;
1758  pProj->GetPlayRegion(&t0, &t1);
1759  if (pProj->mViewInfo.selectedRegion.t0() == t0 &&
1760  pProj->mViewInfo.selectedRegion.t1() == t1) {
1761  return false;
1762  }
1763  }
1764 #endif
1765 
1766  // If there's a label there already don't capture
1768  pProj->mViewInfo.selectedRegion.t1()) != wxNOT_FOUND ) {
1769  return false;
1770  }
1771 
1772  return true;
1773  }
1774  }
1775 
1776  return false;
1777 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
bool IsGoodLabelFirstKey(const wxKeyEvent &evt)
Returns true for keys we capture to start a label.
bool IsStreamActive()
Returns true if the audio i/o is running at all, but not during cleanup.
Definition: AudioIO.cpp:2890
int GetAudioIOToken() const
Definition: Project.cpp:1444
double t1() const
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
int mSelIndex
Definition: LabelTrack.h:280
ViewInfo mViewInfo
Definition: Project.h:558
int GetLabelIndex(double t, double t1)
AudioIO * gAudioIO
Definition: AudioIO.cpp:482
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void GetPlayRegion(double *playRegionStart, double *playRegionEnd)
Definition: Project.cpp:5448
bool IsGoodLabelEditKey(const wxKeyEvent &evt)
This returns true for keys we capture for label editing.
void LabelTrack::Draw ( TrackPanelDrawingContext context,
const wxRect &  r,
const SelectedRegion selectedRegion,
const ZoomInfo zoomInfo 
) const

Draw calls other functions to draw the LabelTrack.

Parameters
dcthe device context
rthe LabelTrack rectangle.

Definition at line 784 of file LabelTrack.cpp.

References ThemeBase::Colour(), TrackPanelDrawingContext::dc, TrackArtist::DrawBackgroundWithSelection(), LabelTextHandle::GetTrack(), AColor::labelSelectedBrush, AColor::labelSurroundPen, AColor::labelTextEditBrush, AColor::labelTextNormalBrush, AColor::labelUnselectedBrush, AColor::Line(), TrackPanelDrawingContext::target, theTheme, and AColor::uglyBrush.

Referenced by TrackArtist::DrawLabelTrack().

787 {
788  auto &dc = context.dc;
789  auto pHit = findHit();
790 
791  if(msFont.Ok())
792  dc.SetFont(msFont);
793 
794  if (mFontHeight == -1)
796 
799  selectedRegion, zoomInfo);
800 
801  wxCoord textWidth, textHeight;
802 
803  // Get the text widths.
804  // TODO: Make more efficient by only re-computing when a
805  // text label title changes.
806  for (auto &labelStruct : mLabels) {
807  dc.GetTextExtent(labelStruct.title, &textWidth, &textHeight);
808  labelStruct.width = textWidth;
809  }
810 
811  // TODO: And this only needs to be done once, but we
812  // do need the dc to do it.
813  // We need to set mTextHeight to something sensible,
814  // guarding against the case where there are no
815  // labels or all are empty strings, which for example
816  // happens with a NEW label track.
817  dc.GetTextExtent(wxT("Demo Text x^y"), &textWidth, &textHeight);
818  mTextHeight = (int)textHeight;
819  ComputeLayout( r, zoomInfo );
820  dc.SetTextForeground(theTheme.Colour( clrLabelTrackText));
821  dc.SetBackgroundMode(wxTRANSPARENT);
822  dc.SetBrush(AColor::labelTextNormalBrush);
823  dc.SetPen(AColor::labelSurroundPen);
824  int GlyphLeft;
825  int GlyphRight;
826  // Now we draw the various items in this order,
827  // so that the correct things overpaint each other.
828 
829  // Draw vertical lines that show where the end positions are.
830  for (auto &labelStruct : mLabels)
831  labelStruct.DrawLines( dc, r );
832 
833  // Draw the end glyphs.
834  { int i = -1; for (auto &labelStruct : mLabels) { ++i;
835  GlyphLeft=0;
836  GlyphRight=1;
837  if( pHit && i == pHit->mMouseOverLabelLeft )
838  GlyphLeft = (pHit->mEdge & 4) ? 6:9;
839  if( pHit && i == pHit->mMouseOverLabelRight )
840  GlyphRight = (pHit->mEdge & 4) ? 7:4;
841  labelStruct.DrawGlyphs( dc, r, GlyphLeft, GlyphRight );
842  }}
843 
844  // Draw the label boxes.
845  {
846 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
847  bool highlightTrack = false;
848  auto target = dynamic_cast<LabelTextHandle*>(context.target.get());
849  highlightTrack = target && target->GetTrack().get() == this;
850 #endif
851  int i = -1; for (auto &labelStruct : mLabels) { ++i;
852  bool highlight = false;
853 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
854  highlight = highlightTrack && target->GetLabelNum() == i;
855 #endif
856  bool selected = mSelIndex == i;
857 
858  if( selected )
859  dc.SetBrush( AColor::labelTextEditBrush );
860  else if ( highlight )
861  dc.SetBrush( AColor::uglyBrush );
862  labelStruct.DrawTextBox( dc, r );
863 
864  if (highlight || selected)
865  dc.SetBrush(AColor::labelTextNormalBrush);
866  }
867  }
868 
869  // Draw highlights
870  if ((mInitialCursorPos != mCurrentCursorPos) && (mSelIndex >= 0 ))
871  {
872  int xpos1, xpos2;
873  CalcHighlightXs(&xpos1, &xpos2);
874  mLabels[mSelIndex].DrawHighlight(dc, xpos1, xpos2, mFontHeight);
875  }
876 
877  // Draw the text and the label boxes.
878  { int i = -1; for (auto &labelStruct : mLabels) { ++i;
879  if( mSelIndex==i)
880  dc.SetBrush(AColor::labelTextEditBrush);
881  labelStruct.DrawText( dc, r );
882  if( mSelIndex==i)
883  dc.SetBrush(AColor::labelTextNormalBrush);
884  }}
885 
886  // Draw the cursor, if there is one.
887  if( mDrawCursor && mSelIndex >=0 )
888  {
889  const auto &labelStruct = mLabels[mSelIndex];
890  int xPos = labelStruct.xText;
891 
892  if( mCurrentCursorPos > 0)
893  {
894  // Calculate the width of the substring and add it to Xpos
895  int partWidth;
896  dc.GetTextExtent(labelStruct.title.Left(mCurrentCursorPos), &partWidth, NULL);
897  xPos += partWidth;
898  }
899 
900  wxPen currentPen = dc.GetPen();
901  const int CursorWidth=2;
902  currentPen.SetWidth(CursorWidth);
903  AColor::Line(dc,
904  xPos-1, labelStruct.y - mFontHeight/2 + 1,
905  xPos-1, labelStruct.y + mFontHeight/2 - 1);
906  currentPen.SetWidth(1);
907  }
908 }
std::shared_ptr< LabelTrack > GetTrack() const
static wxBrush labelSelectedBrush
Definition: AColor.h:129
int mCurrentCursorPos
Definition: LabelTrack.h:291
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
static wxBrush uglyBrush
Definition: AColor.h:148
void calculateFontHeight(wxDC &dc) const
Definition: LabelTrack.cpp:964
static wxBrush labelTextNormalBrush
Definition: AColor.h:126
void ComputeLayout(const wxRect &r, const ZoomInfo &zoomInfo) const
Definition: LabelTrack.cpp:461
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
static void DrawBackgroundWithSelection(wxDC *dc, const wxRect &rect, const Track *track, wxBrush &selBrush, wxBrush &unselBrush, const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo)
int mSelIndex
Definition: LabelTrack.h:280
static int mFontHeight
Definition: LabelTrack.h:290
static wxBrush labelTextEditBrush
Definition: AColor.h:127
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
void CalcHighlightXs(int *x1, int *x2) const
Definition: LabelTrack.cpp:740
static wxFont msFont
Definition: LabelTrack.h:316
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
static wxPen labelSurroundPen
Definition: AColor.h:134
static int mTextHeight
Definition: LabelTrack.h:286
static wxBrush labelUnselectedBrush
Definition: AColor.h:128
Track::Holder LabelTrack::Duplicate ( ) const
overridevirtual

Implements Track.

Definition at line 1141 of file LabelTrack.cpp.

1142 {
1143  return std::make_unique<LabelTrack>( *this );
1144 }
void LabelTrack::Export ( wxTextFile &  f) const

Export labels including label start and end-times.

Definition at line 2281 of file LabelTrack.cpp.

References mLabels.

2282 {
2283  // PRL: to do: export other selection fields
2284  for (auto &labelStruct: mLabels)
2285  labelStruct.Export(f);
2286 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int LabelTrack::FindCurrentCursorPosition ( int  xPos)

uses GetTextExtent to find the character position corresponding to the x pixel position.

Definition at line 912 of file LabelTrack.cpp.

References mLabels, mSelIndex, and msFont.

Referenced by HandleTextClick(), and SetCurrentCursorPosition().

913 {
914  int result = -1;
915  wxMemoryDC dc;
916  if(msFont.Ok())
917  dc.SetFont(msFont);
918 
919  // A bool indicator to see if set the cursor position or not
920  bool finished = false;
921  int charIndex = 1;
922  int partWidth;
923  int oneWidth;
924  double bound;
925  wxString subString;
926  const auto &labelStruct = mLabels[mSelIndex];
927  const auto &title = labelStruct.title;
928  const int length = title.length();
929  while (!finished && (charIndex < length + 1))
930  {
931  subString = title.Left(charIndex);
932  // Get the width of substring
933  dc.GetTextExtent(subString, &partWidth, NULL);
934 
935  // Get the width of the last character
936  dc.GetTextExtent(subString.Right(1), &oneWidth, NULL);
937  bound = labelStruct.xText + partWidth - oneWidth * 0.5;
938 
939  if (xPos <= bound)
940  {
941  // Found
942  result = charIndex - 1;
943  finished = true;
944  }
945  else
946  {
947  // Advance
948  charIndex++;
949  }
950  }
951  if (!finished)
952  // Cursor should be in the last position
953  result = length;
954 
955  return result;
956 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
static wxFont msFont
Definition: LabelTrack.h:316
int LabelTrack::FindNextLabel ( const SelectedRegion currentSelection)

Definition at line 2999 of file LabelTrack.cpp.

References miLastLabel, and SelectedRegion::t0().

Referenced by AudacityProject::OnMoveToLabel().

3000 {
3001  int i = -1;
3002 
3003  if (!mLabels.empty()) {
3004  int len = (int) mLabels.size();
3005  if (miLastLabel >= 0 && miLastLabel + 1 < len
3006  && currentRegion.t0() == mLabels[miLastLabel].getT0()
3007  && currentRegion.t0() == mLabels[miLastLabel + 1].getT0() ) {
3008  i = miLastLabel + 1;
3009  }
3010  else {
3011  i = 0;
3012  if (currentRegion.t0() < mLabels[len - 1].getT0()) {
3013  while (i < len &&
3014  mLabels[i].getT0() <= currentRegion.t0()) {
3015  i++;
3016  }
3017  }
3018  }
3019  }
3020 
3021  miLastLabel = i;
3022  return i;
3023 }
int miLastLabel
Definition: LabelTrack.h:303
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int LabelTrack::FindPrevLabel ( const SelectedRegion currentSelection)

Definition at line 3025 of file LabelTrack.cpp.

References miLastLabel, and SelectedRegion::t0().

Referenced by AudacityProject::OnMoveToLabel().

3026 {
3027  int i = -1;
3028 
3029  if (!mLabels.empty()) {
3030  int len = (int) mLabels.size();
3031  if (miLastLabel > 0 && miLastLabel < len
3032  && currentRegion.t0() == mLabels[miLastLabel].getT0()
3033  && currentRegion.t0() == mLabels[miLastLabel - 1].getT0() ) {
3034  i = miLastLabel - 1;
3035  }
3036  else {
3037  i = len - 1;
3038  if (currentRegion.t0() > mLabels[0].getT0()) {
3039  while (i >=0 &&
3040  mLabels[i].getT0() >= currentRegion.t0()) {
3041  i--;
3042  }
3043  }
3044  }
3045  }
3046 
3047  miLastLabel = i;
3048  return i;
3049 }
int miLastLabel
Definition: LabelTrack.h:303
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
std::shared_ptr< TrackControls > LabelTrack::GetControls ( )
overrideprotectedvirtual

Implements Track.

Definition at line 45 of file LabelTrackUI.cpp.

References Track::Pointer().

46 {
47  return std::make_shared<LabelTrackControls>( Pointer( this ) );
48 }
static std::shared_ptr< Subclass > Pointer(Track *t)
Definition: Track.h:137
double LabelTrack::GetEndTime ( ) const
overridevirtual

Implements Track.

Definition at line 1125 of file LabelTrack.cpp.

References mLabels.

Referenced by Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack(), Paste(), and AudacityProject::UpdateLyrics().

1126 {
1127  //we need to scan through all the labels, because the last
1128  //label might not have the right-most end (if there is overlap).
1129  if (mLabels.empty())
1130  return 0.0;
1131 
1132  double end = 0.0;
1133  for (auto &labelStruct: mLabels) {
1134  const double t1 = labelStruct.getT1();
1135  if(t1 > end)
1136  end = t1;
1137  }
1138  return end;
1139 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
wxFont LabelTrack::GetFont ( const wxString &  faceName,
int  size = DefaultFontSize 
)
static

Definition at line 285 of file LabelTrack.cpp.

Referenced by LabelTrackMenuTable::OnSetFont(), and ResetFont().

286 {
287  wxFontEncoding encoding;
288  if (faceName == wxT(""))
289  encoding = wxFONTENCODING_DEFAULT;
290  else
291  encoding = wxFONTENCODING_SYSTEM;
292  return wxFont(size, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
293  wxFONTWEIGHT_NORMAL, false, faceName, encoding);
294 }
wxBitmap & LabelTrack::GetGlyph ( int  i)
static

Definition at line 2790 of file LabelTrack.cpp.

References ThemeBase::Bitmap(), and theTheme.

Referenced by LabelStruct::DrawGlyphs().

2791 {
2792  return theTheme.Bitmap( i + bmpLabelGlyph0);
2793 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
int LabelTrack::GetKind ( ) const
inlineoverridevirtual

Reimplemented from Track.

Definition at line 156 of file LabelTrack.h.

References Track::Label.

156 { return Label; }
const LabelStruct * LabelTrack::GetLabel ( int  index) const
int LabelTrack::GetLabelIndex ( double  t,
double  t1 
)

Definition at line 2711 of file LabelTrack.cpp.

Referenced by DoCaptureKey(), and OnContextMenu().

2712 {
2713  //We'd have liked to have times in terms of samples,
2714  //because then we're doing an intrger comparison.
2715  //Never mind. Instead we look for near enough.
2716  //This level of (in)accuracy is only a problem if we
2717  //deal with sounds in the MHz range.
2718  const double delta = 1.0e-7;
2719  { int i = -1; for (auto &labelStruct : mLabels) { ++i;
2720  if( fabs( labelStruct.getT0() - t ) > delta )
2721  continue;
2722  if( fabs( labelStruct.getT1() - t1 ) > delta )
2723  continue;
2724  return i;
2725  }}
2726 
2727  return wxNOT_FOUND;
2728 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int LabelTrack::GetNumLabels ( ) const
double LabelTrack::GetOffset ( ) const
overridevirtual

Implements Track.

Definition at line 1112 of file LabelTrack.cpp.

References Track::mOffset.

1113 {
1114  return mOffset;
1115 }
double mOffset
Definition: Track.h:230
int LabelTrack::getSelectedIndex ( ) const
inline

Definition at line 154 of file LabelTrack.h.

154 { return mSelIndex; }
int mSelIndex
Definition: LabelTrack.h:280
double LabelTrack::GetStartTime ( ) const
overridevirtual

Implements Track.

Definition at line 1117 of file LabelTrack.cpp.

References mLabels.

Referenced by AudacityProject::GetTime(), and Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack().

1118 {
1119  if (mLabels.empty())
1120  return 0.0;
1121  else
1122  return mLabels[0].getT0();
1123 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
wxString LabelTrack::GetTextOfLabels ( double  t0,
double  t1 
) const

Definition at line 2980 of file LabelTrack.cpp.

2981 {
2982  bool firstLabel = true;
2983  wxString retVal;
2984 
2985  for (auto &labelStruct: mLabels) {
2986  if (labelStruct.getT0() >= t0 &&
2987  labelStruct.getT1() <= t1)
2988  {
2989  if (!firstLabel)
2990  retVal += '\t';
2991  firstLabel = false;
2992  retVal += labelStruct.title;
2993  }
2994  }
2995 
2996  return retVal;
2997 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
std::shared_ptr< TrackVRulerControls > LabelTrack::GetVRulerControls ( )
overrideprotectedvirtual

Implements Track.

Definition at line 50 of file LabelTrackUI.cpp.

References Track::Pointer().

51 {
52  return std::make_shared<LabelTrackVRulerControls>( Pointer( this ) );
53 }
static std::shared_ptr< Subclass > Pointer(Track *t)
Definition: Track.h:137
void LabelTrack::HandleGlyphClick ( LabelTrackHit hit,
const wxMouseEvent &  evt,
const wxRect &  r,
const ZoomInfo zoomInfo,
SelectedRegion newSel 
)

Definition at line 1583 of file LabelTrack.cpp.

References LabelTrackHit::mbIsMoving, LabelTrackHit::mEdge, LabelTrackHit::mIsAdjustingLabel, LabelTrackHit::mMouseOverLabelLeft, LabelTrackHit::mMouseOverLabelRight, and ZoomInfo::TimeToPosition().

1586 {
1587  if (evt.ButtonDown())
1588  {
1589  //OverGlyph sets mMouseOverLabel to be the chosen label.
1590  OverGlyph(hit, evt.m_x, evt.m_y);
1591  hit.mIsAdjustingLabel = evt.Button(wxMOUSE_BTN_LEFT) &&
1592  ( hit.mEdge & 3 ) != 0;
1593 
1594  if (hit.mIsAdjustingLabel)
1595  {
1596  float t = 0.0;
1597  // We move if we hit the centre, we adjust one edge if we hit a chevron.
1598  // This is if we are moving just one edge.
1599  hit.mbIsMoving = (hit.mEdge & 4)!=0;
1600  // When we start dragging the label(s) we don't want them to jump.
1601  // so we calculate the displacement of the mouse from the drag center
1602  // and use that in subsequent dragging calculations. The mouse stays
1603  // at the same relative displacement throughout dragging.
1604 
1605  // However, if two label's edges are being dragged
1606  // then the displacement is relative to the initial average
1607  // position of them, and in that case there can be a jump of at most
1608  // a few pixels to bring the two label boundaries to exactly the same
1609  // position when we start dragging.
1610 
1611  // Dragging of three label edges at the same time is not supported (yet).
1612  if( ( hit.mMouseOverLabelRight >= 0 ) &&
1613  ( hit.mMouseOverLabelLeft >= 0 )
1614  )
1615  {
1616  t = (mLabels[ hit.mMouseOverLabelRight ].getT1() +
1617  mLabels[ hit.mMouseOverLabelLeft ].getT0()) / 2.0f;
1618  // If we're moving two edges, then it's a move (label size preserved)
1619  // if both edges are the same label, and it's an adjust (label sizes change)
1620  // if we're on a boundary between two different labels.
1621  hit.mbIsMoving =
1623  }
1624  else if( hit.mMouseOverLabelRight >=0)
1625  {
1626  t = mLabels[ hit.mMouseOverLabelRight ].getT1();
1627  }
1628  else if( hit.mMouseOverLabelLeft >=0)
1629  {
1630  t = mLabels[ hit.mMouseOverLabelLeft ].getT0();
1631  }
1632  mxMouseDisplacement = zoomInfo.TimeToPosition(t, r.x) - evt.m_x;
1633  }
1634  }
1635 }
int mxMouseDisplacement
Keeps track of the currently selected label.
Definition: LabelTrack.h:281
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void OverGlyph(LabelTrackHit &hit, int x, int y) const
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ViewInfo.cpp:59
bool mbIsMoving
Keeps track of which right label the mouse is currently over.
bool LabelTrack::HandleGlyphDragRelease ( LabelTrackHit hit,
const wxMouseEvent &  evt,
wxRect &  r,
const ZoomInfo zoomInfo,
SelectedRegion newSel 
)

Definition at line 1474 of file LabelTrack.cpp.

References Constrain(), LabelTrackHit::mbIsMoving, LabelTrackHit::mIsAdjustingLabel, LabelTrackHit::mMouseOverLabelLeft, LabelTrackHit::mMouseOverLabelRight, and ZoomInfo::PositionToTime().

1477 {
1478  if(evt.LeftUp())
1479  {
1480  bool lupd = false, rupd = false;
1481  if( hit.mMouseOverLabelLeft >= 0 ) {
1482  auto &labelStruct = mLabels[ hit.mMouseOverLabelLeft ];
1483  lupd = labelStruct.updated;
1484  labelStruct.updated = false;
1485  }
1486  if( hit.mMouseOverLabelRight >= 0 ) {
1487  auto &labelStruct = mLabels[ hit.mMouseOverLabelRight ];
1488  rupd = labelStruct.updated;
1489  labelStruct.updated = false;
1490  }
1491 
1492  hit.mIsAdjustingLabel = false;
1493  hit.mMouseOverLabelLeft = -1;
1494  hit.mMouseOverLabelRight = -1;
1495  return lupd || rupd;
1496  }
1497 
1498  if(evt.Dragging())
1499  {
1500  //If we are currently adjusting a label,
1501  //just reset its value and redraw.
1502  // LL: Constrain to inside track rectangle for now. Should be changed
1503  // to allow scrolling while dragging labels
1504  int x = Constrain( evt.m_x + mxMouseDisplacement - r.x, 0, r.width);
1505 
1506  // If exactly one edge is selected we allow swapping
1507  bool bAllowSwapping =
1508  ( hit.mMouseOverLabelLeft >=0 ) !=
1509  ( hit.mMouseOverLabelRight >= 0);
1510  // If we're on the 'dot' and nowe're moving,
1511  // Though shift-down inverts that.
1512  // and if both edges the same, then we're always moving the label.
1513  bool bLabelMoving = hit.mbIsMoving;
1514  bLabelMoving ^= evt.ShiftDown();
1515  bLabelMoving |= ( hit.mMouseOverLabelLeft == hit.mMouseOverLabelRight );
1516  double fNewX = zoomInfo.PositionToTime(x, 0);
1517  if( bLabelMoving )
1518  {
1519  MayMoveLabel( hit.mMouseOverLabelLeft, -1, fNewX );
1520  MayMoveLabel( hit.mMouseOverLabelRight, +1, fNewX );
1521  }
1522  else
1523  {
1524  MayAdjustLabel( hit, hit.mMouseOverLabelLeft, -1, bAllowSwapping, fNewX );
1525  MayAdjustLabel( hit, hit.mMouseOverLabelRight, +1, bAllowSwapping, fNewX );
1526  }
1527 
1528  if( mSelIndex >=0 )
1529  {
1530  //Set the selection region to be equal to
1531  //the NEW size of the label.
1532  *newSel = mLabels[mSelIndex].selectedRegion;
1533  }
1534  SortLabels( &hit );
1535  }
1536 
1537  return false;
1538 }
static int Constrain(int value, int min, int max)
int mxMouseDisplacement
Keeps track of the currently selected label.
Definition: LabelTrack.h:281
void MayMoveLabel(int iLabel, int iEdge, double fNewTime)
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
void MayAdjustLabel(LabelTrackHit &hit, int iLabel, int iEdge, bool bAllowSwapping, double fNewTime)
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
void SortLabels(LabelTrackHit *pHit=nullptr)
bool mbIsMoving
Keeps track of which right label the mouse is currently over.
void LabelTrack::HandleTextClick ( const wxMouseEvent &  evt,
const wxRect &  r,
const ZoomInfo zoomInfo,
SelectedRegion newSel 
)

Definition at line 1637 of file LabelTrack.cpp.

References CalcHighlightXs(), FindCurrentCursorPosition(), mCurrentCursorPos, mDrawCursor, mFontHeight, mInitialCursorPos, mLabels, mRightDragging, mSelIndex, OverATextBox(), OverTextBox(), PasteSelectedText(), ZoomInfo::PositionToTime(), SelectedRegion::t0(), and SelectedRegion::t1().

1640 {
1641  static_cast<void>(r);//compiler food.
1642  static_cast<void>(zoomInfo);//compiler food.
1643  if (evt.ButtonDown())
1644  {
1645 
1646  mSelIndex = OverATextBox(evt.m_x, evt.m_y);
1647  if (mSelIndex != -1) {
1648  auto &labelStruct = mLabels[mSelIndex];
1649  *newSel = labelStruct.selectedRegion;
1650 
1651  if (evt.LeftDown()) {
1652  // Find the NEW drag end
1653  auto position = FindCurrentCursorPosition(evt.m_x);
1654 
1655  // Anchor shift-drag at the farther end of the previous highlight
1656  // that is farther from the click, on Mac, for consistency with
1657  // its text editors, but on the others, re-use the previous
1658  // anchor.
1659  if (evt.ShiftDown()) {
1660 #ifdef __WXMAC__
1661  // Set the drag anchor at the end of the previous selection
1662  // that is farther from the NEW drag end
1663  if (abs(position - mCurrentCursorPos) >
1664  abs(position - mInitialCursorPos))
1666 #else
1667  // mInitialCursorPos remains as before
1668 #endif
1669  }
1670  else
1671  mInitialCursorPos = position;
1672 
1673  mCurrentCursorPos = position;
1674 
1675  mDrawCursor = true;
1676  mRightDragging = false;
1677  }
1678  else
1679  // Actually this might be right or middle down
1680  mRightDragging = true;
1681 
1682  // reset the highlight indicator
1683  wxRect highlightedRect;
1684  {
1685  int xpos1, xpos2;
1686  CalcHighlightXs(&xpos1, &xpos2);
1687 
1688  wxASSERT(mFontHeight >= 0); // should have been set up while drawing
1689  // the rectangle of highlighted area
1690  highlightedRect = {
1691  xpos1, labelStruct.y - mFontHeight / 2,
1692  (int)(xpos2 - xpos1 + 0.5), mFontHeight
1693  };
1694  }
1695 
1696  // Middle click on GTK: paste from primary selection
1697 #if defined(__WXGTK__) && (HAVE_GTK)
1698  if (evt.MiddleDown()) {
1699  // Check for a click outside of the selected label's text box; in this
1700  // case PasteSelectedText() will start a NEW label at the click
1701  // location
1702  if (!OverTextBox(&labelStruct, evt.m_x, evt.m_y))
1703  mSelIndex = -1;
1704  double t = zoomInfo.PositionToTime(evt.m_x, r.x);
1705  *newSel = SelectedRegion(t, t);
1706  }
1707 #endif
1708  }
1709 #if defined(__WXGTK__) && (HAVE_GTK)
1710  if (evt.MiddleDown()) {
1711  // Paste text, making a NEW label if none is selected.
1712  wxTheClipboard->UsePrimarySelection(true);
1713  PasteSelectedText(newSel->t0(), newSel->t1());
1714  wxTheClipboard->UsePrimarySelection(false);
1715  }
1716 #endif
1717  }
1718 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
double t0() const
int FindCurrentCursorPosition(int xPos)
Definition: LabelTrack.cpp:912
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const
double t1() const
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
bool mRightDragging
initial cursor position
Definition: LabelTrack.h:294
int mSelIndex
Definition: LabelTrack.h:280
Defines a selected portion of a project.
static int mFontHeight
Definition: LabelTrack.h:290
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
bool PasteSelectedText(double sel0, double sel1)
void CalcHighlightXs(int *x1, int *x2) const
Definition: LabelTrack.cpp:740
int OverATextBox(int xx, int yy) const
void LabelTrack::HandleTextDragRelease ( const wxMouseEvent &  evt)

Definition at line 1540 of file LabelTrack.cpp.

References CopySelectedText(), GetLabel(), mCurrentCursorPos, mInitialCursorPos, mRightDragging, mSelIndex, OverTextBox(), SetCurrentCursorPosition(), and ShowContextMenu().

1541 {
1542  if(evt.LeftUp())
1543  {
1544 #if 0
1545  // AWD: Due to wxWidgets bug #7491 (fix not ported to 2.8 branch) we
1546  // should never write the primary selection. We can enable this block
1547  // when we move to the 3.0 branch (or if a fixed 2.8 version is released
1548  // and we can do a runtime version check)
1549 #if defined (__WXGTK__) && defined (HAVE_GTK)
1550  // On GTK, if we just dragged out a text selection, set the primary
1551  // selection
1553  wxTheClipboard->UsePrimarySelection(true);
1554  CopySelectedText();
1555  wxTheClipboard->UsePrimarySelection(false);
1556  }
1557 #endif
1558 #endif
1559 
1560  return;
1561  }
1562 
1563  if(evt.Dragging())
1564  {
1565  if (!mRightDragging)
1566  // Update drag end
1567  SetCurrentCursorPosition(evt.m_x);
1568 
1569  return;
1570  }
1571 
1572  if (evt.RightUp()) {
1573  if ((mSelIndex != -1) && OverTextBox(GetLabel(mSelIndex), evt.m_x, evt.m_y)) {
1574  // popup menu for editing
1575  ShowContextMenu();
1576  }
1577  }
1578 
1579  return;
1580 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
void SetCurrentCursorPosition(int xPos)
Set the cursor position according to x position of mouse.
Definition: LabelTrack.cpp:959
bool CopySelectedText()
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const
void ShowContextMenu()
bool mRightDragging
initial cursor position
Definition: LabelTrack.h:294
int mSelIndex
Definition: LabelTrack.h:280
const LabelStruct * GetLabel(int index) const
XMLTagHandler * LabelTrack::HandleXMLChild ( const wxChar *  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 2394 of file LabelTrack.cpp.

2395 {
2396  if (!wxStrcmp(tag, wxT("label")))
2397  return this;
2398  else
2399  return NULL;
2400 }
bool LabelTrack::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 2313 of file LabelTrack.cpp.

References SelectedRegion::HandleXMLAttribute(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodString(), mLabels, Track::mName, Track::SetHeight(), Track::SetMinimized(), and SetSelected().

2314 {
2315  if (!wxStrcmp(tag, wxT("label"))) {
2316 
2317  SelectedRegion selectedRegion;
2318  wxString title;
2319 
2320  // loop through attrs, which is a null-terminated list of
2321  // attribute-value pairs
2322  while(*attrs) {
2323  const wxChar *attr = *attrs++;
2324  const wxChar *value = *attrs++;
2325 
2326  if (!value)
2327  break;
2328 
2329  const wxString strValue = value;
2330  if (!XMLValueChecker::IsGoodString(strValue))
2331  {
2332  return false;
2333  }
2334 
2335  if (selectedRegion.HandleXMLAttribute(attr, value, wxT("t"), wxT("t1")))
2336  ;
2337  else if (!wxStrcmp(attr, wxT("title")))
2338  title = strValue;
2339 
2340  } // while
2341 
2342  // Handle files created by Audacity 1.1. Labels in Audacity 1.1
2343  // did not have separate start- and end-times.
2344  // PRL: this superfluous now, given class SelectedRegion's internal
2345  // consistency guarantees
2346  //if (selectedRegion.t1() < 0)
2347  // selectedRegion.collapseToT0();
2348 
2349  LabelStruct l { selectedRegion, title };
2350  mLabels.push_back(l);
2351 
2352  return true;
2353  }
2354  else if (!wxStrcmp(tag, wxT("labeltrack"))) {
2355  long nValue = -1;
2356  while (*attrs) {
2357  const wxChar *attr = *attrs++;
2358  const wxChar *value = *attrs++;
2359 
2360  if (!value)
2361  return true;
2362 
2363  const wxString strValue = value;
2364  if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
2365  mName = strValue;
2366  else if (!wxStrcmp(attr, wxT("numlabels")) &&
2367  XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
2368  {
2369  if (nValue < 0)
2370  {
2371  wxLogWarning(wxT("Project shows negative number of labels: %d"), nValue);
2372  return false;
2373  }
2374  mLabels.clear();
2375  mLabels.reserve(nValue);
2376  }
2377  else if (!wxStrcmp(attr, wxT("height")) &&
2378  XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
2379  SetHeight(nValue);
2380  else if (!wxStrcmp(attr, wxT("minimized")) &&
2381  XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
2382  SetMinimized(nValue != 0);
2383  else if (!wxStrcmp(attr, wxT("isSelected")) &&
2384  XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
2385  this->SetSelected(nValue != 0);
2386  }
2387 
2388  return true;
2389  }
2390 
2391  return false;
2392 }
void SetHeight(int h)
Definition: Track.cpp:189
void SetMinimized(bool isMinimized)
Definition: Track.cpp:219
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
void SetSelected(bool s) override
static bool IsGoodString(const wxString &str)
Defines a selected portion of a project.
bool HandleXMLAttribute(const wxChar *attr, const wxChar *value, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name)
wxString mName
Definition: Track.h:119
void LabelTrack::Import ( wxTextFile &  f)

Import labels, handling files with or without end-times.

Definition at line 2289 of file LabelTrack.cpp.

References _(), AudacityMessageBox(), LabelStruct::Import(), mLabels, and SortLabels().

2290 {
2291  int lines = in.GetLineCount();
2292 
2293  mLabels.clear();
2294  mLabels.reserve(lines);
2295 
2296  //Currently, we expect a tag file to have two values and a label
2297  //on each line. If the second token is not a number, we treat
2298  //it as a single-value label.
2299  bool error = false;
2300  for (int index = 0; index < lines;) {
2301  try {
2302  // Let LabelStruct::Import advance index
2303  LabelStruct l { LabelStruct::Import(in, index) };
2304  mLabels.push_back(l);
2305  }
2306  catch(const LabelStruct::BadFormatException&) { error = true; }
2307  }
2308  if (error)
2309  ::AudacityMessageBox( _("One or more saved labels could not be read.") );
2310  SortLabels();
2311 }
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
static LabelStruct Import(wxTextFile &file, int &index)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void SortLabels(LabelTrackHit *pHit=nullptr)
void LabelTrack::InsertSilence ( double  t,
double  len 
)
override

Definition at line 2687 of file LabelTrack.cpp.

2688 {
2689  for (auto &labelStruct: mLabels) {
2690  double t0 = labelStruct.getT0();
2691  double t1 = labelStruct.getT1();
2692  if (t0 >= t)
2693  t0 += len;
2694 
2695  if (t1 >= t)
2696  t1 += len;
2697  labelStruct.selectedRegion.setTimes(t0, t1);
2698  }
2699 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
bool LabelTrack::IsGoodLabelEditKey ( const wxKeyEvent &  evt)

This returns true for keys we capture for label editing.

Definition at line 2913 of file LabelTrack.cpp.

Referenced by DoCaptureKey(), and OnKeyDown().

2914 {
2915  int keyCode = evt.GetKeyCode();
2916 
2917  // Accept everything outside of WXK_START through WXK_COMMAND, plus the keys
2918  // within that range that are usually printable, plus the ones we use for
2919  // keyboard navigation.
2920  return keyCode < WXK_START ||
2921  (keyCode >= WXK_END && keyCode < WXK_UP) ||
2922  (keyCode == WXK_RIGHT) ||
2923  (keyCode >= WXK_NUMPAD0 && keyCode <= WXK_DIVIDE) ||
2924  (keyCode >= WXK_NUMPAD_SPACE && keyCode <= WXK_NUMPAD_ENTER) ||
2925  (keyCode >= WXK_NUMPAD_HOME && keyCode <= WXK_NUMPAD_END) ||
2926  (keyCode >= WXK_NUMPAD_DELETE && keyCode <= WXK_NUMPAD_DIVIDE) ||
2927 #if defined(__WXMAC__)
2928  (keyCode > WXK_RAW_CONTROL) ||
2929 #endif
2930  (keyCode > WXK_WINDOWS_MENU);
2931 }
bool LabelTrack::IsGoodLabelFirstKey ( const wxKeyEvent &  evt)

Returns true for keys we capture to start a label.

Definition at line 2899 of file LabelTrack.cpp.

Referenced by DoCaptureKey(), and OnKeyDown().

2900 {
2901  int keyCode = evt.GetKeyCode();
2902  return (keyCode < WXK_START
2903  && keyCode != WXK_SPACE && keyCode != WXK_DELETE && keyCode != WXK_RETURN) ||
2904  (keyCode >= WXK_NUMPAD0 && keyCode <= WXK_DIVIDE) ||
2905  (keyCode >= WXK_NUMPAD_EQUAL && keyCode <= WXK_NUMPAD_DIVIDE) ||
2906 #if defined(__WXMAC__)
2907  (keyCode > WXK_RAW_CONTROL) ||
2908 #endif
2909  (keyCode > WXK_WINDOWS_MENU);
2910 }
bool LabelTrack::IsSelected ( ) const

Definition at line 2275 of file LabelTrack.cpp.

References mLabels, and mSelIndex.

Referenced by AudacityProject::HandlePasteText().

2276 {
2277  return (mSelIndex >= 0 && mSelIndex < (int)mLabels.size());
2278 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
bool LabelTrack::IsTextClipSupported ( )
static
Returns
true if the text data is available in the clipboard, false otherwise

Definition at line 1106 of file LabelTrack.cpp.

Referenced by PasteSelectedText(), and ShowContextMenu().

1107 {
1108  return wxTheClipboard->IsSupported(wxDF_TEXT);
1109 }
bool LabelTrack::IsTextSelected ( )

Definition at line 982 of file LabelTrack.cpp.

References mCurrentCursorPos, mInitialCursorPos, and mSelIndex.

Referenced by CutSelectedText(), AudacityProject::GetUpdateFlags(), and ShowContextMenu().

983 {
984  if (mSelIndex == -1)
985  return false;
987  return false;
988  return true;
989 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
int mSelIndex
Definition: LabelTrack.h:280
unsigned LabelTrack::KeyDown ( wxKeyEvent &  event,
ViewInfo viewInfo,
wxWindow *  pParent 
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 1785 of file LabelTrack.cpp.

References _(), CalcCursorX(), CONSOLIDATE, GetActiveProject(), AudacityProject::GetTrackPanel(), OnKeyDown(), AudacityProject::PushState(), RefreshCode::RefreshAll, RefreshCode::RefreshCell, RefreshCode::RefreshNone, TrackPanel::ScrollIntoView(), ViewInfo::selectedRegion, SelectedRegion::t0(), and SelectedRegion::t1().

1786 {
1787  double bkpSel0 = viewInfo.selectedRegion.t0(),
1788  bkpSel1 = viewInfo.selectedRegion.t1();
1789 
1790  AudacityProject *const pProj = GetActiveProject();
1791 
1792  // Pass keystroke to labeltrack's handler and add to history if any
1793  // updates were done
1794  if (OnKeyDown(viewInfo.selectedRegion, event)) {
1795  pProj->PushState(_("Modified Label"),
1796  _("Label Edit"),
1798  }
1799 
1800  // Make sure caret is in view
1801  int x;
1802  if (CalcCursorX(&x)) {
1803  pProj->GetTrackPanel()->ScrollIntoView(x);
1804  }
1805 
1806  // If selection modified, refresh
1807  // Otherwise, refresh track display if the keystroke was handled
1808  if (bkpSel0 != viewInfo.selectedRegion.t0() ||
1809  bkpSel1 != viewInfo.selectedRegion.t1())
1810  return RefreshCode::RefreshAll;
1811  else if (!event.GetSkipped())
1812  return RefreshCode::RefreshCell;
1813 
1814  return RefreshCode::RefreshNone;
1815 }
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
bool CalcCursorX(int *x) const
Definition: LabelTrack.cpp:723
double t1() const
void ScrollIntoView(double pos)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
TrackPanel * GetTrackPanel()
Definition: Project.h:307
bool OnKeyDown(SelectedRegion &sel, wxKeyEvent &event)
KeyEvent is called for every keypress when over the label track.
void LabelTrack::MayAdjustLabel ( LabelTrackHit hit,
int  iLabel,
int  iEdge,
bool  bAllowSwapping,
double  fNewTime 
)

If the index is for a real label, adjust its left or right boundary. - index of label, -1 for none. - which edge is requested to move, -1 for left +1 for right. - if we can switch which edge is being dragged. fNewTime - the NEW time for this edge of the label.

Definition at line 1428 of file LabelTrack.cpp.

References LabelStruct::AdjustEdge(), LabelTrackHit::mMouseOverLabelLeft, and LabelTrackHit::mMouseOverLabelRight.

1429 {
1430  if( iLabel < 0 )
1431  return;
1432  LabelStruct &labelStruct = mLabels[ iLabel ];
1433 
1434  // Adjust the requested edge.
1435  bool flipped = labelStruct.AdjustEdge( iEdge, fNewTime );
1436  // If the edges did not swap, then we are done.
1437  if( ! flipped )
1438  return;
1439 
1440  // If swapping's not allowed we must also move the edge
1441  // we didn't move. Then we're done.
1442  if( !bAllowSwapping )
1443  {
1444  labelStruct.AdjustEdge( -iEdge, fNewTime );
1445  return;
1446  }
1447 
1448  // Swap our record of what we are dragging.
1449  std::swap( hit.mMouseOverLabelLeft, hit.mMouseOverLabelRight );
1450 }
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
bool AdjustEdge(int iEdge, double fNewTime)
void LabelTrack::MayMoveLabel ( int  iLabel,
int  iEdge,
double  fNewTime 
)

Definition at line 1453 of file LabelTrack.cpp.

References mLabels.

1454 {
1455  if( iLabel < 0 )
1456  return;
1457  mLabels[ iLabel ].MoveLabel( iEdge, fNewTime );
1458 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
bool LabelTrack::OnChar ( SelectedRegion sel,
wxKeyEvent &  event 
)

OnChar is called for incoming characters – that's any keypress not handled by OnKeyDown.

Definition at line 2070 of file LabelTrack.cpp.

References _(), AddLabel(), AudacityProject::DialogForLabelName(), GetActiveProject(), gPrefs, mCurrentCursorPos, mDrawCursor, mInitialCursorPos, mLabels, mSelIndex, AudacityProject::mViewInfo, AudacityProject::PushState(), RemoveSelectedText(), ViewInfo::selectedRegion, and SetSelected().

Referenced by Char().

2071 {
2072  // Check for modifiers and only allow shift.
2073  //
2074  // We still need to check this or we will eat the top level menu accelerators
2075  // on Windows if our capture or key down handlers skipped the event.
2076  const int mods = event.GetModifiers();
2077  if (mods != wxMOD_NONE && mods != wxMOD_SHIFT) {
2078  event.Skip();
2079  return false;
2080  }
2081 
2082  // Only track true changes to the label
2083  bool updated = false;
2084 
2085  // Cache the character
2086  wxChar charCode = event.GetUnicodeKey();
2087 
2088  // Skip if it's not a valid unicode character or a control character
2089  if (charCode == 0 || wxIscntrl(charCode)) {
2090  event.Skip();
2091  return false;
2092  }
2093 
2094  // If we've reached this point and aren't currently editing, add NEW label
2095  if (mSelIndex < 0) {
2096  // Don't create a NEW label for a space
2097  if (wxIsspace(charCode)) {
2098  event.Skip();
2099  return false;
2100  }
2101  bool useDialog;
2103  gPrefs->Read(wxT("/Gui/DialogForNameNewLabel"), &useDialog, false);
2104  if (useDialog) {
2105  wxString title;
2106  if (p->DialogForLabelName(charCode, title) == wxID_CANCEL) {
2107  return false;
2108  }
2109  SetSelected(true);
2110  AddLabel(p->mViewInfo.selectedRegion, title, -2);
2111  p->PushState(_("Added label"), _("Label"));
2112  return false;
2113  }
2114  else {
2115  SetSelected(true);
2117  p->PushState(_("Added label"), _("Label"));
2118  }
2119  }
2120 
2121  //
2122  // Now we are definitely in a label; append the incoming character
2123  //
2124 
2125  auto &labelStruct = mLabels[mSelIndex];
2126  auto &title = labelStruct.title;
2127 
2128  // Test if cursor is in the end of string or not
2131 
2132  if (mCurrentCursorPos < (int)title.length()) {
2133  // Get substring on the righthand side of cursor
2134  wxString rightPart = title.Mid(mCurrentCursorPos);
2135  // Set title to substring on the lefthand side of cursor
2136  title = title.Left(mCurrentCursorPos);
2137  //append charcode
2138  title += charCode;
2139  //append the right part substring
2140  title += rightPart;
2141  }
2142  else
2143  //append charCode
2144  title += charCode;
2145 
2146  //moving cursor position forward
2148  updated = true;
2149 
2150  // Make sure the caret is visible
2151  mDrawCursor = true;
2152 
2153  return updated;
2154 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
int mCurrentCursorPos
Definition: LabelTrack.h:291
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int DialogForLabelName(const wxString &initialValue, wxString &value)
Definition: Menus.cpp:8480
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void SetSelected(bool s) override
int mSelIndex
Definition: LabelTrack.h:280
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
ViewInfo mViewInfo
Definition: Project.h:558
void RemoveSelectedText()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
int AddLabel(const SelectedRegion &region, const wxString &title=wxT(""), int restoreFocus=-1)
void LabelTrack::OnContextMenu ( wxCommandEvent &  evt)
private

Cut selected text if cut menu item is selected

Copy selected text if copy menu item is selected

paste selected text if paste menu item is selected

DELETE selected label

Definition at line 2195 of file LabelTrack.cpp.

References _(), CONSOLIDATE, CopySelectedText(), CutSelectedText(), DeleteLabel(), AudacityProject::DoEditLabels(), GetActiveProject(), GetLabelIndex(), AudacityProject::GetSel0(), AudacityProject::GetSel1(), OnCopySelectedTextID, OnCutSelectedTextID, OnDeleteSelectedLabelID, OnEditSelectedLabelID, OnPasteSelectedTextID, PasteSelectedText(), and AudacityProject::PushState().

Referenced by ShowContextMenu().

2196 {
2198 
2199  switch (evt.GetId())
2200  {
2202  case OnCutSelectedTextID:
2203  if (CutSelectedText())
2204  {
2205  p->PushState(_("Modified Label"),
2206  _("Label Edit"),
2208  }
2209  break;
2210 
2212  case OnCopySelectedTextID:
2213  CopySelectedText();
2214  break;
2215 
2217  case OnPasteSelectedTextID:
2218  if (PasteSelectedText(p->GetSel0(), p->GetSel1()))
2219  {
2220  p->PushState(_("Modified Label"),
2221  _("Label Edit"),
2223  }
2224  break;
2225 
2227  case OnDeleteSelectedLabelID: {
2228  int ndx = GetLabelIndex(p->GetSel0(), p->GetSel1());
2229  if (ndx != -1)
2230  {
2231  DeleteLabel(ndx);
2232  p->PushState(_("Deleted Label"),
2233  _("Label Edit"),
2235  }
2236  }
2237  break;
2238 
2239  case OnEditSelectedLabelID: {
2240  int ndx = GetLabelIndex(p->GetSel0(), p->GetSel1());
2241  if (ndx != -1)
2242  p->DoEditLabels(this, ndx);
2243  }
2244  break;
2245  }
2246 }
double GetSel0() const
Definition: Project.h:204
void DeleteLabel(int index)
bool CopySelectedText()
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void DoEditLabels(LabelTrack *lt=nullptr, int index=-1)
Definition: Menus.cpp:8732
bool PasteSelectedText(double sel0, double sel1)
int GetLabelIndex(double t, double t1)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
double GetSel1() const
Definition: Project.h:205
bool CutSelectedText()
Definition: LabelTrack.cpp:993
bool LabelTrack::OnKeyDown ( SelectedRegion sel,
wxKeyEvent &  event 
)

KeyEvent is called for every keypress when over the label track.

Definition at line 1843 of file LabelTrack.cpp.

References DeleteLabel(), TrackListIterator::First(), GetActiveProject(), AudacityProject::GetTrackPanel(), IsGoodLabelEditKey(), IsGoodLabelFirstKey(), mCurrentCursorPos, mDrawCursor, min(), mInitialCursorPos, mLabels, mRestoreFocus, mSelIndex, TrackListIterator::Next(), RemoveSelectedText(), LabelStruct::selectedRegion, TrackPanel::SetFocusedTrack(), ShowContextMenu(), SelectedRegion::t0(), and LabelStruct::title.

Referenced by KeyDown().

1844 {
1845  // Only track true changes to the label
1846  bool updated = false;
1847 
1848  // Cache the keycode
1849  int keyCode = event.GetKeyCode();
1850  const int mods = event.GetModifiers();
1851 
1852  // Check for modifiers and only allow shift
1853  if (mods != wxMOD_NONE && mods != wxMOD_SHIFT) {
1854  event.Skip();
1855  return updated;
1856  }
1857 
1858  // All editing keys are only active if we're currently editing a label
1859  if (mSelIndex >= 0) {
1860  auto &labelStruct = mLabels[mSelIndex];
1861  auto &title = labelStruct.title;
1862  switch (keyCode) {
1863 
1864  case WXK_BACK:
1865  {
1866  int len = title.Length();
1867 
1868  //IF the label is not blank THEN get rid of a letter or letters according to cursor position
1869  if (len > 0)
1870  {
1871  // IF there are some highlighted letters, THEN DELETE them
1874  else
1875  {
1876  // DELETE one letter
1877  if (mCurrentCursorPos > 0) {
1878  title.Remove(mCurrentCursorPos-1, 1);
1880  }
1881  }
1882  }
1883  else
1884  {
1885  // ELSE no text in text box, so DELETE whole label.
1887  }
1889  updated = true;
1890  }
1891  break;
1892 
1893  case WXK_DELETE:
1894  case WXK_NUMPAD_DELETE:
1895  {
1896  int len = title.Length();
1897 
1898  //If the label is not blank get rid of a letter according to cursor position
1899  if (len > 0)
1900  {
1901  // if there are some highlighted letters, DELETE them
1904  else
1905  {
1906  // DELETE one letter
1907  if (mCurrentCursorPos < len) {
1908  title.Remove(mCurrentCursorPos, 1);
1909  }
1910  }
1911  }
1912  else
1913  {
1914  // DELETE whole label if no text in text box
1916  }
1918  updated = true;
1919  }
1920  break;
1921 
1922  case WXK_HOME:
1923  case WXK_NUMPAD_HOME:
1924  // Move cursor to beginning of label
1925  mCurrentCursorPos = 0;
1926  if (mods == wxMOD_SHIFT)
1927  ;
1928  else
1930  break;
1931 
1932  case WXK_END:
1933  case WXK_NUMPAD_END:
1934  // Move cursor to end of label
1935  mCurrentCursorPos = (int)title.length();
1936  if (mods == wxMOD_SHIFT)
1937  ;
1938  else
1940  break;
1941 
1942  case WXK_LEFT:
1943  case WXK_NUMPAD_LEFT:
1944  // Moving cursor left
1945  if (mCurrentCursorPos > 0) {
1947  if (mods == wxMOD_SHIFT)
1948  ;
1949  else
1952  }
1953  break;
1954 
1955  case WXK_RIGHT:
1956  case WXK_NUMPAD_RIGHT:
1957  // Moving cursor right
1958  if (mCurrentCursorPos < (int)title.length()) {
1960  if (mods == wxMOD_SHIFT)
1961  ;
1962  else
1965  }
1966  break;
1967 
1968  case WXK_RETURN:
1969  case WXK_NUMPAD_ENTER:
1970 
1971  case WXK_ESCAPE:
1972  if (mRestoreFocus >= 0) {
1973  TrackListIterator iter(GetActiveProject()->GetTracks());
1974  Track *track = iter.First();
1975  while (track && mRestoreFocus--)
1976  track = iter.Next();
1977  if (track)
1979  mRestoreFocus = -1;
1980  }
1981  mSelIndex = -1;
1982  break;
1983 
1984  case WXK_TAB:
1985  case WXK_NUMPAD_TAB:
1986  if (event.ShiftDown()) {
1987  mSelIndex--;
1988  } else {
1989  mSelIndex++;
1990  }
1991 
1992  mSelIndex = (mSelIndex + (int)mLabels.size()) % (int)mLabels.size(); // wrap round if necessary
1993  {
1994  LabelStruct &newLabel = mLabels[mSelIndex];
1995  mCurrentCursorPos = newLabel.title.Length();
1997  //Set the selection region to be equal to the selection bounds of the tabbed-to label.
1998  newSel = newLabel.selectedRegion;
1999  }
2000  break;
2001 
2002  case '\x10': // OSX
2003  case WXK_MENU:
2004  case WXK_WINDOWS_MENU:
2005  ShowContextMenu();
2006  break;
2007 
2008  default:
2009  if (!IsGoodLabelEditKey(event)) {
2010  event.Skip();
2011  }
2012  break;
2013  }
2014  }
2015  else
2016  {
2017  switch (keyCode) {
2018 
2019  case WXK_TAB:
2020  case WXK_NUMPAD_TAB:
2021  if (!mLabels.empty()) {
2022  int len = (int) mLabels.size();
2023  if (event.ShiftDown()) {
2024  mSelIndex = len - 1;
2025  if (newSel.t0() > mLabels[0].getT0()) {
2026  while (mSelIndex >= 0 &&
2027  mLabels[mSelIndex].getT0() > newSel.t0()) {
2028  mSelIndex--;
2029  }
2030  }
2031  } else {
2032  mSelIndex = 0;
2033  if (newSel.t0() < mLabels[len - 1].getT0()) {
2034  while (mSelIndex < len &&
2035  mLabels[mSelIndex].getT0() < newSel.t0()) {
2036  mSelIndex++;
2037  }
2038  }
2039  }
2040 
2041  if (mSelIndex >= 0 && mSelIndex < len) {
2042  const auto &labelStruct = mLabels[mSelIndex];
2043  mCurrentCursorPos = labelStruct.title.Length();
2045  //Set the selection region to be equal to the selection bounds of the tabbed-to label.
2046  newSel = labelStruct.selectedRegion;
2047  }
2048  else {
2049  mSelIndex = -1;
2050  }
2051  }
2052  break;
2053 
2054  default:
2055  if (!IsGoodLabelFirstKey(event)) {
2056  event.Skip();
2057  }
2058  break;
2059  }
2060  }
2061 
2062  // Make sure the caret is visible
2063  mDrawCursor = true;
2064 
2065  return updated;
2066 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
bool IsGoodLabelFirstKey(const wxKeyEvent &evt)
Returns true for keys we capture to start a label.
void DeleteLabel(int index)
wxString title
Definition: LabelTrack.h:92
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
void ShowContextMenu()
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void SetFocusedTrack(Track *t)
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
int mSelIndex
Definition: LabelTrack.h:280
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
int min(int a, int b)
void RemoveSelectedText()
int mRestoreFocus
cursor or not
Definition: LabelTrack.h:297
An iterator for a TrackList.
Definition: Track.h:402
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
TrackPanel * GetTrackPanel()
Definition: Project.h:307
bool IsGoodLabelEditKey(const wxKeyEvent &evt)
This returns true for keys we capture for label editing.
int LabelTrack::OverATextBox ( int  xx,
int  yy 
) const

Definition at line 1209 of file LabelTrack.cpp.

References mLabels, and OverTextBox().

Referenced by HandleTextClick().

1210 {
1211  for (int nn = (int)mLabels.size(); nn--;) {
1212  const auto &labelStruct = mLabels[nn];
1213  if (OverTextBox(&labelStruct, xx, yy))
1214  return nn;
1215  }
1216 
1217  return -1;
1218 }
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void LabelTrack::OverGlyph ( LabelTrackHit hit,
int  x,
int  y 
) const

TODO: Investigate what happens with large numbers of labels, might need a binary search rather than a linear one.

Definition at line 1156 of file LabelTrack.cpp.

References LabelTrackHit::mEdge, mLabels, LabelTrackHit::mMouseOverLabelLeft, LabelTrackHit::mMouseOverLabelRight, mTextHeight, and OverTextBox().

1157 {
1158  //Determine the NEW selection.
1159  int result=0;
1160  const int d1=10; //distance in pixels, used for have we hit drag handle.
1161  const int d2=5; //distance in pixels, used for have we hit drag handle center.
1162 
1163  //If not over a label, reset it
1164  hit.mMouseOverLabelLeft = -1;
1165  hit.mMouseOverLabelRight = -1;
1166  hit.mEdge = 0;
1167  { int i = -1; for (auto &labelStruct : mLabels) { ++i;
1168  //over left or right selection bound
1169  //Check right bound first, since it is drawn after left bound,
1170  //so give it precedence for matching/highlighting.
1171  if( abs(labelStruct.y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 &&
1172  abs(labelStruct.x1 - d2 -x) < d1)
1173  {
1174  hit.mMouseOverLabelRight = i;
1175  if(abs(labelStruct.x1 - x) < d2 )
1176  {
1177  result |= 4;
1178  // If left and right co-incident at this resolution, then we drag both.
1179  // We could be a little less stringent about co-incidence here if we liked.
1180  if( abs(labelStruct.x1-labelStruct.x) < 1.0 )
1181  {
1182  result |=1;
1183  hit.mMouseOverLabelLeft = i;
1184  }
1185  }
1186  result |= 2;
1187  }
1188  // Use else-if here rather than else to avoid detecting left and right
1189  // of the same label.
1190  else if( abs(labelStruct.y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 &&
1191  abs(labelStruct.x + d2 - x) < d1 )
1192  {
1193  hit.mMouseOverLabelLeft = i;
1194  if(abs(labelStruct.x - x) < d2 )
1195  result |= 4;
1196  result |= 1;
1197  }
1198 
1199  // give text box better priority for selecting
1200  if(OverTextBox(&labelStruct, x, y))
1201  {
1202  result = 0;
1203  }
1204 
1205  }}
1206  hit.mEdge = result;
1207 }
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
static int mTextHeight
Definition: LabelTrack.h:286
bool LabelTrack::OverTextBox ( const LabelStruct pLabel,
int  x,
int  y 
) const

Definition at line 1221 of file LabelTrack.cpp.

References mIconHeight, mIconWidth, LabelStruct::width, LabelStruct::xText, and LabelStruct::y.

Referenced by HandleTextClick(), HandleTextDragRelease(), OverATextBox(), and OverGlyph().

1222 {
1223  if( (pLabel->xText-(mIconWidth/2) < x) &&
1224  (x<pLabel->xText+pLabel->width+(mIconWidth/2)) &&
1225  (abs(pLabel->y-y)<mIconHeight/2))
1226  {
1227  return true;
1228  }
1229  return false;
1230 }
static int mIconHeight
Definition: LabelTrack.h:284
int xText
Pixel position of right hand glyph.
Definition: LabelTrack.h:98
static int mIconWidth
Definition: LabelTrack.h:285
int width
Text of the label.
Definition: LabelTrack.h:93
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:99
void LabelTrack::Paste ( double  t,
const Track src 
)
override

Definition at line 2574 of file LabelTrack.cpp.

References GetEndTime(), Track::GetKind(), Track::Label, mClipLen, PasteOver(), and ShiftLabelsOnInsert().

2575 {
2576  if (src->GetKind() != Track::Label)
2577  // THROW_INCONSISTENCY_EXCEPTION; // ?
2578  return;
2579 
2580  LabelTrack *lt = (LabelTrack *)src;
2581 
2582  double shiftAmt = lt->mClipLen > 0.0 ? lt->mClipLen : lt->GetEndTime();
2583 
2584  ShiftLabelsOnInsert(shiftAmt, t);
2585  PasteOver(t, src);
2586 }
double GetEndTime() const override
virtual int GetKind() const
Definition: Track.h:330
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
double mClipLen
when done editing
Definition: LabelTrack.h:301
bool PasteOver(double t, const Track *src)
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:200
bool LabelTrack::PasteOver ( double  t,
const Track src 
)

Definition at line 2548 of file LabelTrack.cpp.

References Track::GetKind(), Track::Label, and LabelStruct::selectedRegion.

Referenced by Paste().

2549 {
2550  if (src->GetKind() != Track::Label)
2551  // THROW_INCONSISTENCY_EXCEPTION; // ?
2552  return false;
2553 
2554  int len = mLabels.size();
2555  int pos = 0;
2556 
2557  while (pos < len && mLabels[pos].getT0() < t)
2558  pos++;
2559 
2560  auto sl = static_cast<const LabelTrack *>(src);
2561  for (auto &labelStruct: sl->mLabels) {
2562  LabelStruct l {
2563  labelStruct.selectedRegion,
2564  labelStruct.getT0() + t,
2565  labelStruct.getT1() + t,
2566  labelStruct.title
2567  };
2568  mLabels.insert(mLabels.begin() + pos++, l);
2569  }
2570 
2571  return true;
2572 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
virtual int GetKind() const
Definition: Track.h:330
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
bool LabelTrack::PasteSelectedText ( double  sel0,
double  sel1 
)

Paste the text on the clipboard to text box

Returns
true if mouse is clicked in text box, false otherwise

Definition at line 1066 of file LabelTrack.cpp.

References AddLabel(), IsTextClipSupported(), mCurrentCursorPos, mInitialCursorPos, mLabels, and mSelIndex.

Referenced by AudacityProject::HandlePasteText(), HandleTextClick(), OnContextMenu(), and AudacityProject::OnPasteNewLabel().

1067 {
1068  if (mSelIndex == -1)
1069  AddLabel(SelectedRegion(sel0, sel1), wxT(""));
1070 
1071  wxString text, left, right;
1072 
1073  // if text data is available
1074  if (IsTextClipSupported()) {
1075  if (wxTheClipboard->Open()) {
1076  wxTextDataObject data;
1077  wxTheClipboard->GetData(data);
1078  wxTheClipboard->Close();
1079  text = data.GetText();
1080  }
1081 
1082  // Convert control characters to blanks
1083  for (int i = 0; i < (int)text.Length(); i++) {
1084  if (wxIscntrl(text[i])) {
1085  text[i] = wxT(' ');
1086  }
1087  }
1088  }
1089 
1090  auto &labelStruct = mLabels[mSelIndex];
1091  auto &title = labelStruct.title;
1092  int cur = mCurrentCursorPos, init = mInitialCursorPos;
1093  if (init > cur)
1094  std::swap(init, cur);
1095  left = title.Left(init);
1096  if (cur < (int)title.Length())
1097  right = title.Mid(cur);
1098 
1099  title = left + text + right;
1100  mInitialCursorPos = mCurrentCursorPos = left.Length() + text.Length();
1101  return true;
1102 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
static bool IsTextClipSupported()
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
Defines a selected portion of a project.
int AddLabel(const SelectedRegion &region, const wxString &title=wxT(""), int restoreFocus=-1)
void LabelTrack::RemoveSelectedText ( )
private

Definition at line 2248 of file LabelTrack.cpp.

References mCurrentCursorPos, mInitialCursorPos, mLabels, and mSelIndex.

Referenced by OnChar(), and OnKeyDown().

2249 {
2250  wxString left, right;
2251 
2252  int init = mInitialCursorPos;
2253  int cur = mCurrentCursorPos;
2254  if (init > cur)
2255  std::swap(init, cur);
2256 
2257  auto &labelStruct = mLabels[mSelIndex];
2258  auto &title = labelStruct.title;
2259 
2260  if (init > 0)
2261  left = title.Left(init);
2262 
2263  if (cur < (int)title.Length())
2264  right = title.Mid(cur);
2265 
2266  title = left + right;
2267  mInitialCursorPos = mCurrentCursorPos = left.Length();
2268 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
bool LabelTrack::Repeat ( double  t0,
double  t1,
int  n 
)

Definition at line 2589 of file LabelTrack.cpp.

References LabelStruct::BEGINS_IN_LABEL, LabelStruct::getT0(), LabelStruct::getT1(), label, LabelStruct::selectedRegion, ShiftLabelsOnInsert(), LabelStruct::SURROUNDS_LABEL, and LabelStruct::title.

Referenced by EffectRepeat::Process().

2590 {
2591  // Sanity-check the arguments
2592  if (n < 0 || t1 < t0)
2593  return false;
2594 
2595  double tLen = t1 - t0;
2596 
2597  // Insert space for the repetitions
2598  ShiftLabelsOnInsert(tLen * n, t1);
2599 
2600  // mLabels may resize as we iterate, so use subscripting
2601  for (unsigned int i = 0; i < mLabels.size(); ++i)
2602  {
2603  LabelStruct::TimeRelations relation =
2604  mLabels[i].RegionRelation(t0, t1, this);
2605  if (relation == LabelStruct::SURROUNDS_LABEL)
2606  {
2607  // Label is completely inside the selection; duplicate it in each
2608  // repeat interval
2609  unsigned int pos = i; // running label insertion position in mLabels
2610 
2611  for (int j = 1; j <= n; j++)
2612  {
2613  const LabelStruct &label = mLabels[i];
2614  LabelStruct l {
2615  label.selectedRegion,
2616  label.getT0() + j * tLen,
2617  label.getT1() + j * tLen,
2618  label.title
2619  };
2620 
2621  // Figure out where to insert
2622  while (pos < mLabels.size() &&
2623  mLabels[pos].getT0() < l.getT0())
2624  pos++;
2625  mLabels.insert(mLabels.begin() + pos, l);
2626  }
2627  }
2628  else if (relation == LabelStruct::BEGINS_IN_LABEL)
2629  {
2630  // Label ends inside the selection; ShiftLabelsOnInsert() hasn't touched
2631  // it, and we need to extend it through to the last repeat interval
2632  mLabels[i].selectedRegion.moveT1(n * tLen);
2633  }
2634 
2635  // Other cases have already been handled by ShiftLabelsOnInsert()
2636  }
2637 
2638  return true;
2639 }
wxString label
Definition: Tags.cpp:727
wxString title
Definition: LabelTrack.h:92
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:73
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
double getT1() const
Definition: LabelTrack.h:62
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:200
double getT0() const
Definition: LabelTrack.h:61
void LabelTrack::ResetFlags ( )

Definition at line 268 of file LabelTrack.cpp.

References mCurrentCursorPos, mDrawCursor, mInitialCursorPos, and mRightDragging.

Referenced by LabelDefaultClickHandle::Click(), and LabelTrack().

269 {
270  mInitialCursorPos = 1;
271  mCurrentCursorPos = 1;
272  mRightDragging = false;
273  mDrawCursor = false;
274 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
bool mRightDragging
initial cursor position
Definition: LabelTrack.h:294
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
void LabelTrack::ResetFont ( )
static

Definition at line 296 of file LabelTrack.cpp.

References DefaultFontSize, GetFont(), gPrefs, mFontHeight, and msFont.

Referenced by LabelTrack(), and LabelTrackMenuTable::OnSetFont().

297 {
298  mFontHeight = -1;
299  wxString facename = gPrefs->Read(wxT("/GUI/LabelFontFacename"), wxT(""));
300  int size = gPrefs->Read(wxT("/GUI/LabelFontSize"), DefaultFontSize);
301  msFont = GetFont(facename, size);
302 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
static wxFont GetFont(const wxString &faceName, int size=DefaultFontSize)
Definition: LabelTrack.cpp:285
static int mFontHeight
Definition: LabelTrack.h:290
static wxFont msFont
Definition: LabelTrack.h:316
static const int DefaultFontSize
Definition: LabelTrack.h:145
void LabelTrack::RestoreFlags ( const Flags flags)

Definition at line 276 of file LabelTrack.cpp.

References LabelTrack::Flags::mCurrentCursorPos, mCurrentCursorPos, LabelTrack::Flags::mDrawCursor, mDrawCursor, LabelTrack::Flags::mInitialCursorPos, mInitialCursorPos, LabelTrack::Flags::mRightDragging, mRightDragging, LabelTrack::Flags::mSelIndex, and mSelIndex.

277 {
278  mInitialCursorPos = flags.mInitialCursorPos;
279  mCurrentCursorPos = flags.mCurrentCursorPos;
280  mSelIndex = flags.mSelIndex;
281  mRightDragging = flags.mRightDragging;
282  mDrawCursor = flags.mDrawCursor;
283 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
bool mRightDragging
initial cursor position
Definition: LabelTrack.h:294
int mSelIndex
Definition: LabelTrack.h:280
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
Flags LabelTrack::SaveFlags ( ) const
inline

Definition at line 193 of file LabelTrack.h.

Referenced by LabelDefaultClickHandle::SaveState().

194  {
195  return {
198  };
199  }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int mInitialCursorPos
current cursor position
Definition: LabelTrack.h:292
bool mRightDragging
initial cursor position
Definition: LabelTrack.h:294
int mSelIndex
Definition: LabelTrack.h:280
bool mDrawCursor
flag to tell if it's a valid dragging
Definition: LabelTrack.h:295
void LabelTrack::ScaleLabels ( double  b,
double  e,
double  change 
)

Definition at line 228 of file LabelTrack.cpp.

References AdjustTimeStampOnScale(), and mLabels.

229 {
230  for (auto &labelStruct: mLabels) {
231  labelStruct.selectedRegion.setTimes(
232  AdjustTimeStampOnScale(labelStruct.getT0(), b, e, change),
233  AdjustTimeStampOnScale(labelStruct.getT1(), b, e, change));
234  }
235 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
double AdjustTimeStampOnScale(double t, double b, double e, double change)
Definition: LabelTrack.cpp:237
void LabelTrack::SetCurrentCursorPosition ( int  xPos)

Set the cursor position according to x position of mouse.

Definition at line 959 of file LabelTrack.cpp.

References FindCurrentCursorPosition(), and mCurrentCursorPos.

Referenced by HandleTextDragRelease().

960 {
962 }
int mCurrentCursorPos
Definition: LabelTrack.h:291
int FindCurrentCursorPosition(int xPos)
Definition: LabelTrack.cpp:912
void LabelTrack::SetOffset ( double  dOffset)
overridevirtual

Reimplemented from Track.

Definition at line 145 of file LabelTrack.cpp.

References mLabels.

Referenced by Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack().

146 {
147  for (auto &labelStruct: mLabels)
148  labelStruct.selectedRegion.move(dOffset);
149 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void LabelTrack::SetSelected ( bool  s)
overridevirtual

Reimplemented from Track.

Definition at line 1146 of file LabelTrack.cpp.

References Track::SetSelected(), and Unselect().

Referenced by AudacityProject::DoAddLabel(), HandleXMLTag(), and OnChar().

1147 {
1148  Track::SetSelected(s);
1149  if (!s)
1150  Unselect();
1151 }
void Unselect()
virtual void SetSelected(bool s)
Definition: Track.cpp:99
void LabelTrack::ShiftLabelsOnInsert ( double  length,
double  pt 
)

Definition at line 200 of file LabelTrack.cpp.

References LabelStruct::BEFORE_LABEL, mLabels, and LabelStruct::WITHIN_LABEL.

Referenced by Paste(), and Repeat().

201 {
202  for (auto &labelStruct: mLabels) {
203  LabelStruct::TimeRelations relation =
204  labelStruct.RegionRelation(pt, pt, this);
205 
206  if (relation == LabelStruct::BEFORE_LABEL)
207  labelStruct.selectedRegion.move(length);
208  else if (relation == LabelStruct::WITHIN_LABEL)
209  labelStruct.selectedRegion.moveT1(length);
210  }
211 }
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:73
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void LabelTrack::ShowContextMenu ( )
private

Definition at line 2156 of file LabelTrack.cpp.

References _(), CalcCursorX(), GetLabel(), IsTextClipSupported(), IsTextSelected(), mIconHeight, mSelIndex, msFont, OnContextMenu(), OnCopySelectedTextID, OnCutSelectedTextID, OnDeleteSelectedLabelID, OnEditSelectedLabelID, OnPasteSelectedTextID, and LabelStruct::y.

Referenced by HandleTextDragRelease(), and OnKeyDown().

2157 {
2158  wxWindow *parent = wxWindow::FindFocus();
2159 
2160  {
2161  wxMenu menu;
2162  menu.Bind(wxEVT_MENU, &LabelTrack::OnContextMenu, this);
2163 
2164  menu.Append(OnCutSelectedTextID, _("Cu&t"));
2165  menu.Append(OnCopySelectedTextID, _("&Copy"));
2166  menu.Append(OnPasteSelectedTextID, _("&Paste"));
2167  menu.Append(OnDeleteSelectedLabelID, _("&Delete Label"));
2168  menu.Append(OnEditSelectedLabelID, _("&Edit..."));
2169 
2170  menu.Enable(OnCutSelectedTextID, IsTextSelected());
2171  menu.Enable(OnCopySelectedTextID, IsTextSelected());
2173  menu.Enable(OnDeleteSelectedLabelID, true);
2174  menu.Enable(OnEditSelectedLabelID, true);
2175 
2176  wxASSERT(mSelIndex >= 0);
2177  const LabelStruct *ls = GetLabel(mSelIndex);
2178 
2179  wxClientDC dc(parent);
2180 
2181  if (msFont.Ok())
2182  {
2183  dc.SetFont(msFont);
2184  }
2185 
2186  int x = 0;
2187  bool success = CalcCursorX(&x);
2188  wxASSERT(success);
2189  static_cast<void>(success); // Suppress unused variable warning if debug mode is disabled
2190 
2191  parent->PopupMenu(&menu, x, ls->y + (mIconHeight / 2) - 1);
2192  }
2193 }
static int mIconHeight
Definition: LabelTrack.h:284
bool IsTextSelected()
Definition: LabelTrack.cpp:982
static bool IsTextClipSupported()
bool CalcCursorX(int *x) const
Definition: LabelTrack.cpp:723
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
int mSelIndex
Definition: LabelTrack.h:280
const LabelStruct * GetLabel(int index) const
void OnContextMenu(wxCommandEvent &evt)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static wxFont msFont
Definition: LabelTrack.h:316
int y
Pixel position of left hand side of text box.
Definition: LabelTrack.h:99
void LabelTrack::Silence ( double  t0,
double  t1 
)
override

Definition at line 2641 of file LabelTrack.cpp.

References LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, LabelStruct::getT1(), label, LabelStruct::selectedRegion, SortLabels(), LabelStruct::SURROUNDS_LABEL, LabelStruct::title, and LabelStruct::WITHIN_LABEL.

2642 {
2643  int len = mLabels.size();
2644 
2645  // mLabels may resize as we iterate, so use subscripting
2646  for (int i = 0; i < len; ++i) {
2647  LabelStruct::TimeRelations relation =
2648  mLabels[i].RegionRelation(t0, t1, this);
2649  if (relation == LabelStruct::WITHIN_LABEL)
2650  {
2651  // Split label around the selection
2652  const LabelStruct &label = mLabels[i];
2653  LabelStruct l {
2654  label.selectedRegion,
2655  t1,
2656  label.getT1(),
2657  label.title
2658  };
2659 
2660  mLabels[i].selectedRegion.setT1(t0);
2661 
2662  // This might not be the right place to insert, but we sort at the end
2663  ++i;
2664  mLabels.insert(mLabels.begin() + i, l);
2665  }
2666  else if (relation == LabelStruct::ENDS_IN_LABEL)
2667  {
2668  // Beginning of label to selection end
2669  mLabels[i].selectedRegion.setT0(t1);
2670  }
2671  else if (relation == LabelStruct::BEGINS_IN_LABEL)
2672  {
2673  // End of label to selection beginning
2674  mLabels[i].selectedRegion.setT1(t0);
2675  }
2676  else if (relation == LabelStruct::SURROUNDS_LABEL)
2677  {
2678  DeleteLabel( i );
2679  len--;
2680  i--;
2681  }
2682  }
2683 
2684  SortLabels();
2685 }
void DeleteLabel(int index)
wxString label
Definition: Tags.cpp:727
wxString title
Definition: LabelTrack.h:92
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:73
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
double getT1() const
Definition: LabelTrack.h:62
void SortLabels(LabelTrackHit *pHit=nullptr)
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
void LabelTrack::SortLabels ( LabelTrackHit pHit = nullptr)

Sorts the labels in order of their starting times. This function is called often (whilst dragging a label) We expect them to be very nearly in order, so insertion sort (with a linear search) is a reasonable choice.

Definition at line 2937 of file LabelTrack.cpp.

References LabelTrackHit::mMouseOverLabelLeft, LabelTrackHit::mMouseOverLabelRight, and mSelIndex.

Referenced by ChangeLabelsOnReverse(), Import(), Silence(), and WarpLabels().

2938 {
2939  const auto begin = mLabels.begin();
2940  const auto nn = (int)mLabels.size();
2941  int i = 1;
2942  while (true)
2943  {
2944  // Find the next disorder
2945  while (i < nn && mLabels[i - 1].getT0() <= mLabels[i].getT0())
2946  ++i;
2947  if (i >= nn)
2948  break;
2949 
2950  // Where must element i sink to? At most i - 1, maybe less
2951  int j = i - 2;
2952  while( (j >= 0) && (mLabels[j].getT0() > mLabels[i].getT0()) )
2953  --j;
2954  ++j;
2955 
2956  // Now fix the disorder
2957  std::rotate(
2958  begin + j,
2959  begin + i,
2960  begin + i + 1
2961  );
2962 
2963  // Various indices need to be updated with the moved items...
2964  auto update = [=](int &index) {
2965  if( index <= i ) {
2966  if( index == i )
2967  index = j;
2968  else if( index >= j)
2969  ++index;
2970  }
2971  };
2972  if ( pHit ) {
2973  update( pHit->mMouseOverLabelLeft );
2974  update( pHit->mMouseOverLabelRight );
2975  }
2976  update(mSelIndex);
2977  }
2978 }
int mMouseOverLabelRight
Keeps track of which left label the mouse is currently over.
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
int mSelIndex
Definition: LabelTrack.h:280
void LabelTrack::Unselect ( )

Definition at line 2270 of file LabelTrack.cpp.

References mSelIndex.

Referenced by LabelDefaultClickHandle::Click(), AudacityProject::OnPasteNewLabel(), and SetSelected().

2271 {
2272  mSelIndex = -1;
2273 }
int mSelIndex
Definition: LabelTrack.h:280
void LabelTrack::WarpLabels ( const TimeWarper warper)

Definition at line 256 of file LabelTrack.cpp.

References mLabels, SortLabels(), and TimeWarper::Warp().

Referenced by EffectChangeSpeed::ProcessLabelTrack().

256  {
257  for (auto &labelStruct: mLabels) {
258  labelStruct.selectedRegion.setTimes(
259  warper.Warp(labelStruct.getT0()),
260  warper.Warp(labelStruct.getT1()));
261  }
262 
263  // This should not be needed, assuming the warper is nondecreasing, but
264  // let's not assume too much.
265  SortLabels();
266 }
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
void SortLabels(LabelTrackHit *pHit=nullptr)
virtual double Warp(double originalTime) const =0
void LabelTrack::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Implements Track.

Definition at line 2402 of file LabelTrack.cpp.

2404 {
2405  int len = mLabels.size();
2406 
2407  xmlFile.StartTag(wxT("labeltrack"));
2408  xmlFile.WriteAttr(wxT("name"), mName);
2409  xmlFile.WriteAttr(wxT("numlabels"), len);
2410  xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
2411  xmlFile.WriteAttr(wxT("minimized"), this->GetMinimized());
2412  xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
2413 
2414  for (auto &labelStruct: mLabels) {
2415  xmlFile.StartTag(wxT("label"));
2416  labelStruct.getSelectedRegion()
2417  .WriteXMLAttributes(xmlFile, wxT("t"), wxT("t1"));
2418  // PRL: to do: write other selection fields
2419  xmlFile.WriteAttr(wxT("title"), labelStruct.title);
2420  xmlFile.EndTag(wxT("label"));
2421  }
2422 
2423  xmlFile.EndTag(wxT("labeltrack"));
2424 }
int GetActualHeight() const
Definition: Track.h:193
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
bool GetSelected() const
Definition: Track.h:276
bool GetMinimized() const
Definition: Track.cpp:214
LabelArray mLabels
Displacement of mouse cursor from the centre being dragged.
Definition: LabelTrack.h:282
wxString mName
Definition: Track.h:119

Friends And Related Function Documentation

friend class GetInfoCommand
friend

Definition at line 324 of file LabelTrack.h.

friend class LabelStruct
friend

Definition at line 115 of file LabelTrack.h.

friend class SetLabelCommand
friend

Definition at line 325 of file LabelTrack.h.

Member Data Documentation

const int LabelTrack::DefaultFontSize = 12
static

Definition at line 145 of file LabelTrack.h.

Referenced by LabelTrackMenuTable::OnSetFont(), and ResetFont().

bool LabelTrack::mbGlyphsReady =false
staticprivate

Definition at line 287 of file LabelTrack.h.

Referenced by CreateCustomGlyphs().

wxBitmap LabelTrack::mBoundaryGlyphs
staticprivate

We have several variants of the icons (highlighting). The icons are draggable, and you can drag one boundary or all boundaries at the same timecode depending on whether you click the centre (for all) or the arrow part (for one). Currently we have twelve variants but we're only using six.

Definition at line 288 of file LabelTrack.h.

Referenced by CreateCustomGlyphs().

double LabelTrack::mClipLen
private

when done editing

Restore focus to this track

Definition at line 301 of file LabelTrack.h.

Referenced by Paste().

int LabelTrack::mCurrentCursorPos
private
bool LabelTrack::mDrawCursor
private

flag to tell if it's a valid dragging

Definition at line 295 of file LabelTrack.h.

Referenced by AddLabel(), HandleTextClick(), OnChar(), OnKeyDown(), ResetFlags(), and RestoreFlags().

int LabelTrack::mFontHeight =-1
staticprivate

Definition at line 290 of file LabelTrack.h.

Referenced by calculateFontHeight(), HandleTextClick(), and ResetFont().

std::weak_ptr<LabelGlyphHandle> LabelTrack::mGlyphHandle
private

Definition at line 318 of file LabelTrack.h.

int LabelTrack::mIconHeight
staticprivate
int LabelTrack::mIconWidth
staticprivate
int LabelTrack::miLastLabel
private

Definition at line 303 of file LabelTrack.h.

Referenced by FindNextLabel(), and FindPrevLabel().

int LabelTrack::mInitialCursorPos
private
LabelArray LabelTrack::mLabels
private
int LabelTrack::mRestoreFocus
private

cursor or not

flag to tell if drawing the

Definition at line 297 of file LabelTrack.h.

Referenced by AddLabel(), and OnKeyDown().

bool LabelTrack::mRightDragging
private

initial cursor position

Definition at line 294 of file LabelTrack.h.

Referenced by HandleTextClick(), HandleTextDragRelease(), ResetFlags(), and RestoreFlags().

int LabelTrack::mSelIndex
private
wxFont LabelTrack::msFont
staticprivate
std::weak_ptr<LabelTextHandle> LabelTrack::mTextHandle
private

Definition at line 319 of file LabelTrack.h.

int LabelTrack::mTextHeight
staticprivate
int LabelTrack::mxMouseDisplacement
private

Keeps track of the currently selected label.

Definition at line 281 of file LabelTrack.h.


The documentation for this class was generated from the following files: