1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

Add columns to Label editor for low and high spectral selection

This commit is contained in:
Paul Licameli 2016-06-27 10:44:48 -04:00
parent 9c687f055c
commit f8fe26ca36
4 changed files with 80 additions and 7 deletions

View File

@ -47,6 +47,8 @@ enum Column
Col_Label, Col_Label,
Col_Stime, Col_Stime,
Col_Etime, Col_Etime,
Col_Lfreq,
Col_Hfreq,
Col_Max Col_Max
}; };
@ -83,6 +85,8 @@ BEGIN_EVENT_TABLE(LabelDialog, wxDialog)
EVT_BUTTON(wxID_OK, LabelDialog::OnOK) EVT_BUTTON(wxID_OK, LabelDialog::OnOK)
EVT_BUTTON(wxID_CANCEL, LabelDialog::OnCancel) EVT_BUTTON(wxID_CANCEL, LabelDialog::OnCancel)
EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, LabelDialog::OnUpdate) EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, LabelDialog::OnUpdate)
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED,
LabelDialog::OnFreqUpdate)
END_EVENT_TABLE() END_EVENT_TABLE()
LabelDialog::LabelDialog(wxWindow *parent, LabelDialog::LabelDialog(wxWindow *parent,
@ -92,7 +96,7 @@ LabelDialog::LabelDialog(wxWindow *parent,
int index, int index,
ViewInfo &viewinfo, ViewInfo &viewinfo,
double rate, double rate,
const wxString & format) const wxString & format, const wxString &freqFormat)
: wxDialog(parent, : wxDialog(parent,
wxID_ANY, wxID_ANY,
_("Edit Labels"), _("Edit Labels"),
@ -106,6 +110,7 @@ LabelDialog::LabelDialog(wxWindow *parent,
, mViewInfo(&viewinfo), , mViewInfo(&viewinfo),
mRate(rate), mRate(rate),
mFormat(format) mFormat(format)
, mFreqFormat(freqFormat)
{ {
SetName(GetTitle()); SetName(GetTitle());
@ -158,6 +163,10 @@ LabelDialog::LabelDialog(wxWindow *parent,
mGrid->SetColLabelValue(2,_("Start Time")); mGrid->SetColLabelValue(2,_("Start Time"));
/* i18n-hint: (noun) of a label*/ /* i18n-hint: (noun) of a label*/
mGrid->SetColLabelValue(3,_("End Time")); mGrid->SetColLabelValue(3,_("End Time"));
/* i18n-hint: (noun) of a label*/
mGrid->SetColLabelValue(4,_("Low Frequency"));
/* i18n-hint: (noun) of a label*/
mGrid->SetColLabelValue(5,_("High Frequency"));
// Create and remember editors. No need to DELETE these as the wxGrid will // Create and remember editors. No need to DELETE these as the wxGrid will
// do it for us. (The DecRef() that is needed after GetDefaultEditorForType // do it for us. (The DecRef() that is needed after GetDefaultEditorForType
@ -165,6 +174,8 @@ LabelDialog::LabelDialog(wxWindow *parent,
mChoiceEditor = (ChoiceEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_CHOICE); mChoiceEditor = (ChoiceEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_CHOICE);
mTimeEditor = static_cast<NumericEditor*> mTimeEditor = static_cast<NumericEditor*>
(mGrid->GetDefaultEditorForType(GRID_VALUE_TIME)); (mGrid->GetDefaultEditorForType(GRID_VALUE_TIME));
mFrequencyEditor = static_cast<NumericEditor *>
(mGrid->GetDefaultEditorForType(GRID_VALUE_FREQUENCY));
// Initialize and set the track name column attributes // Initialize and set the track name column attributes
wxGridCellAttr *attr; wxGridCellAttr *attr;
@ -181,6 +192,15 @@ LabelDialog::LabelDialog(wxWindow *parent,
mGrid->SetColAttr(Col_Etime, attr->Clone()); mGrid->SetColAttr(Col_Etime, attr->Clone());
// Initialize and set the frequency column attributes
mGrid->SetColAttr(Col_Lfreq, (attr = safenew wxGridCellAttr));
// Don't need DecRef() after this GetDefaultRendererForType.
attr->SetRenderer(mGrid->GetDefaultRendererForType(GRID_VALUE_FREQUENCY));
attr->SetEditor(mFrequencyEditor);
attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
mGrid->SetColAttr(Col_Hfreq, attr->Clone());
// Seems there's a bug in wxGrid. Adding only 1 row does not // Seems there's a bug in wxGrid. Adding only 1 row does not
// allow SetCellSize() to work properly and you will not get // allow SetCellSize() to work properly and you will not get
// the expected 1 row by 4 column cell. // the expected 1 row by 4 column cell.
@ -239,6 +259,8 @@ bool LabelDialog::TransferDataToWindow()
mChoiceEditor->SetChoices(mTrackNames); mChoiceEditor->SetChoices(mTrackNames);
mTimeEditor->SetFormat(mFormat); mTimeEditor->SetFormat(mFormat);
mTimeEditor->SetRate(mRate); mTimeEditor->SetRate(mRate);
mFrequencyEditor->SetFormat(mFreqFormat);
mFrequencyEditor->SetRate(mRate);
// Disable redrawing until we're done // Disable redrawing until we're done
mGrid->BeginBatch(); mGrid->BeginBatch();
@ -262,9 +284,10 @@ bool LabelDialog::TransferDataToWindow()
wxString::Format(wxT("%g"), rd.selectedRegion.t0())); wxString::Format(wxT("%g"), rd.selectedRegion.t0()));
mGrid->SetCellValue(i, Col_Etime, mGrid->SetCellValue(i, Col_Etime,
wxString::Format(wxT("%g"), rd.selectedRegion.t1())); wxString::Format(wxT("%g"), rd.selectedRegion.t1()));
mGrid->SetCellValue(i, Col_Lfreq,
// PRL: to do: -- populate future additional selection fields wxString::Format(wxT("%g"), rd.selectedRegion.f0()));
// and write event code to update them from controls mGrid->SetCellValue(i, Col_Hfreq,
wxString::Format(wxT("%g"), rd.selectedRegion.f1()));
} }
// Autosize all the rows // Autosize all the rows
@ -279,6 +302,8 @@ bool LabelDialog::TransferDataToWindow()
// Autosize the time columns and set their minimal widths // Autosize the time columns and set their minimal widths
mGrid->AutoSizeColumn(Col_Stime); mGrid->AutoSizeColumn(Col_Stime);
mGrid->AutoSizeColumn(Col_Etime); mGrid->AutoSizeColumn(Col_Etime);
mGrid->AutoSizeColumn(Col_Lfreq);
mGrid->AutoSizeColumn(Col_Hfreq);
// We're done, so allow the grid to redraw // We're done, so allow the grid to redraw
mGrid->EndBatch(); mGrid->EndBatch();
@ -467,6 +492,15 @@ void LabelDialog::OnUpdate(wxCommandEvent &event)
event.Skip(false); event.Skip(false);
} }
void LabelDialog::OnFreqUpdate(wxCommandEvent &event)
{
// Remember the NEW format and repopulate grid
mFreqFormat = event.GetString();
TransferDataToWindow();
event.Skip(false);
}
void LabelDialog::OnInsert(wxCommandEvent &event) void LabelDialog::OnInsert(wxCommandEvent &event)
{ {
int cnt = mData.size(); int cnt = mData.size();
@ -717,6 +751,14 @@ void LabelDialog::OnCellChange(wxGridEvent &event)
case Col_Etime: case Col_Etime:
OnChangeEtime(event, row, rd); OnChangeEtime(event, row, rd);
break; break;
case Col_Lfreq:
OnChangeLfreq(event, row, rd);
break;
case Col_Hfreq:
OnChangeHfreq(event, row, rd);
break;
} }
// Done...no need for protection anymore // Done...no need for protection anymore
@ -791,6 +833,30 @@ void LabelDialog::OnChangeEtime(wxGridEvent & WXUNUSED(event), int row, RowData
return; return;
} }
void LabelDialog::OnChangeLfreq(wxGridEvent & WXUNUSED(event), int row, RowData *rd)
{
// Remember the value...no need to repopulate
double f;
mGrid->GetCellValue(row, Col_Lfreq).ToDouble(&f);
rd->selectedRegion.setF0(f, false);
mGrid->SetCellValue(row, Col_Hfreq, wxString::Format(wxT("%g"),
rd->selectedRegion.f1()));
return;
}
void LabelDialog::OnChangeHfreq(wxGridEvent & WXUNUSED(event), int row, RowData *rd)
{
// Remember the value...no need to repopulate
double f;
mGrid->GetCellValue(row, Col_Hfreq).ToDouble(&f);
rd->selectedRegion.setF1(f, false);
mGrid->SetCellValue(row, Col_Lfreq, wxString::Format(wxT("%g"),
rd->selectedRegion.f0()));
return;
}
void LabelDialog::OnOK(wxCommandEvent & WXUNUSED(event)) void LabelDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{ {
if (mGrid->IsCellEditControlShown()) { if (mGrid->IsCellEditControlShown()) {

View File

@ -47,7 +47,7 @@ class LabelDialog final : public wxDialog
ViewInfo &viewinfo, ViewInfo &viewinfo,
double rate, double rate,
const wxString & format); const wxString & format, const wxString &freqFormat);
~LabelDialog(); ~LabelDialog();
bool Show(bool show = true) override; bool Show(bool show = true) override;
@ -63,6 +63,7 @@ class LabelDialog final : public wxDialog
wxString TrackName(int & index, const wxString &dflt = _("Label Track")); wxString TrackName(int & index, const wxString &dflt = _("Label Track"));
void OnUpdate(wxCommandEvent &event); void OnUpdate(wxCommandEvent &event);
void OnFreqUpdate(wxCommandEvent &event);
void OnInsert(wxCommandEvent &event); void OnInsert(wxCommandEvent &event);
void OnRemove(wxCommandEvent &event); void OnRemove(wxCommandEvent &event);
void OnImport(wxCommandEvent &event); void OnImport(wxCommandEvent &event);
@ -73,6 +74,8 @@ class LabelDialog final : public wxDialog
void OnChangeLabel(wxGridEvent &event, int row, RowData *rd); void OnChangeLabel(wxGridEvent &event, int row, RowData *rd);
void OnChangeStime(wxGridEvent &event, int row, RowData *rd); void OnChangeStime(wxGridEvent &event, int row, RowData *rd);
void OnChangeEtime(wxGridEvent &event, int row, RowData *rd); void OnChangeEtime(wxGridEvent &event, int row, RowData *rd);
void OnChangeLfreq(wxGridEvent &event, int row, RowData *rd);
void OnChangeHfreq(wxGridEvent &event, int row, RowData *rd);
void OnOK(wxCommandEvent &event); void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event); void OnCancel(wxCommandEvent &event);
@ -81,6 +84,7 @@ class LabelDialog final : public wxDialog
Grid *mGrid; Grid *mGrid;
ChoiceEditor *mChoiceEditor; ChoiceEditor *mChoiceEditor;
NumericEditor *mTimeEditor; NumericEditor *mTimeEditor;
NumericEditor *mFrequencyEditor;
RowDataArray mData; RowDataArray mData;
@ -92,6 +96,7 @@ class LabelDialog final : public wxDialog
wxArrayString mTrackNames; wxArrayString mTrackNames;
double mRate; double mRate;
wxString mFormat; wxString mFormat;
wxString mFreqFormat;
int mInitialRow; int mInitialRow;

View File

@ -6553,12 +6553,13 @@ void AudacityProject::OnAddLabelPlaying()
void AudacityProject::DoEditLabels(LabelTrack *lt, int index) void AudacityProject::DoEditLabels(LabelTrack *lt, int index)
{ {
wxString format = GetSelectionFormat(); wxString format = GetSelectionFormat(),
freqFormat = GetFrequencySelectionFormatName();
LabelDialog dlg(this, *GetTrackFactory(), mTracks, LabelDialog dlg(this, *GetTrackFactory(), mTracks,
lt, index, lt, index,
mViewInfo, mRate, mViewInfo, mRate,
format); format, freqFormat);
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
PushState(_("Edited labels"), _("Label")); PushState(_("Edited labels"), _("Label"));

View File

@ -35,6 +35,7 @@ class NumericTextCtrl;
// wxGridCellEditor for the NumericTextCtrl. // wxGridCellEditor for the NumericTextCtrl.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#define GRID_VALUE_TIME wxT("Time") #define GRID_VALUE_TIME wxT("Time")
#define GRID_VALUE_FREQUENCY wxT("Frequency")
class NumericEditor /* not final */ : public wxGridCellEditor class NumericEditor /* not final */ : public wxGridCellEditor
{ {