Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
FormatMenuTable Struct Reference
Inheritance diagram for FormatMenuTable:
Collaboration diagram for FormatMenuTable:

Public Member Functions

 FormatMenuTable ()
void InitUserData (void *pUserData) override
 Called before the menu items are appended. More...
void OnFormatChange (wxCommandEvent &event)
- Public Member Functions inherited from PopupMenuTable
 PopupMenuTable (const Identifier &id, const TranslatableString &caption={})
const IdentifierId () const
const TranslatableStringCaption () const
const auto * GetRegistry () const
const auto & Get (void *pUserData)
void Clear ()
- Public Member Functions inherited from PopupMenuHandler
 PopupMenuHandler ()=default
 PopupMenuHandler (const PopupMenuHandler &)=delete
PopupMenuHandleroperator= (const PopupMenuHandler &)=delete
virtual void InitUserData (void *pUserData)=0
 Called before the menu items are appended. More...

Static Public Member Functions

static FormatMenuTableInstance ()
static int IdOfFormat (sampleFormat format)
 Converts a format enumeration to a wxWidgets menu item Id. More...
- Static Public Member Functions inherited from PopupMenuTable
static std::unique_ptr< PopupMenuBuildMenu (PopupMenuTable *pTable, void *pUserData=NULL)
static void ExtendMenu (PopupMenu &menu, PopupMenuTable &otherTable)
template<typename Table , typename Factory >
static auto Adapt (const Factory &factory)

Public Attributes

PlayableTrackControls::InitMenuDatampData {}

Additional Inherited Members

- Public Types inherited from PopupMenuTable
using Entry = PopupMenuTableEntry
- Protected Member Functions inherited from PopupMenuTable
virtual void Populate ()=0
template<typename Ptr >
void Append (Ptr pItem)
void Append (const Identifier &stringId, PopupMenuTableEntry::Type type, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init)
void AppendItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
void AppendRadioItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
void AppendCheckItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
void BeginSection (const Identifier &name)
void EndSection ()
- Static Protected Member Functions inherited from PopupMenuTable
static TranslatableString MakeLabel (const TranslatableString &label, bool useExtra, const TranslatableString &extra)
- Protected Attributes inherited from PopupMenuTable
std::shared_ptr< PopupSubMenumTop
std::vector< PopupMenuGroupItem * > mStack
Identifier mId
TranslatableString mCaption
std::unique_ptr< PopupMenuGroupItemmRegistry

Detailed Description

Definition at line 164 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ FormatMenuTable()

FormatMenuTable::FormatMenuTable ( )

Definition at line 166 of file WaveTrackControls.cpp.

167 : PopupMenuTable{ "SampleFormat", XO("&Format") }
168 {}

Member Function Documentation


FormatMenuTable::DECLARE_POPUP_MENU ( FormatMenuTable  )

◆ IdOfFormat()

int FormatMenuTable::IdOfFormat ( sampleFormat  format)

Converts a format enumeration to a wxWidgets menu item Id.

Definition at line 211 of file WaveTrackControls.cpp.

213 switch (format) {
214 case int16Sample:
215 return On16BitID;
216 case int24Sample:
217 return On24BitID;
218 case floatSample:
219 return OnFloatID;
220 default:
221 // ERROR -- should not happen
222 wxASSERT(false);
223 break;
224 }
225 return OnFloatID;// Compiler food.
@ On16BitID
@ OnFloatID
@ On24BitID

References floatSample, anonymous_namespace{ExportPCM.cpp}::format, int16Sample, int24Sample, On16BitID, On24BitID, and OnFloatID.

◆ InitUserData()

void FormatMenuTable::InitUserData ( void *  pUserData)

Called before the menu items are appended.

Store context data, if needed. May be called more than once before the menu opens. Pointer remains valid for the duration of any callback, if PopupMenuTable::BuildMenu() is called and the result's Popup() is called before any other menus are built.

Implements PopupMenuHandler.

Definition at line 188 of file WaveTrackControls.cpp.

190 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
PlayableTrackControls::InitMenuData * mpData

References mpData.

◆ Instance()

FormatMenuTable & FormatMenuTable::Instance ( )

Definition at line 182 of file WaveTrackControls.cpp.

184 static FormatMenuTable instance;
185 return instance;

◆ OnFormatChange()

void FormatMenuTable::OnFormatChange ( wxCommandEvent &  event)

Handles the selection from the Format submenu of the track menu.

Definition at line 230 of file WaveTrackControls.cpp.

232 int id = event.GetId();
233 wxASSERT(id >= On16BitID && id <= OnFloatID);
234 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
236 sampleFormat newFormat = int16Sample;
238 switch (id) {
239 case On16BitID:
240 newFormat = int16Sample;
241 break;
242 case On24BitID:
243 newFormat = int24Sample;
244 break;
245 case OnFloatID:
246 newFormat = floatSample;
247 break;
248 default:
249 // ERROR -- should not happen
250 wxASSERT(false);
251 break;
252 }
253 if (newFormat == pTrack->GetSampleFormat())
254 return; // Nothing to do.
258 ProgressDialog progress{ XO("Changing sample format"),
259 XO("Processing... 0%%"),
262 // Safe assumption for tracks associated with the context menu
263 assert(pTrack->IsLeader());
265 // Simply finding a denominator for the progress dialog
266 // Hidden samples are processed too, they should be counted as well
267 // (Correctly counting all samples of all channels)
268 sampleCount totalSamples = pTrack->GetSequenceSamplesCount();
269 sampleCount processedSamples{ 0 };
271 // Below is the lambda function that is passed along the call chain to
272 // the Sequence::ConvertToSampleFormat. This callback function is used
273 // to report the conversion progress and update the progress dialog.
274 auto progressUpdate = [&progress, &totalSamples, &processedSamples]
275 (size_t newlyProcessedCount)->void
276 {
277 processedSamples += newlyProcessedCount;
278 double d_processed = processedSamples.as_double();
279 double d_total = totalSamples.as_double();
280 int percentage{ static_cast<int>((d_processed / d_total) * 100) };
282 auto progressStatus = progress.Update(d_processed, d_total,
283 XO("Processing... %i%%").Format(percentage));
285 if (progressStatus != ProgressResult::Success)
286 throw UserException{};
287 };
289 // We get here from the context menu only in the TrackControlPanel cell
290 // which is always associated with a leader track
291 assert(pTrack->IsLeader());
292 pTrack->ConvertToSampleFormat(newFormat, progressUpdate);
295 /* i18n-hint: The strings name a track and a format */
296 .PushState(XO("Changed '%s' to %s")
297 .Format( pTrack->GetName(), GetSampleFormatStr(newFormat) ),
298 XO("Format Change"));
300 using namespace RefreshCode;
@ pdlgHideStopButton
TranslatableString GetSampleFormatStr(sampleFormat format)
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Abstract base class used in importing a file.
ProgressDialog Class.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
Definition: UserException.h:17
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References sampleCount::as_double(), RefreshCode::FixScrollbars, floatSample, ProjectHistory::Get(), GetSampleFormatStr(), int16Sample, int24Sample, mpData, On16BitID, On24BitID, OnFloatID, pdlgHideStopButton, project, CommonTrackControls::InitMenuData::project, CommonTrackControls::InitMenuData::pTrack, ProjectHistory::PushState(), RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, BasicUI::Success, and XO().

Here is the call graph for this function:

Member Data Documentation

◆ mpData

PlayableTrackControls::InitMenuData* FormatMenuTable::mpData {}

Definition at line 175 of file WaveTrackControls.cpp.

Referenced by InitUserData(), and OnFormatChange().

The documentation for this struct was generated from the following file: