diff --git a/panels/timeline.cpp b/panels/timeline.cpp index c1f0d9327..8483aaaeb 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -114,9 +114,9 @@ Timeline::Timeline(QWidget *parent) : toolArrowButton->click(); connect(horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(setScroll(int))); - //connect(videoScrollbar, SIGNAL(valueChanged(int)), video_area, SLOT(setScroll(int))); - //connect(audioScrollbar, SIGNAL(valueChanged(int)), audio_area, SLOT(setScroll(int))); connect(horizontalScrollBar, SIGNAL(resize_move(double)), this, SLOT(resize_move(double))); + connect(this, SIGNAL(SequenceChanged(SequencePtr)), panel_sequence_viewer, SLOT(set_sequence(SequencePtr))); + connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(visibility_changed_slot(bool))); update_sequence(); @@ -1051,6 +1051,13 @@ void Timeline::set_tool() { } } +void Timeline::visibility_changed_slot(bool visibility) +{ + if (visibility) { + emit SequenceChanged(sequence_); + } +} + void olive::timeline::MultiplyTrackSizesByDPI() { kTrackDefaultHeight *= QApplication::desktop()->devicePixelRatio(); diff --git a/panels/timeline.h b/panels/timeline.h index 72f68feb7..b3dc3517b 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -185,6 +185,7 @@ private slots: void transition_menu_select(QAction*); void resize_move(double d); void set_tool(); + void visibility_changed_slot(bool visibility); private: SequencePtr sequence_; diff --git a/panels/viewer.h b/panels/viewer.h index 80485d26b..9ce04ee39 100644 --- a/panels/viewer.h +++ b/panels/viewer.h @@ -53,7 +53,6 @@ public: Mode mode(); virtual bool focused() override; - bool is_main_sequence(); void set_media(Media *m); void compose(); void set_playpause_icon(bool play); @@ -110,6 +109,8 @@ protected: virtual void resizeEvent(QResizeEvent *event) override; public slots: + void set_sequence(SequencePtr s); + void play_wake(); void go_to_start(); void go_to_in(); @@ -138,7 +139,6 @@ private slots: private: void update_window_title(); void clean_created_seq(); - void set_sequence(SequencePtr s); bool created_sequence; long cached_end_frame; QString panel_name; diff --git a/rendering/audio.cpp b/rendering/audio.cpp index e5a7c0747..780d32107 100644 --- a/rendering/audio.cpp +++ b/rendering/audio.cpp @@ -209,6 +209,8 @@ void AudioSenderThread::run() { int AudioSenderThread::send_audio_to_output(qint64 offset, int max) { // send audio to device + audio_write_lock.lock(); + qint64 actual_write = audio_io_device->write(reinterpret_cast(audio_ibuffer)+offset, max); qint64 audio_ibuffer_limit = audio_ibuffer_read + actual_write; @@ -239,6 +241,8 @@ int AudioSenderThread::send_audio_to_output(qint64 offset, int max) { audio_ibuffer_read = audio_ibuffer_limit; + audio_write_lock.unlock(); + return actual_write; } diff --git a/rendering/exportthread.cpp b/rendering/exportthread.cpp index 9bb58ed51..fc4580ebb 100644 --- a/rendering/exportthread.cpp +++ b/rendering/exportthread.cpp @@ -160,7 +160,8 @@ bool ExportThread::SetupVideo() { break; } break; - + default: + break; } // Set export to be multithreaded diff --git a/timeline/timelinefunctions.cpp b/timeline/timelinefunctions.cpp index 3e776b78b..e37a90f89 100644 --- a/timeline/timelinefunctions.cpp +++ b/timeline/timelinefunctions.cpp @@ -119,7 +119,7 @@ QVector olive::timeline::CreateGhostsFromMedia(Sequence *seq, || import_data.type() == olive::timeline::kImportBoth) { for (int j=0;jaudio_tracks.size();j++) { if (m->audio_tracks.at(j).enabled) { - g.track = seq->GetTrackList(Track::kTypeAudio)->First() + j; + g.track = seq->GetTrackList(Track::kTypeAudio)->TrackAt(j); g.media_stream = m->audio_tracks.at(j).file_index; ghosts.append(g); } @@ -130,7 +130,7 @@ QVector olive::timeline::CreateGhostsFromMedia(Sequence *seq, || import_data.type() == olive::timeline::kImportBoth) { for (int j=0;jvideo_tracks.size();j++) { if (m->video_tracks.at(j).enabled) { - g.track = seq->GetTrackList(Track::kTypeVideo)->First() + j; + g.track = seq->GetTrackList(Track::kTypeVideo)->TrackAt(j); g.media_stream = m->video_tracks.at(j).file_index; ghosts.append(g); } diff --git a/timeline/track.cpp b/timeline/track.cpp index 3e35a1e54..079f3f236 100644 --- a/timeline/track.cpp +++ b/timeline/track.cpp @@ -73,6 +73,31 @@ void Track::set_height(int h) height_ = qMax(h, olive::timeline::kTrackMinHeight); } +QString Track::name() +{ + if (name_.isEmpty()) { + int display_index = Index() + 1; + + switch (type_) { + case kTypeVideo: + return tr("Video %1").arg(display_index); + case kTypeAudio: + return tr("Audio %1").arg(display_index); + case kTypeSubtitle: + return tr("Subtitle %1").arg(display_index); + default: + return tr("Unknown %1").arg(display_index); + } + } + + return name_; +} + +void Track::SetName(const QString &s) +{ + name_ = s; +} + void Track::AddClip(ClipPtr clip) { if (clips_.contains(clip)) { diff --git a/timeline/track.h b/timeline/track.h index b21b67c7d..3614064a0 100644 --- a/timeline/track.h +++ b/timeline/track.h @@ -53,6 +53,9 @@ public: int height(); void set_height(int h); + QString name(); + void SetName(const QString& s); + void AddClip(ClipPtr clip); int ClipCount(); ClipPtr GetClip(int i); @@ -105,6 +108,8 @@ private: bool muted_; bool soloed_; bool locked_; + + QString name_; }; #endif // TRACK_H diff --git a/ui/clickablelabel.cpp b/ui/clickablelabel.cpp index 1b8352fa9..dcd2c1c72 100644 --- a/ui/clickablelabel.cpp +++ b/ui/clickablelabel.cpp @@ -31,3 +31,8 @@ ClickableLabel::ClickableLabel(const QString &text, QWidget *parent, Qt::WindowF void ClickableLabel::mousePressEvent(QMouseEvent *) { emit clicked(); } + +void ClickableLabel::mouseDoubleClickEvent(QMouseEvent *ev) +{ + emit double_clicked(); +} diff --git a/ui/clickablelabel.h b/ui/clickablelabel.h index aba75c6ec..2cf9d6848 100644 --- a/ui/clickablelabel.h +++ b/ui/clickablelabel.h @@ -31,11 +31,13 @@ class ClickableLabel : public QLabel { Q_OBJECT public: - ClickableLabel(QWidget * parent = 0, Qt::WindowFlags f = 0); - ClickableLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0); - void mousePressEvent(QMouseEvent *ev); + ClickableLabel(QWidget * parent = nullptr, Qt::WindowFlags f = nullptr); + ClickableLabel(const QString & text, QWidget * parent = nullptr, Qt::WindowFlags f = nullptr); + virtual void mousePressEvent(QMouseEvent *ev) override; + virtual void mouseDoubleClickEvent(QMouseEvent *ev) override; signals: void clicked(); + void double_clicked(); }; #endif // CLICKABLELABEL_H diff --git a/ui/timelinearea.cpp b/ui/timelinearea.cpp index b3dee106d..739180d20 100644 --- a/ui/timelinearea.cpp +++ b/ui/timelinearea.cpp @@ -49,6 +49,7 @@ void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list) labels_.resize(track_list_->TrackCount()); for (int i=0;i(); + labels_[i]->SetTrack(track_list_->TrackAt(i)); label_container_layout_->addWidget(labels_[i].get()); } diff --git a/ui/timelinelabel.cpp b/ui/timelinelabel.cpp index 9148ca41e..5216f442a 100644 --- a/ui/timelinelabel.cpp +++ b/ui/timelinelabel.cpp @@ -1,17 +1,19 @@ #include "timelinelabel.h" #include -#include #include +#include TimelineLabel::TimelineLabel() : track_(nullptr) { QHBoxLayout* layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(layout->spacing()/2); - QLabel* label = new QLabel("Track!"); - layout->addWidget(label); - + label_ = new ClickableLabel(); + layout->addWidget(label_); + connect(label_, SIGNAL(double_clicked()), this, SLOT(RenameTrack())); mute_button_ = new QPushButton("M"); QSize fixed_size(mute_button_->sizeHint().height(), mute_button_->sizeHint().height()); @@ -44,13 +46,36 @@ void TimelineLabel::SetTrack(Track *track) track_ = track; - if (track != nullptr) { - mute_button_->setChecked(track->IsMuted()); - solo_button_->setChecked(track->IsSoloed()); - lock_button_->setChecked(track->IsLocked()); + if (track_ != nullptr) { + UpdateState(); connect(mute_button_, SIGNAL(toggled(bool)), track_, SLOT(SetMuted(bool))); connect(solo_button_, SIGNAL(toggled(bool)), track_, SLOT(SetSoloed(bool))); connect(lock_button_, SIGNAL(toggled(bool)), track_, SLOT(SetLocked(bool))); } } + +void TimelineLabel::UpdateState() +{ + label_->setText(track_->name()); + + mute_button_->setChecked(track_->IsMuted()); + solo_button_->setChecked(track_->IsSoloed()); + lock_button_->setChecked(track_->IsLocked()); +} + +void TimelineLabel::RenameTrack() +{ + bool ok; + QString new_name = QInputDialog::getText(this, + tr("Rename Track"), + tr("Enter the new name for this track"), + QLineEdit::Normal, + track_->name(), + &ok); + if (ok) { + track_->SetName(new_name); + + UpdateState(); + } +} diff --git a/ui/timelinelabel.h b/ui/timelinelabel.h index 6ca1d983f..b4fcdb1da 100644 --- a/ui/timelinelabel.h +++ b/ui/timelinelabel.h @@ -4,6 +4,7 @@ #include #include +#include "ui/clickablelabel.h" #include "timeline/track.h" class TimelineLabel : public QWidget @@ -13,12 +14,17 @@ public: TimelineLabel(); void SetTrack(Track* track); + void UpdateState(); private: QPushButton* mute_button_; QPushButton* solo_button_; QPushButton* lock_button_; + ClickableLabel* label_; + Track* track_; +private slots: + void RenameTrack(); }; using TimelineLabelPtr = std::shared_ptr; diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index 38403af41..c147c30c9 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -534,6 +534,8 @@ void TimelineView::dropEvent(QDropEvent* event) { s->AddClipsFromGhosts(ca, ParentTimeline()->ghosts); + ParentTimeline()->ghosts.clear(); + olive::undo_stack.push(ca); setFocus(); @@ -1905,20 +1907,15 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } if (ParentTimeline()->importing) { - /* - if ((ParentTimeline()->video_ghosts && mouse_track->type() == Track::kTypeVideo) - || (ParentTimeline()->audio_ghosts && mouse_track->type() == Track::kTypeAudio)) { - int abs_track_diff = abs(track_diff); - if (g.old_track < 0) { // clip is video - g.track -= abs_track_diff; - } else { // clip is audio - g.track += abs_track_diff; - } + + if (mouse_track != nullptr) { + g.track = g.track->track_list()->TrackAt(mouse_track->Index()); } - */ - g.track = track_list_->First(); + } else if (g.old_track->type() == ParentTimeline()->drag_track_start->type()) { + g.track += track_diff; + } } else if (effective_tool == olive::timeline::TIMELINE_TOOL_TRANSITION) { if (ParentTimeline()->transition_tool_open_clip != nullptr @@ -2891,12 +2888,8 @@ void TimelineView::paintEvent(QPaintEvent*) { Track* track = track_list_->TrackAt(i); - qDebug() << "track clip cound was" << track->ClipCount(); - for (int j=0;jClipCount();j++) { - qDebug() << "going to draw a clip!!!"; - Clip* clip = track->GetClip(j).get(); QRect clip_rect(ParentTimeline()->getTimelineScreenPointFromFrame(clip->timeline_in()), @@ -3291,11 +3284,13 @@ void TimelineView::paintEvent(QPaintEvent*) { } // draw border + /* p.setPen(QColor(0, 0, 0, 64)); int edge_y = 0; p.drawLine(0, edge_y, rect().width(), edge_y); edge_y = rect().height()-1; p.drawLine(0, edge_y, rect().width(), edge_y); + */ // draw snap point if (olive::timeline::snapped) { @@ -3318,8 +3313,11 @@ Track *TimelineView::getTrackFromScreenPoint(int y) { y += scroll; int heights = 0; + for (int i=0;iTrackCount();i++) { - int new_heights = heights + track_list_->TrackAt(i)->height() + 1; + int new_heights = heights + 1; + + new_heights += track_list_->TrackAt(i)->height(); if (y >= heights && y < new_heights) { return track_list_->TrackAt(i); @@ -3333,6 +3331,7 @@ Track *TimelineView::getTrackFromScreenPoint(int y) { int TimelineView::getScreenPointFromTrack(Track *track) { int point = 0; + for (int i=0;iTrackCount();i++) { if (track == track_list_->TrackAt(i)) { return point;