| 1 |
/* |
| 2 |
* Audacity: A Digital Audio Editor |
| 3 |
*/ |
| 4 |
#include "playbacktoolbartimeitem.h" |
| 5 |
|
| 6 |
#include <QVariantMap> |
| 7 |
|
| 8 |
#include "playback/iaudiooutput.h" |
| 9 |
|
| 10 |
using namespace au::playback; |
| 11 |
using namespace au::audio; |
| 12 |
|
| 13 |
PlaybackToolBarTimeItem::PlaybackToolBarTimeItem(const muse::ui::UiAction& action, muse::uicomponents::ToolBarItemType::Type type, |
| 14 |
QObject* parent) |
| 15 |
: muse::uicomponents::ToolBarItem(action, type, parent) |
| 16 |
{ |
| 17 |
playbackState()->playbackPositionChanged().onReceive(this, [this](audio::secs_t) { |
| 18 |
emit currentValueChanged(); |
| 19 |
}); |
| 20 |
|
| 21 |
playback()->audioOutput()->sampleRateChanged().onReceive(this, [this](audio::sample_rate_t) { |
| 22 |
emit sampleRateChanged(); |
| 23 |
}); |
| 24 |
|
| 25 |
globalContext()->currentTrackeditProjectChanged().onNotify(this, [this](){ |
| 26 |
auto project = globalContext()->currentTrackeditProject(); |
| 27 |
if (!project) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
emit timeSignatureChanged(); |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
int PlaybackToolBarTimeItem::currentFormat() const |
| 36 |
{ |
| 37 |
return m_currentFormat; // from settings |
| 38 |
} |
| 39 |
|
| 40 |
void PlaybackToolBarTimeItem::setCurrentFormat(int format) |
| 41 |
{ |
| 42 |
if (m_currentFormat == format) { |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
m_currentFormat = format; |
| 47 |
emit currentFormatChanged(); |
| 48 |
} |
| 49 |
|
| 50 |
double PlaybackToolBarTimeItem::currentValue() const |
| 51 |
{ |
| 52 |
return playbackState()->playbackPosition(); |
| 53 |
} |
| 54 |
|
| 55 |
void PlaybackToolBarTimeItem::setCurrentValue(double value) |
| 56 |
{ |
| 57 |
if (currentValue() == value) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
dispatcher()->dispatch("playback_seek", muse::actions::ActionData::make_arg1(value)); |
| 62 |
} |
| 63 |
|
| 64 |
au::context::IPlaybackStatePtr PlaybackToolBarTimeItem::playbackState() const |
| 65 |
{ |
| 66 |
return globalContext()->playbackState(); |
| 67 |
} |
| 68 |
|
| 69 |
double PlaybackToolBarTimeItem::sampleRate() const |
| 70 |
{ |
| 71 |
return playback()->audioOutput()->sampleRate(); |
| 72 |
} |
| 73 |
|
| 74 |
double PlaybackToolBarTimeItem::tempo() const |
| 75 |
{ |
| 76 |
auto project = globalContext()->currentTrackeditProject(); |
| 77 |
if (!project) { |
| 78 |
return 0.0; |
| 79 |
} |
| 80 |
|
| 81 |
return project->timeSignature().tempo; |
| 82 |
} |
| 83 |
|
| 84 |
int PlaybackToolBarTimeItem::upperTimeSignature() const |
| 85 |
{ |
| 86 |
auto project = globalContext()->currentTrackeditProject(); |
| 87 |
if (!project) { |
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
return project->timeSignature().upper; |
| 92 |
} |
| 93 |
|
| 94 |
int PlaybackToolBarTimeItem::lowerTimeSignature() const |
| 95 |
{ |
| 96 |
auto project = globalContext()->currentTrackeditProject(); |
| 97 |
if (!project) { |
| 98 |
return 0.0; |
| 99 |
} |
| 100 |
|
| 101 |
return project->timeSignature().lower; |
| 102 |
} |