]> git.sesse.net Git - nageru/blob - mainwindow.cpp
Serialize state to disk between runs, using SQLite.
[nageru] / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include "clip_list.h"
4 #include "player.h"
5 #include "post_to_main_thread.h"
6 #include "timebase.h"
7 #include "ui_mainwindow.h"
8
9 #include <string>
10 #include <vector>
11
12 #include <QMouseEvent>
13 #include <QWheelEvent>
14 #include <QShortcut>
15 #include <QTimer>
16
17 #include <sqlite3.h>
18
19 using namespace std;
20
21 MainWindow *global_mainwindow = nullptr;
22 ClipList *cliplist_clips;
23 PlayList *playlist_clips;
24
25 extern int64_t current_pts;
26 extern mutex frame_mu;
27 extern vector<int64_t> frames[MAX_STREAMS];
28
29 MainWindow::MainWindow()
30         : ui(new Ui::MainWindow),
31           db("futatabi.db")
32 {
33         global_mainwindow = this;
34         ui->setupUi(this);
35
36         StateProto state = db.get_state();
37
38         cliplist_clips = new ClipList(state.clip_list());
39         ui->clip_list->setModel(cliplist_clips);
40         connect(cliplist_clips, &ClipList::any_content_changed, this, &MainWindow::content_changed);
41
42         playlist_clips = new PlayList(state.play_list());
43         ui->playlist->setModel(playlist_clips);
44         connect(playlist_clips, &PlayList::any_content_changed, this, &MainWindow::content_changed);
45
46         // For scrubbing in the pts columns.
47         ui->clip_list->viewport()->installEventFilter(this);
48         ui->playlist->viewport()->installEventFilter(this);
49
50         QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
51         connect(cue_in, &QShortcut::activated, ui->cue_in_btn, &QPushButton::click);
52         connect(ui->cue_in_btn, &QPushButton::clicked, this, &MainWindow::cue_in_clicked);
53
54         QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
55         connect(cue_out, &QShortcut::activated, ui->cue_out_btn, &QPushButton::click);
56         connect(ui->cue_out_btn, &QPushButton::clicked, this, &MainWindow::cue_out_clicked);
57
58         QShortcut *queue = new QShortcut(QKeySequence(Qt::Key_Q), this);
59         connect(queue, &QShortcut::activated, ui->queue_btn, &QPushButton::click);
60         connect(ui->queue_btn, &QPushButton::clicked, this, &MainWindow::queue_clicked);
61
62         QShortcut *preview = new QShortcut(QKeySequence(Qt::Key_W), this);
63         connect(preview, &QShortcut::activated, ui->preview_btn, &QPushButton::click);
64         connect(ui->preview_btn, &QPushButton::clicked, this, &MainWindow::preview_clicked);
65
66         QShortcut *play = new QShortcut(QKeySequence(Qt::Key_Space), this);
67         connect(play, &QShortcut::activated, ui->play_btn, &QPushButton::click);
68         connect(ui->play_btn, &QPushButton::clicked, this, &MainWindow::play_clicked);
69
70         QShortcut *preview_1 = new QShortcut(QKeySequence(Qt::Key_1), this);
71         connect(preview_1, &QShortcut::activated, ui->preview_1_btn, &QPushButton::click);
72         connect(ui->input1_display, &JPEGFrameView::clicked, ui->preview_1_btn, &QPushButton::click);
73         connect(ui->preview_1_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(0); });
74         ui->input1_display->set_overlay("1");
75
76         QShortcut *preview_2 = new QShortcut(QKeySequence(Qt::Key_2), this);
77         connect(preview_2, &QShortcut::activated, ui->preview_2_btn, &QPushButton::click);
78         connect(ui->input2_display, &JPEGFrameView::clicked, ui->preview_2_btn, &QPushButton::click);
79         connect(ui->preview_2_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(1); });
80         ui->input2_display->set_overlay("2");
81
82         QShortcut *preview_3 = new QShortcut(QKeySequence(Qt::Key_3), this);
83         connect(preview_3, &QShortcut::activated, ui->preview_3_btn, &QPushButton::click);
84         connect(ui->input3_display, &JPEGFrameView::clicked, ui->preview_3_btn, &QPushButton::click);
85         connect(ui->preview_3_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(2); });
86         ui->input3_display->set_overlay("3");
87
88         QShortcut *preview_4 = new QShortcut(QKeySequence(Qt::Key_4), this);
89         connect(preview_4, &QShortcut::activated, ui->preview_4_btn, &QPushButton::click);
90         connect(ui->input4_display, &JPEGFrameView::clicked, ui->preview_4_btn, &QPushButton::click);
91         connect(ui->preview_4_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(3); });
92         ui->input4_display->set_overlay("4");
93
94         connect(ui->playlist_duplicate_btn, &QPushButton::clicked, this, &MainWindow::playlist_duplicate);
95
96         connect(ui->playlist_remove_btn, &QPushButton::clicked, this, &MainWindow::playlist_remove);
97         QShortcut *delete_key = new QShortcut(QKeySequence(Qt::Key_Delete), ui->playlist);
98         connect(delete_key, &QShortcut::activated, [this] {
99                 if (ui->playlist->hasFocus()) {
100                         playlist_remove();
101                 }
102         });
103
104         // TODO: support drag-and-drop.
105         connect(ui->playlist_move_up_btn, &QPushButton::clicked, [this]{ playlist_move(-1); });
106         connect(ui->playlist_move_down_btn, &QPushButton::clicked, [this]{ playlist_move(1); });
107
108         connect(ui->playlist->selectionModel(), &QItemSelectionModel::selectionChanged,
109                 this, &MainWindow::playlist_selection_changed);
110         playlist_selection_changed();  // First time set-up.
111
112         preview_player = new Player(ui->preview_display, /*also_output_to_stream=*/false);
113         live_player = new Player(ui->live_display, /*also_output_to_stream=*/true);
114         live_player->set_done_callback([this]{
115                 post_to_main_thread([this]{
116                         live_player_clip_done();
117                 });
118         });
119         live_player->set_progress_callback([this](double played_this_clip, double total_length) {
120                 post_to_main_thread([this, played_this_clip, total_length] {
121                         live_player_clip_progress(played_this_clip, total_length);
122                 });
123         });
124
125         defer_timeout = new QTimer(this);
126         defer_timeout->setSingleShot(true);
127         connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
128 }
129
130 void MainWindow::cue_in_clicked()
131 {
132         if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
133                 cliplist_clips->mutable_back()->pts_in = current_pts;
134                 return;
135         }
136         Clip clip;
137         clip.pts_in = current_pts;
138         cliplist_clips->add_clip(clip);
139         playlist_selection_changed();
140 }
141
142 void MainWindow::cue_out_clicked()
143 {
144         if (!cliplist_clips->empty()) {
145                 cliplist_clips->mutable_back()->pts_out = current_pts;
146                 // TODO: select the row in the clip list?
147         }
148 }
149
150 void MainWindow::queue_clicked()
151 {
152         if (cliplist_clips->empty()) {
153                 return;
154         }
155
156         QItemSelectionModel *selected = ui->clip_list->selectionModel();
157         if (!selected->hasSelection()) {
158                 Clip clip = *cliplist_clips->back();
159                 clip.stream_idx = 0;
160                 if (clip.pts_out != -1) {
161                         playlist_clips->add_clip(clip);
162                         playlist_selection_changed();
163                 }
164                 return;
165         }
166
167         QModelIndex index = selected->currentIndex();
168         Clip clip = *cliplist_clips->clip(index.row());
169         if (index.column() >= int(ClipList::Column::CAMERA_1) &&
170             index.column() <= int(ClipList::Column::CAMERA_4)) {
171                 clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
172         } else {
173                 clip.stream_idx = ui->preview_display->get_stream_idx();
174         }
175
176         if (clip.pts_out != -1) {
177                 playlist_clips->add_clip(clip);
178                 playlist_selection_changed();
179         }
180 }
181
182 void MainWindow::preview_clicked()
183 {
184         if (cliplist_clips->empty()) return;
185
186         QItemSelectionModel *selected = ui->clip_list->selectionModel();
187         if (!selected->hasSelection()) {
188                 preview_player->play_clip(*cliplist_clips->back(), 0);
189                 return;
190         }
191
192         QModelIndex index = selected->currentIndex();
193         unsigned stream_idx;
194         if (index.column() >= int(ClipList::Column::CAMERA_1) &&
195             index.column() <= int(ClipList::Column::CAMERA_4)) {
196                 stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
197         } else {
198                 stream_idx = ui->preview_display->get_stream_idx();
199         }
200         preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx);
201 }
202
203 void MainWindow::preview_angle_clicked(unsigned stream_idx)
204 {
205         preview_player->override_angle(stream_idx);
206
207         // Change the selection if we were previewing a clip from the clip list.
208         // (The only other thing we could be showing is a pts scrub, and if so,
209         // that would be selected.)
210         QItemSelectionModel *selected = ui->clip_list->selectionModel();
211         if (selected->hasSelection()) {
212                 QModelIndex cell = selected->selectedIndexes()[0];
213                 int column = int(ClipList::Column::CAMERA_1) + stream_idx;
214                 selected->setCurrentIndex(cell.sibling(cell.row(), column), QItemSelectionModel::ClearAndSelect);
215         }
216 }
217
218 void MainWindow::playlist_duplicate()
219 {
220         QItemSelectionModel *selected = ui->playlist->selectionModel();
221         if (!selected->hasSelection()) {
222                 // Should have been grayed out, but OK.
223                 return;
224         }
225         QModelIndexList rows = selected->selectedRows();
226         int first = rows.front().row(), last = rows.back().row();
227         playlist_clips->duplicate_clips(first, last);
228         playlist_selection_changed();
229 }
230
231 void MainWindow::playlist_remove()
232 {
233         QItemSelectionModel *selected = ui->playlist->selectionModel();
234         if (!selected->hasSelection()) {
235                 // Should have been grayed out, but OK.
236                 return;
237         }
238         QModelIndexList rows = selected->selectedRows();
239         int first = rows.front().row(), last = rows.back().row();
240         playlist_clips->erase_clips(first, last);
241
242         // TODO: select the next one in the list?
243
244         playlist_selection_changed();
245 }
246
247 void MainWindow::playlist_move(int delta)
248 {
249         QItemSelectionModel *selected = ui->playlist->selectionModel();
250         if (!selected->hasSelection()) {
251                 // Should have been grayed out, but OK.
252                 return;
253         }
254
255         QModelIndexList rows = selected->selectedRows();
256         int first = rows.front().row(), last = rows.back().row();
257         if ((delta == -1 && first == 0) ||
258             (delta == 1 && size_t(last) == playlist_clips->size() - 1)) {
259                 // Should have been grayed out, but OK.
260                 return;
261         }
262
263         playlist_clips->move_clips(first, last, delta);
264         playlist_selection_changed();
265 }
266
267 void MainWindow::defer_timer_expired()
268 {
269         state_changed(deferred_state);
270 }
271
272 void MainWindow::content_changed()
273 {
274         if (defer_timeout->isActive() &&
275             (!currently_deferring_model_changes || deferred_change_id != current_change_id)) {
276                 // There's some deferred event waiting, but this event is unrelated.
277                 // So it's time to short-circuit that timer and do the work it wanted to do.
278                 defer_timeout->stop();
279                 state_changed(deferred_state);
280         }
281         StateProto state;
282         *state.mutable_clip_list() = cliplist_clips->serialize();
283         *state.mutable_play_list() = playlist_clips->serialize();
284         if (currently_deferring_model_changes) {
285                 deferred_change_id = current_change_id;
286                 deferred_state = std::move(state);
287                 defer_timeout->start(200);
288                 return;
289         }
290         state_changed(state);
291 }
292
293 void MainWindow::state_changed(const StateProto &state)
294 {
295         db.store_state(state);
296 }
297
298 void MainWindow::play_clicked()
299 {
300         if (playlist_clips->empty()) return;
301
302         QItemSelectionModel *selected = ui->playlist->selectionModel();
303         int row;
304         if (!selected->hasSelection()) {
305                 row = 0;
306         } else {
307                 row = selected->selectedRows(0)[0].row();
308         }
309
310         const Clip &clip = *playlist_clips->clip(row);
311         live_player->play_clip(clip, clip.stream_idx);
312         playlist_clips->set_currently_playing(row, 0.0f);
313         playlist_selection_changed();
314 }
315
316 void MainWindow::live_player_clip_done()
317 {
318         int row = playlist_clips->get_currently_playing();
319         if (row != -1 && row < int(playlist_clips->size()) - 1) {
320                 ++row;
321                 const Clip &clip = *playlist_clips->clip(row);
322                 live_player->play_clip(clip, clip.stream_idx);
323                 playlist_clips->set_currently_playing(row, 0.0f);
324         } else {
325                 playlist_clips->set_currently_playing(-1, 0.0f);
326                 ui->live_label->setText("Current output (paused)");
327         }
328 }
329
330 void MainWindow::live_player_clip_progress(double played_this_clip, double total_length)
331 {
332         playlist_clips->set_currently_playing(playlist_clips->get_currently_playing(), played_this_clip / total_length);
333
334         double remaining = total_length - played_this_clip;
335         for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) {
336                 const Clip clip = *playlist_clips->clip(row);
337                 remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5;   // FIXME: stop hardcoding speed.
338         }
339         int remaining_ms = lrint(remaining * 1e3);
340
341         int ms = remaining_ms % 1000;
342         remaining_ms /= 1000;
343         int s = remaining_ms % 60;
344         remaining_ms /= 60;
345         int m = remaining_ms;
346
347         char buf[256];
348         snprintf(buf, sizeof(buf), "Current output (%d:%02d.%03d left)", m, s, ms);
349         ui->live_label->setText(buf);
350 }
351
352 void MainWindow::resizeEvent(QResizeEvent *event)
353 {
354         QMainWindow::resizeEvent(event);
355
356         // Ask for a relayout, but only after the event loop is done doing relayout
357         // on everything else.
358         QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
359 }
360
361 void MainWindow::relayout()
362 {
363         ui->live_display->setMinimumWidth(ui->live_display->height() * 16 / 9);
364         ui->preview_display->setMinimumWidth(ui->preview_display->height() * 16 / 9);
365 }
366
367 void set_pts_in(int64_t pts, int64_t current_pts, ClipProxy &clip)
368 {
369         pts = std::max<int64_t>(pts, 0);
370         if (clip->pts_out == -1) {
371                 pts = std::min(pts, current_pts);
372         } else {
373                 pts = std::min(pts, clip->pts_out);
374         }
375         clip->pts_in = pts;
376 }
377
378 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
379 {
380         constexpr int dead_zone_pixels = 3;  // To avoid that simple clicks get misinterpreted.
381         constexpr int scrub_sensitivity = 100;  // pts units per pixel.
382         constexpr int wheel_sensitivity = 100;  // pts units per degree.
383         constexpr int camera_degrees_per_pixel = 15;  // One click of most mice.
384
385         unsigned stream_idx = ui->preview_display->get_stream_idx();
386
387         if (event->type() != QEvent::Wheel) {
388                 last_mousewheel_camera_row = -1;
389         }
390
391         if (event->type() == QEvent::MouseButtonPress) {
392                 QMouseEvent *mouse = (QMouseEvent *)event;
393
394                 QTableView *destination;
395                 ScrubType type;
396
397                 if (watched == ui->clip_list->viewport()) {
398                         destination = ui->clip_list;
399                         type = SCRUBBING_CLIP_LIST;
400                 } else if (watched == ui->playlist->viewport()) {
401                         destination = ui->playlist;
402                         type = SCRUBBING_PLAYLIST;
403                 } else {
404                         return false;
405                 }
406                 int column = destination->columnAt(mouse->x());
407                 int row = destination->rowAt(mouse->y());
408                 if (column == -1 || row == -1) return false;
409
410                 if (type == SCRUBBING_CLIP_LIST) {
411                         if (ClipList::Column(column) == ClipList::Column::IN) {
412                                 scrub_pts_origin = cliplist_clips->clip(row)->pts_in;
413                                 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
414                         } else if (ClipList::Column(column) == ClipList::Column::OUT) {
415                                 scrub_pts_origin = cliplist_clips->clip(row)->pts_out;
416                                 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
417                         } else {
418                                 return false;
419                         }
420                 } else {
421                         if (PlayList::Column(column) == PlayList::Column::IN) {
422                                 scrub_pts_origin = playlist_clips->clip(row)->pts_in;
423                                 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
424                         } else if (PlayList::Column(column) == PlayList::Column::OUT) {
425                                 scrub_pts_origin = playlist_clips->clip(row)->pts_out;
426                                 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
427                         } else {
428                                 return false;
429                         }
430                 }
431
432                 scrubbing = true;
433                 scrub_row = row;
434                 scrub_column = column;
435                 scrub_x_origin = mouse->x();
436                 scrub_type = type;
437         } else if (event->type() == QEvent::MouseMove) {
438                 if (scrubbing) {
439                         QMouseEvent *mouse = (QMouseEvent *)event;
440                         int offset = mouse->x() - scrub_x_origin;
441                         int adjusted_offset;
442                         if (offset >= dead_zone_pixels) {
443                                 adjusted_offset = offset - dead_zone_pixels;
444                         } else if (offset < -dead_zone_pixels) {
445                                 adjusted_offset = offset + dead_zone_pixels;
446                         } else {
447                                 adjusted_offset = 0;
448                         }
449
450                         int64_t pts = scrub_pts_origin + adjusted_offset * scrub_sensitivity;
451                         currently_deferring_model_changes = true;
452                         if (scrub_type == SCRUBBING_CLIP_LIST) {
453                                 ClipProxy clip = cliplist_clips->mutable_clip(scrub_row);
454                                 if (scrub_column == int(ClipList::Column::IN)) {
455                                         current_change_id = "cliplist:in:" + to_string(scrub_row);
456                                         set_pts_in(pts, current_pts, clip);
457                                         preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
458                                 } else {
459                                         current_change_id = "cliplist:out" + to_string(scrub_row);
460                                         pts = std::max(pts, clip->pts_in);
461                                         pts = std::min(pts, current_pts);
462                                         clip->pts_out = pts;
463                                         preview_single_frame(pts, stream_idx, LAST_BEFORE);
464                                 }
465                         } else {
466                                 ClipProxy clip = playlist_clips->mutable_clip(scrub_row);
467                                 if (scrub_column == int(PlayList::Column::IN)) {
468                                         current_change_id = "playlist:in:" + to_string(scrub_row);
469                                         set_pts_in(pts, current_pts, clip);
470                                         preview_single_frame(pts, clip->stream_idx, FIRST_AT_OR_AFTER);
471                                 } else {
472                                         current_change_id = "playlist:out:" + to_string(scrub_row);
473                                         pts = std::max(pts, clip->pts_in);
474                                         pts = std::min(pts, current_pts);
475                                         clip->pts_out = pts;
476                                         preview_single_frame(pts, clip->stream_idx, LAST_BEFORE);
477                                 }
478                         }
479                         currently_deferring_model_changes = false;
480
481                         return true;  // Don't use this mouse movement for selecting things.
482                 }
483         } else if (event->type() == QEvent::Wheel) {
484                 QWheelEvent *wheel = (QWheelEvent *)event;
485
486                 QTableView *destination;
487                 int in_column, out_column, camera_column;
488                 if (watched == ui->clip_list->viewport()) {
489                         destination = ui->clip_list;
490                         in_column = int(ClipList::Column::IN);
491                         out_column = int(ClipList::Column::OUT);
492                         camera_column = -1;
493                         last_mousewheel_camera_row = -1;
494                 } else if (watched == ui->playlist->viewport()) {
495                         destination = ui->playlist;
496                         in_column = int(PlayList::Column::IN);
497                         out_column = int(PlayList::Column::OUT);
498                         camera_column = int(PlayList::Column::CAMERA);
499                 } else {
500                         last_mousewheel_camera_row = -1;
501                         return false;
502                 }
503                 int column = destination->columnAt(wheel->x());
504                 int row = destination->rowAt(wheel->y());
505                 if (column == -1 || row == -1) return false;
506
507                 currently_deferring_model_changes = true;
508                 {
509                         current_change_id = (watched == ui->clip_list->viewport()) ? "cliplist:" : "playlist:";
510                         ClipProxy clip = (watched == ui->clip_list->viewport()) ?
511                                 cliplist_clips->mutable_clip(row) : playlist_clips->mutable_clip(row);
512                         if (watched == ui->playlist->viewport()) {
513                                 stream_idx = clip->stream_idx;
514                         }
515
516                         if (column != camera_column) {
517                                 last_mousewheel_camera_row = -1;
518                         }
519                         if (column == in_column) {
520                                 current_change_id += "in:" + to_string(row);
521                                 int64_t pts = clip->pts_in + wheel->angleDelta().y() * wheel_sensitivity;
522                                 set_pts_in(pts, current_pts, clip);
523                                 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
524                         } else if (column == out_column) {
525                                 current_change_id += "out:" + to_string(row);
526                                 int64_t pts = clip->pts_out + wheel->angleDelta().y() * wheel_sensitivity;
527                                 pts = std::max(pts, clip->pts_in);
528                                 pts = std::min(pts, current_pts);
529                                 clip->pts_out = pts;
530                                 preview_single_frame(pts, stream_idx, LAST_BEFORE);
531                         } else if (column == camera_column) {
532                                 current_change_id += "camera:" + to_string(row);
533                                 int angle_degrees = wheel->angleDelta().y();
534                                 if (last_mousewheel_camera_row == row) {
535                                         angle_degrees += leftover_angle_degrees;
536                                 }
537
538                                 int stream_idx = clip->stream_idx + angle_degrees / camera_degrees_per_pixel;
539                                 stream_idx = std::max(stream_idx, 0);
540                                 stream_idx = std::min(stream_idx, NUM_CAMERAS - 1);
541                                 clip->stream_idx = stream_idx;
542
543                                 last_mousewheel_camera_row = row;
544                                 leftover_angle_degrees = angle_degrees % camera_degrees_per_pixel;
545
546                                 // Don't update the live view, that's rarely what the operator wants.
547                         }
548                 }
549                 currently_deferring_model_changes = false;
550         } else if (event->type() == QEvent::MouseButtonRelease) {
551                 scrubbing = false;
552         }
553         return false;
554 }
555
556 void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWindow::Rounding rounding)
557 {
558         if (rounding == LAST_BEFORE) {
559                 lock_guard<mutex> lock(frame_mu);
560                 if (frames[stream_idx].empty()) return;
561                 auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts);
562                 if (it != frames[stream_idx].end()) {
563                         pts = *it;
564                 }
565         } else {
566                 assert(rounding == FIRST_AT_OR_AFTER);
567                 lock_guard<mutex> lock(frame_mu);
568                 if (frames[stream_idx].empty()) return;
569                 auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1);
570                 if (it != frames[stream_idx].end()) {
571                         pts = *it;
572                 }
573         }
574
575         Clip fake_clip;
576         fake_clip.pts_in = pts;
577         fake_clip.pts_out = pts + 1;
578         preview_player->play_clip(fake_clip, stream_idx);
579 }
580
581 void MainWindow::playlist_selection_changed()
582 {
583         QItemSelectionModel *selected = ui->playlist->selectionModel();
584         bool any_selected = selected->hasSelection();
585         ui->playlist_duplicate_btn->setEnabled(any_selected);
586         ui->playlist_remove_btn->setEnabled(any_selected);
587         ui->playlist_move_up_btn->setEnabled(
588                 any_selected && selected->selectedRows().front().row() > 0);
589         ui->playlist_move_down_btn->setEnabled(
590                 any_selected && selected->selectedRows().back().row() < int(playlist_clips->size()) - 1);
591         ui->play_btn->setEnabled(!playlist_clips->empty());
592 }