Skip to content

Commit

Permalink
feat(Playback Controlls): Use 0-9 number keys to skip to percentage o…
Browse files Browse the repository at this point in the history
…f the total playtime
  • Loading branch information
SebiAi committed Jan 25, 2024
1 parent 335ba42 commit c00897b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/composition_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ void CompositionManager::loadComposition(const QString &filepathAudio, const QSt
this->playerInit(filepathAudio);
}

void CompositionManager::skipToPercentage(const qreal& percentage)
{
// Check if the percentage is out of range
if (percentage > 1.0 || percentage < 0.0)
return;

// Check if the player has a media loaded and is seekable
if (!this->player->isSeekable() || !this->player->hasAudio())
return;

this->player->setPosition(this->player->duration() * percentage);
}

void CompositionManager::playerInit(const QString &filepathAudio)
{
// connect(this->player, SIGNAL(metaDataChanged()), this, SLOT(player_onMetaDataChanged()), Qt::UniqueConnection);
Expand Down
5 changes: 5 additions & 0 deletions src/composition_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class CompositionManager : private QObject
* @throws CompositionManager::InvalidLightDataContentException Invalid light data in light data file.
*/
void loadComposition(const QString &filepathAudio, const QString &filepathLightData);
/**
* @brief Skip to the provided percentage in the composition if one is loaded.
* @param percentage The percentage. Range 0 to 1.
*/
void skipToPercentage(const qreal& percentage);


/**
Expand Down
11 changes: 11 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ MainWindow::MainWindow(QWidget *parent)
playerControlsLayout->addWidget(this->seekBar);
connect(this->seekBar, SIGNAL(valueChanged(int)), this, SLOT(seekBar_onValueChanged(int)));
connect(this->seekBar, SIGNAL(sliderReleased()), this, SLOT(seekBar_onSliderReleased()));
// Create shortcuts to skip time
connect(new QShortcut(QKeySequence("0"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.0); });
connect(new QShortcut(QKeySequence("1"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.1); });
connect(new QShortcut(QKeySequence("2"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.2); });
connect(new QShortcut(QKeySequence("3"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.3); });
connect(new QShortcut(QKeySequence("4"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.4); });
connect(new QShortcut(QKeySequence("5"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.5); });
connect(new QShortcut(QKeySequence("6"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.6); });
connect(new QShortcut(QKeySequence("7"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.7); });
connect(new QShortcut(QKeySequence("8"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.8); });
connect(new QShortcut(QKeySequence("9"), this), &QShortcut::activated, this, [=](){ this->glyphWidget->compositionManager->skipToPercentage(0.9); });

// Length time label
this->lengthTimeLabel = new QLabel("--:--");
Expand Down

0 comments on commit c00897b

Please sign in to comment.