mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-08 07:51:28 +12:00
Emu: Implement BlockingCallFromMainThread
Reduces some copy-paste clutter throughout the project
This commit is contained in:
parent
7842812e24
commit
9cf7a63c77
13 changed files with 95 additions and 223 deletions
|
@ -20,30 +20,20 @@ qt_music_handler::qt_music_handler()
|
|||
|
||||
qt_music_handler::~qt_music_handler()
|
||||
{
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, this]()
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
{
|
||||
music_log.notice("Destroying Qt music handler...");
|
||||
m_media_player->stop();
|
||||
m_media_player.reset();
|
||||
m_error_handler.reset();
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
}
|
||||
|
||||
void qt_music_handler::play(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, &path, this]()
|
||||
Emu.BlockingCallFromMainThread([&path, this]()
|
||||
{
|
||||
if (m_state == CELL_MUSIC_PB_STATUS_PAUSE)
|
||||
{
|
||||
|
@ -57,141 +47,86 @@ void qt_music_handler::play(const std::string& path)
|
|||
}
|
||||
|
||||
m_media_player->play();
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_PLAY;
|
||||
}
|
||||
|
||||
void qt_music_handler::stop()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, this]()
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
{
|
||||
music_log.notice("Stopping music...");
|
||||
m_media_player->stop();
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_STOP;
|
||||
}
|
||||
|
||||
void qt_music_handler::pause()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, this]()
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
{
|
||||
music_log.notice("Pausing music...");
|
||||
m_media_player->pause();
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_PAUSE;
|
||||
}
|
||||
|
||||
void qt_music_handler::fast_forward()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, this]()
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
{
|
||||
music_log.notice("Fast-forwarding music...");
|
||||
m_media_player->setPlaybackRate(2.0);
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_FASTFORWARD;
|
||||
}
|
||||
|
||||
void qt_music_handler::fast_reverse()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, this]()
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
{
|
||||
music_log.notice("Fast-reversing music...");
|
||||
m_media_player->setPlaybackRate(-2.0);
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_FASTREVERSE;
|
||||
}
|
||||
|
||||
void qt_music_handler::set_volume(f32 volume)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, &volume, this]()
|
||||
Emu.BlockingCallFromMainThread([&volume, this]()
|
||||
{
|
||||
const int new_volume = std::max<int>(0, std::min<int>(volume * 100, 100));
|
||||
music_log.notice("Setting volume to %d%%", new_volume);
|
||||
m_media_player->setVolume(new_volume);
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
}
|
||||
|
||||
f32 qt_music_handler::get_volume() const
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
atomic_t<bool> wake_up = false;
|
||||
f32 volume = 0.0f;
|
||||
|
||||
Emu.CallFromMainThread([&wake_up, &volume, this]()
|
||||
Emu.BlockingCallFromMainThread([&volume, this]()
|
||||
{
|
||||
const int current_volume = std::max(0, std::min(m_media_player->volume(), 100));
|
||||
music_log.notice("Getting volume: %d%%", current_volume);
|
||||
volume = current_volume / 100.0f;
|
||||
wake_up = true;
|
||||
wake_up.notify_one();
|
||||
});
|
||||
|
||||
while (!wake_up && !Emu.IsStopped())
|
||||
{
|
||||
thread_ctrl::wait_on(wake_up, false);
|
||||
}
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue