- Fixed a bug in GaplessTransport that could result in two streams

playing simultaneously.
- More color tweaks to make things more monokaiesque
This commit is contained in:
casey 2016-06-29 00:35:48 -07:00
parent 86f523089c
commit 569c3df3d1
4 changed files with 37 additions and 28 deletions

View File

@ -73,7 +73,7 @@ GaplessTransport::GaplessTransport()
GaplessTransport::~GaplessTransport() {
}
GaplessTransport::PlaybackState GaplessTransport::GetPlaybackState() {
ITransport::PlaybackState GaplessTransport::GetPlaybackState() {
boost::recursive_mutex::scoped_lock lock(this->stateMutex);
return this->state;
}
@ -131,7 +131,7 @@ void GaplessTransport::StartWithPlayer(Player* newPlayer) {
newPlayer->Play();
}
this->RaiseStreamEvent(GaplessTransport::StreamScheduled, newPlayer);
this->RaiseStreamEvent(ITransport::StreamScheduled, newPlayer);
}
}
@ -212,7 +212,7 @@ bool GaplessTransport::Resume() {
}
if (count) {
this->SetPlaybackState(GaplessTransport::PlaybackPlaying);
this->SetPlaybackState(ITransport::PlaybackPlaying);
return true;
}
@ -292,8 +292,8 @@ void GaplessTransport::SetNextCanStart(bool nextCanStart) {
}
void GaplessTransport::OnPlaybackStarted(Player* player) {
this->RaiseStreamEvent(GaplessTransport::StreamPlaying, player);
this->SetPlaybackState(GaplessTransport::PlaybackPlaying);
this->RaiseStreamEvent(ITransport::StreamPlaying, player);
this->SetPlaybackState(ITransport::PlaybackPlaying);
}
void GaplessTransport::OnPlaybackAlmostEnded(Player* player) {
@ -309,11 +309,11 @@ void GaplessTransport::OnPlaybackAlmostEnded(Player* player) {
}
}
this->RaiseStreamEvent(GaplessTransport::StreamAlmostDone, player);
this->RaiseStreamEvent(ITransport::StreamAlmostDone, player);
}
void GaplessTransport::OnPlaybackFinished(Player* player) {
this->RaiseStreamEvent(GaplessTransport::StreamFinished, player);
this->RaiseStreamEvent(ITransport::StreamFinished, player);
bool stopped = false;
@ -322,7 +322,13 @@ void GaplessTransport::OnPlaybackFinished(Player* player) {
bool startedNext = false;
if (this->nextPlayer) {
size_t count = this->active.size();
Player* front = count ? this->active.front() : nullptr;
bool playerIsFront = (player == front);
/* only start the next player if the currently active player is the
one that just finished. */
if (this->nextPlayer && playerIsFront) {
this->StartWithPlayer(this->nextPlayer);
startedNext = true;
}
@ -332,9 +338,7 @@ void GaplessTransport::OnPlaybackFinished(Player* player) {
of players is one, and it's the current player. remember, we free
players asynchronously. */
if (!startedNext) {
stopped =
!this->active.size() ||
(this->active.size() == 1 && this->active.front() == player);
stopped = !count || (count == 1 && playerIsFront);
}
}
@ -346,8 +350,8 @@ void GaplessTransport::OnPlaybackFinished(Player* player) {
}
void GaplessTransport::OnPlaybackError(Player* player) {
this->RaiseStreamEvent(GaplessTransport::StreamError, player);
this->SetPlaybackState(GaplessTransport::PlaybackStopped);
this->RaiseStreamEvent(ITransport::StreamError, player);
this->SetPlaybackState(ITransport::PlaybackStopped);
DEFER(&GaplessTransport::RemoveActive, player);
}

View File

@ -53,11 +53,11 @@ namespace musik { namespace core { namespace audio {
} PlaybackState;
typedef enum {
StreamScheduled = 0,
StreamPlaying = 1,
StreamAlmostDone = 4,
StreamFinished = 5,
StreamStopped = 6,
StreamScheduled = 1,
StreamPlaying = 2,
StreamAlmostDone = 3,
StreamFinished = 4,
StreamStopped = 5,
StreamError = -1
} StreamEventType;

View File

@ -98,8 +98,11 @@ Player::~Player() {
void Player::Play() {
boost::mutex::scoped_lock lock(this->queueMutex);
this->state = Player::Playing;
this->writeToOutputCondition.notify_all();
if (this->state != Player::Quit) {
this->state = Player::Playing;
this->writeToOutputCondition.notify_all();
}
}
void Player::Stop() {

View File

@ -52,6 +52,13 @@ static int background = -1;
#define COLOR_CUSTOM_GREEN 20
#define COLOR_CUSTOM_BLACK 21
#define SCALE(x) ((x * 1000) / 255)
static int initColor(int id, int r, int g, int b) {
init_color(id, SCALE(r), SCALE(g), SCALE(b));
return id;
}
Colors::Colors() {
}
@ -63,14 +70,9 @@ void Colors::Init() {
let's use custom colors if the terminal supports it. in
the future we'll allow users to configure this via setting */
if (COLORS > 8) {
init_color(COLOR_CUSTOM_RED, 1000, 431, 392);
red = COLOR_CUSTOM_RED;
init_color(COLOR_CUSTOM_GREEN, 373, 980, 392);
green = COLOR_CUSTOM_GREEN;
init_color(COLOR_CUSTOM_YELLOW, 913, 858, 427);
yellow = COLOR_CUSTOM_YELLOW;
red = initColor(COLOR_CUSTOM_RED, 220, 82, 86);
green = initColor(COLOR_CUSTOM_GREEN, 166, 226, 46);
yellow = initColor(COLOR_CUSTOM_YELLOW, 230, 220, 116);
}
init_pair(CURSESPP_WHITE_ON_BLUE, white, blue);