]> git.sesse.net Git - nageru/commitdiff
Fix an issue where it was not possible to add new infinite clips to a playlist
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Wed, 30 Oct 2019 23:14:55 +0000 (00:14 +0100)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Wed, 30 Oct 2019 23:14:59 +0000 (00:14 +0100)
that was already playing.

Non-infinite clips were okay all along, but infinite clips would have zero
(well, negative) length.

futatabi/mainwindow.cpp
futatabi/mainwindow.h

index f55ad0e489083572e9d86fa80e0dd2f8c749d656..0ebb75ca35ba22f737c0a7a772d062fa332ffc18 100644 (file)
@@ -629,10 +629,7 @@ void MainWindow::defer_timer_expired()
 void MainWindow::content_changed()
 {
        // If we are playing, update the part of the playlist that's not playing yet.
-       vector<ClipWithID> clips;
-       for (unsigned row = 0; row < playlist_clips->size(); ++row) {
-               clips.emplace_back(*playlist_clips->clip_with_id(row));
-       }
+       vector<ClipWithID> clips = get_playlist(0, playlist_clips->size());
        live_player->splice_play(clips);
 
        // Serialize the state.
@@ -693,14 +690,7 @@ void MainWindow::play_clicked()
        }
        unsigned start_row = selected->selectedRows(0)[0].row();
 
-       vector<ClipWithID> clips;
-       for (unsigned row = start_row; row < playlist_clips->size(); ++row) {
-               ClipWithID clip = *playlist_clips->clip_with_id(row);
-               if (clip.clip.pts_out == -1) {
-                       clip.clip.pts_out = clip.clip.pts_in + int64_t(TIMEBASE) * 86400 * 7;  // One week; effectively infinite, but without overflow issues.
-               }
-               clips.emplace_back(clip);
-       }
+       vector<ClipWithID> clips = get_playlist(start_row, playlist_clips->size());
        live_player->play(clips);
        playlist_clips->set_progress({ { start_row, 0.0f } });
        ui->playlist->selectionModel()->clear();
@@ -1054,6 +1044,19 @@ void MainWindow::clip_list_selection_changed(const QModelIndex &current, const Q
        enable_or_disable_queue_button();
 }
 
+vector<ClipWithID> MainWindow::get_playlist(size_t start_row, size_t end_row)
+{
+       vector<ClipWithID> clips;
+       for (unsigned row = start_row; row < end_row; ++row) {
+               ClipWithID clip = *playlist_clips->clip_with_id(row);
+               if (clip.clip.pts_out == -1) {
+                       clip.clip.pts_out = clip.clip.pts_in + int64_t(TIMEBASE) * 86400 * 7;  // One week; effectively infinite, but without overflow issues.
+               }
+               clips.emplace_back(clip);
+       }
+       return clips;
+}
+
 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
 {
        char time_str[256];
index 592309ab6208a72d0e396c5de2e83db749657ca1..1fbfb948de072a866f1c38b9edcab4445d3fa5d9 100644 (file)
@@ -168,6 +168,7 @@ private:
        void playlist_selection_changed();
 
        void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
+       std::vector<ClipWithID> get_playlist(size_t start_row, size_t end_row);
 
        void resizeEvent(QResizeEvent *event) override;
        bool eventFilter(QObject *watched, QEvent *event) override;