diff --git a/playback/audio.cpp b/playback/audio.cpp index feb0d7aee..0b48f9a9b 100644 --- a/playback/audio.cpp +++ b/playback/audio.cpp @@ -86,17 +86,17 @@ void clear_audio_ibuffer() { int get_buffer_offset_from_frame(Sequence* s, long frame) { // currently debugging this function. since it has a high potential of failure and isn't actually fatal, we only assert on debug mode -#ifdef QT_DEBUG +/*#ifdef QT_DEBUG Q_ASSERT(frame >= audio_ibuffer_frame); return qFloor(av_samples_get_buffer_size(NULL, av_get_channel_layout_nb_channels(s->audio_layout), qRound(((frame-audio_ibuffer_frame)/s->frame_rate)*s->audio_frequency), AV_SAMPLE_FMT_S16, 1)/4)*4; -#else +#else*/ if (frame >= audio_ibuffer_frame) { return qFloor(av_samples_get_buffer_size(NULL, av_get_channel_layout_nb_channels(s->audio_layout), qRound(((frame-audio_ibuffer_frame)/s->frame_rate)*s->audio_frequency), AV_SAMPLE_FMT_S16, 1)/4)*4; } else { dout << "[WARNING] Invalid values passed to get_buffer_offset_from_frame"; return 0; } -#endif +//#endif } AudioSenderThread::AudioSenderThread() : close(false) { diff --git a/project/undo.cpp b/project/undo.cpp index bd8a92d50..e82c75051 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1745,8 +1745,25 @@ void RemoveClipsFromClipboard::undo() { } void RemoveClipsFromClipboard::redo() { - qDebug() << "removed" << pos << "from clipboard"; clip = panel_timeline->clip_clipboard.at(pos); panel_timeline->clip_clipboard.removeAt(pos); done = true; } + +RenameClipCommand::RenameClipCommand() : + old_project_changed(mainWindow->isWindowModified()) +{} + +void RenameClipCommand::undo() { + for (int i=0;iname = old_names.at(i); + } +} + +void RenameClipCommand::redo() { + old_names.resize(clips.size()); + for (int i=0;iname; + clips.at(i)->name = new_name; + } +} diff --git a/project/undo.h b/project/undo.h index ae1242aa2..b831edb50 100644 --- a/project/undo.h +++ b/project/undo.h @@ -570,4 +570,16 @@ private: bool done; }; +class RenameClipCommand : public QUndoCommand { +public: + RenameClipCommand(); + QVector clips; + QString new_name; + void undo(); + void redo(); +private: + QVector old_names; + bool old_project_changed; +}; + #endif // UNDO_H diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 60c9addce..dd4885f04 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #define MAX_TEXT_WIDTH 20 @@ -83,7 +84,16 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { redoAction->setEnabled(undo_stack.canRedo()); menu.addSeparator(); - if (sequence->selections.size() == 0) { + // collect all the selected clips + QVector selected_clips; + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && panel_timeline->is_clip_selected(c, true)) { + selected_clips.append(c); + } + } + + if (selected_clips.size() == 0) { // no clips are selected panel_timeline->cursor_frame = panel_timeline->getTimelineFrameFromScreenPoint(pos.x()); @@ -114,14 +124,13 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { } if (can_ripple_delete && !at_end_of_sequence) { - QAction* ripple_delete_action = menu.addAction("&Ripple Delete"); + QAction* ripple_delete_action = menu.addAction("R&ipple Delete"); connect(ripple_delete_action, SIGNAL(triggered(bool)), this, SLOT(right_click_ripple())); } menu.addAction("Sequence settings coming soon..."); } else { // clips are selected - QAction* cutAction = menu.addAction("C&ut"); connect(cutAction, SIGNAL(triggered(bool)), mainWindow, SLOT(cut())); QAction* copyAction = menu.addAction("Cop&y"); @@ -135,15 +144,6 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { autoscaleAction->setCheckable(true); connect(autoscaleAction, SIGNAL(triggered(bool)), this, SLOT(toggle_autoscale())); - // collect all the selected clips - QVector selected_clips; - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && panel_timeline->is_clip_selected(c, true)) { - selected_clips.append(c); - } - } - // set autoscale arbitrarily to the first selected clip autoscaleAction->setChecked(selected_clips.at(0)->autoscale); @@ -160,8 +160,10 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { if (same_media) { QAction* revealInProjectAction = menu.addAction("&Reveal in Project"); connect(revealInProjectAction, SIGNAL(triggered(bool)), this, SLOT(reveal_media())); - } + + QAction* rename = menu.addAction("R&ename"); + connect(rename, SIGNAL(triggered(bool)), this, SLOT(rename_clip())); } menu.exec(mapToGlobal(pos)); @@ -198,6 +200,31 @@ void TimelineWidget::tooltip_timer_timeout() { tooltip_timer.stop(); } +void TimelineWidget::rename_clip() { + QVector selected_clips; + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && panel_timeline->is_clip_selected(c, true)) { + selected_clips.append(c); + } + } + if (selected_clips.size() > 0) { + QString s = QInputDialog::getText(this, + (selected_clips.size() == 1) ? "Rename '" + selected_clips.at(0)->name + "'" : "Rename multiple clips", + "Enter a new name for this clip:", + QLineEdit::Normal, + selected_clips.at(0)->name + ); + if (!s.isEmpty()) { + RenameClipCommand* rcc = new RenameClipCommand(); + rcc->new_name = s; + rcc->clips = selected_clips; + undo_stack.push(rcc); + update_ui(true); + } + } +} + bool same_sign(int a, int b) { return (a < 0) == (b < 0); } diff --git a/ui/timelinewidget.h b/ui/timelinewidget.h index 2597fd962..5486c6790 100644 --- a/ui/timelinewidget.h +++ b/ui/timelinewidget.h @@ -91,6 +91,7 @@ private slots: void show_context_menu(const QPoint& pos); void toggle_autoscale(); void tooltip_timer_timeout(); + void rename_clip(); }; #endif // TIMELINEWIDGET_H