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

Public Member Functions

 FormatMenuTable ()
 
 DECLARE_POPUP_MENU (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 166 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ FormatMenuTable()

FormatMenuTable::FormatMenuTable ( )
inline

Definition at line 168 of file WaveTrackControls.cpp.

169 : PopupMenuTable{ "SampleFormat", XO("&Format") }
170 {}
XO("Cut/Copy/Paste")

Member Function Documentation

◆ DECLARE_POPUP_MENU()

FormatMenuTable::DECLARE_POPUP_MENU ( FormatMenuTable  )

◆ IdOfFormat()

int FormatMenuTable::IdOfFormat ( sampleFormat  format)
static

Converts a format enumeration to a wxWidgets menu item Id.

Definition at line 213 of file WaveTrackControls.cpp.

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

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

◆ InitUserData()

void FormatMenuTable::InitUserData ( void *  pUserData)
overridevirtual

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 190 of file WaveTrackControls.cpp.

191{
192 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
193}
PlayableTrackControls::InitMenuData * mpData

References mpData.

◆ Instance()

FormatMenuTable & FormatMenuTable::Instance ( )
static

Definition at line 184 of file WaveTrackControls.cpp.

185{
186 static FormatMenuTable instance;
187 return instance;
188}

◆ OnFormatChange()

void FormatMenuTable::OnFormatChange ( wxCommandEvent &  event)

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

Definition at line 232 of file WaveTrackControls.cpp.

233{
234 int id = event.GetId();
235 wxASSERT(id >= On16BitID && id <= OnFloatID);
236 auto &track = static_cast<WaveTrack&>(mpData->track);
237
238 sampleFormat newFormat = int16Sample;
239
240 switch (id) {
241 case On16BitID:
242 newFormat = int16Sample;
243 break;
244 case On24BitID:
245 newFormat = int24Sample;
246 break;
247 case OnFloatID:
248 newFormat = floatSample;
249 break;
250 default:
251 // ERROR -- should not happen
252 wxASSERT(false);
253 break;
254 }
255 if (newFormat == track.GetSampleFormat())
256 return; // Nothing to do.
257
259
260 ProgressDialog progress{ XO("Changing sample format"),
261 XO("Processing... 0%%"),
263
264 // Simply finding a denominator for the progress dialog
265 // Hidden samples are processed too, they should be counted as well
266 // (Correctly counting all samples of all channels)
267 const sampleCount totalSamples =
269 sampleCount processedSamples{ 0 };
270
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) };
281
282 auto progressStatus = progress.Update(d_processed, d_total,
283 XO("Processing... %i%%").Format(percentage));
284
285 if (progressStatus != ProgressResult::Success)
286 throw UserException{};
287 };
288
289 track.ConvertToSampleFormat(newFormat, progressUpdate);
290
292 /* i18n-hint: The strings name a track and a format */
293 .PushState(XO("Changed '%s' to %s")
294 .Format(track.GetName(), GetSampleFormatStr(newFormat)),
295 XO("Format Change"));
296
297 using namespace RefreshCode;
299}
@ pdlgHideStopButton
TranslatableString GetSampleFormatStr(sampleFormat format)
sampleFormat
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:203
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
WAVE_TRACK_API sampleCount GetSequenceSamplesCount(const WaveTrack &track)

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

Here is the call graph for this function:

Member Data Documentation

◆ mpData

PlayableTrackControls::InitMenuData* FormatMenuTable::mpData {}

Definition at line 177 of file WaveTrackControls.cpp.

Referenced by InitUserData(), and OnFormatChange().


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