Skip to content

Commit

Permalink
MusicPlayer: Synced with MixerX
Browse files Browse the repository at this point in the history
- Added the real-time gain factor change support
  • Loading branch information
Wohlstand committed Nov 28, 2024
1 parent 6d8af0a commit 12fbf5d
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 268 deletions.
54 changes: 48 additions & 6 deletions MusicPlayer/MainWindow/musplayer_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ void MusPlayer_Qt::contextMenu(const QPoint &pos)
QAction *echo = x.addAction("Echo");
QAction *echoTuner = x.addAction("Echo tuner...");
QAction *musicFX = x.addAction("Music FX...");
QAction *resetGain = x.addAction("Reset gain");
QAction *resetTempo = x.addAction("Reset tempo");
QAction *resetSpeed = x.addAction("Reset speed");
QAction *resetPitch = x.addAction("Reset pitch");
resetGain->setEnabled(ui->gainFrame->isEnabled());
resetTempo->setEnabled(ui->tempoFrame->isEnabled());
resetSpeed->setEnabled(ui->speedFrame->isEnabled());
resetPitch->setEnabled(ui->pitchFrame->isEnabled());
Expand All @@ -281,7 +283,8 @@ void MusPlayer_Qt::contextMenu(const QPoint &pos)
version->setEnabled(false);
QAction *license = about->addAction("Licensed under GNU GPLv3 license");
about->addSeparator();
QAction *source = about->addAction("Get source code");
QAction *sourceMoondust = about->addAction("Get source code for Moondust Project");
QAction *sourceMixerX = about->addAction("Get source code for MixerX library");
QAction *ret = x.exec(this->mapToGlobal(pos));

if(open == ret)
Expand All @@ -306,6 +309,8 @@ void MusPlayer_Qt::contextMenu(const QPoint &pos)
on_actionTuneEcho_triggered();
else if(musicFX == ret)
on_actionMusicFX_triggered();
else if(resetGain == ret)
ui->gain->setValue(m_setupMidi->getGainDefault());
else if(resetTempo == ret)
ui->tempo->setValue(0);
else if(resetSpeed == ret)
Expand All @@ -322,8 +327,10 @@ void MusPlayer_Qt::contextMenu(const QPoint &pos)
#endif
else if(ret == license)
on_actionHelpLicense_triggered();
else if(ret == source)
else if(ret == sourceMoondust)
on_actionHelpGitHub_triggered();
else if(ret == sourceMixerX)
on_actionHelpGitHubMixerX_triggered();
}

void MusPlayer_Qt::openMusicByArg(QString musPath)
Expand Down Expand Up @@ -442,20 +449,34 @@ void MusPlayer_Qt::on_play_clicked()

if(PGE_MusicPlayer::openFile(musicPath))
{
float gain = Mix_GetMusicGain(PGE_MusicPlayer::s_playMus);
int gainDefault = gain >= 0.0f ? static_cast<int>(gain * 100): 100;
double tempo = Mix_GetMusicTempo(PGE_MusicPlayer::s_playMus);
double speed = Mix_GetMusicSpeed(PGE_MusicPlayer::s_playMus);
double pitch = Mix_GetMusicPitch(PGE_MusicPlayer::s_playMus);

m_setupMidi->setGainDefault(gainDefault);
m_setupMidi->setGain(gainDefault);

ui->gain->blockSignals(true);
ui->gain->setValue(gainDefault);
ui->gain->blockSignals(false);
ui->gainFrame->setEnabled(gain >= 0.0f);

ui->tempo->blockSignals(true);
ui->tempo->setValue(0);
ui->tempo->blockSignals(false);
ui->tempoFrame->setEnabled(Mix_GetMusicTempo(PGE_MusicPlayer::s_playMus) >= 0.0);
ui->tempoFrame->setEnabled(tempo >= 0.0);

ui->speed->blockSignals(true);
ui->speed->setValue(0);
ui->speed->blockSignals(false);
ui->speedFrame->setEnabled(Mix_GetMusicSpeed(PGE_MusicPlayer::s_playMus) >= 0.0);
ui->speedFrame->setEnabled(speed >= 0.0);

ui->pitch->blockSignals(true);
ui->pitch->setValue(0);
ui->pitch->blockSignals(false);
ui->pitchFrame->setEnabled(Mix_GetMusicPitch(PGE_MusicPlayer::s_playMus) >= 0.0);
ui->pitchFrame->setEnabled(pitch >= 0.0);

PGE_MusicPlayer::changeVolume(ui->volume->value());
playSuccess = PGE_MusicPlayer::playMusic();
Expand Down Expand Up @@ -595,6 +616,22 @@ void MusPlayer_Qt::on_disableSpcEcho_clicked(bool checked)
Mix_GME_SetSpcEchoDisabled(PGE_MusicPlayer::s_playMus, checked ? 1 : 0);
}

void MusPlayer_Qt::on_gain_valueChanged(int gain)
{
#ifdef SDL_MIXER_X
if(Mix_PlayingMusicStream(PGE_MusicPlayer::s_playMus))
{
float gainFactor = 0.01 * float(gain);
Mix_SetMusicGain(PGE_MusicPlayer::s_playMus, gainFactor);
qDebug() << "Changed gain factor: " << gainFactor;
QToolTip::showText(QCursor::pos(), QString("%1").arg(gainFactor), this);
m_setupMidi->setGain(gain);
}
#else
Q_UNUSED(gain);
#endif
}

void MusPlayer_Qt::on_tempo_valueChanged(int tempo)
{
#ifdef SDL_MIXER_X
Expand Down Expand Up @@ -845,7 +882,12 @@ void MusPlayer_Qt::on_actionHelpAbout_triggered()

void MusPlayer_Qt::on_actionHelpGitHub_triggered()
{
QDesktopServices::openUrl(QUrl("https://github.com/WohlSoft/PGE-Project"));
QDesktopServices::openUrl(QUrl("https://github.com/WohlSoft/Moondust-Project/"));
}

void MusPlayer_Qt::on_actionHelpGitHubMixerX_triggered()
{
QDesktopServices::openUrl(QUrl("https://github.com/WohlSoft/SDL-Mixer-X/"));
}

void MusPlayer_Qt::on_actionMidiSetup_triggered()
Expand Down
2 changes: 2 additions & 0 deletions MusicPlayer/MainWindow/musplayer_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private slots:
void on_trackNext_clicked();
void on_disableSpcEcho_clicked(bool checked);

void on_gain_valueChanged(int tempo);
void on_tempo_valueChanged(int tempo);
void on_speed_valueChanged(int speed);
void on_pitch_valueChanged(int pitch);
Expand All @@ -100,6 +101,7 @@ private slots:
void on_actionHelpLicense_triggered();
void on_actionHelpAbout_triggered();
void on_actionHelpGitHub_triggered();
void on_actionHelpGitHubMixerX_triggered();
void on_actionMidiSetup_triggered();
void on_actionSfxTesting_triggered();
void on_actionMultiMusicTesting_triggered();
Expand Down
Loading

0 comments on commit 12fbf5d

Please sign in to comment.