mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-04 03:17:30 +01:00
Inform of song change on play restart, add playlist auto sorting.
Fixes #511
This commit is contained in:
parent
d09e2daf00
commit
872da05ff6
@ -1455,7 +1455,7 @@ void MainWindow::PlaylistDoubleClick(const QModelIndex &idx) {
|
|||||||
switch (doubleclick_playlist_addmode_) {
|
switch (doubleclick_playlist_addmode_) {
|
||||||
case BehaviourSettingsPage::PlaylistAddBehaviour_Play:
|
case BehaviourSettingsPage::PlaylistAddBehaviour_Play:
|
||||||
app_->playlist_manager()->SetActiveToCurrent();
|
app_->playlist_manager()->SetActiveToCurrent();
|
||||||
app_->player()->PlayAt(row, Engine::Manual, Playlist::AutoScroll_Never, true);
|
app_->player()->PlayAt(row, Engine::Manual, Playlist::AutoScroll_Never, true, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BehaviourSettingsPage::PlaylistAddBehaviour_Enqueue:
|
case BehaviourSettingsPage::PlaylistAddBehaviour_Enqueue:
|
||||||
|
@ -478,7 +478,6 @@ void Player::Stop(bool stop_after) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::StopAfterCurrent() {
|
void Player::StopAfterCurrent() {
|
||||||
|
|
||||||
app_->playlist_manager()->active()->StopAfter(app_->playlist_manager()->active()->current_row());
|
app_->playlist_manager()->active()->StopAfter(app_->playlist_manager()->active()->current_row());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,14 +498,14 @@ void Player::PreviousItem(const Engine::TrackChangeFlags change) {
|
|||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
if (last_pressed_previous_.isValid() && last_pressed_previous_.secsTo(now) >= 2) {
|
if (last_pressed_previous_.isValid() && last_pressed_previous_.secsTo(now) >= 2) {
|
||||||
last_pressed_previous_ = now;
|
last_pressed_previous_ = now;
|
||||||
PlayAt(app_->playlist_manager()->active()->current_row(), change, Playlist::AutoScroll_Always, false);
|
PlayAt(app_->playlist_manager()->active()->current_row(), change, Playlist::AutoScroll_Always, false, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
last_pressed_previous_ = now;
|
last_pressed_previous_ = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = app_->playlist_manager()->active()->previous_row(ignore_repeat_track);
|
int i = app_->playlist_manager()->active()->previous_row(ignore_repeat_track);
|
||||||
app_->playlist_manager()->active()->set_current_row(i, Playlist::AutoScroll_Always);
|
app_->playlist_manager()->active()->set_current_row(i, Playlist::AutoScroll_Always, false, true);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
Stop();
|
Stop();
|
||||||
PlayAt(i, change, Playlist::AutoScroll_Always, true);
|
PlayAt(i, change, Playlist::AutoScroll_Always, true);
|
||||||
@ -561,7 +560,7 @@ void Player::SetVolume(const int value) {
|
|||||||
|
|
||||||
int Player::GetVolume() const { return engine_->volume(); }
|
int Player::GetVolume() const { return engine_->volume(); }
|
||||||
|
|
||||||
void Player::PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle) {
|
void Player::PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform) {
|
||||||
|
|
||||||
if (current_item_ && change == Engine::Manual && engine_->position_nanosec() != engine_->length_nanosec()) {
|
if (current_item_ && change == Engine::Manual && engine_->position_nanosec() != engine_->length_nanosec()) {
|
||||||
emit TrackSkipped(current_item_);
|
emit TrackSkipped(current_item_);
|
||||||
@ -572,7 +571,8 @@ void Player::PlayAt(const int index, Engine::TrackChangeFlags change, const Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reshuffle) app_->playlist_manager()->active()->ReshuffleIndices();
|
if (reshuffle) app_->playlist_manager()->active()->ReshuffleIndices();
|
||||||
app_->playlist_manager()->active()->set_current_row(index, autoscroll);
|
|
||||||
|
app_->playlist_manager()->active()->set_current_row(index, autoscroll, false, force_inform);
|
||||||
if (app_->playlist_manager()->active()->current_row() == -1) {
|
if (app_->playlist_manager()->active()->current_row() == -1) {
|
||||||
// Maybe index didn't exist in the playlist.
|
// Maybe index didn't exist in the playlist.
|
||||||
return;
|
return;
|
||||||
@ -620,6 +620,10 @@ void Player::SeekTo(const int seconds) {
|
|||||||
|
|
||||||
emit Seeked(nanosec / 1000);
|
emit Seeked(nanosec / 1000);
|
||||||
|
|
||||||
|
if (seconds == 0) {
|
||||||
|
app_->playlist_manager()->active()->InformOfCurrentSongChange(Playlist::AutoScroll_Maybe, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SeekForward() {
|
void Player::SeekForward() {
|
||||||
|
@ -73,7 +73,7 @@ class PlayerInterface : public QObject {
|
|||||||
virtual void ReloadSettings() = 0;
|
virtual void ReloadSettings() = 0;
|
||||||
|
|
||||||
// Manual track change to the specified track
|
// Manual track change to the specified track
|
||||||
virtual void PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle) = 0;
|
virtual void PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) = 0;
|
||||||
|
|
||||||
// If there's currently a song playing, pause it, otherwise play the track that was playing last, or the first one on the playlist
|
// If there's currently a song playing, pause it, otherwise play the track that was playing last, or the first one on the playlist
|
||||||
virtual void PlayPause(Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) = 0;
|
virtual void PlayPause(Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) = 0;
|
||||||
@ -158,7 +158,7 @@ class Player : public PlayerInterface {
|
|||||||
public slots:
|
public slots:
|
||||||
void ReloadSettings() override;
|
void ReloadSettings() override;
|
||||||
|
|
||||||
void PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle) override;
|
void PlayAt(const int index, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) override;
|
||||||
void PlayPause(Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) override;
|
void PlayPause(Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) override;
|
||||||
void RestartOrPrevious() override;
|
void RestartOrPrevious() override;
|
||||||
void Next() override;
|
void Next() override;
|
||||||
|
@ -135,7 +135,11 @@ Playlist::Playlist(PlaylistBackend *backend, TaskManager *task_manager, Collecti
|
|||||||
cancel_restore_(false),
|
cancel_restore_(false),
|
||||||
scrobbled_(false),
|
scrobbled_(false),
|
||||||
scrobble_point_(-1),
|
scrobble_point_(-1),
|
||||||
editing_(-1) {
|
editing_(-1),
|
||||||
|
auto_sort_(false),
|
||||||
|
sort_column_(Column_Title),
|
||||||
|
sort_order_(Qt::AscendingOrder)
|
||||||
|
{
|
||||||
|
|
||||||
undo_stack_->setUndoLimit(kUndoStackSize);
|
undo_stack_->setUndoLimit(kUndoStackSize);
|
||||||
|
|
||||||
@ -591,10 +595,11 @@ int Playlist::previous_row(const bool ignore_repeat_track) const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const bool is_stopping) {
|
void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const bool is_stopping, const bool force_inform) {
|
||||||
|
|
||||||
QModelIndex old_current_item_index = current_item_index_;
|
QModelIndex old_current_item_index = current_item_index_;
|
||||||
QModelIndex new_current_item_index = QPersistentModelIndex(index(i, 0, QModelIndex()));
|
QModelIndex new_current_item_index;
|
||||||
|
if (i != -1) new_current_item_index = QPersistentModelIndex(index(i, 0, QModelIndex()));
|
||||||
|
|
||||||
if (new_current_item_index != current_item_index_) ClearStreamMetadata();
|
if (new_current_item_index != current_item_index_) ClearStreamMetadata();
|
||||||
|
|
||||||
@ -610,11 +615,11 @@ void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const b
|
|||||||
current_item_index_ = new_current_item_index;
|
current_item_index_ = new_current_item_index;
|
||||||
|
|
||||||
// if the given item is the first in the queue, remove it from the queue
|
// if the given item is the first in the queue, remove it from the queue
|
||||||
if (current_item_index_.row() == queue_->PeekNext()) {
|
if (current_item_index_.isValid() && current_item_index_.row() == queue_->PeekNext()) {
|
||||||
queue_->TakeNext();
|
queue_->TakeNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_item_index_ == old_current_item_index) {
|
if (current_item_index_ == old_current_item_index && !force_inform) {
|
||||||
UpdateScrobblePoint();
|
UpdateScrobblePoint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -653,26 +658,24 @@ void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const b
|
|||||||
if (dynamic_playlist_ && current_item_index_.isValid()) {
|
if (dynamic_playlist_ && current_item_index_.isValid()) {
|
||||||
|
|
||||||
// When advancing to the next track
|
// When advancing to the next track
|
||||||
if (i > old_current_item_index.row()) {
|
if (old_current_item_index.isValid() && i > old_current_item_index.row()) {
|
||||||
// Move the new item one position ahead of the last item in the history.
|
// Move the new item one position ahead of the last item in the history.
|
||||||
MoveItemWithoutUndo(current_item_index_.row(), dynamic_history_length());
|
MoveItemWithoutUndo(current_item_index_.row(), dynamic_history_length());
|
||||||
|
|
||||||
// Compute the number of new items that have to be inserted. This is not
|
// Compute the number of new items that have to be inserted
|
||||||
// necessarily 1 because the user might have added or removed items
|
// This is not necessarily 1 because the user might have added or removed items manually.
|
||||||
// manually. Note that the future excludes the current item.
|
// Note that the future excludes the current item.
|
||||||
const int count = dynamic_history_length() + 1 + dynamic_playlist_->GetDynamicFuture() - items_.count();
|
const int count = dynamic_history_length() + 1 + dynamic_playlist_->GetDynamicFuture() - items_.count();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
InsertDynamicItems(count);
|
InsertDynamicItems(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shrink the history, again this is not necessarily by 1, because the
|
// Shrink the history, again this is not necessarily by 1, because the user might have moved items by hand.
|
||||||
// user might have moved items by hand.
|
|
||||||
const int remove_count = dynamic_history_length() - dynamic_playlist_->GetDynamicHistory();
|
const int remove_count = dynamic_history_length() - dynamic_playlist_->GetDynamicHistory();
|
||||||
if (0 < remove_count) RemoveItemsWithoutUndo(0, remove_count);
|
if (0 < remove_count) RemoveItemsWithoutUndo(0, remove_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the above actions make all commands on the undo stack invalid, so we
|
// the above actions make all commands on the undo stack invalid, so we better clear it.
|
||||||
// better clear it.
|
|
||||||
undo_stack_->clear();
|
undo_stack_->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1060,7 +1063,13 @@ void Playlist::InsertItemsWithoutUndo(const PlaylistItemList &items, const int p
|
|||||||
}
|
}
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
ReshuffleIndices();
|
|
||||||
|
if (auto_sort_) {
|
||||||
|
sort(sort_column_, sort_order_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ReshuffleIndices();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1308,6 +1317,9 @@ QString Playlist::abbreviated_column_name(const Column column) {
|
|||||||
|
|
||||||
void Playlist::sort(int column, Qt::SortOrder order) {
|
void Playlist::sort(int column, Qt::SortOrder order) {
|
||||||
|
|
||||||
|
sort_column_ = column;
|
||||||
|
sort_order_ = order;
|
||||||
|
|
||||||
if (ignore_sorting_) return;
|
if (ignore_sorting_) return;
|
||||||
|
|
||||||
PlaylistItemList new_items(items_);
|
PlaylistItemList new_items(items_);
|
||||||
|
@ -295,8 +295,10 @@ class Playlist : public QAbstractListModel {
|
|||||||
void RateSong(const QModelIndex &idx, const double rating);
|
void RateSong(const QModelIndex &idx, const double rating);
|
||||||
void RateSongs(const QModelIndexList &index_list, const double rating);
|
void RateSongs(const QModelIndexList &index_list, const double rating);
|
||||||
|
|
||||||
|
void set_auto_sort(const bool auto_sort) { auto_sort_ = auto_sort; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void set_current_row(const int i, const AutoScroll autoscroll = AutoScroll_Maybe, const bool is_stopping = false);
|
void set_current_row(const int i, const AutoScroll autoscroll = AutoScroll_Maybe, const bool is_stopping = false, const bool force_inform = false);
|
||||||
void Paused();
|
void Paused();
|
||||||
void Playing();
|
void Playing();
|
||||||
void Stopped();
|
void Stopped();
|
||||||
@ -430,6 +432,10 @@ class Playlist : public QAbstractListModel {
|
|||||||
|
|
||||||
PlaylistGeneratorPtr dynamic_playlist_;
|
PlaylistGeneratorPtr dynamic_playlist_;
|
||||||
|
|
||||||
|
bool auto_sort_;
|
||||||
|
int sort_column_;
|
||||||
|
Qt::SortOrder sort_order_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLIST_H
|
#endif // PLAYLIST_H
|
||||||
|
@ -158,6 +158,7 @@ PlaylistView::PlaylistView(QWidget *parent)
|
|||||||
previous_background_image_y_(0),
|
previous_background_image_y_(0),
|
||||||
glow_enabled_(true),
|
glow_enabled_(true),
|
||||||
select_track_(false),
|
select_track_(false),
|
||||||
|
auto_sort_(false),
|
||||||
currently_glowing_(false),
|
currently_glowing_(false),
|
||||||
glow_intensity_step_(0),
|
glow_intensity_step_(0),
|
||||||
inhibit_autoscroll_timer_(new QTimer(this)),
|
inhibit_autoscroll_timer_(new QTimer(this)),
|
||||||
@ -309,6 +310,7 @@ void PlaylistView::SetPlaylist(Playlist *playlist) {
|
|||||||
DynamicModeChanged(playlist->is_dynamic());
|
DynamicModeChanged(playlist->is_dynamic());
|
||||||
setFocus();
|
setFocus();
|
||||||
JumpToLastPlayedTrack();
|
JumpToLastPlayedTrack();
|
||||||
|
playlist->set_auto_sort(auto_sort_);
|
||||||
|
|
||||||
connect(playlist_, SIGNAL(RestoreFinished()), SLOT(JumpToLastPlayedTrack()));
|
connect(playlist_, SIGNAL(RestoreFinished()), SLOT(JumpToLastPlayedTrack()));
|
||||||
connect(playlist_, SIGNAL(MaybeAutoscroll(Playlist::AutoScroll)), SLOT(MaybeAutoscroll(Playlist::AutoScroll)));
|
connect(playlist_, SIGNAL(MaybeAutoscroll(Playlist::AutoScroll)), SLOT(MaybeAutoscroll(Playlist::AutoScroll)));
|
||||||
@ -1133,6 +1135,7 @@ void PlaylistView::ReloadSettings() {
|
|||||||
glow_enabled_ = s.value("glow_effect", glow_effect).toBool();
|
glow_enabled_ = s.value("glow_effect", glow_effect).toBool();
|
||||||
bool editmetadatainline = s.value("editmetadatainline", false).toBool();
|
bool editmetadatainline = s.value("editmetadatainline", false).toBool();
|
||||||
select_track_ = s.value("select_track", false).toBool();
|
select_track_ = s.value("select_track", false).toBool();
|
||||||
|
auto_sort_ = s.value("auto_sort", false).toBool();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
|
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
|
||||||
@ -1221,6 +1224,8 @@ void PlaylistView::ReloadSettings() {
|
|||||||
else
|
else
|
||||||
setEditTriggers(editTriggers() & ~QAbstractItemView::SelectedClicked);
|
setEditTriggers(editTriggers() & ~QAbstractItemView::SelectedClicked);
|
||||||
|
|
||||||
|
if (playlist_) playlist_->set_auto_sort(auto_sort_);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistView::SaveSettings() {
|
void PlaylistView::SaveSettings() {
|
||||||
|
@ -257,6 +257,7 @@ class PlaylistView : public QTreeView {
|
|||||||
|
|
||||||
bool glow_enabled_;
|
bool glow_enabled_;
|
||||||
bool select_track_;
|
bool select_track_;
|
||||||
|
bool auto_sort_;
|
||||||
|
|
||||||
bool currently_glowing_;
|
bool currently_glowing_;
|
||||||
QBasicTimer glow_timer_;
|
QBasicTimer glow_timer_;
|
||||||
|
@ -64,6 +64,7 @@ void PlaylistSettingsPage::Load() {
|
|||||||
ui_->checkbox_greyout_songs_play->setChecked(s.value("greyout_songs_play", true).toBool());
|
ui_->checkbox_greyout_songs_play->setChecked(s.value("greyout_songs_play", true).toBool());
|
||||||
ui_->checkbox_select_track->setChecked(s.value("select_track", false).toBool());
|
ui_->checkbox_select_track->setChecked(s.value("select_track", false).toBool());
|
||||||
ui_->checkbox_playlist_clear->setChecked(s.value("playlist_clear", true).toBool());
|
ui_->checkbox_playlist_clear->setChecked(s.value("playlist_clear", true).toBool());
|
||||||
|
ui_->checkbox_auto_sort->setChecked(s.value("auto_sort", false).toBool());
|
||||||
|
|
||||||
Playlist::Path path = Playlist::Path(s.value(Playlist::kPathType, Playlist::Path_Automatic).toInt());
|
Playlist::Path path = Playlist::Path(s.value(Playlist::kPathType, Playlist::Path_Automatic).toInt());
|
||||||
switch (path) {
|
switch (path) {
|
||||||
@ -126,6 +127,7 @@ void PlaylistSettingsPage::Save() {
|
|||||||
s.setValue("editmetadatainline", ui_->checkbox_editmetadatainline->isChecked());
|
s.setValue("editmetadatainline", ui_->checkbox_editmetadatainline->isChecked());
|
||||||
s.setValue(Playlist::kWriteMetadata, ui_->checkbox_writemetadata->isChecked());
|
s.setValue(Playlist::kWriteMetadata, ui_->checkbox_writemetadata->isChecked());
|
||||||
s.setValue("delete_files", ui_->checkbox_delete_files->isChecked());
|
s.setValue("delete_files", ui_->checkbox_delete_files->isChecked());
|
||||||
|
s.setValue("auto_sort", ui_->checkbox_auto_sort->isChecked());
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkbox_auto_sort">
|
||||||
|
<property name="text">
|
||||||
|
<string>Automatically sort playlist when inserting songs</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupbox_paths">
|
<widget class="QGroupBox" name="groupbox_paths">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user