Audacity 3.2.0
ImportUtils.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ImportUtils.cpp
6
7 Dominic Mazzoni
8
9 Vitaly Sverchinsky split from ImportPlugin.cpp
10
11**********************************************************************/
12
13#include "ImportUtils.h"
14
15#include "WaveTrack.h"
16#include "QualitySettings.h"
17#include "BasicUI.h"
18
20{
21 // Consult user preference
22 auto defaultFormat = QualitySettings::SampleFormatChoice();
23
24 // Don't choose format narrower than effective or default
25 auto format = std::max(effectiveFormat, defaultFormat);
26
27 // But also always promote 24 bits to float
28 if (format > int16Sample)
30
31 return format;
32}
33
36 unsigned nChannels,
37 sampleFormat effectiveFormat,
38 double rate)
39{
40 return trackFactory.Create(nChannels, ChooseFormat(effectiveFormat), rate);
41}
42
44{
46 BasicUI::MessageBoxOptions().Caption(caption));
47}
48
49void ImportUtils::FinalizeImport(TrackHolders& outTracks, const std::vector<WaveTrack::Holder>& importedStreams)
50{
51 for(auto& stream : importedStreams)
52 FinalizeImport(outTracks, *stream);
53}
54
56{
57 if(trackList.empty())
58 return;
59
60 for(const auto track : trackList.Any<WaveTrack>())
61 track->Flush();
62
63 while (!trackList.empty())
64 outTracks.push_back(trackList.DetachFirst());
65}
66
68{
69 track.Flush();
70 outTracks.push_back(track.shared_from_this());
71}
72
73void ImportUtils::ForEachChannel(TrackList& trackList, const std::function<void(WaveChannel&)>& op)
74{
75 for(auto track : trackList.Any<WaveTrack>())
76 {
77 for(auto channel : track->Channels())
78 {
79 op(*channel);
80 }
81 }
82}
83
84void ImportUtils::ForEachChannel(WaveTrack &track, const std::function<void(WaveChannel&)>& op)
85{
86 for(auto channel : track.Channels())
87 {
88 op(*channel);
89 }
90}
Toolkit-neutral facade for basic user interface services.
std::vector< std::shared_ptr< Track > > TrackHolders
Definition: ImportRaw.h:24
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
static void ShowMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Import Project"))
Definition: ImportUtils.cpp:43
static std::shared_ptr< WaveTrack > NewWaveTrack(WaveTrackFactory &trackFactory, unsigned nChannels, sampleFormat effectiveFormat, double rate)
Definition: ImportUtils.cpp:35
static sampleFormat ChooseFormat(sampleFormat effectiveFormat)
Choose appropriate format, which will not be narrower than the specified one.
Definition: ImportUtils.cpp:19
static void ForEachChannel(TrackList &trackList, const std::function< void(WaveChannel &)> &op)
Iterates over channels in each wave track from the list.
Definition: ImportUtils.cpp:73
static void FinalizeImport(TrackHolders &outTracks, const std::vector< std::shared_ptr< WaveTrack > > &importedStreams)
Flushes the given channels and moves them to outTracks.
Definition: ImportUtils.cpp:49
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
Holds a msgid for the translation catalog; may also bind format arguments.
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:871
std::shared_ptr< WaveTrack > Create()
Creates an unnamed empty WaveTrack with default sample format and default rate.
Definition: WaveTrack.cpp:391
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
auto Channels()
Definition: WaveTrack.h:263
void Flush() override
Definition: WaveTrack.cpp:2315
std::shared_ptr< WaveTrack > Holder
Definition: WaveTrack.h:247
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
PROJECT_RATE_API sampleFormat SampleFormatChoice()