| 1 |
/* |
| 2 |
* Audacity: A Digital Audio Editor |
| 3 |
*/ |
| 4 |
#include "playbacktoolbarbpmitem.h" |
| 5 |
|
| 6 |
using namespace au::playback; |
| 7 |
|
| 8 |
PlaybackToolBarBPMItem::PlaybackToolBarBPMItem(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 |
double PlaybackToolBarBPMItem::currentValue() const |
| 21 |
{ |
| 22 |
return m_currentValue; |
| 23 |
} |
| 24 |
|
| 25 |
void PlaybackToolBarBPMItem::setCurrentValue(double value) |
| 26 |
{ |
| 27 |
if (qFuzzyCompare(m_currentValue, value)) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
auto project = globalContext()->currentTrackeditProject(); |
| 32 |
if (!project) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
trackedit::TimeSignature timeSignature = project->timeSignature(); |
| 37 |
timeSignature.tempo = value; |
| 38 |
project->setTimeSignature(timeSignature); |
| 39 |
} |
| 40 |
|
| 41 |
void PlaybackToolBarBPMItem::onProjectChanged() |
| 42 |
{ |
| 43 |
auto project = globalContext()->currentTrackeditProject(); |
| 44 |
if (!project) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
project->timeSignatureChanged().onReceive(this, [this](const trackedit::TimeSignature&) { |
| 49 |
updateValues(); |
| 50 |
}); |
| 51 |
|
| 52 |
updateValues(); |
| 53 |
} |
| 54 |
|
| 55 |
void PlaybackToolBarBPMItem::updateValues() |
| 56 |
{ |
| 57 |
auto project = globalContext()->currentTrackeditProject(); |
| 58 |
if (!project) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
trackedit::TimeSignature timeSignature = project->timeSignature(); |
| 63 |
|
| 64 |
m_currentValue = timeSignature.tempo; |
| 65 |
emit currentValueChanged(); |
| 66 |
} |