PlayerThread: use strictly typed enum
This commit is contained in:
@@ -43,10 +43,10 @@
|
|||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#define G_LOG_DOMAIN "player_thread"
|
#define G_LOG_DOMAIN "player_thread"
|
||||||
|
|
||||||
enum xfade_state {
|
enum class CrossFadeState : int8_t {
|
||||||
XFADE_DISABLED = -1,
|
DISABLED = -1,
|
||||||
XFADE_UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
XFADE_ENABLED = 1
|
ENABLED = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct player {
|
struct player {
|
||||||
@@ -95,7 +95,7 @@ struct player {
|
|||||||
/**
|
/**
|
||||||
* is cross fading enabled?
|
* is cross fading enabled?
|
||||||
*/
|
*/
|
||||||
enum xfade_state xfade;
|
CrossFadeState xfade_state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* has cross-fading begun?
|
* has cross-fading begun?
|
||||||
@@ -137,7 +137,7 @@ struct player {
|
|||||||
queued(true),
|
queued(true),
|
||||||
output_open(false),
|
output_open(false),
|
||||||
song(nullptr),
|
song(nullptr),
|
||||||
xfade(XFADE_UNKNOWN),
|
xfade_state(CrossFadeState::UNKNOWN),
|
||||||
cross_fading(false),
|
cross_fading(false),
|
||||||
cross_fade_chunks(0),
|
cross_fade_chunks(0),
|
||||||
cross_fade_tag(nullptr),
|
cross_fade_tag(nullptr),
|
||||||
@@ -575,7 +575,7 @@ player::SeekDecoder()
|
|||||||
|
|
||||||
player_command_finished(pc);
|
player_command_finished(pc);
|
||||||
|
|
||||||
xfade = XFADE_UNKNOWN;
|
xfade_state = CrossFadeState::UNKNOWN;
|
||||||
|
|
||||||
/* re-fill the buffer after seeking */
|
/* re-fill the buffer after seeking */
|
||||||
buffering = true;
|
buffering = true;
|
||||||
@@ -750,7 +750,7 @@ player::PlayNextChunk()
|
|||||||
|
|
||||||
unsigned cross_fade_position;
|
unsigned cross_fade_position;
|
||||||
struct music_chunk *chunk = nullptr;
|
struct music_chunk *chunk = nullptr;
|
||||||
if (xfade == XFADE_ENABLED && IsDecoderAtNextSong() &&
|
if (xfade_state == CrossFadeState::ENABLED && IsDecoderAtNextSong() &&
|
||||||
(cross_fade_position = pipe->GetSize()) <= cross_fade_chunks) {
|
(cross_fade_position = pipe->GetSize()) <= cross_fade_chunks) {
|
||||||
/* perform cross fade */
|
/* perform cross fade */
|
||||||
music_chunk *other_chunk = dc.pipe->Shift();
|
music_chunk *other_chunk = dc.pipe->Shift();
|
||||||
@@ -807,7 +807,7 @@ player::PlayNextChunk()
|
|||||||
cross fading */
|
cross fading */
|
||||||
dc.Unlock();
|
dc.Unlock();
|
||||||
|
|
||||||
xfade = XFADE_DISABLED;
|
xfade_state = CrossFadeState::DISABLED;
|
||||||
} else {
|
} else {
|
||||||
/* wait for the decoder */
|
/* wait for the decoder */
|
||||||
dc.Signal();
|
dc.Signal();
|
||||||
@@ -826,7 +826,7 @@ player::PlayNextChunk()
|
|||||||
|
|
||||||
/* insert the postponed tag if cross-fading is finished */
|
/* insert the postponed tag if cross-fading is finished */
|
||||||
|
|
||||||
if (xfade != XFADE_ENABLED && cross_fade_tag != nullptr) {
|
if (xfade_state != CrossFadeState::ENABLED && cross_fade_tag != nullptr) {
|
||||||
chunk->tag = Tag::MergeReplace(chunk->tag, cross_fade_tag);
|
chunk->tag = Tag::MergeReplace(chunk->tag, cross_fade_tag);
|
||||||
cross_fade_tag = nullptr;
|
cross_fade_tag = nullptr;
|
||||||
}
|
}
|
||||||
@@ -871,7 +871,7 @@ player::PlayNextChunk()
|
|||||||
inline bool
|
inline bool
|
||||||
player::SongBorder()
|
player::SongBorder()
|
||||||
{
|
{
|
||||||
xfade = XFADE_UNKNOWN;
|
xfade_state = CrossFadeState::UNKNOWN;
|
||||||
|
|
||||||
char *uri = song->GetURI();
|
char *uri = song->GetURI();
|
||||||
g_message("played \"%s\"", uri);
|
g_message("played \"%s\"", uri);
|
||||||
@@ -992,7 +992,7 @@ player::Run()
|
|||||||
end of the current song */
|
end of the current song */
|
||||||
!pc.border_pause &&
|
!pc.border_pause &&
|
||||||
IsDecoderAtNextSong() &&
|
IsDecoderAtNextSong() &&
|
||||||
xfade == XFADE_UNKNOWN &&
|
xfade_state == CrossFadeState::UNKNOWN &&
|
||||||
!dc.LockIsStarting()) {
|
!dc.LockIsStarting()) {
|
||||||
/* enable cross fading in this song? if yes,
|
/* enable cross fading in this song? if yes,
|
||||||
calculate how many chunks will be required
|
calculate how many chunks will be required
|
||||||
@@ -1010,12 +1010,12 @@ player::Run()
|
|||||||
buffer.GetSize() -
|
buffer.GetSize() -
|
||||||
pc.buffered_before_play);
|
pc.buffered_before_play);
|
||||||
if (cross_fade_chunks > 0) {
|
if (cross_fade_chunks > 0) {
|
||||||
xfade = XFADE_ENABLED;
|
xfade_state = CrossFadeState::ENABLED;
|
||||||
cross_fading = false;
|
cross_fading = false;
|
||||||
} else
|
} else
|
||||||
/* cross fading is disabled or the
|
/* cross fading is disabled or the
|
||||||
next song is too short */
|
next song is too short */
|
||||||
xfade = XFADE_DISABLED;
|
xfade_state = CrossFadeState::DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
|
Reference in New Issue
Block a user