Skip to content

Commit

Permalink
Editor: Make gain change don't cause song restart
Browse files Browse the repository at this point in the history
When changing the gaining factor in the music extra settings, the change of gaining factor now won't cause song restart since the necessary API is implemented on the MixerX side.
  • Loading branch information
Wohlstand committed Nov 28, 2024
1 parent 12fbf5d commit e9e3991
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Editor/audio/music_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ void LvlMusPlay::setTempo(double tempo)
PGE_MusPlayer::setTempo(tempo);
}

void LvlMusPlay::setGain(double gain)
{
PGE_MusPlayer::setGain(gain);
}

// TODO: Refactor this
void LvlMusPlay::updateMusic(MainWindow *mw)
{
Expand Down
1 change: 1 addition & 0 deletions Editor/audio/music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class LvlMusPlay
static void setMusic(MainWindow *mw, MusicType mt, unsigned long id, QString cmus);
static void setNoMusic();
static void setTempo(double tempo);
static void setGain(double gain);
static void updateMusic(MainWindow *mw);
static void updatePlayerState(MainWindow *mw, bool playing = true, bool force = false);
static void stopMusic(MainWindow *mw);
Expand Down
6 changes: 6 additions & 0 deletions Editor/audio/sdl_music_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ void PGE_MusPlayer::setTempo(double tempo)
Mix_SetMusicTempo(play_mus, tempo);
}

void PGE_MusPlayer::setGain(double gain)
{
if(play_mus)
Mix_SetMusicGain(play_mus, gain);
}


// //////////////////////// Sound Player //////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions Editor/audio/sdl_music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PGE_MusPlayer : public QObject
static void play();

static void setTempo(double tempo);
static void setGain(double gain);

public slots:
void setVolume(int volume);
Expand Down
5 changes: 5 additions & 0 deletions Editor/common_features/json_settings_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@ QString JsonSettingsWidget::browseForFileValue(QWidget* target, LineEditType typ
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&muz, &MusicFileList::musicGainChanged, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});

QObject::connect(&muz, &MusicFileList::playSoundFile, [this, &audioPath](const QString &file)->void
{
PGE_SfxPlayer::playFile(file);
Expand Down
6 changes: 6 additions & 0 deletions Editor/editing/_dialogs/itemselectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,12 @@ void ItemSelectDialog::on_Sel_DiaButtonBox_accepted()
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&musicList, &MusicFileList::musicGainChanged, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});


QObject::connect(&musicList, &MusicFileList::musicButtonClicked, [this, &testMusicFile](bool st)->void
{
MainWinConnect::pMainWin->getPlayMusicAction()->setChecked(st);
Expand Down
11 changes: 11 additions & 0 deletions Editor/main_window/dock/lvl_sctc_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ void LvlSectionProps::on_LVLPropsMusicCustomBrowse_clicked()
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&musicList, &MusicFileList::musicGainChanged, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});


QObject::connect(&musicList, &MusicFileList::musicButtonClicked, [this, &musicPath](bool st)->void
{
mw()->getPlayMusicAction()->setChecked(st);
Expand Down Expand Up @@ -775,6 +781,11 @@ void LvlSectionProps::on_musicSetup_clicked()
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&set, &CustomMusicSetup::updateSongGain, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});

QObject::connect(&set, &CustomMusicSetup::musicButtonClicked, [this, &musicPath](bool st)->void
{
mw()->getPlayMusicAction()->setChecked(st);
Expand Down
5 changes: 5 additions & 0 deletions Editor/main_window/dock/wld_item_toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ void WorldItemBox::MusicList_itemClicked(const QModelIndex &item)
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&musicList, &MusicFileList::musicGainChanged, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});

QObject::connect(&musicList, &MusicFileList::musicButtonClicked, [this, &customMusicFile](bool st)->void
{
mw()->getPlayMusicAction()->setChecked(st);
Expand Down
5 changes: 5 additions & 0 deletions Editor/main_window/dock/wld_musicbox_itemset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ void WorldMusicBoxItemBox::MusicList_itemClicked(const QModelIndex &item)
LvlMusPlay::setTempo(tempo);
});

QObject::connect(&musicList, &MusicFileList::musicGainChanged, [](double gain)->void
{
LvlMusPlay::setGain(gain);
});

QObject::connect(&musicList, &MusicFileList::musicButtonClicked, [this, &customMusicFile](bool st)->void
{
mw()->getPlayMusicAction()->setChecked(st);
Expand Down
18 changes: 9 additions & 9 deletions _common/qt-modules/custom_music_setup/custom_music_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,10 +1052,10 @@ void CustomMusicSetup::on_midiSynth_currentIndexChanged(int)
void CustomMusicSetup::on_midiGain_valueChanged(int)
{}

void CustomMusicSetup::on_midiGainAbs_valueChanged(double)
void CustomMusicSetup::on_midiGainAbs_valueChanged(double arg1)
{
buildSettings();
emit updateSongPlay();
emit updateSongGain(arg1);
}

void CustomMusicSetup::on_midiGainReset_clicked()
Expand All @@ -1076,7 +1076,7 @@ void CustomMusicSetup::on_midiGainReset_clicked()
if(!signalsBlocked())
buildSettings();

emit updateSongPlay();
emit updateSongGain(ui->midiGainAbs->value());
}

void CustomMusicSetup::on_midiTempo_valueChanged(int)
Expand Down Expand Up @@ -1239,10 +1239,10 @@ void CustomMusicSetup::on_gmeGoToFirst_clicked()
void CustomMusicSetup::on_gmeGain_valueChanged(int)
{}

void CustomMusicSetup::on_gmeGainAbs_valueChanged(double)
void CustomMusicSetup::on_gmeGainAbs_valueChanged(double arg1)
{
buildSettings();
emit updateSongPlay();
emit updateSongGain(arg1);
}

void CustomMusicSetup::on_gmeGainReset_clicked()
Expand All @@ -1251,7 +1251,7 @@ void CustomMusicSetup::on_gmeGainReset_clicked()
ui->gmeGainAbs->setValue(1.0);
if(!signalsBlocked())
buildSettings();
emit updateSongPlay();
emit updateSongGain(ui->gmeGainAbs->value());
}

void CustomMusicSetup::on_gmeTempo_valueChanged(int)
Expand Down Expand Up @@ -1281,10 +1281,10 @@ void CustomMusicSetup::on_gmeDisableSpcEcho_clicked(bool)
void CustomMusicSetup::on_pxtoneGain_valueChanged(int)
{}

void CustomMusicSetup::on_pxtoneGainAbs_valueChanged(double)
void CustomMusicSetup::on_pxtoneGainAbs_valueChanged(double arg1)
{
buildSettings();
emit updateSongPlay();
emit updateSongGain(arg1);
}

void CustomMusicSetup::on_pxtoneGainReset_clicked()
Expand All @@ -1293,7 +1293,7 @@ void CustomMusicSetup::on_pxtoneGainReset_clicked()
ui->pxtoneGainAbs->setValue(1.0);
if(!signalsBlocked())
buildSettings();
emit updateSongPlay();
emit updateSongGain(ui->pxtoneGainAbs->value());
}

void CustomMusicSetup::on_pxtoneTempo_valueChanged(int)
Expand Down
1 change: 1 addition & 0 deletions _common/qt-modules/custom_music_setup/custom_music_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class CustomMusicSetup : public QDialog
void musicSetupChanged(const QString &music);
void updateSongPlay();
void updateSongTempo(double tempo);
void updateSongGain(double tempo);
void musicButtonClicked(bool checked);

protected:
Expand Down
5 changes: 5 additions & 0 deletions _common/qt-modules/file_list_browser/musicfilelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ MusicFileList::MusicFileList(QString searchDirectory, QString curFile, QWidget *
emit musicTempoChanged(tempo);
});

QObject::connect(&set, &CustomMusicSetup::updateSongGain, this, [this](double gain)->void
{
emit musicGainChanged(gain);
});

QObject::connect(&set, &CustomMusicSetup::musicButtonClicked, this, [this, &musicPath](bool st)->void
{
m_previewButton->setChecked(st);
Expand Down
1 change: 1 addition & 0 deletions _common/qt-modules/file_list_browser/musicfilelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MusicFileList : public FileListBrowser
void updateSongPlay();
void musicButtonClicked(bool checked);
void musicTempoChanged(double tempo);
void musicGainChanged(double gain);

void playSoundFile(const QString &sfx);

Expand Down

0 comments on commit e9e3991

Please sign in to comment.