feat: make everything threads-safe.
feat: complete `uninstall.sh` logic to make everything synced. feat: complete basic play logic to handle background, music, lyric play.
This commit is contained in:
+12
-8
@@ -10,6 +10,7 @@
|
||||
#include "backgroundDisplay.h"
|
||||
#include "lyricResolve.h"
|
||||
#include "musicPlayer.h"
|
||||
#include "timeline.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
@@ -42,8 +43,9 @@ static void usage(const char* argv0) {
|
||||
argv0, HMS_DEMO_VIDEO, HMS_DEMO_MUSIC, HMS_DEMO_LYRICS);
|
||||
}
|
||||
|
||||
static void playMusicQuietly(const std::string& path, std::atomic<bool>* stop) {
|
||||
const int rc = mp::play(path, stop);
|
||||
static void playMusicQuietly(const std::string& path, Timeline* timeline,
|
||||
std::atomic<bool>* stop) {
|
||||
const int rc = mp::play(path, timeline, stop);
|
||||
if (rc == 2) {
|
||||
std::fprintf(stderr, "demo: cannot open audio file '%s'\n", path.c_str());
|
||||
} else if (rc == 3) {
|
||||
@@ -86,6 +88,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
std::atomic<bool> stop{false};
|
||||
Timeline timeline;
|
||||
timeline.start();
|
||||
|
||||
// Optional hard deadline (e.g. for quick verification).
|
||||
std::thread deadlineThread;
|
||||
@@ -99,8 +103,8 @@ int main(int argc, char** argv) {
|
||||
if (!useVideo) {
|
||||
// No video: just music + lyrics.
|
||||
std::thread musicThread, lyricThread;
|
||||
if (useMusic) musicThread = std::thread([&] { playMusicQuietly(music, &stop); });
|
||||
if (useLyrics) lyricThread = std::thread([&] { lr::playLyricsFile(lyrics, {}, &stop); });
|
||||
if (useMusic) musicThread = std::thread([&] { playMusicQuietly(music, &timeline, &stop); });
|
||||
if (useLyrics) lyricThread = std::thread([&] { lr::playLyricsFile(lyrics, {}, &timeline, &stop); });
|
||||
if (musicThread.joinable()) musicThread.join();
|
||||
if (lyricThread.joinable()) lyricThread.join();
|
||||
} else if (!useMusic && !useLyrics) {
|
||||
@@ -110,7 +114,7 @@ int main(int argc, char** argv) {
|
||||
vo.loop = false;
|
||||
vo.tryResize = tryResize;
|
||||
vo.stop = &stop;
|
||||
bd::playVideo(video, vo);
|
||||
bd::playVideo(video, &timeline, vo);
|
||||
} else {
|
||||
// Full show: video loops in the background, music + lyrics on top.
|
||||
// Reserve the bottom row for the lyric line.
|
||||
@@ -121,7 +125,7 @@ int main(int argc, char** argv) {
|
||||
vo.tryResize = tryResize;
|
||||
vo.bottomRows = useLyrics ? 1 : 0;
|
||||
vo.stop = &stop;
|
||||
bd::playVideo(video, vo);
|
||||
bd::playVideo(video, &timeline, vo);
|
||||
});
|
||||
|
||||
// Give the video a moment to detect and adjust the terminal size so
|
||||
@@ -129,8 +133,8 @@ int main(int argc, char** argv) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(400));
|
||||
|
||||
std::thread musicThread, lyricThread;
|
||||
if (useMusic) musicThread = std::thread([&] { playMusicQuietly(music, &stop); });
|
||||
if (useLyrics) lyricThread = std::thread([&] { lr::playLyricsFile(lyrics, {}, &stop); });
|
||||
if (useMusic) musicThread = std::thread([&] { playMusicQuietly(music, &timeline, &stop); });
|
||||
if (useLyrics) lyricThread = std::thread([&] { lr::playLyricsFile(lyrics, {}, &timeline, &stop); });
|
||||
if (musicThread.joinable()) musicThread.join();
|
||||
if (lyricThread.joinable()) lyricThread.join();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user