- Fixed a bug in TrackListView where we may end up selecting the album

header after a rquery after being hidden, then re-displayed. ugh.
- Added explicit Interrupt() method to IDataStream because we're bumping
  the API version anyway
This commit is contained in:
casey langen 2017-03-22 22:59:50 -07:00
parent 0a271dbc25
commit 8f448e86ad
11 changed files with 31 additions and 14 deletions

View File

@ -176,6 +176,10 @@ bool CddaDataStream::Close() {
return true;
}
void CddaDataStream::Interrupt() {
}
void CddaDataStream::Destroy() {
delete this;
}

View File

@ -48,6 +48,7 @@ class CddaDataStream : public IDataStream {
virtual bool Open(const char *filename, unsigned int options = 0);
virtual bool Close();
virtual void Interrupt();
virtual PositionType Read(void* buffer, PositionType readBytes);
virtual bool SetPosition(PositionType position);
virtual PositionType Position();

View File

@ -57,7 +57,7 @@ namespace musik { namespace core { namespace audio {
virtual double SetPosition(double seconds) = 0;
virtual double GetDuration() = 0;
virtual bool OpenStream(std::string uri) = 0;
virtual void Close() = 0;
virtual void Interrupt() = 0;
};
typedef std::shared_ptr<IStream> IStreamPtr;

View File

@ -169,7 +169,7 @@ void Player::Destroy() {
return; /* already terminated (or terminating) */
}
this->stream->Close();
this->stream->Interrupt();
this->state = Player::Quit;
this->writeToOutputCondition.notify_all();
this->thread->detach();

View File

@ -136,9 +136,9 @@ bool Stream::OpenStream(std::string uri) {
return false;
}
void Stream::Close() {
void Stream::Interrupt() {
if (this->dataStream) {
this->dataStream->Close();
this->dataStream->Interrupt();
}
}

View File

@ -67,7 +67,7 @@ namespace musik { namespace core { namespace audio {
virtual double SetPosition(double seconds);
virtual double GetDuration();
virtual bool OpenStream(std::string uri);
virtual void Close();
virtual void Interrupt();
private:
bool GetNextBufferFromDecoder();

View File

@ -103,6 +103,10 @@ bool LocalFileStream::Open(const char *filename, unsigned int options) {
return false;
}
void LocalFileStream::Interrupt() {
}
bool LocalFileStream::Close() {
auto file = this->file.exchange(nullptr);
if (file) {

View File

@ -49,6 +49,7 @@ namespace musik { namespace core { namespace io {
virtual bool Open(const char *filename, unsigned int options = 0);
virtual bool Close();
virtual void Interrupt();
virtual void Destroy();
virtual PositionType Read(void* buffer, PositionType readBytes);
virtual bool SetPosition(PositionType position);

View File

@ -42,6 +42,7 @@ namespace musik { namespace core { namespace sdk {
public:
virtual bool Open(const char *uri, unsigned int options = 0) = 0;
virtual bool Close() = 0;
virtual void Interrupt() = 0;
virtual void Destroy() = 0;
virtual PositionType Read(void *buffer, PositionType readBytes) = 0;
virtual bool SetPosition(PositionType position) = 0;

View File

@ -160,12 +160,12 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::db::local::TrackListQue
size_t index = playback.GetIndex();
if (index == ListWindow::NO_SELECTION) { /* not playing? */
this->trackListView->SetSelectedIndex(0);
this->trackListView->ScrollTo(0);
this->trackListView->SetSelectedIndex(0);
}
else { /* playing... */
this->trackListView->SetSelectedIndex(index);
this->trackListView->ScrollTo(index == 0 ? index : index - 1);
this->trackListView->SetSelectedIndex(index);
}
}
/* user just finished an edit. this is a bit of a hack; we're notified

View File

@ -113,20 +113,26 @@ void TrackListView::SelectFirstTrack() {
void TrackListView::OnQueryCompleted(IQuery* query) {
if (this->query && query == this->query.get()) {
if (this->query->GetStatus() == IQuery::Finished) {
bool hadTracks = this->tracks && this->tracks->Count() > 0;
bool prevQuerySame = this->lastQueryHash != this->query->GetQueryHash();
this->tracks = this->query->GetResult();
this->headers.Set(this->query->GetHeaders());
this->lastQueryHash = this->query->GetQueryHash();
/* if the query was functionally the same as the last query, don't
mess with the selected index */
if (this->lastQueryHash != this->query->GetQueryHash()) {
/* update our internal state */
this->OnAdapterChanged();
/* if the query was functionally the same as the last query, or we
previously had no tracks, let's scroll to the top and select the first
track */
if (!hadTracks || !prevQuerySame) {
this->ScrollToTop();
this->SelectFirstTrack();
}
this->lastQueryHash = this->query->GetQueryHash();
this->OnAdapterChanged(); /* internal handling */
this->Requeried(this->query.get()); /* for external handlers */
/* let external listeners know we updated */
this->Requeried(this->query.get());
this->query.reset();
}