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 Registry::GroupItemGetRegistry () const
 
const std::shared_ptr< Registry::GroupItem > & 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 >
static Registry::BaseItemPtr Computed (const std::function< Registry::BaseItemPtr(Table &) > &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
 
void Append (Registry::BaseItemPtr 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< Registry::GroupItemmTop
 
std::vector< Registry::GroupItem * > mStack
 
Identifier mId
 
TranslatableString mCaption
 
std::unique_ptr< Registry::GroupItemmRegistry
 

Detailed Description

Definition at line 164 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ FormatMenuTable()

FormatMenuTable::FormatMenuTable ( )
inline

Definition at line 166 of file WaveTrackControls.cpp.

167 : PopupMenuTable{ "SampleFormat", XO("&Format") }
168 {}
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 211 of file WaveTrackControls.cpp.

212{
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.
226}
int format
Definition: ExportPCM.cpp:53
@ On16BitID
@ OnFloatID
@ On24BitID

References floatSample, 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 188 of file WaveTrackControls.cpp.

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

References mpData.

◆ Instance()

FormatMenuTable & FormatMenuTable::Instance ( )
static

Definition at line 182 of file WaveTrackControls.cpp.

183{
184 static FormatMenuTable instance;
185 return instance;
186}

◆ 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.

231{
232 int id = event.GetId();
233 wxASSERT(id >= On16BitID && id <= OnFloatID);
234 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
235
236 sampleFormat newFormat = int16Sample;
237
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.
255
256 AudacityProject *const project = &mpData->project;
257
258 ProgressDialog progress{ XO("Changing sample format"),
259 XO("Processing... 0%%"),
261
262 sampleCount totalSamples{ 0 };
263 for (const auto& channel : TrackList::Channels(pTrack))
264 // Hidden samples are processed too, they should be counted as well
265 totalSamples += channel->GetSequenceSamplesCount();
266 sampleCount processedSamples{ 0 };
267
268 // Below is the lambda function that is passed along the call chain to
269 // the Sequence::ConvertToSampleFormat. This callback function is used
270 // to report the conversion progress and update the progress dialog.
271 auto progressUpdate = [&progress, &totalSamples, &processedSamples]
272 (size_t newlyProcessedCount)->void
273 {
274 processedSamples += newlyProcessedCount;
275 double d_processed = processedSamples.as_double();
276 double d_total = totalSamples.as_double();
277 int percentage{ static_cast<int>((d_processed / d_total) * 100) };
278
279 auto progressStatus = progress.Update(d_processed, d_total,
280 XO("Processing... %i%%").Format(percentage));
281
282 if (progressStatus != ProgressResult::Success)
283 throw UserException{};
284 };
285
286 for (auto channel : TrackList::Channels(pTrack))
287 channel->ConvertToSampleFormat(
288 newFormat, progressUpdate);
289
290 ProjectHistory::Get( *project )
291 /* i18n-hint: The strings name a track and a format */
292 .PushState(XO("Changed '%s' to %s")
293 .Format( pTrack->GetName(), GetSampleFormatStr(newFormat) ),
294 XO("Format Change"));
295
296 using namespace RefreshCode;
298}
@ 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
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)
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544
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:51
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(), TrackList::Channels(), RefreshCode::FixScrollbars, floatSample, ProjectHistory::Get(), GetSampleFormatStr(), int16Sample, int24Sample, mpData, On16BitID, On24BitID, OnFloatID, pdlgHideStopButton, 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: