Audacity 3.2.0
ProjectTimeSignature.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 @file ProjectTimeSignature.cpp
7
8 Dmitry Vedenko
9
10 **********************************************************************/
12
13#include "Beats.h"
14#include "Project.h"
16#include "XMLWriter.h"
17
19{
21 { return std::make_shared<ProjectTimeSignature>(); }
22};
23
25{
26 return project.AttachedObjects::Get<ProjectTimeSignature&>(key);
27}
28
31{
32 return Get(const_cast<AudacityProject&>(project));
33}
34
36 : mTempo { BeatsPerMinute.Read() }
37 , mUpperTimeSignature { UpperTimeSignature.Read() }
38 , mLowerTimeSignature { LowerTimeSignature.Read() }
39{}
40
42
44{
45 return mTempo;
46}
47
49{
50 if (mTempo != tempo)
51 {
52 mTempo = tempo;
53
54 BeatsPerMinute.Write(tempo);
55 gPrefs->Flush();
56
58 }
59}
60
62{
64}
65
67{
68 if (mUpperTimeSignature != upperTimeSignature)
69 {
70 mUpperTimeSignature = upperTimeSignature;
71
72 UpperTimeSignature.Write(upperTimeSignature);
73 gPrefs->Flush();
74
76 }
77}
78
80{
82}
83
85{
86 if (mLowerTimeSignature != lowerTimeSignature)
87 {
88 mLowerTimeSignature = lowerTimeSignature;
89
90 LowerTimeSignature.Write(lowerTimeSignature);
91 gPrefs->Flush();
92
94 }
95}
96
98{
99 return 60.0 / mTempo;
100}
101
103{
105}
106
108{
110}
111
113{
116}
117
119 [](const AudacityProject &project, XMLWriter &xmlFile){
120 auto& formats = ProjectTimeSignature::Get(project);
121 xmlFile.WriteAttr(wxT("time_signature_tempo"), formats.GetTempo());
122 xmlFile.WriteAttr(wxT("time_signature_upper"), formats.GetUpperTimeSignature());
123 xmlFile.WriteAttr(wxT("time_signature_lower"), formats.GetLowerTimeSignature());
124 }
125};
126
128 // Just a pointer to function, but needing overload resolution as non-const:
130 {
131 { "time_signature_tempo", [](auto& signature, auto value)
132 { signature.SetTempo(value.Get(BeatsPerMinute.Read())); } },
133 { "time_signature_upper", [](auto& signature, auto value)
134 { signature.SetUpperTimeSignature(value.Get(UpperTimeSignature.Read())); } },
135 { "time_signature_lower", [](auto& signature, auto value)
136 { signature.SetLowerTimeSignature(value.Get(LowerTimeSignature.Read())); } },
137 }
138};
wxT("CloseDown"))
IntSetting UpperTimeSignature
The upper time signature of the Beats & Measures ruler.
Definition: Beats.cpp:14
IntSetting LowerTimeSignature
The lower time signature of the Beats & Measures ruler.
Definition: Beats.cpp:15
DoubleSetting BeatsPerMinute
The tempo used for drawing the Beats & Measures ruler.
Definition: Beats.cpp:13
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
static const AttachedProjectObjects::RegisteredFactory key
static ProjectFileIORegistry::AttributeWriterEntry entry
static ProjectFileIORegistry::AttributeReaderEntries entries
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
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
CallbackReturn Publish(const TimeSignatureChangedMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
double GetQuarterDuration() const
void SetUpperTimeSignature(int upperTimeSignature)
void SetLowerTimeSignature(int lowerTimeSignature)
void SetTempo(double tempo)
static ProjectTimeSignature & Get(AudacityProject &project)
~ProjectTimeSignature() override
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:259
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
virtual bool Flush() noexcept=0
Typically statically constructed.