| 1 |
/* |
| 2 |
* Audacity: A Digital Audio Editor |
| 3 |
*/ |
| 4 |
#include "playbacktoolbartimesignatureitem.h" |
| 5 |
|
| 6 |
using namespace au::playback; |
| 7 |
|
| 8 |
PlaybackToolBarTimeSignatureItem::PlaybackToolBarTimeSignatureItem(const muse::ui::UiAction& action, |
| 9 |
muse::uicomponents::ToolBarItemType::Type type, |
| 10 |
QObject* parent) |
| 11 |
: muse::uicomponents::ToolBarItem(action, type, parent) |
| 12 |
{ |
| 13 |
globalContext()->currentTrackeditProjectChanged().onNotify(this, [this](){ |
| 14 |
onProjectChanged(); |
| 15 |
}); |
| 16 |
|
| 17 |
onProjectChanged(); |
| 18 |
} |
| 19 |
|
| 20 |
int PlaybackToolBarTimeSignatureItem::upper() const |
| 21 |
{ |
| 22 |
return m_upper; |
| 23 |
} |
| 24 |
|
| 25 |
void PlaybackToolBarTimeSignatureItem::setUpper(int newUpper) |
| 26 |
{ |
| 27 |
if (m_upper == newUpper) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
auto project = globalContext()->currentTrackeditProject(); |
| 32 |
if (!project) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
trackedit::TimeSignature timeSignature = project->timeSignature(); |
| 37 |
timeSignature.upper = newUpper; |
| 38 |
project->setTimeSignature(timeSignature); |
| 39 |
} |
| 40 |
|
| 41 |
int PlaybackToolBarTimeSignatureItem::lower() const |
| 42 |
{ |
| 43 |
return m_lower; |
| 44 |
} |
| 45 |
|
| 46 |
void PlaybackToolBarTimeSignatureItem::setLower(int newLower) |
| 47 |
{ |
| 48 |
if (m_lower == newLower) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
auto project = globalContext()->currentTrackeditProject(); |
| 53 |
if (!project) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
trackedit::TimeSignature timeSignature = project->timeSignature(); |
| 58 |
timeSignature.lower = newLower; |
| 59 |
project->setTimeSignature(timeSignature); |
| 60 |
} |
| 61 |
|
| 62 |
void PlaybackToolBarTimeSignatureItem::onProjectChanged() |
| 63 |
{ |
| 64 |
auto project = globalContext()->currentTrackeditProject(); |
| 65 |
if (!project) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
project->timeSignatureChanged().onReceive(this, [this](const trackedit::TimeSignature&) { |
| 70 |
updateValues(); |
| 71 |
}); |
| 72 |
|
| 73 |
updateValues(); |
| 74 |
} |
| 75 |
|
| 76 |
void PlaybackToolBarTimeSignatureItem::updateValues() |
| 77 |
{ |
| 78 |
auto project = globalContext()->currentTrackeditProject(); |
| 79 |
if (!project) { |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
trackedit::TimeSignature timeSignature = project->timeSignature(); |
| 84 |
|
| 85 |
m_upper = timeSignature.upper; |
| 86 |
emit upperChanged(); |
| 87 |
|
| 88 |
m_lower = timeSignature.lower; |
| 89 |
emit lowerChanged(); |
| 90 |
} |