Skip to content

Commit ab2bd4f

Browse files
committed
Update playback settings
1 parent b1413f8 commit ab2bd4f

7 files changed

Lines changed: 228 additions & 2 deletions

File tree

src/plugins/audio/internal/AudioPlugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <audio/internal/AudioPreference.h>
2424
#include <audio/internal/ProjectAudioAddOn.h>
2525
#include <audio/internal/PlaybackAddOn.h>
26+
#include <audio/internal/PlaybackPage.h>
2627
#include <audio/internal/AudioSystem.h>
2728
#include <audio/internal/OutputSystem.h>
2829

@@ -83,6 +84,7 @@ namespace Audio::Internal {
8384
auto sc = Core::CoreInterface::settingCatalog();
8485
auto audioAndMidiPage = new AudioAndMidiPage;
8586
audioAndMidiPage->addPage(new AudioOutputPage);
87+
audioAndMidiPage->addPage(new PlaybackPage);
8688
sc->addPage(audioAndMidiPage);
8789
}
8890

src/plugins/audio/internal/AudioPreference.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Audio::Internal {
99
class AudioPreferencePrivate {
1010
public:
1111
AudioPreference::PlayheadBehavior playbackBehavior{};
12+
AudioPreference::PlaybackTogglingAction playbackTogglingAction{AudioPreference::PTA_PlayStop};
1213
};
1314

1415
static AudioPreference *m_instance = nullptr;
@@ -31,7 +32,9 @@ namespace Audio::Internal {
3132
auto settings = Core::RuntimeInterface::settings();
3233
settings->beginGroup(staticMetaObject.className());
3334
d->playbackBehavior = settings->value("playbackBehavior", QVariant::fromValue(PB_ReturnToStart)).value<PlayheadBehavior>();
35+
d->playbackTogglingAction = settings->value("playbackTogglingAction", QVariant::fromValue(PTA_PlayStop)).value<PlaybackTogglingAction>();
3436
emit playbackBehaviorChanged();
37+
emit playbackTogglingActionChanged();
3538
settings->endGroup();
3639
}
3740

@@ -40,6 +43,7 @@ namespace Audio::Internal {
4043
auto settings = Core::RuntimeInterface::settings();
4144
settings->beginGroup(staticMetaObject.className());
4245
settings->setValue("playbackBehavior", d->playbackBehavior);
46+
settings->setValue("playbackTogglingAction", d->playbackTogglingAction);
4347
settings->endGroup();
4448
}
4549

@@ -60,4 +64,17 @@ namespace Audio::Internal {
6064
emit m_instance->playbackBehaviorChanged();
6165
}
6266

67+
AudioPreference::PlaybackTogglingAction AudioPreference::playbackTogglingAction() {
68+
M_INSTANCE_D;
69+
return d->playbackTogglingAction;
70+
}
71+
72+
void AudioPreference::setPlaybackTogglingAction(PlaybackTogglingAction playbackTogglingAction) {
73+
M_INSTANCE_D;
74+
if (d->playbackTogglingAction == playbackTogglingAction)
75+
return;
76+
d->playbackTogglingAction = playbackTogglingAction;
77+
emit m_instance->playbackTogglingActionChanged();
78+
}
79+
6380
}

src/plugins/audio/internal/AudioPreference.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Audio::Internal {
2020
QML_SINGLETON
2121
Q_DECLARE_PRIVATE(AudioPreference)
2222
Q_PROPERTY(AudioPreference::PlayheadBehavior playbackBehavior READ playbackBehavior WRITE setPlaybackBehavior NOTIFY playbackBehaviorChanged)
23+
Q_PROPERTY(AudioPreference::PlaybackTogglingAction playbackTogglingAction READ playbackTogglingAction WRITE setPlaybackTogglingAction NOTIFY playbackTogglingActionChanged)
2324

2425
public:
2526
~AudioPreference() override;
@@ -40,11 +41,20 @@ namespace Audio::Internal {
4041
};
4142
Q_ENUM(PlayheadBehavior)
4243

44+
enum PlaybackTogglingAction {
45+
PTA_PlayStop,
46+
PTA_PlayPause,
47+
};
48+
Q_ENUM(PlaybackTogglingAction)
49+
4350
static PlayheadBehavior playbackBehavior();
4451
static void setPlaybackBehavior(PlayheadBehavior playbackBehavior);
52+
static PlaybackTogglingAction playbackTogglingAction();
53+
static void setPlaybackTogglingAction(PlaybackTogglingAction playbackTogglingAction);
4554

4655
Q_SIGNALS:
4756
void playbackBehaviorChanged();
57+
void playbackTogglingActionChanged();
4858

4959
private:
5060
friend class AudioPlugin;

src/plugins/audio/internal/addon/PlaybackAddOn.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ namespace Audio::Internal {
119119
void PlaybackAddOn::togglePlayback() {
120120
if (m_context) {
121121
if (m_context->status() == ProjectAudioContext::Playing) {
122-
// TODO use configuration to decide whether to stop or to pause
123-
stop();
122+
if (AudioPreference::playbackTogglingAction() == AudioPreference::PTA_PlayPause) {
123+
pause();
124+
} else {
125+
stop();
126+
}
124127
} else {
125128
play();
126129
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "PlaybackPage.h"
2+
3+
#include <QLoggingCategory>
4+
#include <QQmlComponent>
5+
6+
#include <CoreApi/runtimeinterface.h>
7+
8+
#include <audio/internal/AudioPreference.h>
9+
10+
namespace Audio::Internal {
11+
12+
Q_STATIC_LOGGING_CATEGORY(lcPlaybackPage, "diffscope.audio.playbackpage")
13+
14+
PlaybackPage::PlaybackPage(QObject *parent) : Core::ISettingPage("audio.Playback", parent) {
15+
setTitle(tr("Playback"));
16+
setDescription(tr("Configure playback behavior"));
17+
}
18+
19+
PlaybackPage::~PlaybackPage() {
20+
delete m_widget;
21+
}
22+
23+
bool PlaybackPage::matches(const QString &word) {
24+
return ISettingPage::matches(word) || widgetMatches(word);
25+
}
26+
27+
QString PlaybackPage::sortKeyword() const {
28+
return QStringLiteral("Playback");
29+
}
30+
31+
QObject *PlaybackPage::widget() {
32+
if (m_widget)
33+
return m_widget;
34+
qCDebug(lcPlaybackPage) << "Creating widget";
35+
QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.Audio", "PlaybackPage");
36+
if (component.isError()) {
37+
qFatal() << component.errorString();
38+
}
39+
m_widget = component.createWithInitialProperties({{"pageHandle", QVariant::fromValue(this)}});
40+
m_widget->setParent(this);
41+
return m_widget;
42+
}
43+
44+
void PlaybackPage::beginSetting() {
45+
qCInfo(lcPlaybackPage) << "Beginning setting";
46+
widget();
47+
m_widget->setProperty("playbackBehavior", AudioPreference::instance()->property("playbackBehavior"));
48+
qCDebug(lcPlaybackPage) << "playbackBehavior" << m_widget->property("playbackBehavior");
49+
m_widget->setProperty("playbackTogglingAction", AudioPreference::instance()->property("playbackTogglingAction"));
50+
qCDebug(lcPlaybackPage) << "playbackTogglingAction" << m_widget->property("playbackTogglingAction");
51+
m_widget->setProperty("started", true);
52+
ISettingPage::beginSetting();
53+
}
54+
55+
bool PlaybackPage::accept() {
56+
qCInfo(lcPlaybackPage) << "Accepting";
57+
qCDebug(lcPlaybackPage) << "playbackBehavior" << m_widget->property("playbackBehavior");
58+
AudioPreference::instance()->setProperty("playbackBehavior", m_widget->property("playbackBehavior"));
59+
qCDebug(lcPlaybackPage) << "playbackTogglingAction" << m_widget->property("playbackTogglingAction");
60+
AudioPreference::instance()->setProperty("playbackTogglingAction", m_widget->property("playbackTogglingAction"));
61+
AudioPreference::instance()->save();
62+
return ISettingPage::accept();
63+
}
64+
65+
void PlaybackPage::endSetting() {
66+
qCInfo(lcPlaybackPage) << "Ending setting";
67+
m_widget->setProperty("started", false);
68+
ISettingPage::endSetting();
69+
}
70+
71+
bool PlaybackPage::widgetMatches(const QString &word) {
72+
widget();
73+
auto matcher = m_widget->property("matcher").value<QObject *>();
74+
bool ret = false;
75+
QMetaObject::invokeMethod(matcher, "matches", qReturnArg(ret), word);
76+
return ret;
77+
}
78+
79+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef DIFFSCOPE_AUDIOPLUGIN_PLAYBACKPAGE_H
2+
#define DIFFSCOPE_AUDIOPLUGIN_PLAYBACKPAGE_H
3+
4+
#include <CoreApi/isettingpage.h>
5+
6+
namespace Audio::Internal {
7+
8+
class PlaybackPage : public Core::ISettingPage {
9+
Q_OBJECT
10+
public:
11+
explicit PlaybackPage(QObject *parent = nullptr);
12+
~PlaybackPage() override;
13+
14+
bool matches(const QString &word) override;
15+
QString sortKeyword() const override;
16+
QObject *widget() override;
17+
void beginSetting() override;
18+
bool accept() override;
19+
void endSetting() override;
20+
21+
private:
22+
bool widgetMatches(const QString &word);
23+
QObject *m_widget{};
24+
};
25+
26+
}
27+
28+
#endif // DIFFSCOPE_AUDIOPLUGIN_PLAYBACKPAGE_H
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import QtQml
2+
import QtQuick
3+
import QtQuick.Controls
4+
import QtQuick.Layouts
5+
6+
import SVSCraft
7+
import SVSCraft.UIComponents
8+
9+
import DiffScope.Audio
10+
11+
ScrollView {
12+
id: page
13+
14+
required property QtObject pageHandle
15+
property bool started: false
16+
17+
property int playbackBehavior
18+
property int playbackTogglingAction
19+
20+
readonly property var playbackBehaviorModel: [
21+
{text: qsTr("Return to start position"), value: AudioPreference.PB_ReturnToStart},
22+
{text: qsTr("Keep at current position"), value: AudioPreference.PB_KeepAtCurrent},
23+
{text: qsTr("Keep at current position, but play from start position next time"), value: AudioPreference.PB_KeepAtCurrentButPlayFromStart},
24+
]
25+
readonly property var playbackTogglingActionModel: [
26+
{text: qsTr("Play/Stop"), value: AudioPreference.PTA_PlayStop},
27+
{text: qsTr("Play/Pause"), value: AudioPreference.PTA_PlayPause},
28+
]
29+
30+
onPlaybackBehaviorChanged: if (started) pageHandle.markDirty()
31+
onPlaybackTogglingActionChanged: if (started) pageHandle.markDirty()
32+
33+
anchors.fill: parent
34+
contentWidth: availableWidth
35+
36+
readonly property TextMatcher matcher: TextMatcher {}
37+
38+
ColumnLayout {
39+
width: page.width
40+
ColumnLayout {
41+
Layout.fillWidth: true
42+
Layout.margins: 12
43+
spacing: 32
44+
GroupBox {
45+
title: qsTr("Playback")
46+
TextMatcherItem on title {
47+
matcher: page.matcher
48+
}
49+
Layout.fillWidth: true
50+
GridLayout {
51+
columns: 2
52+
anchors.fill: parent
53+
Label {
54+
Layout.columnSpan: 2
55+
text: qsTr("When playback stops, make playhead")
56+
TextMatcherItem on text {
57+
matcher: page.matcher
58+
}
59+
}
60+
ComboBox {
61+
Layout.columnSpan: 2
62+
Layout.fillWidth: true
63+
textRole: "text"
64+
valueRole: "value"
65+
model: page.playbackBehaviorModel
66+
currentIndex: page.playbackBehavior
67+
onCurrentValueChanged: page.playbackBehavior = currentValue
68+
}
69+
Label {
70+
text: qsTr("Playback toggling action")
71+
TextMatcherItem on text {
72+
matcher: page.matcher
73+
}
74+
}
75+
ComboBox {
76+
Layout.fillWidth: true
77+
textRole: "text"
78+
valueRole: "value"
79+
model: page.playbackTogglingActionModel
80+
currentIndex: page.playbackTogglingAction
81+
onCurrentValueChanged: page.playbackTogglingAction = currentValue
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)