Audacity 3.2.0
AudacityMirProject.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AudacityMirProject.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "AudacityMirProject.h"
12#include "AdornedRulerPanel.h"
14#include "Project.h"
15#include "ProjectHistory.h"
17#include "ProjectWindows.h"
18#include "TimeDisplayMode.h"
19#include "WaveTrack.h"
21
22namespace
23{
24auto FormatTempo(double value)
25{
26 auto rounded = std::to_string(std::round(value * 100) / 100);
27 rounded.erase(rounded.find_last_not_of('0') + 1, std::string::npos);
28 rounded.erase(rounded.find_last_not_of('.') + 1, std::string::npos);
29 return rounded;
30}
31} // namespace
32
34 : mProject { project }
35 , mImportedOnEmptyProject { TrackList::Get(mProject)
36 .Any<WaveTrack>()
37 .empty() }
38 , mProjectTempo { ProjectTimeSignature::Get(mProject).GetTempo() }
39{
40}
41
43{
45 return;
46 assert(mMostSignificantModification.has_value());
47 auto& ph = ProjectHistory::Get(mProject);
49 ph.ModifyState(true);
51 ph.PushState(
52 XO("Configure Project from Music File"),
53 XO("Automatic Music Configuration"));
54}
55
57{
60}
61
63 double newTempo, std::optional<MIR::TimeSignature> timeSignature)
64{
67 auto& projTimeSignature = ProjectTimeSignature::Get(mProject);
68 projTimeSignature.SetTempo(newTempo);
69 if (timeSignature.has_value())
70 {
71 projTimeSignature.SetUpperTimeSignature(
72 MIR::GetNumerator(*timeSignature));
73 projTimeSignature.SetLowerTimeSignature(
74 MIR::GetDenominator(*timeSignature));
75 }
77}
78
80{
81 return mProjectTempo;
82}
83
85 double newTempo, bool isSingleFileImport)
86{
88 if (policy == wxString("Ask"))
89 {
90 const auto displayedTempo = FormatTempo(newTempo);
91 const auto message =
92 isSingleFileImport ?
93 XO("Audacity detected this file to be %s bpm.\nWould you like to enable music view and set the project tempo to %s?")
94 .Format(displayedTempo, displayedTempo) :
95 XO("Audacity detected one or more files to be %s bpm.\nWould you like to enable music view and set the project tempo to %s?")
96 .Format(displayedTempo, displayedTempo);
98 &GetProjectPanel(mProject), XO("Music Import"), message);
99 const auto yes = m.ShowDialog();
100 if (m.IsChecked())
102 yes ? wxString("Yes") : wxString("No"));
103 if (yes)
105 return yes;
106 }
107 const auto yes = policy == wxString("Yes");
108 if (yes)
110 return yes;
111}
112
114{
115 mProjectWasModified = true;
118}
XO("Cut/Copy/Paste")
AUDACITY_DLL_API wxWindow & GetProjectPanel(AudacityProject &project)
Get the main sub-window of the project frame that displays track data.
accessors for certain important windows associated with each project
const auto project
void SetTimeDisplayMode(TimeDisplayMode rulerType)
TimeDisplayMode GetTimeDisplayMode() const
static AdornedRulerPanel & Get(AudacityProject &project)
double GetTempo() const override
std::optional< ModificationType > mMostSignificantModification
void OnClipsSynchronized() override
AudacityProject & mProject
void ReconfigureMusicGrid(double newTempo, std::optional< MIR::TimeSignature > timeSignature) override
const double mProjectTempo
bool ShouldBeReconfigured(double newTempo, bool isSingleFileImport) override
bool ViewIsBeatsAndMeasures() const override
AudacityMirProject(AudacityProject &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
bool Write(const wxString &value)
Definition: Prefs.cpp:424
wxString Read() const
Definition: Prefs.cpp:388
static EnumSetting< bool > MusicFileImportSetting
static ProjectHistory & Get(AudacityProject &project)
static ProjectTimeSignature & Get(AudacityProject &project)
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:201
int GetNumerator(TimeSignature ts)
Definition: MirTypes.h:39
int GetDenominator(TimeSignature ts)
Definition: MirTypes.h:46
constexpr size_t npos(-1)
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512