Skip to content

Commit

Permalink
add "skip to start" to menu in TrackControls
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
ddanilov committed Oct 27, 2024
1 parent 14eb33a commit 775ae1d
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ void Player::pauseActive()
pause();
}

bool Player::skipToStartActive(const bool with_pause)
{
if (with_pause) { pause(); }
if (m_active)
{
setPosition(0);
return true;
}
return false;
}

void Player::mediaPlayerStatusChanged(MediaStatus status)
{
if (!m_ready && status == QMediaPlayer::MediaStatus::LoadedMedia)
Expand Down
1 change: 1 addition & 0 deletions src/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Player : public QMediaPlayer
void setNextPlayer(Player* mediaPlayer);
bool playActive(bool force = false);
void pauseActive();
bool skipToStartActive(bool with_pause = false);

signals:
void playerLoaded();
Expand Down
6 changes: 6 additions & 0 deletions src/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ void Track::pause()
m_player_B->pauseActive();
}

void Track::skipToStart()
{
const auto a = m_player_A->skipToStartActive();
m_player_B->skipToStartActive(a);
}

qint64 Track::duration() const
{
return m_track_duration;
Expand Down
1 change: 1 addition & 0 deletions src/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Track : public QObject
bool isPlaying() const;
void play();
void pause();
void skipToStart();

qint64 duration() const;

Expand Down
8 changes: 8 additions & 0 deletions src/TrackControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ void TrackControls::statusChanged(int state)
}
}

void TrackControls::skipToStart()
{
m_track->skipToStart();
}

void TrackControls::trackLoaded()
{
if (m_track->errors().empty())
Expand Down Expand Up @@ -170,6 +175,9 @@ bool TrackControls::eventFilter(QObject* watched, QEvent* event)

void TrackControls::addItemsToMenu(QMenu* menu) const
{
auto* skip_to_start = menu->addAction(tr("Skip to start"));
connect(skip_to_start, &QAction::triggered, this, &TrackControls::skipToStart);

auto* show_settings = menu->addAction(tr("Edit Settings"));
connect(show_settings, &QAction::triggered, this, [this]() { m_settings->show(); });

Expand Down
1 change: 1 addition & 0 deletions src/TrackControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public slots:
void volumeChanged(int value);
void transitionChanged(int state);
void statusChanged(int state);
void skipToStart();
void trackLoaded();
void playerError();

Expand Down
13 changes: 9 additions & 4 deletions src/translations/soundscape_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,27 @@ für Anwendungsmenü</translation>
<context>
<name>TrackControls</name>
<message>
<location filename="../TrackControls.cpp" line="173"/>
<location filename="../TrackControls.cpp" line="178"/>
<source>Skip to start</source>
<translation>An den Anfang springen</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="181"/>
<source>Edit Settings</source>
<translation>Spur-Einstellungen</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="176"/>
<location filename="../TrackControls.cpp" line="184"/>
<source>Move Up</source>
<translation>Spur hoch schieben</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="179"/>
<location filename="../TrackControls.cpp" line="187"/>
<source>Move Down</source>
<translation>Spur runter schieben</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="182"/>
<location filename="../TrackControls.cpp" line="190"/>
<source>Remove</source>
<translation>Spur entfernen</translation>
</message>
Expand Down
13 changes: 9 additions & 4 deletions src/translations/soundscape_it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,27 @@ to access application menu</source>
<context>
<name>TrackControls</name>
<message>
<location filename="../TrackControls.cpp" line="173"/>
<location filename="../TrackControls.cpp" line="178"/>
<source>Skip to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="181"/>
<source>Edit Settings</source>
<translation>Modifica impostazioni</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="176"/>
<location filename="../TrackControls.cpp" line="184"/>
<source>Move Up</source>
<translation>Sposta in alto</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="179"/>
<location filename="../TrackControls.cpp" line="187"/>
<source>Move Down</source>
<translation>Sposta in basso</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="182"/>
<location filename="../TrackControls.cpp" line="190"/>
<source>Remove</source>
<translation>Rimuovi</translation>
</message>
Expand Down
13 changes: 9 additions & 4 deletions src/translations/soundscape_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,27 @@ to access application menu</source>
<context>
<name>TrackControls</name>
<message>
<location filename="../TrackControls.cpp" line="173"/>
<location filename="../TrackControls.cpp" line="178"/>
<source>Skip to start</source>
<translation>Перейти на начало трека</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="181"/>
<source>Edit Settings</source>
<translation>Параметры</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="176"/>
<location filename="../TrackControls.cpp" line="184"/>
<source>Move Up</source>
<translation>Переместить вверх</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="179"/>
<location filename="../TrackControls.cpp" line="187"/>
<source>Move Down</source>
<translation>Переместить вниз</translation>
</message>
<message>
<location filename="../TrackControls.cpp" line="182"/>
<location filename="../TrackControls.cpp" line="190"/>
<source>Remove</source>
<translation>Удалить</translation>
</message>
Expand Down
21 changes: 21 additions & 0 deletions tests/TestPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private slots:
void testNextPlayerOutGapIn();
void testNextPlayerCrossFade();
void testPlayPauseActive();
void testSkipToStartActive();

private:
const QTemporaryDir tmp_dir;
Expand Down Expand Up @@ -255,5 +256,25 @@ void TestPlayer::testPlayPauseActive()
QVERIFY(player->playbackState() == QMediaPlayer::PlaybackState::PlayingState);
}

void TestPlayer::testSkipToStartActive()
{
Track track;
auto* player = track.playerA();
QSignalSpy player_loaded(player, &Player::playerLoaded);
player->setSource(QUrl::fromLocalFile(file_name_audio_ok));
QVERIFY(player_loaded.wait());
player->m_active = false;
player->stop();

QVERIFY(!player->playActive());
QVERIFY(!player->skipToStartActive());

QVERIFY(player->playActive(true));
QVERIFY(player->playbackState() == QMediaPlayer::PlaybackState::PlayingState);
QVERIFY(player->skipToStartActive(true));
QVERIFY(player->playbackState() != QMediaPlayer::PlaybackState::PlayingState);
QVERIFY(player->position() == 0);
}

QTEST_MAIN(TestPlayer)
#include "TestPlayer.moc"
9 changes: 5 additions & 4 deletions tests/TestTrackControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ void TestTrackControls::testMenu()
TrackControls track_controls(QJsonObject(), QDir(), &main_window);
auto menu = track_controls.m_mouse_menu;
auto actions = menu->actions();
QCOMPARE(actions.at(0)->text(), "Edit Settings");
QCOMPARE(actions.at(1)->text(), "Move Up");
QCOMPARE(actions.at(2)->text(), "Move Down");
QCOMPARE(actions.at(3)->text(), "Remove");
QCOMPARE(actions.at(0)->text(), "Skip to start");
QCOMPARE(actions.at(1)->text(), "Edit Settings");
QCOMPARE(actions.at(2)->text(), "Move Up");
QCOMPARE(actions.at(3)->text(), "Move Down");
QCOMPARE(actions.at(4)->text(), "Remove");
}

void TestTrackControls::testPauseAndResume()
Expand Down

0 comments on commit 775ae1d

Please sign in to comment.