diff --git a/effects/internal/crossdissolvetransition.cpp b/effects/internal/crossdissolvetransition.cpp index 2e0a01600..a9d3fae35 100644 --- a/effects/internal/crossdissolvetransition.cpp +++ b/effects/internal/crossdissolvetransition.cpp @@ -29,8 +29,8 @@ CrossDissolveTransition::CrossDissolveTransition(ClipPtr c, ClipPtr s, const Eff } void CrossDissolveTransition::process_coords(double progress, GLTextureCoords& coords, int data) { - if (!(data == TA_CLOSING_TRANSITION && secondary_clip != nullptr)) { - if (data == TA_CLOSING_TRANSITION) progress = 1.0 - progress; + if (!(data == kTransitionClosing && secondary_clip != nullptr)) { + if (data == kTransitionClosing) progress = 1.0 - progress; coords.opacity *= progress; } } diff --git a/effects/internal/exponentialfadetransition.cpp b/effects/internal/exponentialfadetransition.cpp index be558d7cd..e82c0275d 100644 --- a/effects/internal/exponentialfadetransition.cpp +++ b/effects/internal/exponentialfadetransition.cpp @@ -41,10 +41,10 @@ void ExponentialFadeTransition::process_audio(double timecode_start, double time break; }*/ switch (type) { - case TA_OPENING_TRANSITION: + case kTransitionOpening: samp *= qPow(timecode_start + (interval * i), 2); break; - case TA_CLOSING_TRANSITION: + case kTransitionClosing: samp *= qPow(1 - (timecode_start + (interval * i)), 2); break; } diff --git a/effects/internal/linearfadetransition.cpp b/effects/internal/linearfadetransition.cpp index 5cfb5edb7..c8e65c95f 100644 --- a/effects/internal/linearfadetransition.cpp +++ b/effects/internal/linearfadetransition.cpp @@ -29,10 +29,10 @@ void LinearFadeTransition::process_audio(double timecode_start, double timecode_ qint16 samp = (qint16) (((samples[i+1] & 0xFF) << 8) | (samples[i] & 0xFF)); switch (type) { - case TA_OPENING_TRANSITION: + case kTransitionOpening: samp *= timecode_start + (interval * i); break; - case TA_CLOSING_TRANSITION: + case kTransitionClosing: samp *= 1 - (timecode_start + (interval * i)); break; } diff --git a/effects/internal/logarithmicfadetransition.cpp b/effects/internal/logarithmicfadetransition.cpp index 4da914e9f..d4af9d860 100644 --- a/effects/internal/logarithmicfadetransition.cpp +++ b/effects/internal/logarithmicfadetransition.cpp @@ -31,10 +31,10 @@ void LogarithmicFadeTransition::process_audio(double timecode_start, double time qint16 samp = (qint16) (((samples[i+1] & 0xFF) << 8) | (samples[i] & 0xFF)); switch (type) { - case TA_OPENING_TRANSITION: + case kTransitionOpening: samp *= qSqrt(timecode_start + (interval * i)); break; - case TA_CLOSING_TRANSITION: + case kTransitionClosing: samp *= qSqrt(1 - (timecode_start + (interval * i))); break; } diff --git a/io/loadthread.cpp b/io/loadthread.cpp index bb951a159..e95034694 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -80,11 +80,11 @@ void LoadThread::load_effect(QXmlStreamReader& stream, ClipPtr c) { int type; if (tag == "opening") { - type = TA_OPENING_TRANSITION; + type = kTransitionOpening; } else if (tag == "closing") { - type = TA_CLOSING_TRANSITION; + type = kTransitionClosing; } else { - type = TA_NO_TRANSITION; + type = kTransitionNone; } emit start_create_effect_ui(&stream, c, type, &effect_name, meta, effect_length, effect_enabled); @@ -391,11 +391,11 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { } else if (attr.name() == "track") { c->track = attr.value().toInt(); } else if (attr.name() == "r") { - c->color_r = attr.value().toInt(); + c->color_r = quint8(attr.value().toInt()); } else if (attr.name() == "g") { - c->color_g = attr.value().toInt(); + c->color_g = quint8(attr.value().toInt()); } else if (attr.name() == "b") { - c->color_b = attr.value().toInt(); + c->color_b = quint8(attr.value().toInt()); } else if (attr.name() == "autoscale") { c->autoscale = (attr.value() == "1"); } else if (attr.name() == "media") { @@ -409,10 +409,12 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { c->maintain_audio_pitch = (attr.value() == "1"); } else if (attr.name() == "reverse") { c->reverse = (attr.value() == "1"); + /* } else if (attr.name() == "opening") { c->opening_transition = attr.value().toInt(); } else if (attr.name() == "closing") { c->closing_transition = attr.value().toInt(); + */ } else if (attr.name() == "sequence") { media_type = MEDIA_TYPE_SEQUENCE; @@ -514,6 +516,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { } } + /* // re-link clips to transitions if (correct_clip->opening_transition > -1) { for (int j=0;jcreate_sequence_internal(nullptr, s, false, parent); @@ -792,7 +796,7 @@ void LoadThread::create_effect_ui( mutex.lock(); if (cancelled) return; - if (type == TA_NO_TRANSITION) { + if (type == kTransitionNone) { if (meta == nullptr) { // create void effect EffectPtr ve(new VoidEffect(c, *effect_name)); @@ -807,17 +811,19 @@ void LoadThread::create_effect_ui( c->effects.append(e); } } else { + /* int transition_index = create_transition(c, nullptr, meta); TransitionPtr t = c->sequence->transitions.at(transition_index); if (effect_length > -1) t->set_length(effect_length); t->set_enabled(effect_enabled); t->load(*stream); - if (type == TA_OPENING_TRANSITION) { + if (type == kTransitionOpening) { c->opening_transition = transition_index; } else { c->closing_transition = transition_index; } + */ } mutex.unlock(); @@ -829,10 +835,12 @@ void LoadThread::create_dual_transition(const TransitionData* td, ClipPtr primar // lock mutex - ensures the load thread is suspended while this happens mutex.lock(); + /* int transition_index = create_transition(primary, secondary, meta); primary->sequence->transitions.at(transition_index)->set_length(td->length); if (td->otc != nullptr) td->otc->opening_transition = transition_index; if (td->ctc != nullptr) td->ctc->closing_transition = transition_index; + */ mutex.unlock(); diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index dce3522cf..e04e5e340 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -40,555 +40,543 @@ QSemaphore sem(5); // only 5 preview generators can run at one time PreviewGenerator::PreviewGenerator(Media* i, FootagePtr m, bool r) : - QThread(nullptr), - fmt_ctx(nullptr), - media(i), - footage(m), - retrieve_duration(false), - contains_still_image(false), - replace(r), - cancelled(false) + QThread(nullptr), + fmt_ctx(nullptr), + media(i), + footage(m), + retrieve_duration(false), + contains_still_image(false), + replace(r), + cancelled(false) { - data_dir = QDir(get_data_dir().filePath("previews")); - if (!data_dir.exists()) { - data_dir.mkpath("."); - } + data_dir = QDir(get_data_dir().filePath("previews")); + if (!data_dir.exists()) { + data_dir.mkpath("."); + } - connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); + connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); } void PreviewGenerator::parse_media() { - // detect video/audio streams in file - for (int i=0;inb_streams);i++) { - // Find the decoder for the video stream - if (avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id) == nullptr) { - qCritical() << "Unsupported codec in stream" << i << "of file" << footage->name; - } else { - FootageStream ms; - ms.preview_done = false; - ms.file_index = i; - ms.enabled = true; - ms.infinite_length = false; + // detect video/audio streams in file + for (int i=0;inb_streams);i++) { + // Find the decoder for the video stream + if (avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id) == nullptr) { + qCritical() << "Unsupported codec in stream" << i << "of file" << footage->name; + } else { + FootageStream ms; + ms.preview_done = false; + ms.file_index = i; + ms.enabled = true; + ms.infinite_length = false; - bool append = false; + bool append = false; - if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO - && fmt_ctx->streams[i]->codecpar->width > 0 - && fmt_ctx->streams[i]->codecpar->height > 0) { + if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO + && fmt_ctx->streams[i]->codecpar->width > 0 + && fmt_ctx->streams[i]->codecpar->height > 0) { - // heuristic to determine if video is a still image (if it is, we treat it differently in the playback/render process) - if (fmt_ctx->streams[i]->avg_frame_rate.den == 0 - && fmt_ctx->streams[i]->codecpar->codec_id != AV_CODEC_ID_DNXHD) { // silly hack but this is the only scenario i've seen this - if (footage->url.contains('%')) { - // must be an image sequence - ms.video_frame_rate = 25; - } else { - ms.infinite_length = true; - contains_still_image = true; - ms.video_frame_rate = 0; - } + // heuristic to determine if video is a still image (if it is, we treat it differently in the playback/render process) + if (fmt_ctx->streams[i]->avg_frame_rate.den == 0 + && fmt_ctx->streams[i]->codecpar->codec_id != AV_CODEC_ID_DNXHD) { // silly hack but this is the only scenario i've seen this + if (footage->url.contains('%')) { + // must be an image sequence + ms.video_frame_rate = 25; + } else { + ms.infinite_length = true; + contains_still_image = true; + ms.video_frame_rate = 0; + } - } else { - // using ffmpeg's built-in heuristic - ms.video_frame_rate = av_q2d(av_guess_frame_rate(fmt_ctx, fmt_ctx->streams[i], nullptr)); - } + } else { + // using ffmpeg's built-in heuristic + ms.video_frame_rate = av_q2d(av_guess_frame_rate(fmt_ctx, fmt_ctx->streams[i], nullptr)); + } - ms.video_width = fmt_ctx->streams[i]->codecpar->width; - ms.video_height = fmt_ctx->streams[i]->codecpar->height; + ms.video_width = fmt_ctx->streams[i]->codecpar->width; + ms.video_height = fmt_ctx->streams[i]->codecpar->height; - // default value, we get the true value later in generate_waveform() - ms.video_auto_interlacing = VIDEO_PROGRESSIVE; - ms.video_interlacing = VIDEO_PROGRESSIVE; + // default value, we get the true value later in generate_waveform() + ms.video_auto_interlacing = VIDEO_PROGRESSIVE; + ms.video_interlacing = VIDEO_PROGRESSIVE; - append = true; - } else if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - ms.audio_channels = fmt_ctx->streams[i]->codecpar->channels; - ms.audio_layout = int(fmt_ctx->streams[i]->codecpar->channel_layout); - ms.audio_frequency = fmt_ctx->streams[i]->codecpar->sample_rate; + append = true; + } else if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + ms.audio_channels = fmt_ctx->streams[i]->codecpar->channels; + ms.audio_layout = int(fmt_ctx->streams[i]->codecpar->channel_layout); + ms.audio_frequency = fmt_ctx->streams[i]->codecpar->sample_rate; - append = true; - } + append = true; + } - if (append) { - QVector& stream_list = (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? footage->audio_tracks : footage->video_tracks; - for (int j=0;jlength = fmt_ctx->duration; + if (append) { + QVector& stream_list = (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? footage->audio_tracks : footage->video_tracks; + for (int j=0;jlength = fmt_ctx->duration; - if (fmt_ctx->duration == INT64_MIN) { - retrieve_duration = true; - } else { - finalize_media(); - } + if (fmt_ctx->duration == INT64_MIN) { + retrieve_duration = true; + } else { + finalize_media(); + } } bool PreviewGenerator::retrieve_preview(const QString& hash) { - // returns true if generate_waveform must be run, false if we got all previews from cached files - if (retrieve_duration) { - //dout << "[NOTE] " << media->name << "needs to retrieve duration"; - return true; - } + // returns true if generate_waveform must be run, false if we got all previews from cached files + if (retrieve_duration) { + //dout << "[NOTE] " << media->name << "needs to retrieve duration"; + return true; + } - bool found = true; - for (int i=0;ivideo_tracks.size();i++) { - FootageStream& ms = footage->video_tracks[i]; - QString thumb_path = get_thumbnail_path(hash, ms); - QFile f(thumb_path); - if (f.exists() && ms.video_preview.load(thumb_path)) { - //dout << "loaded thumb" << ms->file_index << "from" << thumb_path; - ms.make_square_thumb(); - ms.preview_done = true; - } else { - found = false; - break; - } - } - for (int i=0;iaudio_tracks.size();i++) { - FootageStream& ms = footage->audio_tracks[i]; - QString waveform_path = get_waveform_path(hash, ms); - QFile f(waveform_path); - if (f.exists()) { - //dout << "loaded wave" << ms->file_index << "from" << waveform_path; - f.open(QFile::ReadOnly); - QByteArray data = f.readAll(); - ms.audio_preview.resize(data.size()); - for (int j=0;jvideo_tracks.size();i++) { - FootageStream& ms = footage->video_tracks[i]; - ms.preview_done = false; - } - for (int i=0;iaudio_tracks.size();i++) { - FootageStream& ms = footage->audio_tracks[i]; - ms.audio_preview.clear(); - ms.preview_done = false; - } - } - return !found; + bool found = true; + for (int i=0;ivideo_tracks.size();i++) { + FootageStream& ms = footage->video_tracks[i]; + QString thumb_path = get_thumbnail_path(hash, ms); + QFile f(thumb_path); + if (f.exists() && ms.video_preview.load(thumb_path)) { + //dout << "loaded thumb" << ms->file_index << "from" << thumb_path; + ms.make_square_thumb(); + ms.preview_done = true; + } else { + found = false; + break; + } + } + for (int i=0;iaudio_tracks.size();i++) { + FootageStream& ms = footage->audio_tracks[i]; + QString waveform_path = get_waveform_path(hash, ms); + QFile f(waveform_path); + if (f.exists()) { + //dout << "loaded wave" << ms->file_index << "from" << waveform_path; + f.open(QFile::ReadOnly); + QByteArray data = f.readAll(); + ms.audio_preview.resize(data.size()); + for (int j=0;jvideo_tracks.size();i++) { + FootageStream& ms = footage->video_tracks[i]; + ms.preview_done = false; + } + for (int i=0;iaudio_tracks.size();i++) { + FootageStream& ms = footage->audio_tracks[i]; + ms.audio_preview.clear(); + ms.preview_done = false; + } + } + return !found; } void PreviewGenerator::finalize_media() { - footage->ready_lock.unlock(); - footage->ready = true; + footage->ready_lock.unlock(); + footage->ready = true; - if (!cancelled) { - if (footage->video_tracks.size() == 0) { - olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_AUDIO); - } else if (contains_still_image) { - olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_IMAGE); - } else { - olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_VIDEO); - } - - /*if (!contains_still_image || media->audio_tracks.size() > 0) { - double frame_rate = 30; - if (!contains_still_image && media->video_tracks.size() > 0) frame_rate = media->video_tracks.at(0)->video_frame_rate; - item->setText(1, frame_to_timecode(media->get_length_in_frames(frame_rate), config.timecode_view, frame_rate)); - - if (media->video_tracks.size() > 0) { - item->setText(2, QString::number(frame_rate) + " FPS"); - } else { - item->setText(2, QString::number(media->audio_tracks.at(0)->audio_frequency) + " Hz"); - } - }*/ - } + if (!cancelled) { + if (footage->video_tracks.size() == 0) { + olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_AUDIO); + } else if (contains_still_image) { + olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_IMAGE); + } else { + olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_VIDEO); + } + } } void thumb_data_cleanup(void *info) { - delete [] static_cast(info); + delete [] static_cast(info); } void PreviewGenerator::generate_waveform() { - SwsContext* sws_ctx; - SwrContext* swr_ctx; - AVFrame* temp_frame = av_frame_alloc(); + SwsContext* sws_ctx; + SwrContext* swr_ctx; + AVFrame* temp_frame = av_frame_alloc(); - // stores codec contexts for format's streams - AVCodecContext** codec_ctx = new AVCodecContext* [fmt_ctx->nb_streams]; + // stores codec contexts for format's streams + AVCodecContext** codec_ctx = new AVCodecContext* [fmt_ctx->nb_streams]; - // stores media lengths while scanning in case the format has no duration metadata - int64_t* media_lengths = new int64_t[fmt_ctx->nb_streams]{0}; + // stores media lengths while scanning in case the format has no duration metadata + int64_t* media_lengths = new int64_t[fmt_ctx->nb_streams]{0}; - // stores samples while scanning before they get sent to preview file - qint16*** waveform_cache_data = new qint16** [fmt_ctx->nb_streams]; - int waveform_cache_count = 0; + // stores samples while scanning before they get sent to preview file + qint16*** waveform_cache_data = new qint16** [fmt_ctx->nb_streams]; + int waveform_cache_count = 0; - // defaults to false, sets to true if we find a valid stream to make a preview of - bool create_previews = false; + // defaults to false, sets to true if we find a valid stream to make a preview of + bool create_previews = false; - for (unsigned int i=0;inb_streams;i++) { + for (unsigned int i=0;inb_streams;i++) { - // default to nullptr values for easier memory management later - codec_ctx[i] = nullptr; - waveform_cache_data[i] = nullptr; + // default to nullptr values for easier memory management later + codec_ctx[i] = nullptr; + waveform_cache_data[i] = nullptr; - // we only generate previews for video and audio - // and only if the thumbnail and waveform sizes are > 0 - if ((fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && olive::CurrentConfig.thumbnail_resolution > 0) - || (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && olive::CurrentConfig.waveform_resolution > 0)) { - AVCodec* codec = avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id); - if (codec != nullptr) { + // we only generate previews for video and audio + // and only if the thumbnail and waveform sizes are > 0 + if ((fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && olive::CurrentConfig.thumbnail_resolution > 0) + || (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && olive::CurrentConfig.waveform_resolution > 0)) { + AVCodec* codec = avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id); + if (codec != nullptr) { - // alloc the context and load the params into it - codec_ctx[i] = avcodec_alloc_context3(codec); - avcodec_parameters_to_context(codec_ctx[i], fmt_ctx->streams[i]->codecpar); + // alloc the context and load the params into it + codec_ctx[i] = avcodec_alloc_context3(codec); + avcodec_parameters_to_context(codec_ctx[i], fmt_ctx->streams[i]->codecpar); - // open the decoder - avcodec_open2(codec_ctx[i], codec, nullptr); + // open the decoder + avcodec_open2(codec_ctx[i], codec, nullptr); - // audio specific functions - if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + // audio specific functions + if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - // allocate sample cache for this stream - waveform_cache_data[i] = new qint16* [fmt_ctx->streams[i]->codecpar->channels]; + // allocate sample cache for this stream + waveform_cache_data[i] = new qint16* [fmt_ctx->streams[i]->codecpar->channels]; - // each channel gets a min and a max value so we allocate two ints for each one - for (int j=0;jstreams[i]->codecpar->channels;j++) { - waveform_cache_data[i][j] = new qint16[2]; - } + // each channel gets a min and a max value so we allocate two ints for each one + for (int j=0;jstreams[i]->codecpar->channels;j++) { + waveform_cache_data[i][j] = new qint16[2]; + } - // if codec context has no defined channel layout, guess it from the channel count - if (codec_ctx[i]->channel_layout == 0) { - codec_ctx[i]->channel_layout = av_get_default_channel_layout(fmt_ctx->streams[i]->codecpar->channels); - } + // if codec context has no defined channel layout, guess it from the channel count + if (codec_ctx[i]->channel_layout == 0) { + codec_ctx[i]->channel_layout = av_get_default_channel_layout(fmt_ctx->streams[i]->codecpar->channels); + } - } + } - // enable next step of process - create_previews = true; - } - } + // enable next step of process + create_previews = true; + } + } + } + + if (create_previews) { + // TODO may be unnecessary - doesn't av_read_frame allocate a packet itself? + AVPacket* packet = av_packet_alloc(); + + bool done = true; + + bool end_of_file = false; + + // get the ball rolling + do { + av_read_frame(fmt_ctx, packet); + } while (codec_ctx[packet->stream_index] == nullptr); + avcodec_send_packet(codec_ctx[packet->stream_index], packet); + + while (!end_of_file) { + while (codec_ctx[packet->stream_index] == nullptr || avcodec_receive_frame(codec_ctx[packet->stream_index], temp_frame) == AVERROR(EAGAIN)) { + av_packet_unref(packet); + int read_ret = av_read_frame(fmt_ctx, packet); + + //dout << "read frame for" << footage->name << footage->url << read_ret << "retrieve_duration:" << retrieve_duration << "eof:" << end_of_file << "packet pts:" << packet->pts; + + if (read_ret < 0) { + end_of_file = true; + if (read_ret != AVERROR_EOF) qCritical() << "Failed to read packet for preview generation" << read_ret; + break; + } + if (codec_ctx[packet->stream_index] != nullptr) { + int send_ret = avcodec_send_packet(codec_ctx[packet->stream_index], packet); + if (send_ret < 0 && send_ret != AVERROR(EAGAIN)) { + qCritical() << "Failed to send packet for preview generation - aborting" << send_ret; + end_of_file = true; + break; + } + } + } + if (!end_of_file) { + FootageStream* s = footage->get_stream_from_file_index(fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO, packet->stream_index); + if (s != nullptr) { + if (fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!s->preview_done) { + int dstH = olive::CurrentConfig.thumbnail_resolution; + int dstW = qRound(dstH * (float(temp_frame->width)/float(temp_frame->height))); + uint8_t* data = new uint8_t[size_t(dstW*dstH*4)]; + + sws_ctx = sws_getContext( + temp_frame->width, + temp_frame->height, + static_cast(temp_frame->format), + dstW, + dstH, + static_cast(AV_PIX_FMT_RGBA), + SWS_FAST_BILINEAR, + nullptr, + nullptr, + nullptr + ); + + int linesize[AV_NUM_DATA_POINTERS]; + linesize[0] = dstW*4; + sws_scale(sws_ctx, temp_frame->data, temp_frame->linesize, 0, temp_frame->height, &data, linesize); + + s->video_preview = QImage(data, dstW, dstH, linesize[0], QImage::Format_RGBA8888, thumb_data_cleanup); + s->make_square_thumb(); + + // is video interlaced? + s->video_auto_interlacing = (temp_frame->interlaced_frame) ? ((temp_frame->top_field_first) ? VIDEO_TOP_FIELD_FIRST : VIDEO_BOTTOM_FIELD_FIRST) : VIDEO_PROGRESSIVE; + s->video_interlacing = s->video_auto_interlacing; + + s->preview_done = true; + + sws_freeContext(sws_ctx); + + if (!retrieve_duration) { + avcodec_close(codec_ctx[packet->stream_index]); + codec_ctx[packet->stream_index] = nullptr; + } + } + media_lengths[packet->stream_index]++; + } else if (fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + AVFrame* swr_frame = av_frame_alloc(); + swr_frame->channel_layout = temp_frame->channel_layout; + swr_frame->sample_rate = temp_frame->sample_rate; + swr_frame->format = AV_SAMPLE_FMT_S16P; + + swr_ctx = swr_alloc_set_opts( + nullptr, + temp_frame->channel_layout, + static_cast(swr_frame->format), + temp_frame->sample_rate, + temp_frame->channel_layout, + static_cast(temp_frame->format), + temp_frame->sample_rate, + 0, + nullptr + ); + + swr_init(swr_ctx); + + swr_convert_frame(swr_ctx, swr_frame, temp_frame); + + // `config.waveform_resolution` determines how many samples per second are stored in waveform. + // `sample_rate` is samples per second, so `interval` is how many samples are averaged in + // each "point" of the waveform + int interval = qFloor((temp_frame->sample_rate/olive::CurrentConfig.waveform_resolution)/4)*4; + + // get the amount of bytes in an audio sample + int sample_size = av_get_bytes_per_sample(static_cast(swr_frame->format)); + + // total amount of data in this frame + int nb_bytes = swr_frame->nb_samples * sample_size; + + // loop through entire frame + for (int i=0;ichannels;j++) { + qint16& min = waveform_cache_data[packet->stream_index][j][0]; + qint16& max = waveform_cache_data[packet->stream_index][j][1]; + + s->audio_preview.append(min >> 8); + s->audio_preview.append(max >> 8); + } + + waveform_cache_count = 0; + } + + // standard processing for each channel of information + for (int j=0;jchannels;j++) { + qint16& min = waveform_cache_data[packet->stream_index][j][0]; + qint16& max = waveform_cache_data[packet->stream_index][j][1]; + + // if we're starting over, reset cache to zero + if (waveform_cache_count == 0) { + min = 0; + max = 0; + } + + // store most minimum and most maximum samples of this interval + qint16 sample = qint16((swr_frame->data[j][i+1] << 8) | swr_frame->data[j][i]); + min = qMin(min, sample); + max = qMax(max, sample); + } + + waveform_cache_count++; + + if (cancelled) { + break; + } + } + + swr_free(&swr_ctx); + av_frame_free(&swr_frame); + + if (cancelled) { + end_of_file = true; + break; + } + } + } + + // check if we've got all our previews + if (retrieve_duration) { + done = false; + } else if (footage->audio_tracks.size() == 0) { + done = true; + for (int i=0;ivideo_tracks.size();i++) { + if (!footage->video_tracks.at(i).preview_done) { + done = false; + break; + } + } + if (done) { + end_of_file = true; + break; + } + } + av_packet_unref(packet); + } } - if (create_previews) { - // TODO may be unnecessary - doesn't av_read_frame allocate a packet itself? - AVPacket* packet = av_packet_alloc(); + av_frame_free(&temp_frame); + av_packet_free(&packet); - bool done = true; - - bool end_of_file = false; - - // get the ball rolling - do { - av_read_frame(fmt_ctx, packet); - } while (codec_ctx[packet->stream_index] == nullptr); - avcodec_send_packet(codec_ctx[packet->stream_index], packet); - - while (!end_of_file) { - while (codec_ctx[packet->stream_index] == nullptr || avcodec_receive_frame(codec_ctx[packet->stream_index], temp_frame) == AVERROR(EAGAIN)) { - av_packet_unref(packet); - int read_ret = av_read_frame(fmt_ctx, packet); - - //dout << "read frame for" << footage->name << footage->url << read_ret << "retrieve_duration:" << retrieve_duration << "eof:" << end_of_file << "packet pts:" << packet->pts; - - if (read_ret < 0) { - end_of_file = true; - if (read_ret != AVERROR_EOF) qCritical() << "Failed to read packet for preview generation" << read_ret; - break; - } - if (codec_ctx[packet->stream_index] != nullptr) { - int send_ret = avcodec_send_packet(codec_ctx[packet->stream_index], packet); - if (send_ret < 0 && send_ret != AVERROR(EAGAIN)) { - qCritical() << "Failed to send packet for preview generation - aborting" << send_ret; - end_of_file = true; - break; - } - } - } - if (!end_of_file) { - FootageStream* s = footage->get_stream_from_file_index(fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO, packet->stream_index); - if (s != nullptr) { - if (fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - if (!s->preview_done) { - int dstH = olive::CurrentConfig.thumbnail_resolution; - int dstW = qRound(dstH * (float(temp_frame->width)/float(temp_frame->height))); - uint8_t* data = new uint8_t[size_t(dstW*dstH*4)]; - - sws_ctx = sws_getContext( - temp_frame->width, - temp_frame->height, - static_cast(temp_frame->format), - dstW, - dstH, - static_cast(AV_PIX_FMT_RGBA), - SWS_FAST_BILINEAR, - nullptr, - nullptr, - nullptr - ); - - int linesize[AV_NUM_DATA_POINTERS]; - linesize[0] = dstW*4; - sws_scale(sws_ctx, temp_frame->data, temp_frame->linesize, 0, temp_frame->height, &data, linesize); - - s->video_preview = QImage(data, dstW, dstH, linesize[0], QImage::Format_RGBA8888, thumb_data_cleanup); - s->make_square_thumb(); - - // is video interlaced? - s->video_auto_interlacing = (temp_frame->interlaced_frame) ? ((temp_frame->top_field_first) ? VIDEO_TOP_FIELD_FIRST : VIDEO_BOTTOM_FIELD_FIRST) : VIDEO_PROGRESSIVE; - s->video_interlacing = s->video_auto_interlacing; - - s->preview_done = true; - - sws_freeContext(sws_ctx); - - if (!retrieve_duration) { - avcodec_close(codec_ctx[packet->stream_index]); - codec_ctx[packet->stream_index] = nullptr; - } - } - media_lengths[packet->stream_index]++; - } else if (fmt_ctx->streams[packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - AVFrame* swr_frame = av_frame_alloc(); - swr_frame->channel_layout = temp_frame->channel_layout; - swr_frame->sample_rate = temp_frame->sample_rate; - swr_frame->format = AV_SAMPLE_FMT_S16P; - - swr_ctx = swr_alloc_set_opts( - nullptr, - temp_frame->channel_layout, - static_cast(swr_frame->format), - temp_frame->sample_rate, - temp_frame->channel_layout, - static_cast(temp_frame->format), - temp_frame->sample_rate, - 0, - nullptr - ); - - swr_init(swr_ctx); - - swr_convert_frame(swr_ctx, swr_frame, temp_frame); - - // `config.waveform_resolution` determines how many samples per second are stored in waveform. - // `sample_rate` is samples per second, so `interval` is how many samples are averaged in - // each "point" of the waveform - int interval = qFloor((temp_frame->sample_rate/olive::CurrentConfig.waveform_resolution)/4)*4; - - // get the amount of bytes in an audio sample - int sample_size = av_get_bytes_per_sample(static_cast(swr_frame->format)); - - // total amount of data in this frame - int nb_bytes = swr_frame->nb_samples * sample_size; - - // loop through entire frame - for (int i=0;ichannels;j++) { - qint16& min = waveform_cache_data[packet->stream_index][j][0]; - qint16& max = waveform_cache_data[packet->stream_index][j][1]; - - s->audio_preview.append(min >> 8); - s->audio_preview.append(max >> 8); - } - - waveform_cache_count = 0; - } - - // standard processing for each channel of information - for (int j=0;jchannels;j++) { - qint16& min = waveform_cache_data[packet->stream_index][j][0]; - qint16& max = waveform_cache_data[packet->stream_index][j][1]; - - // if we're starting over, reset cache to zero - if (waveform_cache_count == 0) { - min = 0; - max = 0; - } - - // store most minimum and most maximum samples of this interval - qint16 sample = qint16((swr_frame->data[j][i+1] << 8) | swr_frame->data[j][i]); - min = qMin(min, sample); - max = qMax(max, sample); - } - - waveform_cache_count++; - - if (cancelled) { - break; - } - } - - swr_free(&swr_ctx); - av_frame_free(&swr_frame); - - if (cancelled) { - end_of_file = true; - break; - } - } - } - - // check if we've got all our previews - if (retrieve_duration) { - done = false; - } else if (footage->audio_tracks.size() == 0) { - done = true; - for (int i=0;ivideo_tracks.size();i++) { - if (!footage->video_tracks.at(i).preview_done) { - done = false; - break; - } - } - if (done) { - end_of_file = true; - break; - } - } - av_packet_unref(packet); - } + for (unsigned int i=0;inb_streams;i++) { + if (waveform_cache_data[i] != nullptr) { + for (int j=0;jchannels;j++) { + delete [] waveform_cache_data[i][j]; } + delete [] waveform_cache_data[i]; + } - av_frame_free(&temp_frame); - av_packet_free(&packet); - - for (unsigned int i=0;inb_streams;i++) { - if (waveform_cache_data[i] != nullptr) { - for (int j=0;jchannels;j++) { - delete [] waveform_cache_data[i][j]; - } - delete [] waveform_cache_data[i]; - } - - if (codec_ctx[i] != nullptr) { - avcodec_close(codec_ctx[i]); - avcodec_free_context(&codec_ctx[i]); - } - } - - // by this point, we'll have made all audio waveform previews - for (int i=0;iaudio_tracks.size();i++) { - footage->audio_tracks[i].preview_done = true; - } + if (codec_ctx[i] != nullptr) { + avcodec_close(codec_ctx[i]); + avcodec_free_context(&codec_ctx[i]); + } } - if (retrieve_duration) { - footage->length = 0; - unsigned int maximum_stream = 0; - for (unsigned int i=0;inb_streams;i++) { - if (media_lengths[i] > media_lengths[maximum_stream]) { - maximum_stream = i; - } - } + // by this point, we'll have made all audio waveform previews + for (int i=0;iaudio_tracks.size();i++) { + footage->audio_tracks[i].preview_done = true; + } + } - // FIXME: length is currently retrieved as a frame count rather than a timestamp - footage->length = qRound(double(media_lengths[maximum_stream]) / av_q2d(fmt_ctx->streams[maximum_stream]->avg_frame_rate) * AV_TIME_BASE); + if (retrieve_duration) { + footage->length = 0; + unsigned int maximum_stream = 0; + for (unsigned int i=0;inb_streams;i++) { + if (media_lengths[i] > media_lengths[maximum_stream]) { + maximum_stream = i; + } + } - finalize_media(); - } + // FIXME: length is currently retrieved as a frame count rather than a timestamp + footage->length = qRound(double(media_lengths[maximum_stream]) / av_q2d(fmt_ctx->streams[maximum_stream]->avg_frame_rate) * AV_TIME_BASE); - delete [] waveform_cache_data; - delete [] media_lengths; - delete [] codec_ctx; + finalize_media(); + } + + delete [] waveform_cache_data; + delete [] media_lengths; + delete [] codec_ctx; } QString PreviewGenerator::get_thumbnail_path(const QString& hash, const FootageStream& ms) { - return data_dir.filePath(QString("%1t%2").arg(hash, QString::number(ms.file_index))); + return data_dir.filePath(QString("%1t%2").arg(hash, QString::number(ms.file_index))); } QString PreviewGenerator::get_waveform_path(const QString& hash, const FootageStream& ms) { - return data_dir.filePath(QString("%1w%2").arg(hash, QString::number(ms.file_index))); + return data_dir.filePath(QString("%1w%2").arg(hash, QString::number(ms.file_index))); } void PreviewGenerator::run() { - Q_ASSERT(footage != nullptr); - Q_ASSERT(media != nullptr); + Q_ASSERT(footage != nullptr); + Q_ASSERT(media != nullptr); - QByteArray ba = footage->url.toUtf8(); - char* filename = new char[ba.size()+1]; - strcpy(filename, ba.data()); + QByteArray ba = footage->url.toUtf8(); + char* filename = new char[ba.size()+1]; + strcpy(filename, ba.data()); - QString errorStr; - bool error = false; - int errCode = avformat_open_input(&fmt_ctx, filename, nullptr, nullptr); - if(errCode != 0) { - char err[1024]; - av_strerror(errCode, err, 1024); - errorStr = tr("Could not open file - %1").arg(err); - error = true; - } else { - errCode = avformat_find_stream_info(fmt_ctx, nullptr); - if (errCode < 0) { - char err[1024]; - av_strerror(errCode, err, 1024); - errorStr = tr("Could not find stream information - %1").arg(err); - error = true; - } else { - av_dump_format(fmt_ctx, 0, filename, 0); - parse_media(); + QString errorStr; + bool error = false; + int errCode = avformat_open_input(&fmt_ctx, filename, nullptr, nullptr); + if(errCode != 0) { + char err[1024]; + av_strerror(errCode, err, 1024); + errorStr = tr("Could not open file - %1").arg(err); + error = true; + } else { + errCode = avformat_find_stream_info(fmt_ctx, nullptr); + if (errCode < 0) { + char err[1024]; + av_strerror(errCode, err, 1024); + errorStr = tr("Could not find stream information - %1").arg(err); + error = true; + } else { + av_dump_format(fmt_ctx, 0, filename, 0); + parse_media(); - // see if we already have data for this - QString hash = get_file_hash(footage->url); + // see if we already have data for this + QString hash = get_file_hash(footage->url); - if (retrieve_preview(hash)) { - sem.acquire(); + if (retrieve_preview(hash)) { + sem.acquire(); - if (!cancelled) { - generate_waveform(); + if (!cancelled) { + generate_waveform(); - if (!cancelled) { - // save preview to file - for (int i=0;ivideo_tracks.size();i++) { - FootageStream& ms = footage->video_tracks[i]; - ms.video_preview.save(get_thumbnail_path(hash, ms), "PNG"); - //dout << "saved" << ms->file_index << "thumbnail to" << get_thumbnail_path(hash, ms); - } - for (int i=0;iaudio_tracks.size();i++) { - FootageStream& ms = footage->audio_tracks[i]; - QFile f(get_waveform_path(hash, ms)); - f.open(QFile::WriteOnly); - f.write(ms.audio_preview.constData(), ms.audio_preview.size()); - f.close(); - //dout << "saved" << ms->file_index << "waveform to" << get_waveform_path(hash, ms); - } - } - } - - sem.release(); - } - } - avformat_close_input(&fmt_ctx); - } - - if (!cancelled) { - if (error) { - media->update_tooltip(errorStr); - olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_ERROR); - footage->invalid = true; - footage->ready_lock.unlock(); - } else { - media->update_tooltip(); + if (!cancelled) { + // save preview to file + for (int i=0;ivideo_tracks.size();i++) { + FootageStream& ms = footage->video_tracks[i]; + ms.video_preview.save(get_thumbnail_path(hash, ms), "PNG"); + //dout << "saved" << ms->file_index << "thumbnail to" << get_thumbnail_path(hash, ms); + } + for (int i=0;iaudio_tracks.size();i++) { + FootageStream& ms = footage->audio_tracks[i]; + QFile f(get_waveform_path(hash, ms)); + f.open(QFile::WriteOnly); + f.write(ms.audio_preview.constData(), ms.audio_preview.size()); + f.close(); + //dout << "saved" << ms->file_index << "waveform to" << get_waveform_path(hash, ms); + } + } } - } - delete [] filename; - footage->preview_gen = nullptr; + sem.release(); + } + } + avformat_close_input(&fmt_ctx); + } + + if (!cancelled) { + if (error) { + media->update_tooltip(errorStr); + olive::media_icon_service->SetMediaIcon(media, ICON_TYPE_ERROR); + footage->invalid = true; + footage->ready_lock.unlock(); + } else { + media->update_tooltip(); + } + } + + delete [] filename; + footage->preview_gen = nullptr; } void PreviewGenerator::cancel() { - cancelled = true; - wait(); + cancelled = true; + wait(); } diff --git a/io/previewgenerator.h b/io/previewgenerator.h index 21bae9be7..1443a5b8f 100644 --- a/io/previewgenerator.h +++ b/io/previewgenerator.h @@ -29,34 +29,34 @@ #include "project/media.h" extern "C" { - #include - #include - #include - #include +#include +#include +#include +#include } class PreviewGenerator : public QThread { - Q_OBJECT + Q_OBJECT public: - PreviewGenerator(Media*, FootagePtr, bool); - void run(); - void cancel(); + PreviewGenerator(Media*, FootagePtr, bool); + void run(); + void cancel(); private: - void parse_media(); - bool retrieve_preview(const QString &hash); - void generate_waveform(); - void finalize_media(); - AVFormatContext* fmt_ctx; - Media* media; - FootagePtr footage; - bool retrieve_duration; - bool contains_still_image; - bool replace; - bool cancelled; - QDir data_dir; - QString get_thumbnail_path(const QString &hash, const FootageStream &ms); - QString get_waveform_path(const QString& hash, const FootageStream &ms); + void parse_media(); + bool retrieve_preview(const QString &hash); + void generate_waveform(); + void finalize_media(); + AVFormatContext* fmt_ctx; + Media* media; + FootagePtr footage; + bool retrieve_duration; + bool contains_still_image; + bool replace; + bool cancelled; + QDir data_dir; + QString get_thumbnail_path(const QString &hash, const FootageStream &ms); + QString get_waveform_path(const QString& hash, const FootageStream &ms); }; #endif // PREVIEWGENERATOR_H diff --git a/main.cpp b/main.cpp index a4d93a56d..b6a25d844 100644 --- a/main.cpp +++ b/main.cpp @@ -29,107 +29,114 @@ #include "io/config.h" extern "C" { - #include - #include +#include +#include } int main(int argc, char *argv[]) { - olive::Global = std::unique_ptr(new OliveGlobal); + olive::Global = std::unique_ptr(new OliveGlobal); - bool launch_fullscreen = false; - QString load_proj; + bool launch_fullscreen = false; + QString load_proj; - bool use_internal_logger = true; + bool use_internal_logger = true; - if (argc > 1) { - for (int i=1;i 1) { + for (int i=1;i\tSet an external language file to use\n" - "\n" - "Environment Variables:\n" - "\tOLIVE_EFFECTS_PATH\tSpecify a path to search for GLSL shader effects\n" - "\tFREI0R_PATH\t\tSpecify a path to search for Frei0r effects\n" - "\tOLIVE_LANG_PATH\t\tSpecify a path to search for translation files\n" - "\n", argv[0]); - return 0; - } else if (!strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f")) { - launch_fullscreen = true; - } else if (!strcmp(argv[i], "--disable-shaders")) { - olive::CurrentRuntimeConfig.shaders_are_enabled = false; - } else if (!strcmp(argv[i], "--no-debug")) { - use_internal_logger = false; - } else if (!strcmp(argv[i], "--disable-blend-modes")) { - olive::CurrentRuntimeConfig.disable_blending = true; - } else if (!strcmp(argv[i], "--translation")) { - if (i + 1 < argc && argv[i + 1][0] != '-') { - // load translation file - olive::CurrentRuntimeConfig.external_translation_file = argv[i + 1]; + printf("%s\n", olive::AppName.toUtf8().constData()); + return 0; + } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { + printf("Usage: %s [options] [filename]\n\n" + "[filename] is the file to open on startup.\n\n" + "Options:\n" + "\t-v, --version\t\tShow version information\n" + "\t-h, --help\t\tShow this help\n" + "\t-f, --fullscreen\tStart in full screen mode\n" + "\t--disable-shaders\tDisable OpenGL shaders (for debugging)\n" + "\t--no-debug\t\tDisable internal debug log and output directly to console\n" + "\t--disable-blend-modes\tDisable shader-based blending for older GPUs\n" + "\t--translation \tSet an external language file to use\n" + "\n" + "Environment Variables:\n" + "\tOLIVE_EFFECTS_PATH\tSpecify a path to search for GLSL shader effects\n" + "\tFREI0R_PATH\t\tSpecify a path to search for Frei0r effects\n" + "\tOLIVE_LANG_PATH\t\tSpecify a path to search for translation files\n" + "\n", argv[0]); + return 0; + } else if (!strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f")) { + launch_fullscreen = true; + } else if (!strcmp(argv[i], "--disable-shaders")) { + olive::CurrentRuntimeConfig.shaders_are_enabled = false; + } else if (!strcmp(argv[i], "--no-debug")) { + use_internal_logger = false; + } else if (!strcmp(argv[i], "--disable-blend-modes")) { + olive::CurrentRuntimeConfig.disable_blending = true; + } else if (!strcmp(argv[i], "--translation")) { + if (i + 1 < argc && argv[i + 1][0] != '-') { + // load translation file + olive::CurrentRuntimeConfig.external_translation_file = argv[i + 1]; - i++; - } else { - printf("[ERROR] No translation file specified\n"); - return 1; - } - } else { - printf("[ERROR] Unknown argument '%s'\n", argv[1]); - return 1; - } - } else if (load_proj.isEmpty()) { - load_proj = argv[i]; - } - } - } - - if (use_internal_logger) { - qInstallMessageHandler(debug_message_handler); + i++; + } else { + printf("[ERROR] No translation file specified\n"); + return 1; + } + } else { + printf("[ERROR] Unknown argument '%s'\n", argv[1]); + return 1; + } + } else if (load_proj.isEmpty()) { + load_proj = argv[i]; + } } + } - // Initialize ffmpeg subsystem - // (these have been deprecated in FFmpeg 4, but are still necessary for FFmpeg 3) - av_register_all(); - avfilter_register_all(); + if (use_internal_logger) { + qInstallMessageHandler(debug_message_handler); + } - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + // Initialize ffmpeg subsystem + // (these have been deprecated in FFmpeg 4, but are still necessary for FFmpeg 3) +#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100) + av_register_all(); +#endif - QApplication a(argc, argv); - a.setWindowIcon(QIcon(":/icons/olive64.png")); +#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(7, 14, 100) + avfilter_register_all(); +#endif - olive::media_icon_service = std::unique_ptr(new MediaIconService()); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); - QCoreApplication::setOrganizationName("olivevideoeditor.org"); - QCoreApplication::setOrganizationDomain("olivevideoeditor.org"); - QCoreApplication::setApplicationName("Olive"); - QGuiApplication::setDesktopFileName("org.olivevideoeditor.Olive"); + QApplication a(argc, argv); + a.setWindowIcon(QIcon(":/icons/olive64.png")); - MainWindow w(nullptr); + // start media icon service (uses QPixmaps which require a QGuiApplication to have been created) + olive::media_icon_service = std::unique_ptr(new MediaIconService()); - // connect main window's first paint to global's init finished function - QObject::connect(&w, SIGNAL(finished_first_paint()), olive::Global.get(), SLOT(finished_initialize())); + // set app name data + QCoreApplication::setOrganizationName("olivevideoeditor.org"); + QCoreApplication::setOrganizationDomain("olivevideoeditor.org"); + QCoreApplication::setApplicationName("Olive"); + QGuiApplication::setDesktopFileName("org.olivevideoeditor.Olive"); - if (!load_proj.isEmpty()) { - olive::Global->load_project_on_launch(load_proj); - } - if (launch_fullscreen) { - w.showFullScreen(); - } else { - w.showMaximized(); - } + MainWindow w(nullptr); - return a.exec(); + // connect main window's first paint to global's init finished function + QObject::connect(&w, SIGNAL(finished_first_paint()), olive::Global.get(), SLOT(finished_initialize())); + + if (!load_proj.isEmpty()) { + olive::Global->load_project_on_launch(load_proj); + } + if (launch_fullscreen) { + w.showFullScreen(); + } else { + w.showMaximized(); + } + + return a.exec(); } diff --git a/panels/effectcontrols.cpp b/panels/effectcontrols.cpp index c052daed2..6619b9701 100644 --- a/panels/effectcontrols.cpp +++ b/panels/effectcontrols.cpp @@ -52,567 +52,567 @@ #include "debug.h" EffectControls::EffectControls(QWidget *parent) : - QDockWidget(parent), - multiple(false), - zoom(1), - panel_name(tr("Effects: ")), - mode(TA_NO_TRANSITION) + QDockWidget(parent), + multiple(false), + zoom(1), + panel_name(tr("Effects: ")), + mode(kTransitionNone) { - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setup_ui(); + setup_ui(); - clear_effects(false); - headers->viewer = panel_sequence_viewer; - headers->snapping = false; + clear_effects(false); + headers->viewer = panel_sequence_viewer; + headers->snapping = false; - effects_area->parent_widget = scrollArea; - effects_area->keyframe_area = keyframeView; - effects_area->header = headers; - keyframeView->header = headers; + effects_area->parent_widget = scrollArea; + effects_area->keyframe_area = keyframeView; + effects_area->header = headers; + keyframeView->header = headers; - lblMultipleClipsSelected->setVisible(false); + lblMultipleClipsSelected->setVisible(false); - connect(keyframeView, SIGNAL(wheel_event_signal(QWheelEvent*)), effects_area, SLOT(receive_wheel_event(QWheelEvent*))); - connect(horizontalScrollBar, SIGNAL(valueChanged(int)), headers, SLOT(set_scroll(int))); - connect(horizontalScrollBar, SIGNAL(resize_move(double)), keyframeView, SLOT(resize_move(double))); - connect(horizontalScrollBar, SIGNAL(valueChanged(int)), keyframeView, SLOT(set_x_scroll(int))); - connect(verticalScrollBar, SIGNAL(valueChanged(int)), keyframeView, SLOT(set_y_scroll(int))); - connect(verticalScrollBar, SIGNAL(valueChanged(int)), scrollArea->verticalScrollBar(), SLOT(setValue(int))); - connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)), verticalScrollBar, SLOT(setValue(int))); + connect(keyframeView, SIGNAL(wheel_event_signal(QWheelEvent*)), effects_area, SLOT(receive_wheel_event(QWheelEvent*))); + connect(horizontalScrollBar, SIGNAL(valueChanged(int)), headers, SLOT(set_scroll(int))); + connect(horizontalScrollBar, SIGNAL(resize_move(double)), keyframeView, SLOT(resize_move(double))); + connect(horizontalScrollBar, SIGNAL(valueChanged(int)), keyframeView, SLOT(set_x_scroll(int))); + connect(verticalScrollBar, SIGNAL(valueChanged(int)), keyframeView, SLOT(set_y_scroll(int))); + connect(verticalScrollBar, SIGNAL(valueChanged(int)), scrollArea->verticalScrollBar(), SLOT(setValue(int))); + connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)), verticalScrollBar, SLOT(setValue(int))); } EffectControls::~EffectControls() {} int EffectControls::get_mode() { - return mode; + return mode; } bool EffectControls::keyframe_focus() { - return headers->hasFocus() || keyframeView->hasFocus(); + return headers->hasFocus() || keyframeView->hasFocus(); } void EffectControls::set_zoom(bool in) { - zoom *= (in) ? 2 : 0.5; - update_keyframes(); + zoom *= (in) ? 2 : 0.5; + update_keyframes(); } void EffectControls::menu_select(QAction* q) { - ComboAction* ca = new ComboAction(); - for (int i=0;iclips.at(selected_clips.at(i)); - if ((c->track < 0) == (effect_menu_subtype == EFFECT_TYPE_VIDEO)) { - const EffectMeta* meta = reinterpret_cast(q->data().value()); - if (effect_menu_type == EFFECT_TYPE_TRANSITION) { - if (c->get_opening_transition() == nullptr) { - ca->append(new AddTransitionCommand(c, nullptr, nullptr, meta, TA_OPENING_TRANSITION, 30)); - } - if (c->get_closing_transition() == nullptr) { - ca->append(new AddTransitionCommand(c, nullptr, nullptr, meta, TA_CLOSING_TRANSITION, 30)); - } - } else { - ca->append(new AddEffectCommand(c, nullptr, meta)); - } - } - } - olive::UndoStack.push(ca); - if (effect_menu_type == EFFECT_TYPE_TRANSITION) { - update_ui(true); - } else { - reload_clips(); - panel_sequence_viewer->viewer_widget->frame_update(); - } + ComboAction* ca = new ComboAction(); + for (int i=0;iclips.at(selected_clips.at(i)); + if ((c->track < 0) == (effect_menu_subtype == EFFECT_TYPE_VIDEO)) { + const EffectMeta* meta = reinterpret_cast(q->data().value()); + if (effect_menu_type == EFFECT_TYPE_TRANSITION) { + if (c->opening_transition == nullptr) { + ca->append(new AddTransitionCommand(c, nullptr, nullptr, meta, kTransitionOpening, 30)); + } + if (c->closing_transition == nullptr) { + ca->append(new AddTransitionCommand(c, nullptr, nullptr, meta, kTransitionClosing, 30)); + } + } else { + ca->append(new AddEffectCommand(c, nullptr, meta)); + } + } + } + olive::UndoStack.push(ca); + if (effect_menu_type == EFFECT_TYPE_TRANSITION) { + update_ui(true); + } else { + reload_clips(); + panel_sequence_viewer->viewer_widget->frame_update(); + } } void EffectControls::update_keyframes() { - headers->update_zoom(zoom); - keyframeView->update(); + headers->update_zoom(zoom); + keyframeView->update(); } void EffectControls::delete_selected_keyframes() { - keyframeView->delete_selected_keyframes(); + keyframeView->delete_selected_keyframes(); } void EffectControls::copy(bool del) { - if (mode == TA_NO_TRANSITION) { - bool cleared = false; + if (mode == kTransitionNone) { + bool cleared = false; - ComboAction* ca = new ComboAction(); - EffectDeleteCommand* del_com = (del) ? new EffectDeleteCommand() : nullptr; - for (int i=0;iclips.at(selected_clips.at(i)); - for (int j=0;jeffects.size();j++) { - EffectPtr effect = c->effects.at(j); - if (effect->container->selected) { - if (!cleared) { - clear_clipboard(); - cleared = true; - clipboard_type = CLIPBOARD_TYPE_EFFECT; - } + ComboAction* ca = new ComboAction(); + EffectDeleteCommand* del_com = (del) ? new EffectDeleteCommand() : nullptr; + for (int i=0;iclips.at(selected_clips.at(i)); + for (int j=0;jeffects.size();j++) { + EffectPtr effect = c->effects.at(j); + if (effect->container->selected) { + if (!cleared) { + clear_clipboard(); + cleared = true; + clipboard_type = CLIPBOARD_TYPE_EFFECT; + } - clipboard.append(EffectPtr(effect->copy(nullptr))); + clipboard.append(EffectPtr(effect->copy(nullptr))); - if (del_com != nullptr) { - del_com->clips.append(c); - del_com->fx.append(j); - } - } - } - } - if (del_com != nullptr) { - if (del_com->clips.size() > 0) { - ca->append(del_com); - } else { - delete del_com; - } - } - olive::UndoStack.push(ca); - } + if (del_com != nullptr) { + del_com->clips.append(c); + del_com->fx.append(j); + } + } + } + } + if (del_com != nullptr) { + if (del_com->clips.size() > 0) { + ca->append(del_com); + } else { + delete del_com; + } + } + olive::UndoStack.push(ca); + } } void EffectControls::scroll_to_frame(long frame) { - scroll_to_frame_internal(horizontalScrollBar, frame, zoom, keyframeView->width()); + scroll_to_frame_internal(horizontalScrollBar, frame, zoom, keyframeView->width()); } void EffectControls::add_effect_paste_action(QMenu *menu) { - QAction* paste_action = menu->addAction(tr("&Paste"), panel_timeline, SLOT(paste(bool))); - paste_action->setEnabled(clipboard.size() > 0 && clipboard_type == CLIPBOARD_TYPE_EFFECT); + QAction* paste_action = menu->addAction(tr("&Paste"), panel_timeline, SLOT(paste(bool))); + paste_action->setEnabled(clipboard.size() > 0 && clipboard_type == CLIPBOARD_TYPE_EFFECT); } void EffectControls::cut() { - copy(true); + copy(true); } void EffectControls::show_effect_menu(int type, int subtype) { - effect_menu_type = type; - effect_menu_subtype = subtype; + effect_menu_type = type; + effect_menu_subtype = subtype; - effects_loaded.lock(); + effects_loaded.lock(); - QMenu effects_menu(this); - effects_menu.setToolTipsVisible(true); + QMenu effects_menu(this); + effects_menu.setToolTipsVisible(true); - for (int i=0;isetText(em.name); - action->setData(reinterpret_cast(&em)); - if (!em.tooltip.isEmpty()) { - action->setToolTip(em.tooltip); + if (em.type == type && em.subtype == subtype) { + QAction* action = new QAction(&effects_menu); + action->setText(em.name); + action->setData(reinterpret_cast(&em)); + if (!em.tooltip.isEmpty()) { + action->setToolTip(em.tooltip); + } + + QMenu* parent = &effects_menu; + if (!em.category.isEmpty()) { + bool found = false; + for (int j=0;jmenu() != nullptr) { + if (action->menu()->title() == em.category) { + parent = action->menu(); + found = true; + break; } - - QMenu* parent = &effects_menu; - if (!em.category.isEmpty()) { - bool found = false; - for (int j=0;jmenu() != nullptr) { - if (action->menu()->title() == em.category) { - parent = action->menu(); - found = true; - break; - } - } - } - if (!found) { - parent = new QMenu(&effects_menu); - parent->setToolTipsVisible(true); - parent->setTitle(em.category); - - bool found = false; - for (int i=0;itext() > em.category) { - effects_menu.insertMenu(comp_action, parent); - found = true; - break; - } - } - if (!found) effects_menu.addMenu(parent); - } - } - - bool found = false; - for (int i=0;iactions().size();i++) { - QAction* comp_action = parent->actions().at(i); - if (comp_action->text() > action->text()) { - parent->insertAction(comp_action, action); - found = true; - break; - } - } - if (!found) parent->addAction(action); + } } + if (!found) { + parent = new QMenu(&effects_menu); + parent->setToolTipsVisible(true); + parent->setTitle(em.category); + + bool found = false; + for (int i=0;itext() > em.category) { + effects_menu.insertMenu(comp_action, parent); + found = true; + break; + } + } + if (!found) effects_menu.addMenu(parent); + } + } + + bool found = false; + for (int i=0;iactions().size();i++) { + QAction* comp_action = parent->actions().at(i); + if (comp_action->text() > action->text()) { + parent->insertAction(comp_action, action); + found = true; + break; + } + } + if (!found) parent->addAction(action); } + } - effects_loaded.unlock(); + effects_loaded.unlock(); - connect(&effects_menu, SIGNAL(triggered(QAction*)), this, SLOT(menu_select(QAction*))); - effects_menu.exec(QCursor::pos()); + connect(&effects_menu, SIGNAL(triggered(QAction*)), this, SLOT(menu_select(QAction*))); + effects_menu.exec(QCursor::pos()); } void EffectControls::clear_effects(bool clear_cache) { - // clear existing clips - deselect_all_effects(nullptr); + // clear existing clips + deselect_all_effects(nullptr); - // clear graph editor - if (panel_graph_editor != nullptr) panel_graph_editor->set_row(nullptr); + // clear graph editor + if (panel_graph_editor != nullptr) panel_graph_editor->set_row(nullptr); - QVBoxLayout* video_layout = static_cast(video_effect_area->layout()); - QVBoxLayout* audio_layout = static_cast(audio_effect_area->layout()); - QLayoutItem* item; - while ((item = video_layout->takeAt(0))) { - item->widget()->setParent(nullptr); - disconnect(static_cast(item->widget()), SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); - } - while ((item = audio_layout->takeAt(0))) { - item->widget()->setParent(nullptr); - disconnect(static_cast(item->widget()), SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); - } - lblMultipleClipsSelected->setVisible(false); - vcontainer->setVisible(false); - acontainer->setVisible(false); - headers->setVisible(false); - keyframeView->setEnabled(false); - if (clear_cache) selected_clips.clear(); - setWindowTitle(panel_name + "(none)"); + QVBoxLayout* video_layout = static_cast(video_effect_area->layout()); + QVBoxLayout* audio_layout = static_cast(audio_effect_area->layout()); + QLayoutItem* item; + while ((item = video_layout->takeAt(0))) { + item->widget()->setParent(nullptr); + disconnect(static_cast(item->widget()), SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); + } + while ((item = audio_layout->takeAt(0))) { + item->widget()->setParent(nullptr); + disconnect(static_cast(item->widget()), SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); + } + lblMultipleClipsSelected->setVisible(false); + vcontainer->setVisible(false); + acontainer->setVisible(false); + headers->setVisible(false); + keyframeView->setEnabled(false); + if (clear_cache) selected_clips.clear(); + setWindowTitle(panel_name + "(none)"); } void EffectControls::deselect_all_effects(QWidget* sender) { - for (int i=0;iclips.at(selected_clips.at(i)); - for (int j=0;jeffects.size();j++) { - if (c->effects.at(j)->container != sender) { - c->effects.at(j)->container->header_click(false, false); - } - } - } - panel_sequence_viewer->viewer_widget->update(); + for (int i=0;iclips.at(selected_clips.at(i)); + for (int j=0;jeffects.size();j++) { + if (c->effects.at(j)->container != sender) { + c->effects.at(j)->container->header_click(false, false); + } + } + } + panel_sequence_viewer->viewer_widget->update(); } void EffectControls::open_effect(QVBoxLayout* layout, EffectPtr e) { - CollapsibleWidget* container = e->container; - layout->addWidget(container); - connect(container, SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); + CollapsibleWidget* container = e->container; + layout->addWidget(container); + connect(container, SIGNAL(deselect_others(QWidget*)), this, SLOT(deselect_all_effects(QWidget*))); } void EffectControls::setup_ui() { - QWidget* contents = new QWidget(this); + QWidget* contents = new QWidget(this); - QHBoxLayout* hlayout = new QHBoxLayout(contents); - hlayout->setSpacing(0); - hlayout->setMargin(0); + QHBoxLayout* hlayout = new QHBoxLayout(contents); + hlayout->setSpacing(0); + hlayout->setMargin(0); - QSplitter* splitter = new QSplitter(); - splitter->setOrientation(Qt::Horizontal); - splitter->setChildrenCollapsible(false); + QSplitter* splitter = new QSplitter(); + splitter->setOrientation(Qt::Horizontal); + splitter->setChildrenCollapsible(false); - scrollArea = new QScrollArea(); - scrollArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); - scrollArea->setFrameShape(QFrame::NoFrame); - scrollArea->setFrameShadow(QFrame::Plain); - scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - scrollArea->setWidgetResizable(true); + scrollArea = new QScrollArea(); + scrollArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + scrollArea->setFrameShape(QFrame::NoFrame); + scrollArea->setFrameShadow(QFrame::Plain); + scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + scrollArea->setWidgetResizable(true); - QWidget* scrollAreaWidgetContents = new QWidget(); + QWidget* scrollAreaWidgetContents = new QWidget(); - QHBoxLayout* scrollAreaLayout = new QHBoxLayout(scrollAreaWidgetContents); - scrollAreaLayout->setSpacing(0); - scrollAreaLayout->setMargin(0); + QHBoxLayout* scrollAreaLayout = new QHBoxLayout(scrollAreaWidgetContents); + scrollAreaLayout->setSpacing(0); + scrollAreaLayout->setMargin(0); - effects_area = new EffectsArea(); - effects_area->setContextMenuPolicy(Qt::CustomContextMenu); - connect(effects_area, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(effects_area_context_menu())); + effects_area = new EffectsArea(); + effects_area->setContextMenuPolicy(Qt::CustomContextMenu); + connect(effects_area, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(effects_area_context_menu())); - QVBoxLayout* effects_area_layout = new QVBoxLayout(effects_area); - effects_area_layout->setSpacing(0); - effects_area_layout->setMargin(0); + QVBoxLayout* effects_area_layout = new QVBoxLayout(effects_area); + effects_area_layout->setSpacing(0); + effects_area_layout->setMargin(0); - vcontainer = new QWidget(); - QVBoxLayout* vcontainerLayout = new QVBoxLayout(vcontainer); - vcontainerLayout->setSpacing(0); - vcontainerLayout->setMargin(0); + vcontainer = new QWidget(); + QVBoxLayout* vcontainerLayout = new QVBoxLayout(vcontainer); + vcontainerLayout->setSpacing(0); + vcontainerLayout->setMargin(0); - QWidget* veHeader = new QWidget(); - veHeader->setObjectName(QStringLiteral("veHeader")); - veHeader->setStyleSheet(QLatin1String("#veHeader { background: rgba(0, 0, 0, 0.25); }")); + QWidget* veHeader = new QWidget(); + veHeader->setObjectName(QStringLiteral("veHeader")); + veHeader->setStyleSheet(QLatin1String("#veHeader { background: rgba(0, 0, 0, 0.25); }")); - QHBoxLayout* veHeaderLayout = new QHBoxLayout(veHeader); - veHeaderLayout->setSpacing(0); - veHeaderLayout->setMargin(0); + QHBoxLayout* veHeaderLayout = new QHBoxLayout(veHeader); + veHeaderLayout->setSpacing(0); + veHeaderLayout->setMargin(0); - QPushButton* btnAddVideoEffect = new QPushButton(); - btnAddVideoEffect->setIcon(QIcon(":/icons/add-effect.png")); - btnAddVideoEffect->setToolTip(tr("Add Video Effect")); - veHeaderLayout->addWidget(btnAddVideoEffect); - connect(btnAddVideoEffect, SIGNAL(clicked(bool)), this, SLOT(video_effect_click())); + QPushButton* btnAddVideoEffect = new QPushButton(); + btnAddVideoEffect->setIcon(QIcon(":/icons/add-effect.png")); + btnAddVideoEffect->setToolTip(tr("Add Video Effect")); + veHeaderLayout->addWidget(btnAddVideoEffect); + connect(btnAddVideoEffect, SIGNAL(clicked(bool)), this, SLOT(video_effect_click())); - veHeaderLayout->addStretch(); + veHeaderLayout->addStretch(); - QLabel* lblVideoEffects = new QLabel(); - QFont font; - font.setPointSize(9); - lblVideoEffects->setFont(font); - lblVideoEffects->setAlignment(Qt::AlignCenter); - lblVideoEffects->setText(tr("VIDEO EFFECTS")); - veHeaderLayout->addWidget(lblVideoEffects); + QLabel* lblVideoEffects = new QLabel(); + QFont font; + font.setPointSize(9); + lblVideoEffects->setFont(font); + lblVideoEffects->setAlignment(Qt::AlignCenter); + lblVideoEffects->setText(tr("VIDEO EFFECTS")); + veHeaderLayout->addWidget(lblVideoEffects); - veHeaderLayout->addStretch(); + veHeaderLayout->addStretch(); - QPushButton* btnAddVideoTransition = new QPushButton(); - btnAddVideoTransition->setIcon(QIcon(":/icons/add-transition.png")); - btnAddVideoTransition->setToolTip(tr("Add Video Transition")); - connect(btnAddVideoTransition, SIGNAL(clicked(bool)), this, SLOT(video_transition_click())); - veHeaderLayout->addWidget(btnAddVideoTransition); + QPushButton* btnAddVideoTransition = new QPushButton(); + btnAddVideoTransition->setIcon(QIcon(":/icons/add-transition.png")); + btnAddVideoTransition->setToolTip(tr("Add Video Transition")); + connect(btnAddVideoTransition, SIGNAL(clicked(bool)), this, SLOT(video_transition_click())); + veHeaderLayout->addWidget(btnAddVideoTransition); - vcontainerLayout->addWidget(veHeader); + vcontainerLayout->addWidget(veHeader); - video_effect_area = new QWidget(); - QVBoxLayout* veAreaLayout = new QVBoxLayout(video_effect_area); - veAreaLayout->setSpacing(0); - veAreaLayout->setMargin(0); + video_effect_area = new QWidget(); + QVBoxLayout* veAreaLayout = new QVBoxLayout(video_effect_area); + veAreaLayout->setSpacing(0); + veAreaLayout->setMargin(0); - vcontainerLayout->addWidget(video_effect_area); + vcontainerLayout->addWidget(video_effect_area); - effects_area_layout->addWidget(vcontainer); + effects_area_layout->addWidget(vcontainer); - acontainer = new QWidget(); - QVBoxLayout* acontainerLayout = new QVBoxLayout(acontainer); - acontainerLayout->setSpacing(0); - acontainerLayout->setMargin(0); - QWidget* aeHeader = new QWidget(); - aeHeader->setObjectName(QStringLiteral("aeHeader")); - aeHeader->setStyleSheet(QLatin1String("#aeHeader { background: rgba(0, 0, 0, 0.25); }")); + acontainer = new QWidget(); + QVBoxLayout* acontainerLayout = new QVBoxLayout(acontainer); + acontainerLayout->setSpacing(0); + acontainerLayout->setMargin(0); + QWidget* aeHeader = new QWidget(); + aeHeader->setObjectName(QStringLiteral("aeHeader")); + aeHeader->setStyleSheet(QLatin1String("#aeHeader { background: rgba(0, 0, 0, 0.25); }")); - QHBoxLayout* aeHeaderLayout = new QHBoxLayout(aeHeader); - aeHeaderLayout->setSpacing(0); - aeHeaderLayout->setMargin(0); + QHBoxLayout* aeHeaderLayout = new QHBoxLayout(aeHeader); + aeHeaderLayout->setSpacing(0); + aeHeaderLayout->setMargin(0); - QPushButton* btnAddAudioEffect = new QPushButton(); - btnAddAudioEffect->setIcon(QIcon(":/icons/add-effect.png")); - btnAddAudioEffect->setToolTip(tr("Add Audio Effect")); - connect(btnAddAudioEffect, SIGNAL(clicked(bool)), this, SLOT(audio_effect_click())); - aeHeaderLayout->addWidget(btnAddAudioEffect); + QPushButton* btnAddAudioEffect = new QPushButton(); + btnAddAudioEffect->setIcon(QIcon(":/icons/add-effect.png")); + btnAddAudioEffect->setToolTip(tr("Add Audio Effect")); + connect(btnAddAudioEffect, SIGNAL(clicked(bool)), this, SLOT(audio_effect_click())); + aeHeaderLayout->addWidget(btnAddAudioEffect); - aeHeaderLayout->addStretch(); + aeHeaderLayout->addStretch(); - QLabel* lblAudioEffects = new QLabel(); - lblAudioEffects->setFont(font); - lblAudioEffects->setAlignment(Qt::AlignCenter); - lblAudioEffects->setText(tr("AUDIO EFFECTS")); - aeHeaderLayout->addWidget(lblAudioEffects); + QLabel* lblAudioEffects = new QLabel(); + lblAudioEffects->setFont(font); + lblAudioEffects->setAlignment(Qt::AlignCenter); + lblAudioEffects->setText(tr("AUDIO EFFECTS")); + aeHeaderLayout->addWidget(lblAudioEffects); - aeHeaderLayout->addStretch(); + aeHeaderLayout->addStretch(); - QPushButton* btnAddAudioTransition = new QPushButton(); - btnAddAudioTransition->setIcon(QIcon(":/icons/add-transition.png")); - btnAddAudioTransition->setToolTip(tr("Add Audio Transition")); - connect(btnAddAudioTransition, SIGNAL(clicked(bool)), this, SLOT(audio_transition_click())); - aeHeaderLayout->addWidget(btnAddAudioTransition); + QPushButton* btnAddAudioTransition = new QPushButton(); + btnAddAudioTransition->setIcon(QIcon(":/icons/add-transition.png")); + btnAddAudioTransition->setToolTip(tr("Add Audio Transition")); + connect(btnAddAudioTransition, SIGNAL(clicked(bool)), this, SLOT(audio_transition_click())); + aeHeaderLayout->addWidget(btnAddAudioTransition); - acontainerLayout->addWidget(aeHeader); + acontainerLayout->addWidget(aeHeader); - audio_effect_area = new QWidget(); - QVBoxLayout* aeAreaLayout = new QVBoxLayout(audio_effect_area); - aeAreaLayout->setSpacing(0); - aeAreaLayout->setMargin(0); + audio_effect_area = new QWidget(); + QVBoxLayout* aeAreaLayout = new QVBoxLayout(audio_effect_area); + aeAreaLayout->setSpacing(0); + aeAreaLayout->setMargin(0); - acontainerLayout->addWidget(audio_effect_area); + acontainerLayout->addWidget(audio_effect_area); - effects_area_layout->addWidget(acontainer); + effects_area_layout->addWidget(acontainer); - lblMultipleClipsSelected = new QLabel(); - lblMultipleClipsSelected->setAlignment(Qt::AlignCenter); - lblMultipleClipsSelected->setText(tr("(Multiple clips selected)")); - effects_area_layout->addWidget(lblMultipleClipsSelected); + lblMultipleClipsSelected = new QLabel(); + lblMultipleClipsSelected->setAlignment(Qt::AlignCenter); + lblMultipleClipsSelected->setText(tr("(Multiple clips selected)")); + effects_area_layout->addWidget(lblMultipleClipsSelected); - effects_area_layout->addStretch(); + effects_area_layout->addStretch(); - scrollAreaLayout->addWidget(effects_area); + scrollAreaLayout->addWidget(effects_area); - scrollArea->setWidget(scrollAreaWidgetContents); - splitter->addWidget(scrollArea); + scrollArea->setWidget(scrollAreaWidgetContents); + splitter->addWidget(scrollArea); - QWidget* keyframeArea = new QWidget(); + QWidget* keyframeArea = new QWidget(); - QSizePolicy keyframe_sp; - keyframe_sp.setHorizontalPolicy(QSizePolicy::Minimum); - keyframe_sp.setVerticalPolicy(QSizePolicy::Preferred); - keyframe_sp.setHorizontalStretch(1); - keyframeArea->setSizePolicy(keyframe_sp); + QSizePolicy keyframe_sp; + keyframe_sp.setHorizontalPolicy(QSizePolicy::Minimum); + keyframe_sp.setVerticalPolicy(QSizePolicy::Preferred); + keyframe_sp.setHorizontalStretch(1); + keyframeArea->setSizePolicy(keyframe_sp); - QVBoxLayout* keyframeAreaLayout = new QVBoxLayout(keyframeArea); - keyframeAreaLayout->setSpacing(0); - keyframeAreaLayout->setMargin(0); + QVBoxLayout* keyframeAreaLayout = new QVBoxLayout(keyframeArea); + keyframeAreaLayout->setSpacing(0); + keyframeAreaLayout->setMargin(0); - headers = new TimelineHeader(); - keyframeAreaLayout->addWidget(headers); + headers = new TimelineHeader(); + keyframeAreaLayout->addWidget(headers); - QWidget* keyframeCenterWidget = new QWidget(); + QWidget* keyframeCenterWidget = new QWidget(); - QHBoxLayout* keyframeCenterLayout = new QHBoxLayout(keyframeCenterWidget); - keyframeCenterLayout->setSpacing(0); - keyframeCenterLayout->setMargin(0); + QHBoxLayout* keyframeCenterLayout = new QHBoxLayout(keyframeCenterWidget); + keyframeCenterLayout->setSpacing(0); + keyframeCenterLayout->setMargin(0); - keyframeView = new KeyframeView(); + keyframeView = new KeyframeView(); - keyframeCenterLayout->addWidget(keyframeView); + keyframeCenterLayout->addWidget(keyframeView); - verticalScrollBar = new QScrollBar(); - verticalScrollBar->setOrientation(Qt::Vertical); + verticalScrollBar = new QScrollBar(); + verticalScrollBar->setOrientation(Qt::Vertical); - keyframeCenterLayout->addWidget(verticalScrollBar); + keyframeCenterLayout->addWidget(verticalScrollBar); - keyframeAreaLayout->addWidget(keyframeCenterWidget); + keyframeAreaLayout->addWidget(keyframeCenterWidget); - horizontalScrollBar = new ResizableScrollBar(); - horizontalScrollBar->setOrientation(Qt::Horizontal); + horizontalScrollBar = new ResizableScrollBar(); + horizontalScrollBar->setOrientation(Qt::Horizontal); - keyframeAreaLayout->addWidget(horizontalScrollBar); + keyframeAreaLayout->addWidget(horizontalScrollBar); - splitter->addWidget(keyframeArea); + splitter->addWidget(keyframeArea); - hlayout->addWidget(splitter); + hlayout->addWidget(splitter); - setWidget(contents); + setWidget(contents); } void EffectControls::update_scrollbar() { - verticalScrollBar->setMaximum(qMax(0, effects_area->height() - keyframeView->height() - headers->height())); - verticalScrollBar->setPageStep(verticalScrollBar->height()); + verticalScrollBar->setMaximum(qMax(0, effects_area->height() - keyframeView->height() - headers->height())); + verticalScrollBar->setPageStep(verticalScrollBar->height()); } void EffectControls::queue_post_update() { - keyframeView->update(); - update_scrollbar(); + keyframeView->update(); + update_scrollbar(); } void EffectControls::effects_area_context_menu() { - QMenu menu(this); + QMenu menu(this); - add_effect_paste_action(&menu); + add_effect_paste_action(&menu); - menu.exec(QCursor::pos()); + menu.exec(QCursor::pos()); } void EffectControls::load_effects() { - lblMultipleClipsSelected->setVisible(multiple); + lblMultipleClipsSelected->setVisible(multiple); - if (!multiple) { - // load in new clips - for (int i=0;iclips.at(selected_clips.at(i)); - QVBoxLayout* layout; - if (c->track < 0) { - vcontainer->setVisible(true); - layout = static_cast(video_effect_area->layout()); - } else { - acontainer->setVisible(true); - layout = static_cast(audio_effect_area->layout()); - } - if (mode == TA_NO_TRANSITION) { - for (int j=0;jeffects.size();j++) { - open_effect(layout, c->effects.at(j)); - } - } else if (mode == TA_OPENING_TRANSITION && c->get_opening_transition() != nullptr) { - open_effect(layout, c->get_opening_transition()); - } else if (mode == TA_CLOSING_TRANSITION && c->get_closing_transition() != nullptr) { - open_effect(layout, c->get_closing_transition()); - } - } - if (selected_clips.size() > 0) { - setWindowTitle(panel_name + olive::ActiveSequence->clips.at(selected_clips.at(0))->name); - keyframeView->setEnabled(true); - headers->setVisible(true); + if (!multiple) { + // load in new clips + for (int i=0;iclips.at(selected_clips.at(i)); + QVBoxLayout* layout; + if (c->track < 0) { + vcontainer->setVisible(true); + layout = static_cast(video_effect_area->layout()); + } else { + acontainer->setVisible(true); + layout = static_cast(audio_effect_area->layout()); + } + if (mode == kTransitionNone) { + for (int j=0;jeffects.size();j++) { + open_effect(layout, c->effects.at(j)); + } + } else if (mode == kTransitionOpening && c->opening_transition != nullptr) { + open_effect(layout, c->opening_transition); + } else if (mode == kTransitionClosing && c->closing_transition != nullptr) { + open_effect(layout, c->closing_transition); + } + } + if (selected_clips.size() > 0) { + setWindowTitle(panel_name + olive::ActiveSequence->clips.at(selected_clips.at(0))->name); + keyframeView->setEnabled(true); + headers->setVisible(true); - QTimer::singleShot(50, this, SLOT(queue_post_update())); - } - } + QTimer::singleShot(50, this, SLOT(queue_post_update())); + } + } } void EffectControls::delete_effects() { - // load in new clips - if (mode == TA_NO_TRANSITION) { - EffectDeleteCommand* command = new EffectDeleteCommand(); - for (int i=0;iclips.at(selected_clips.at(i)); - for (int j=0;jeffects.size();j++) { - EffectPtr effect = c->effects.at(j); - if (effect->container->selected) { - command->clips.append(c); - command->fx.append(j); - } - } - } - if (command->clips.size() > 0) { - olive::UndoStack.push(command); - panel_sequence_viewer->viewer_widget->frame_update(); - } else { - delete command; - } - } + // load in new clips + if (mode == kTransitionNone) { + EffectDeleteCommand* command = new EffectDeleteCommand(); + for (int i=0;iclips.at(selected_clips.at(i)); + for (int j=0;jeffects.size();j++) { + EffectPtr effect = c->effects.at(j); + if (effect->container->selected) { + command->clips.append(c); + command->fx.append(j); + } + } + } + if (command->clips.size() > 0) { + olive::UndoStack.push(command); + panel_sequence_viewer->viewer_widget->frame_update(); + } else { + delete command; + } + } } void EffectControls::reload_clips() { - clear_effects(false); - load_effects(); + clear_effects(false); + load_effects(); } void EffectControls::set_clips(QVector& clips, int m) { - clear_effects(true); + clear_effects(true); - // replace clip vector - selected_clips = clips; - mode = m; + // replace clip vector + selected_clips = clips; + mode = m; - load_effects(); + load_effects(); } void EffectControls::video_effect_click() { - show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_VIDEO); + show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_VIDEO); } void EffectControls::audio_effect_click() { - show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_AUDIO); + show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_AUDIO); } void EffectControls::video_transition_click() { - show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_VIDEO); + show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_VIDEO); } void EffectControls::audio_transition_click() { - show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_AUDIO); + show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_AUDIO); } void EffectControls::resizeEvent(QResizeEvent*) { - update_scrollbar(); + update_scrollbar(); } bool EffectControls::is_focused() { - if (this->hasFocus()) return true; - for (int i=0;iclips.at(selected_clips.at(i)); - if (c != nullptr) { - for (int j=0;jeffects.size();j++) { - if (c->effects.at(j)->container->is_focused()) { - return true; - } - } - } else { - qWarning() << "Tried to check focus of a nullptr clip"; - } - } - return false; + if (this->hasFocus()) return true; + for (int i=0;iclips.at(selected_clips.at(i)); + if (c != nullptr) { + for (int j=0;jeffects.size();j++) { + if (c->effects.at(j)->container->is_focused()) { + return true; + } + } + } else { + qWarning() << "Tried to check focus of a nullptr clip"; + } + } + return false; } EffectsArea::EffectsArea(QWidget* parent) : - QWidget(parent) + QWidget(parent) {} void EffectsArea::receive_wheel_event(QWheelEvent *e) { - QApplication::sendEvent(this, e); + QApplication::sendEvent(this, e); } diff --git a/panels/panels.cpp b/panels/panels.cpp index 4f8e3e0f2..0bc9bf83a 100644 --- a/panels/panels.cpp +++ b/panels/panels.cpp @@ -47,7 +47,7 @@ void update_effect_controls() { int vclip = -1; int aclip = -1; QVector selected_clips; - int mode = TA_NO_TRANSITION; + int mode = kTransitionNone; if (olive::ActiveSequence != nullptr) { for (int i=0;iclips.size();i++) { ClipPtr clip = olive::ActiveSequence->clips.at(i); @@ -56,11 +56,11 @@ void update_effect_controls() { const Selection& s = olive::ActiveSequence->selections.at(j); bool add = true; if (clip->timeline_in >= s.in && clip->timeline_out <= s.out && clip->track == s.track) { - mode = TA_NO_TRANSITION; - } else if (selection_contains_transition(s, clip, TA_OPENING_TRANSITION)) { - mode = TA_OPENING_TRANSITION; - } else if (selection_contains_transition(s, clip, TA_CLOSING_TRANSITION)) { - mode = TA_CLOSING_TRANSITION; + mode = kTransitionNone; + } else if (selection_contains_transition(s, clip, kTransitionOpening)) { + mode = kTransitionOpening; + } else if (selection_contains_transition(s, clip, kTransitionClosing)) { + mode = kTransitionClosing; } else { add = false; } diff --git a/panels/project.cpp b/panels/project.cpp index 37c99194f..34c7ff843 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -1081,6 +1081,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeAttribute("workareaIn", QString::number(s->workarea_in)); stream.writeAttribute("workareaOut", QString::number(s->workarea_out)); + /* for (int j=0;jtransitions.size();j++) { TransitionPtr t = s->transitions.at(j); if (t != nullptr) { @@ -1091,6 +1092,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeEndElement(); // transition } } + */ for (int j=0;jclips.size();j++) { const ClipPtr& c = s->clips.at(j); @@ -1103,8 +1105,10 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeAttribute("in", QString::number(c->timeline_in)); stream.writeAttribute("out", QString::number(c->timeline_out)); stream.writeAttribute("track", QString::number(c->track)); + /* stream.writeAttribute("opening", QString::number(c->opening_transition)); stream.writeAttribute("closing", QString::number(c->closing_transition)); + */ stream.writeAttribute("r", QString::number(c->color_r)); stream.writeAttribute("g", QString::number(c->color_g)); diff --git a/panels/timeline.cpp b/panels/timeline.cpp index c8349a387..b3fb23bb2 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -371,11 +371,11 @@ void Timeline::add_transition() { if (c != nullptr && is_clip_selected(c, true)) { int transition_to_add = (c->track < 0) ? TRANSITION_INTERNAL_CROSSDISSOLVE : TRANSITION_INTERNAL_LINEARFADE; if (c->get_opening_transition() == nullptr) { - ca->append(new AddTransitionCommand(c, nullptr, nullptr, get_internal_meta(transition_to_add, EFFECT_TYPE_TRANSITION), TA_OPENING_TRANSITION, 30)); + ca->append(new AddTransitionCommand(c, nullptr, nullptr, get_internal_meta(transition_to_add, EFFECT_TYPE_TRANSITION), kTransitionOpening, 30)); adding = true; } if (c->get_closing_transition() == nullptr) { - ca->append(new AddTransitionCommand(c, nullptr, nullptr, get_internal_meta(transition_to_add, EFFECT_TYPE_TRANSITION), TA_CLOSING_TRANSITION, 30)); + ca->append(new AddTransitionCommand(c, nullptr, nullptr, get_internal_meta(transition_to_add, EFFECT_TYPE_TRANSITION), kTransitionClosing, 30)); adding = true; } } @@ -843,19 +843,17 @@ ClipPtr Timeline::split_clip(ComboAction* ca, bool transitions, int p, long fram // } if (pre->get_opening_transition()->get_true_length() > new_clip_length) { - ca->append(new ModifyTransitionCommand(pre, TA_OPENING_TRANSITION, new_clip_length)); - } - - post->sequence->hard_delete_transition(post, TA_OPENING_TRANSITION); + ca->append(new ModifyTransitionCommand(pre->get_opening_transition(), new_clip_length)); + } } if (pre->get_closing_transition() != nullptr) { if (splitting_closing_dual_transition) { // just move closing transition to post clip // WORKAROUND - ca->append(new DeleteTransitionCommand(pre->sequence, pre->closing_transition)); + ca->append(new DeleteTransitionCommand(pre->closing_transition)); } else { - ca->append(new DeleteTransitionCommand(pre->sequence, pre->closing_transition)); + ca->append(new DeleteTransitionCommand(pre->closing_transition)); if (post->get_closing_transition() != nullptr) { if (pre->get_closing_transition()->secondary_clip == nullptr) { @@ -964,7 +962,7 @@ void Timeline::clean_up_selections(QVector& areas) { } bool selection_contains_transition(const Selection& s, ClipPtr c, int type) { - if (type == TA_OPENING_TRANSITION) { + if (type == kTransitionOpening) { return c->get_opening_transition() != nullptr && s.out == c->timeline_in + c->get_opening_transition()->get_true_length() && ((c->get_opening_transition()->secondary_clip == nullptr && s.in == c->timeline_in) @@ -989,12 +987,12 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area for (int j=0;jclips.size();j++) { ClipPtr c = olive::ActiveSequence->clips.at(j); if (c != nullptr && c->track == s.track && !c->undeletable) { - if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { + if (selection_contains_transition(s, c, kTransitionOpening)) { // delete opening transition - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); - } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { + ca->append(new DeleteTransitionCommand(c->opening_transition)); + } else if (selection_contains_transition(s, c, kTransitionClosing)) { // delete closing transition - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + ca->append(new DeleteTransitionCommand(c->closing_transition)); } else if (c->timeline_in >= s.in && c->timeline_out <= s.out) { // clips falls entirely within deletion area ca->append(new DeleteClipAction(olive::ActiveSequence, j)); @@ -1012,9 +1010,9 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area if (c->get_closing_transition() != nullptr) { if (s.in < c->timeline_out - c->get_closing_transition()->get_true_length()) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + ca->append(new DeleteTransitionCommand(c->closing_transition)); } else { - ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, c->get_closing_transition()->get_true_length() - (c->timeline_out - s.in))); + ca->append(new ModifyTransitionCommand(c->closing_transition, c->get_closing_transition()->get_true_length() - (c->timeline_out - s.in))); } } } else if (c->timeline_in < s.out && c->timeline_out > s.out) { @@ -1023,9 +1021,9 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area if (c->get_opening_transition() != nullptr) { if (s.out > c->timeline_in + c->get_opening_transition()->get_true_length()) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + ca->append(new DeleteTransitionCommand(c->opening_transition)); } else { - ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, c->get_opening_transition()->get_true_length() - (s.out - c->timeline_in))); + ca->append(new ModifyTransitionCommand(c->opening_transition, c->get_opening_transition()->get_true_length() - (s.out - c->timeline_in))); } } } @@ -2070,13 +2068,13 @@ void move_clip(ComboAction* ca, ClipPtr c, long iin, long iout, long iclip_in, i if (c->get_opening_transition() != nullptr && c->get_opening_transition()->secondary_clip != nullptr && c->get_opening_transition()->secondary_clip->timeline_out != iin) { // separate transition ca->append(new SetPointer(reinterpret_cast(&c->get_opening_transition()->secondary_clip), nullptr)); - ca->append(new AddTransitionCommand(c->get_opening_transition()->secondary_clip, nullptr, c->get_opening_transition(), nullptr, TA_CLOSING_TRANSITION, 0)); + ca->append(new AddTransitionCommand(c->get_opening_transition()->secondary_clip, nullptr, c->get_opening_transition(), nullptr, kTransitionClosing, 0)); } if (c->get_closing_transition() != nullptr && c->get_closing_transition()->secondary_clip != nullptr && c->get_closing_transition()->parent_clip->timeline_in != iout) { // separate transition ca->append(new SetPointer(reinterpret_cast(&c->get_closing_transition()->secondary_clip), nullptr)); - ca->append(new AddTransitionCommand(c, nullptr, c->get_closing_transition(), nullptr, TA_CLOSING_TRANSITION, 0)); + ca->append(new AddTransitionCommand(c, nullptr, c->get_closing_transition(), nullptr, kTransitionClosing, 0)); } } } diff --git a/playback/cacher.cpp b/playback/cacher.cpp index 3c36f2f5f..86dc423b3 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -79,7 +79,7 @@ void apply_audio_effects(ClipPtr c, double timecode_start, AVFrame* frame, int n double adjustment = transition_end - transition_start; double adjusted_range_start = (timecode_start - transition_start) / adjustment; double adjusted_range_end = (timecode_end - transition_start) / adjustment; - c->get_opening_transition()->process_audio(adjusted_range_start, adjusted_range_end, frame->data[0], nb_bytes, TA_OPENING_TRANSITION); + c->get_opening_transition()->process_audio(adjusted_range_start, adjusted_range_end, frame->data[0], nb_bytes, kTransitionOpening); } } } @@ -92,7 +92,7 @@ void apply_audio_effects(ClipPtr c, double timecode_start, AVFrame* frame, int n double adjustment = transition_end - transition_start; double adjusted_range_start = (timecode_start - transition_start) / adjustment; double adjusted_range_end = (timecode_end - transition_start) / adjustment; - c->get_closing_transition()->process_audio(adjusted_range_start, adjusted_range_end, frame->data[0], nb_bytes, TA_CLOSING_TRANSITION); + c->get_closing_transition()->process_audio(adjusted_range_start, adjusted_range_end, frame->data[0], nb_bytes, kTransitionClosing); } } } diff --git a/project/clip.cpp b/project/clip.cpp index bcfa76d35..4b0a2e80c 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -35,312 +35,299 @@ #include "debug.h" Clip::Clip(SequencePtr s) : - sequence(s), - enabled(true), - clip_in(0), - timeline_in(0), - timeline_out(0), - track(0), - media(nullptr), - speed(1.0), - reverse(false), - maintain_audio_pitch(false), - autoscale(olive::CurrentConfig.autoscale_by_default), - opening_transition(-1), - closing_transition(-1), - undeletable(false), - replaced(false), - ignore_reverse(false), - use_existing_frame(false), - filter_graph(nullptr), - fbo(nullptr), - opts(nullptr) + sequence(s), + enabled(true), + clip_in(0), + timeline_in(0), + timeline_out(0), + track(0), + media(nullptr), + speed(1.0), + reverse(false), + maintain_audio_pitch(false), + autoscale(olive::CurrentConfig.autoscale_by_default), + opening_transition(nullptr), + closing_transition(nullptr), + undeletable(false), + replaced(false), + ignore_reverse(false), + use_existing_frame(false), + filter_graph(nullptr), + fbo(nullptr), + opts(nullptr) { - pkt = av_packet_alloc(); - reset(); + pkt = av_packet_alloc(); + reset(); } ClipPtr Clip::copy(SequencePtr s, bool duplicate_transitions) { - ClipPtr copy(new Clip(s)); + ClipPtr copy(new Clip(s)); - copy->enabled = enabled; - copy->name = QString(name); - copy->clip_in = clip_in; - copy->timeline_in = timeline_in; - copy->timeline_out = timeline_out; - copy->track = track; - copy->color_r = color_r; - copy->color_g = color_g; - copy->color_b = color_b; - copy->media = media; - copy->media_stream = media_stream; - copy->autoscale = autoscale; - copy->speed = speed; - copy->maintain_audio_pitch = maintain_audio_pitch; - copy->reverse = reverse; + copy->enabled = enabled; + copy->name = QString(name); + copy->clip_in = clip_in; + copy->timeline_in = timeline_in; + copy->timeline_out = timeline_out; + copy->track = track; + copy->color_r = color_r; + copy->color_g = color_g; + copy->color_b = color_b; + copy->media = media; + copy->media_stream = media_stream; + copy->autoscale = autoscale; + copy->speed = speed; + copy->maintain_audio_pitch = maintain_audio_pitch; + copy->reverse = reverse; - for (int i=0;ieffects.append(effects.at(i)->copy(copy)); - } + for (int i=0;ieffects.append(effects.at(i)->copy(copy)); + } - copy->cached_fr = (this->sequence == nullptr) ? cached_fr : this->sequence->frame_rate; + copy->cached_fr = (this->sequence == nullptr) ? cached_fr : this->sequence->frame_rate; - if (duplicate_transitions) { - if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip == nullptr) copy->opening_transition = get_opening_transition()->copy(copy, nullptr); - if (get_closing_transition() != nullptr && get_closing_transition()->secondary_clip == nullptr) copy->closing_transition = get_closing_transition()->copy(copy, nullptr); - } + if (duplicate_transitions) { + if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip == nullptr) { + copy->opening_transition = get_opening_transition()->copy(copy, nullptr); + } + if (get_closing_transition() != nullptr && get_closing_transition()->secondary_clip == nullptr) { + copy->closing_transition = get_closing_transition()->copy(copy, nullptr); + } + } - copy->recalculateMaxLength(); + copy->recalculateMaxLength(); - return copy; + return copy; } void Clip::reset() { - audio_just_reset = false; - open = false; - finished_opening = false; - pkt_written = false; - audio_reset = false; - frame_sample_index = -1; - audio_buffer_write = false; - texture_frame = -1; - formatCtx = nullptr; - stream = nullptr; - codec = nullptr; - codecCtx = nullptr; - texture = nullptr; - last_invalid_ts = -1; + audio_just_reset = false; + open = false; + finished_opening = false; + pkt_written = false; + audio_reset = false; + frame_sample_index = -1; + audio_buffer_write = false; + texture_frame = -1; + formatCtx = nullptr; + stream = nullptr; + codec = nullptr; + codecCtx = nullptr; + texture = nullptr; + last_invalid_ts = -1; } void Clip::reset_audio() { - if (media == nullptr || media->get_type() == MEDIA_TYPE_FOOTAGE) { - audio_reset = true; - frame_sample_index = -1; - audio_buffer_write = 0; - } else if (media->get_type() == MEDIA_TYPE_SEQUENCE) { - SequencePtr nested_sequence = media->to_sequence(); - for (int i=0;iclips.size();i++) { - ClipPtr c = nested_sequence->clips.at(i); - if (c != nullptr) c->reset_audio(); - } - } + if (media == nullptr || media->get_type() == MEDIA_TYPE_FOOTAGE) { + audio_reset = true; + frame_sample_index = -1; + audio_buffer_write = 0; + } else if (media->get_type() == MEDIA_TYPE_SEQUENCE) { + SequencePtr nested_sequence = media->to_sequence(); + for (int i=0;iclips.size();i++) { + ClipPtr c = nested_sequence->clips.at(i); + if (c != nullptr) c->reset_audio(); + } + } } void Clip::refresh() { - // validates media if it was replaced - if (replaced && media != nullptr && media->get_type() == MEDIA_TYPE_FOOTAGE) { - FootagePtr m = media->to_footage(); + // validates media if it was replaced + if (replaced && media != nullptr && media->get_type() == MEDIA_TYPE_FOOTAGE) { + FootagePtr m = media->to_footage(); - if (track < 0 && m->video_tracks.size() > 0) { - media_stream = m->video_tracks.at(0).file_index; - } else if (track >= 0 && m->audio_tracks.size() > 0) { - media_stream = m->audio_tracks.at(0).file_index; - } - } - replaced = false; + if (track < 0 && m->video_tracks.size() > 0) { + media_stream = m->video_tracks.at(0).file_index; + } else if (track >= 0 && m->audio_tracks.size() > 0) { + media_stream = m->audio_tracks.at(0).file_index; + } + } + replaced = false; - // reinitializes all effects... just in case - for (int i=0;irefresh(); - } + // reinitializes all effects... just in case + for (int i=0;irefresh(); + } - recalculateMaxLength(); + recalculateMaxLength(); } void Clip::queue_clear() { - while (queue.size() > 0) { - av_frame_free(&queue.first()); - queue.removeFirst(); - } + while (queue.size() > 0) { + av_frame_free(&queue.first()); + queue.removeFirst(); + } } void Clip::queue_remove_earliest() { - int earliest_frame = 0; - for (int i=1;ipts < queue.at(earliest_frame)->pts) { - earliest_frame = i; - } - } - av_frame_free(&queue[earliest_frame]); - queue.removeAt(earliest_frame); + int earliest_frame = 0; + for (int i=1;ipts < queue.at(earliest_frame)->pts) { + earliest_frame = i; + } + } + av_frame_free(&queue[earliest_frame]); + queue.removeAt(earliest_frame); } QVector &Clip::get_markers() { - if (media != nullptr) { - return media->get_markers(); - } - return markers; + if (media != nullptr) { + return media->get_markers(); + } + return markers; } TransitionPtr Clip::get_opening_transition() { - if (opening_transition > -1) { - if (this->sequence == nullptr) { - return clipboard_transitions.at(opening_transition); - } else { - return this->sequence->transitions.at(opening_transition); - } - } - return nullptr; + return opening_transition; } TransitionPtr Clip::get_closing_transition() { - if (closing_transition > -1) { - if (this->sequence == nullptr) { - return clipboard_transitions.at(closing_transition); - } else { - return this->sequence->transitions.at(closing_transition); - } - } - return nullptr; + return closing_transition; } Clip::~Clip() { - if (open) { - close_clip(ClipPtr(this), true); - } + if (open) { + close_clip(ClipPtr(this), true); + } - if (opening_transition != -1) this->sequence->hard_delete_transition(ClipPtr(this), TA_OPENING_TRANSITION); - if (closing_transition != -1) this->sequence->hard_delete_transition(ClipPtr(this), TA_CLOSING_TRANSITION); - - effects.clear(); - av_packet_free(&pkt); + effects.clear(); + av_packet_free(&pkt); } long Clip::get_clip_in_with_transition() { - if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip != nullptr) { - // we must be the secondary clip, so return (timeline in - length) - return clip_in - get_opening_transition()->get_true_length(); - } - return clip_in; + if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip != nullptr) { + // we must be the secondary clip, so return (timeline in - length) + return clip_in - get_opening_transition()->get_true_length(); + } + return clip_in; } long Clip::get_timeline_in_with_transition() { - if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip != nullptr) { - // we must be the secondary clip, so return (timeline in - length) - return timeline_in - get_opening_transition()->get_true_length(); - } - return timeline_in; + if (get_opening_transition() != nullptr && get_opening_transition()->secondary_clip != nullptr) { + // we must be the secondary clip, so return (timeline in - length) + return timeline_in - get_opening_transition()->get_true_length(); + } + return timeline_in; } long Clip::get_timeline_out_with_transition() { - if (get_closing_transition() != nullptr && get_closing_transition()->secondary_clip != nullptr) { - // we must be the primary clip, so return (timeline out + length2) - return timeline_out + get_closing_transition()->get_true_length(); - } else { - return timeline_out; - } + if (get_closing_transition() != nullptr && get_closing_transition()->secondary_clip != nullptr) { + // we must be the primary clip, so return (timeline out + length2) + return timeline_out + get_closing_transition()->get_true_length(); + } else { + return timeline_out; + } } // timeline functions long Clip::getLength() { - return timeline_out - timeline_in; + return timeline_out - timeline_in; } double Clip::getMediaFrameRate() { - Q_ASSERT(track < 0); - if (media != nullptr) { - double rate = media->get_frame_rate(media_stream); - if (!qIsNaN(rate)) return rate; - } - if (sequence != nullptr) return sequence->frame_rate; - return qSNaN(); + Q_ASSERT(track < 0); + if (media != nullptr) { + double rate = media->get_frame_rate(media_stream); + if (!qIsNaN(rate)) return rate; + } + if (sequence != nullptr) return sequence->frame_rate; + return qSNaN(); } void Clip::recalculateMaxLength() { - if (this->sequence != nullptr) { - double fr = this->sequence->frame_rate; + if (this->sequence != nullptr) { + double fr = this->sequence->frame_rate; - fr /= speed; + fr /= speed; - calculated_length = LONG_MAX; + calculated_length = LONG_MAX; - if (media != nullptr) { - switch (media->get_type()) { - case MEDIA_TYPE_FOOTAGE: - { - FootagePtr m = media->to_footage(); - const FootageStream* ms = m->get_stream_from_file_index(track < 0, media_stream); - if (ms != nullptr && ms->infinite_length) { - calculated_length = LONG_MAX; - } else { - calculated_length = m->get_length_in_frames(fr); - } - } - break; - case MEDIA_TYPE_SEQUENCE: - { - SequencePtr s = media->to_sequence(); - calculated_length = refactor_frame_number(s->getEndFrame(), s->frame_rate, fr); - } - break; - } - } - } + if (media != nullptr) { + switch (media->get_type()) { + case MEDIA_TYPE_FOOTAGE: + { + FootagePtr m = media->to_footage(); + const FootageStream* ms = m->get_stream_from_file_index(track < 0, media_stream); + if (ms != nullptr && ms->infinite_length) { + calculated_length = LONG_MAX; + } else { + calculated_length = m->get_length_in_frames(fr); + } + } + break; + case MEDIA_TYPE_SEQUENCE: + { + SequencePtr s = media->to_sequence(); + calculated_length = refactor_frame_number(s->getEndFrame(), s->frame_rate, fr); + } + break; + } + } + } } long Clip::getMaximumLength() { - return calculated_length; + return calculated_length; } int Clip::getWidth() { - if (media == nullptr && sequence != nullptr) return sequence->width; - switch (media->get_type()) { - case MEDIA_TYPE_FOOTAGE: - { - const FootageStream* ms = media->to_footage()->get_stream_from_file_index(track < 0, media_stream); - if (ms != nullptr) return ms->video_width; - if (sequence != nullptr) return sequence->width; - break; - } - case MEDIA_TYPE_SEQUENCE: - { - SequencePtr s = media->to_sequence(); - return s->width; - break; - } - } - return 0; + if (media == nullptr && sequence != nullptr) return sequence->width; + switch (media->get_type()) { + case MEDIA_TYPE_FOOTAGE: + { + const FootageStream* ms = media->to_footage()->get_stream_from_file_index(track < 0, media_stream); + if (ms != nullptr) return ms->video_width; + if (sequence != nullptr) return sequence->width; + break; + } + case MEDIA_TYPE_SEQUENCE: + { + SequencePtr s = media->to_sequence(); + return s->width; + break; + } + } + return 0; } int Clip::getHeight() { - if (media == nullptr && sequence != nullptr) return sequence->height; - switch (media->get_type()) { - case MEDIA_TYPE_FOOTAGE: - { - const FootageStream* ms = media->to_footage()->get_stream_from_file_index(track < 0, media_stream); - if (ms != nullptr) return ms->video_height; - if (sequence != nullptr) return sequence->height; - } - case MEDIA_TYPE_SEQUENCE: - { - SequencePtr s = media->to_sequence(); - return s->height; - } - } - return 0; + if (media == nullptr && sequence != nullptr) return sequence->height; + switch (media->get_type()) { + case MEDIA_TYPE_FOOTAGE: + { + const FootageStream* ms = media->to_footage()->get_stream_from_file_index(track < 0, media_stream); + if (ms != nullptr) return ms->video_height; + if (sequence != nullptr) return sequence->height; + } + case MEDIA_TYPE_SEQUENCE: + { + SequencePtr s = media->to_sequence(); + return s->height; + } + } + return 0; } void Clip::refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points) { - if (change_timeline_points) { - move_clip(ca, ClipPtr(this), - qRound((double) timeline_in * multiplier), - qRound((double) timeline_out * multiplier), - qRound((double) clip_in * multiplier), - track); - } + if (change_timeline_points) { + move_clip(ca, ClipPtr(this), + qRound((double) timeline_in * multiplier), + qRound((double) timeline_out * multiplier), + qRound((double) clip_in * multiplier), + track); + } - // move keyframes - for (int i=0;irow_count();j++) { - EffectRow* r = e->row(j); - for (int l=0;lfieldCount();l++) { - EffectField* f = r->field(l); - for (int k=0;kkeyframes.size();k++) { - ca->append(new SetLong(&f->keyframes[k].time, f->keyframes[k].time, f->keyframes[k].time * multiplier)); - } - } - } - } + // move keyframes + for (int i=0;irow_count();j++) { + EffectRow* r = e->row(j); + for (int l=0;lfieldCount();l++) { + EffectField* f = r->field(l); + for (int k=0;kkeyframes.size();k++) { + ca->append(new SetLong(&f->keyframes[k].time, f->keyframes[k].time, f->keyframes[k].time * multiplier)); + } + } + } + } } diff --git a/project/clip.h b/project/clip.h index ab6eb934a..0644cf43c 100644 --- a/project/clip.h +++ b/project/clip.h @@ -38,8 +38,8 @@ #include "marker.h" extern "C" { - #include - #include +#include +#include } using ClipPtr = std::shared_ptr; @@ -49,109 +49,109 @@ using SequencePtr = std::shared_ptr; class Clip { public: - Clip(SequencePtr s); - ~Clip(); - ClipPtr copy(SequencePtr s, bool duplicate_transitions = true); - void reset_audio(); - void reset(); - void refresh(); - long get_clip_in_with_transition(); - long get_timeline_in_with_transition(); - long get_timeline_out_with_transition(); - long getLength(); - double getMediaFrameRate(); - long getMaximumLength(); - void recalculateMaxLength(); - int getWidth(); - int getHeight(); - void refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points); - SequencePtr sequence; + Clip(SequencePtr s); + ~Clip(); + ClipPtr copy(SequencePtr s, bool duplicate_transitions = true); + void reset_audio(); + void reset(); + void refresh(); + long get_clip_in_with_transition(); + long get_timeline_in_with_transition(); + long get_timeline_out_with_transition(); + long getLength(); + double getMediaFrameRate(); + long getMaximumLength(); + void recalculateMaxLength(); + int getWidth(); + int getHeight(); + void refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points); + SequencePtr sequence; - // queue functions - void queue_clear(); - void queue_remove_earliest(); + // queue functions + void queue_clear(); + void queue_remove_earliest(); - // timeline variables (should be copied in copy()) - bool enabled; - long clip_in; - long timeline_in; - long timeline_out; - int track; - QString name; - quint8 color_r; - quint8 color_g; - quint8 color_b; - Media* media; - int media_stream; - double speed; - double cached_fr; - bool reverse; - bool maintain_audio_pitch; - bool autoscale; + // timeline variables (should be copied in copy()) + bool enabled; + long clip_in; + long timeline_in; + long timeline_out; + int track; + QString name; + quint8 color_r; + quint8 color_g; + quint8 color_b; + Media* media; + int media_stream; + double speed; + double cached_fr; + bool reverse; + bool maintain_audio_pitch; + bool autoscale; - // markers - QVector& get_markers(); + // markers + QVector& get_markers(); - // other variables (should be deep copied/duplicated in copy()) - QList effects; - QVector linked; - int opening_transition; - TransitionPtr get_opening_transition(); - int closing_transition; - TransitionPtr get_closing_transition(); + // other variables (should be deep copied/duplicated in copy()) + QList effects; + QVector linked; + TransitionPtr opening_transition; + TransitionPtr get_opening_transition(); + TransitionPtr closing_transition; + TransitionPtr get_closing_transition(); - // media handling - AVFormatContext* formatCtx; - AVStream* stream; - AVCodec* codec; - AVCodecContext* codecCtx; - AVPacket* pkt; - AVFrame* frame; - AVDictionary* opts; - long calculated_length; + // media handling + AVFormatContext* formatCtx; + AVStream* stream; + AVCodec* codec; + AVCodecContext* codecCtx; + AVPacket* pkt; + AVFrame* frame; + AVDictionary* opts; + long calculated_length; - // temporary variables - int load_id; - bool undeletable; - bool reached_end; - bool pkt_written; - bool open; - bool finished_opening; - bool replaced; - bool ignore_reverse; - int pix_fmt; + // temporary variables + int load_id; + bool undeletable; + bool reached_end; + bool pkt_written; + bool open; + bool finished_opening; + bool replaced; + bool ignore_reverse; + int pix_fmt; - // caching functions - bool use_existing_frame; - bool multithreaded; - Cacher* cacher; - QWaitCondition can_cache; - int max_queue_size; - QVector queue; - QMutex queue_lock; - QMutex lock; - QMutex open_lock; - int64_t last_invalid_ts; + // caching functions + bool use_existing_frame; + bool multithreaded; + Cacher* cacher; + QWaitCondition can_cache; + int max_queue_size; + QVector queue; + QMutex queue_lock; + QMutex lock; + QMutex open_lock; + int64_t last_invalid_ts; - // converters/filters - AVFilterGraph* filter_graph; - AVFilterContext* buffersink_ctx; - AVFilterContext* buffersrc_ctx; + // converters/filters + AVFilterGraph* filter_graph; + AVFilterContext* buffersink_ctx; + AVFilterContext* buffersrc_ctx; - // video playback variables - QOpenGLFramebufferObject** fbo; - QOpenGLTexture* texture; - long texture_frame; + // video playback variables + QOpenGLFramebufferObject** fbo; + QOpenGLTexture* texture; + long texture_frame; - // audio playback variables - int64_t reverse_target; - int frame_sample_index; - qint64 audio_buffer_write; - bool audio_reset; - bool audio_just_reset; - long audio_target_frame; + // audio playback variables + int64_t reverse_target; + int frame_sample_index; + qint64 audio_buffer_write; + bool audio_reset; + bool audio_just_reset; + long audio_target_frame; private: - QVector markers; + QVector markers; }; #endif // CLIP_H diff --git a/project/sequence.cpp b/project/sequence.cpp index 8d6d15535..cd671b712 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -67,42 +67,6 @@ long Sequence::getEndFrame() { return end; } -void Sequence::hard_delete_transition(ClipPtr c, int type) { - int transition_index = (type == TA_OPENING_TRANSITION) ? c->opening_transition : c->closing_transition; - if (transition_index > -1) { - bool del = true; - - TransitionPtr t = transitions.at(transition_index); - if (t->secondary_clip != nullptr) { - for (int i=0;iopening_transition == transition_index - || c->closing_transition == transition_index)) { - if (type == TA_OPENING_TRANSITION) { - // convert to closing transition - t->parent_clip = t->secondary_clip; - } - - del = false; - t->secondary_clip = nullptr; - } - } - } - - if (del) { - transitions[transition_index].reset(); - } - - if (type == TA_OPENING_TRANSITION) { - c->opening_transition = -1; - } else { - c->closing_transition = -1; - } - } -} - void Sequence::getTrackLimits(int* video_tracks, int* audio_tracks) { int vt = 0; int at = 0; diff --git a/project/sequence.h b/project/sequence.h index 60ac73192..bdb150305 100644 --- a/project/sequence.h +++ b/project/sequence.h @@ -35,8 +35,7 @@ public: SequencePtr copy(); QString name; void getTrackLimits(int* video_tracks, int* audio_tracks); - long getEndFrame(); - void hard_delete_transition(ClipPtr c, int type); + long getEndFrame(); int width; int height; double frame_rate; @@ -56,7 +55,6 @@ public: QVector markers; QVector clips; - QVector transitions; }; using SequencePtr = std::shared_ptr; diff --git a/project/transition.cpp b/project/transition.cpp index b11b00f15..d4ff4f6e1 100644 --- a/project/transition.cpp +++ b/project/transition.cpp @@ -42,74 +42,92 @@ #include Transition::Transition(ClipPtr c, ClipPtr s, const EffectMeta* em) : - Effect(c, em), secondary_clip(s), - length(30) + Effect(c, em), secondary_clip(s), + length(30) { - length_field = add_row(tr("Length"), false)->add_field(EFFECT_FIELD_DOUBLE, "length"); - connect(length_field, SIGNAL(changed()), this, SLOT(set_length_from_slider())); - length_field->set_double_default_value(30); - length_field->set_double_minimum_value(0); + length_field = add_row(tr("Length"), false)->add_field(EFFECT_FIELD_DOUBLE, "length"); + connect(length_field, SIGNAL(changed()), this, SLOT(set_length_from_slider())); + length_field->set_double_default_value(30); + length_field->set_double_minimum_value(0); - LabelSlider* length_ui_ele = static_cast(length_field->ui_element); - length_ui_ele->set_display_type(LABELSLIDER_FRAMENUMBER); - length_ui_ele->set_frame_rate(parent_clip->sequence == nullptr ? parent_clip->cached_fr : parent_clip->sequence->frame_rate); + LabelSlider* length_ui_ele = static_cast(length_field->ui_element); + length_ui_ele->set_display_type(LABELSLIDER_FRAMENUMBER); + length_ui_ele->set_frame_rate(parent_clip->sequence == nullptr ? parent_clip->cached_fr : parent_clip->sequence->frame_rate); } -int Transition::copy(ClipPtr c, ClipPtr s) { - return create_transition(c, s, meta, length); +TransitionPtr Transition::copy(ClipPtr c, ClipPtr s) { + return create_transition(c, s, meta, length); } void Transition::set_length(long l) { - length = l; - length_field->set_double_value(l); + length = l; + length_field->set_double_value(l); } long Transition::get_true_length() { - return length; + return length; } long Transition::get_length() { - if (secondary_clip != nullptr) { - return length * 2; - } - return length; + if (secondary_clip != nullptr) { + return length * 2; + } + return length; +} + +ClipPtr Transition::get_opened_clip() { + if (parent_clip->opening_transition.get() == this) { + return parent_clip; + } else if (secondary_clip != nullptr && secondary_clip->opening_transition.get() == this) { + return secondary_clip; + } + return nullptr; +} + +ClipPtr Transition::get_closed_clip() { + if (parent_clip->closing_transition.get() == this) { + return parent_clip; + } else if (secondary_clip != nullptr && secondary_clip->closing_transition.get() == this) { + return secondary_clip; + } + return nullptr; } void Transition::set_length_from_slider() { - set_length(length_field->get_double_value(0)); - update_ui(false); + set_length(length_field->get_double_value(0)); + update_ui(false); } TransitionPtr get_transition_from_meta(ClipPtr c, ClipPtr s, const EffectMeta* em) { - if (!em->filename.isEmpty()) { - // load effect from file - return TransitionPtr(new Transition(c, s, em)); - } else if (em->internal >= 0 && em->internal < TRANSITION_INTERNAL_COUNT) { - // must be an internal effect - switch (em->internal) { - case TRANSITION_INTERNAL_CROSSDISSOLVE: return TransitionPtr(new CrossDissolveTransition(c, s, em)); - case TRANSITION_INTERNAL_LINEARFADE: return TransitionPtr(new LinearFadeTransition(c, s, em)); - case TRANSITION_INTERNAL_EXPONENTIALFADE: return TransitionPtr(new ExponentialFadeTransition(c, s, em)); - case TRANSITION_INTERNAL_LOGARITHMICFADE: return TransitionPtr(new LogarithmicFadeTransition(c, s, em)); - case TRANSITION_INTERNAL_CUBE: return TransitionPtr(new CubeTransition(c, s, em)); - } - } else { - qCritical() << "Invalid transition data"; - QMessageBox::critical(olive::MainWindow, - QCoreApplication::translate("transition", "Invalid transition"), - QCoreApplication::translate("transition", "No candidate for transition '%1'. This transition may be corrupt. Try reinstalling it or Olive.").arg(em->name) - ); - } - return nullptr; + if (!em->filename.isEmpty()) { + // load effect from file + return TransitionPtr(new Transition(c, s, em)); + } else if (em->internal >= 0 && em->internal < TRANSITION_INTERNAL_COUNT) { + // must be an internal effect + switch (em->internal) { + case TRANSITION_INTERNAL_CROSSDISSOLVE: return TransitionPtr(new CrossDissolveTransition(c, s, em)); + case TRANSITION_INTERNAL_LINEARFADE: return TransitionPtr(new LinearFadeTransition(c, s, em)); + case TRANSITION_INTERNAL_EXPONENTIALFADE: return TransitionPtr(new ExponentialFadeTransition(c, s, em)); + case TRANSITION_INTERNAL_LOGARITHMICFADE: return TransitionPtr(new LogarithmicFadeTransition(c, s, em)); + case TRANSITION_INTERNAL_CUBE: return TransitionPtr(new CubeTransition(c, s, em)); + } + } else { + qCritical() << "Invalid transition data"; + QMessageBox::critical(olive::MainWindow, + QCoreApplication::translate("transition", "Invalid transition"), + QCoreApplication::translate("transition", "No candidate for transition '%1'. This transition may be corrupt. Try reinstalling it or Olive.").arg(em->name) + ); + } + return nullptr; } -int create_transition(ClipPtr c, ClipPtr s, const EffectMeta* em, long length) { - TransitionPtr t(get_transition_from_meta(c, s, em)); - if (t != nullptr) { - if (length >= 0) t->set_length(length); - QVector& transition_list = (c->sequence == nullptr) ? clipboard_transitions : c->sequence->transitions; - transition_list.append(t); - return transition_list.size() - 1; - } - return -1; +TransitionPtr create_transition(ClipPtr c, ClipPtr s, const EffectMeta* em, long length) { + TransitionPtr t(get_transition_from_meta(c, s, em)); + if (t != nullptr) { + if (length > 0) { + t->set_length(length); + } + return t; + } + return nullptr; } diff --git a/project/transition.h b/project/transition.h index 2677fb332..b8677b119 100644 --- a/project/transition.h +++ b/project/transition.h @@ -23,35 +23,45 @@ #include "effect.h" -#define TA_NO_TRANSITION 0 -#define TA_OPENING_TRANSITION 1 -#define TA_CLOSING_TRANSITION 2 - -#define TRANSITION_INTERNAL_CROSSDISSOLVE 0 -#define TRANSITION_INTERNAL_LINEARFADE 1 -#define TRANSITION_INTERNAL_EXPONENTIALFADE 2 -#define TRANSITION_INTERNAL_LOGARITHMICFADE 3 -#define TRANSITION_INTERNAL_CUBE 4 -#define TRANSITION_INTERNAL_COUNT 5 - -int create_transition(ClipPtr c, ClipPtr s, const EffectMeta* em, long length = -1); - -class Transition : public Effect { - Q_OBJECT -public: - Transition(ClipPtr c, ClipPtr s, const EffectMeta* em); - int copy(ClipPtr c, ClipPtr s); - ClipPtr secondary_clip; - void set_length(long l); - long get_true_length(); - long get_length(); -private slots: - void set_length_from_slider(); -private: - long length; // used only for transitions - EffectField* length_field; +enum TransitionType { + kTransitionNone, + kTransitionOpening, + kTransitionClosing }; +enum TransitionInternal { + TRANSITION_INTERNAL_CROSSDISSOLVE, + TRANSITION_INTERNAL_LINEARFADE, + TRANSITION_INTERNAL_EXPONENTIALFADE, + TRANSITION_INTERNAL_LOGARITHMICFADE, + TRANSITION_INTERNAL_CUBE, + TRANSITION_INTERNAL_COUNT +}; + +class Transition; using TransitionPtr = std::shared_ptr; +TransitionPtr get_transition_from_meta(ClipPtr c, ClipPtr s, const EffectMeta* em); + +TransitionPtr create_transition(ClipPtr c, ClipPtr s, const EffectMeta* em, long length = 0); + +class Transition : public Effect { + Q_OBJECT +public: + Transition(ClipPtr c, ClipPtr s, const EffectMeta* em); + virtual TransitionPtr copy(ClipPtr c, ClipPtr s); + ClipPtr secondary_clip; + void set_length(long l); + long get_true_length(); + long get_length(); + + ClipPtr get_opened_clip(); + ClipPtr get_closed_clip(); +private slots: + void set_length_from_slider(); +private: + long length; // used only for transitions + EffectField* length_field; +}; + #endif // TRANSITION_H diff --git a/project/undo.cpp b/project/undo.cpp index 27a5b1344..7a5c596dc 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -49,201 +49,175 @@ QUndoStack olive::UndoStack; MoveClipAction::MoveClipAction(ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool irelative) { - clip = c; + clip = c; - old_in = c->timeline_in; - old_out = c->timeline_out; - old_clip_in = c->clip_in; - old_track = c->track; + old_in = c->timeline_in; + old_out = c->timeline_out; + old_clip_in = c->clip_in; + old_track = c->track; - new_in = iin; - new_out = iout; - new_clip_in = iclip_in; - new_track = itrack; + new_in = iin; + new_out = iout; + new_clip_in = iclip_in; + new_track = itrack; - relative = irelative; + relative = irelative; } void MoveClipAction::doUndo() { - if (relative) { - clip->timeline_in -= new_in; - clip->timeline_out -= new_out; - clip->clip_in -= new_clip_in; - clip->track -= new_track; - } else { - clip->timeline_in = old_in; - clip->timeline_out = old_out; - clip->clip_in = old_clip_in; - clip->track = old_track; - } + if (relative) { + clip->timeline_in -= new_in; + clip->timeline_out -= new_out; + clip->clip_in -= new_clip_in; + clip->track -= new_track; + } else { + clip->timeline_in = old_in; + clip->timeline_out = old_out; + clip->clip_in = old_clip_in; + clip->track = old_track; + } } void MoveClipAction::doRedo() { - if (relative) { - clip->timeline_in += new_in; - clip->timeline_out += new_out; - clip->clip_in += new_clip_in; - clip->track += new_track; - } else { - clip->timeline_in = new_in; - clip->timeline_out = new_out; - clip->clip_in = new_clip_in; - clip->track = new_track; - } + if (relative) { + clip->timeline_in += new_in; + clip->timeline_out += new_out; + clip->clip_in += new_clip_in; + clip->track += new_track; + } else { + clip->timeline_in = new_in; + clip->timeline_out = new_out; + clip->clip_in = new_clip_in; + clip->track = new_track; + } } DeleteClipAction::DeleteClipAction(SequencePtr s, int clip) { - seq = s; - index = clip; - opening_transition = -1; - closing_transition = -1; + seq = s; + index = clip; + opening_transition = -1; + closing_transition = -1; } DeleteClipAction::~DeleteClipAction() {} void DeleteClipAction::doUndo() { - // restore ref to clip - seq->clips[index] = ref; + // restore ref to clip + seq->clips[index] = ref; - // restore shared transitions - if (opening_transition > -1) { - seq->transitions.at(opening_transition)->secondary_clip = seq->transitions.at(opening_transition)->parent_clip; - seq->transitions.at(opening_transition)->parent_clip = ref; - ref->opening_transition = opening_transition; - opening_transition = -1; - } - if (closing_transition > -1) { - seq->transitions.at(closing_transition)->secondary_clip = ref; - ref->closing_transition = closing_transition; - closing_transition = -1; - } + // restore links to this clip + for (int i=linkClipIndex.size()-1;i>=0;i--) { + seq->clips.at(linkClipIndex.at(i))->linked.insert(linkLinkIndex.at(i), index); + } - // restore links to this clip - for (int i=linkClipIndex.size()-1;i>=0;i--) { - seq->clips.at(linkClipIndex.at(i))->linked.insert(linkLinkIndex.at(i), index); - } - - ref = nullptr; + ref = nullptr; } void DeleteClipAction::doRedo() { - // remove ref to clip - ref = seq->clips.at(index); - if (ref->open) { - close_clip(ref, true); - } - seq->clips[index] = nullptr; + // remove ref to clip + ref = seq->clips.at(index); + if (ref->open) { + close_clip(ref, true); + } + seq->clips[index] = nullptr; - // save shared transitions - if (ref->opening_transition > -1 && ref->get_opening_transition()->secondary_clip != nullptr) { - opening_transition = ref->opening_transition; - ref->get_opening_transition()->parent_clip = ref->get_opening_transition()->secondary_clip; - ref->get_opening_transition()->secondary_clip = nullptr; - ref->opening_transition = -1; - } - if (ref->closing_transition > -1 && ref->get_closing_transition()->secondary_clip != nullptr) { - closing_transition = ref->closing_transition; - ref->get_closing_transition()->secondary_clip = nullptr; - ref->closing_transition = -1; - } - - // delete link to this clip - linkClipIndex.clear(); - linkLinkIndex.clear(); - for (int i=0;iclips.size();i++) { - ClipPtr c = seq->clips.at(i); - if (c != nullptr) { - for (int j=0;jlinked.size();j++) { - if (c->linked.at(j) == index) { - linkClipIndex.append(i); - linkLinkIndex.append(j); - c->linked.removeAt(j); - } - } - } + // delete link to this clip + linkClipIndex.clear(); + linkLinkIndex.clear(); + for (int i=0;iclips.size();i++) { + ClipPtr c = seq->clips.at(i); + if (c != nullptr) { + for (int j=0;jlinked.size();j++) { + if (c->linked.at(j) == index) { + linkClipIndex.append(i); + linkLinkIndex.append(j); + c->linked.removeAt(j); + } + } } + } } ChangeSequenceAction::ChangeSequenceAction(SequencePtr s) { - new_sequence = s; + new_sequence = s; } void ChangeSequenceAction::doUndo() { - set_sequence(old_sequence); + set_sequence(old_sequence); } void ChangeSequenceAction::doRedo() { - old_sequence = olive::ActiveSequence; - set_sequence(new_sequence); + old_sequence = olive::ActiveSequence; + set_sequence(new_sequence); } SetTimelineInOutCommand::SetTimelineInOutCommand(SequencePtr s, bool enabled, long in, long out) { - seq = s; - new_enabled = enabled; - new_in = in; - new_out = out; + seq = s; + new_enabled = enabled; + new_in = in; + new_out = out; } void SetTimelineInOutCommand::doUndo() { - seq->using_workarea = old_enabled; - seq->workarea_in = old_in; - seq->workarea_out = old_out; + seq->using_workarea = old_enabled; + seq->workarea_in = old_in; + seq->workarea_out = old_out; - // footage viewer functions - if (seq->wrapper_sequence) { - FootagePtr m = seq->clips.at(0)->media->to_footage(); - m->using_inout = old_enabled; - m->in = old_in; - m->out = old_out; - } + // footage viewer functions + if (seq->wrapper_sequence) { + FootagePtr m = seq->clips.at(0)->media->to_footage(); + m->using_inout = old_enabled; + m->in = old_in; + m->out = old_out; + } } void SetTimelineInOutCommand::doRedo() { - old_enabled = seq->using_workarea; - old_in = seq->workarea_in; - old_out = seq->workarea_out; + old_enabled = seq->using_workarea; + old_in = seq->workarea_in; + old_out = seq->workarea_out; - seq->using_workarea = new_enabled; - seq->workarea_in = new_in; - seq->workarea_out = new_out; + seq->using_workarea = new_enabled; + seq->workarea_in = new_in; + seq->workarea_out = new_out; - // footage viewer functions - if (seq->wrapper_sequence) { - FootagePtr m = seq->clips.at(0)->media->to_footage(); - m->using_inout = new_enabled; - m->in = new_in; - m->out = new_out; - } + // footage viewer functions + if (seq->wrapper_sequence) { + FootagePtr m = seq->clips.at(0)->media->to_footage(); + m->using_inout = new_enabled; + m->in = new_in; + m->out = new_out; + } } AddEffectCommand::AddEffectCommand(ClipPtr c, EffectPtr e, const EffectMeta *m, int insert_pos) { - clip = c; - ref = e; - meta = m; - pos = insert_pos; - done = false; + clip = c; + ref = e; + meta = m; + pos = insert_pos; + done = false; } void AddEffectCommand::doUndo() { - clip->effects.last()->close(); - if (pos < 0) { - clip->effects.removeLast(); - } else { - clip->effects.removeAt(pos); - } - done = false; + clip->effects.last()->close(); + if (pos < 0) { + clip->effects.removeLast(); + } else { + clip->effects.removeAt(pos); + } + done = false; } void AddEffectCommand::doRedo() { - if (ref == nullptr) { - ref = create_effect(clip, meta); - } - if (pos < 0) { - clip->effects.append(ref); - } else { - clip->effects.insert(pos, ref); - } - done = true; + if (ref == nullptr) { + ref = create_effect(clip, meta); + } + if (pos < 0) { + clip->effects.append(ref); + } else { + clip->effects.insert(pos, ref); + } + done = true; } AddTransitionCommand::AddTransitionCommand(ClipPtr c, @@ -252,939 +226,930 @@ AddTransitionCommand::AddTransitionCommand(ClipPtr c, const EffectMeta *itransition, int itype, int ilength) { - clip = c; - secondary = s; - transition_to_copy = copy; - transition = itransition; - type = itype; - length = ilength; + primary = c; + secondary = s; + transition_to_copy = copy; + transition_meta_ = itransition; + type = itype; + length = ilength; } void AddTransitionCommand::doUndo() { - clip->sequence->hard_delete_transition(clip, type); - if (secondary != nullptr) secondary->sequence->hard_delete_transition(secondary, (type == TA_OPENING_TRANSITION) ? TA_CLOSING_TRANSITION : TA_OPENING_TRANSITION); - - if (type == TA_OPENING_TRANSITION) { - clip->opening_transition = old_ptransition; - if (secondary != nullptr) secondary->closing_transition = old_stransition; - } else { - clip->closing_transition = old_ptransition; - if (secondary != nullptr) secondary->opening_transition = old_stransition; - } + if (type == kTransitionOpening) { + primary->opening_transition = old_ptransition; + if (secondary != nullptr) secondary->closing_transition = old_stransition; + } else { + primary->closing_transition = old_ptransition; + if (secondary != nullptr) secondary->opening_transition = old_stransition; + } } void AddTransitionCommand::doRedo() { - if (type == TA_OPENING_TRANSITION) { - old_ptransition = clip->opening_transition; - clip->opening_transition = (transition_to_copy == nullptr) ? create_transition(clip, secondary, transition) : transition_to_copy->copy(clip, nullptr); - if (secondary != nullptr) { - old_stransition = secondary->closing_transition; - secondary->closing_transition = clip->opening_transition; - } - if (length > 0) { - clip->get_opening_transition()->set_length(length); - } - } else { - old_ptransition = clip->closing_transition; - clip->closing_transition = (transition_to_copy == nullptr) ? create_transition(clip, secondary, transition) : transition_to_copy->copy(clip, nullptr); - if (secondary != nullptr) { - old_stransition = secondary->opening_transition; - secondary->opening_transition = clip->closing_transition; - } - if (length > 0) { - clip->get_closing_transition()->set_length(length); - } - } + // store old transition of primary clip + old_ptransition = primary->opening_transition; + + // create new transition object + TransitionPtr new_transition; + if (transition_to_copy == nullptr) { + new_transition = get_transition_from_meta(primary, secondary, transition_meta_); + } else { + new_transition = transition_to_copy->copy(primary, nullptr); + } + + primary->opening_transition = new_transition; + + if (secondary != nullptr) { + // store old secondary transition + old_stransition = secondary->closing_transition; + + // set secondary transition to the same transition + secondary->closing_transition = new_transition; + } + + // if a length was specified, set it now + if (length > 0) { + new_transition->set_length(length); + } } -ModifyTransitionCommand::ModifyTransitionCommand(ClipPtr c, int itype, long ilength) { - clip = c; - type = itype; - new_length = ilength; +ModifyTransitionCommand::ModifyTransitionCommand(TransitionPtr t, long ilength) { + transition_ref_ = t; + new_length_ = ilength; } void ModifyTransitionCommand::doUndo() { - TransitionPtr t = (type == TA_OPENING_TRANSITION) ? clip->get_opening_transition() : clip->get_closing_transition(); - t->set_length(old_length); + transition_ref_->set_length(old_length_); } void ModifyTransitionCommand::doRedo() { - TransitionPtr t = (type == TA_OPENING_TRANSITION) ? clip->get_opening_transition() : clip->get_closing_transition(); - old_length = t->get_true_length(); - t->set_length(new_length); + old_length_ = transition_ref_->get_true_length(); + transition_ref_->set_length(new_length_); } -DeleteTransitionCommand::DeleteTransitionCommand(SequencePtr s, int transition_index) { - seq = s; - index = transition_index; - transition = nullptr; - otc = nullptr; - ctc = nullptr; +DeleteTransitionCommand::DeleteTransitionCommand(TransitionPtr t) { + transition_ref_ = t; } -DeleteTransitionCommand::~DeleteTransitionCommand() {} - void DeleteTransitionCommand::doUndo() { - seq->transitions[index] = transition; + if (opened_clip_ != nullptr) { + opened_clip_->opening_transition = transition_ref_; + } - if (otc != nullptr) otc->opening_transition = index; - if (ctc != nullptr) ctc->closing_transition = index; - - transition = nullptr; + if (closed_clip_ != nullptr) { + closed_clip_->closing_transition = transition_ref_; + } } void DeleteTransitionCommand::doRedo() { - for (int i=0;iclips.size();i++) { - ClipPtr c = seq->clips.at(i); - if (c != nullptr) { - if (c->opening_transition == index) { - otc = c; - c->opening_transition = -1; - } - if (c->closing_transition == index) { - ctc = c; - c->closing_transition = -1; - } - } - } + opened_clip_ = transition_ref_->get_opened_clip(); + closed_clip_ = transition_ref_->get_closed_clip(); - transition = seq->transitions.at(index); - seq->transitions[index] = nullptr; + if (opened_clip_ != nullptr) { + opened_clip_->opening_transition = nullptr; + } + + if (closed_clip_ != nullptr) { + closed_clip_->closing_transition = nullptr; + } } NewSequenceCommand::NewSequenceCommand(Media *s, Media* iparent) { - seq = s; - parent = iparent; - done = false; + seq = s; + parent = iparent; + done = false; - if (parent == nullptr) parent = olive::project_model.get_root(); + if (parent == nullptr) parent = olive::project_model.get_root(); } NewSequenceCommand::~NewSequenceCommand() { - if (!done) delete seq; + if (!done) delete seq; } void NewSequenceCommand::doUndo() { - olive::project_model.removeChild(parent, seq); + olive::project_model.removeChild(parent, seq); - done = false; + done = false; } void NewSequenceCommand::doRedo() { - olive::project_model.appendChild(parent, seq); + olive::project_model.appendChild(parent, seq); - done = true; + done = true; } AddMediaCommand::AddMediaCommand(Media* iitem, Media *iparent) { - item = iitem; - parent = iparent; - done = false; + item = iitem; + parent = iparent; + done = false; } AddMediaCommand::~AddMediaCommand() { - if (!done) { - delete item; - } + if (!done) { + delete item; + } } void AddMediaCommand::doUndo() { - olive::project_model.removeChild(parent, item); - done = false; - + olive::project_model.removeChild(parent, item); + done = false; + } void AddMediaCommand::doRedo() { - olive::project_model.appendChild(parent, item); + olive::project_model.appendChild(parent, item); - done = true; + done = true; } DeleteMediaCommand::DeleteMediaCommand(Media* i) { - item = i; - parent = i->parentItem(); + item = i; + parent = i->parentItem(); } DeleteMediaCommand::~DeleteMediaCommand() { - if (done) { - delete item; - } + if (done) { + delete item; + } } void DeleteMediaCommand::doUndo() { - olive::project_model.appendChild(parent, item); + olive::project_model.appendChild(parent, item); - - done = false; + + done = false; } void DeleteMediaCommand::doRedo() { - olive::project_model.removeChild(parent, item); + olive::project_model.removeChild(parent, item); - done = true; + done = true; } AddClipCommand::AddClipCommand(SequencePtr s, QVector& add) { - seq = s; - clips = add; + seq = s; + clips = add; } AddClipCommand::~AddClipCommand() {} void AddClipCommand::doUndo() { - panel_effect_controls->clear_effects(true); - for (int i=0;iclips.last(); - panel_timeline->deselect_area(c->timeline_in, c->timeline_out, c->track); - undone_clips.prepend(c); - if (c->open) close_clip(c, true); - seq->clips.removeLast(); - } - + panel_effect_controls->clear_effects(true); + for (int i=0;iclips.last(); + panel_timeline->deselect_area(c->timeline_in, c->timeline_out, c->track); + undone_clips.prepend(c); + if (c->open) close_clip(c, true); + seq->clips.removeLast(); + } + } void AddClipCommand::doRedo() { - if (undone_clips.size() > 0) { - for (int i=0;iclips.append(undone_clips.at(i)); - } - undone_clips.clear(); - } else { - int linkOffset = seq->clips.size(); - for (int i=0;icopy(seq); - copy->linked.resize(original->linked.size()); - for (int j=0;jlinked.size();j++) { - copy->linked[j] = original->linked.at(j) + linkOffset; - } - if (original->opening_transition > -1) copy->opening_transition = original->get_opening_transition()->copy(copy, nullptr); - if (original->closing_transition > -1) copy->closing_transition = original->get_closing_transition()->copy(copy, nullptr); - seq->clips.append(copy); - } else { - seq->clips.append(nullptr); - } - } - } + if (undone_clips.size() > 0) { + for (int i=0;iclips.append(undone_clips.at(i)); + } + undone_clips.clear(); + } else { + int linkOffset = seq->clips.size(); + for (int i=0;icopy(seq); + copy->linked.resize(original->linked.size()); + for (int j=0;jlinked.size();j++) { + copy->linked[j] = original->linked.at(j) + linkOffset; + } + if (original->opening_transition != nullptr) { + copy->opening_transition = original->get_opening_transition()->copy(copy, nullptr); + } + if (original->closing_transition != nullptr) { + copy->closing_transition = original->get_closing_transition()->copy(copy, nullptr); + } + seq->clips.append(copy); + } else { + seq->clips.append(nullptr); + } + } + } } LinkCommand::LinkCommand() { - link = true; + link = true; } void LinkCommand::doUndo() { - for (int i=0;iclips.at(clips.at(i)); - if (link) { - c->linked.clear(); - } else { - c->linked = old_links.at(i); - } - } - + for (int i=0;iclips.at(clips.at(i)); + if (link) { + c->linked.clear(); + } else { + c->linked = old_links.at(i); + } + } + } void LinkCommand::doRedo() { - old_links.clear(); - for (int i=0;iclips.at(clips.at(i)); - if (link) { - for (int j=0;jlinked.append(clips.at(j)); - } - } - } else { - old_links.append(c->linked); - c->linked.clear(); - } - } + old_links.clear(); + for (int i=0;iclips.at(clips.at(i)); + if (link) { + for (int j=0;jlinked.append(clips.at(j)); + } + } + } else { + old_links.append(c->linked); + c->linked.clear(); + } + } } CheckboxCommand::CheckboxCommand(QCheckBox* b) { - box = b; - checked = box->isChecked(); - done = true; + box = b; + checked = box->isChecked(); + done = true; } CheckboxCommand::~CheckboxCommand() {} void CheckboxCommand::doUndo() { - box->setChecked(!checked); - done = false; - + box->setChecked(!checked); + done = false; + } void CheckboxCommand::doRedo() { - if (!done) { - box->setChecked(checked); - } + if (!done) { + box->setChecked(checked); + } } ReplaceMediaCommand::ReplaceMediaCommand(Media* i, QString s) { - item = i; - new_filename = s; - old_filename = item->to_footage()->url; + item = i; + new_filename = s; + old_filename = item->to_footage()->url; } void ReplaceMediaCommand::replace(QString& filename) { - // close any clips currently using this media - QVector all_sequences = panel_project->list_all_project_sequences(); - for (int i=0;ito_sequence(); - for (int j=0;jclips.size();j++) { - ClipPtr c = s->clips.at(j); - if (c != nullptr && c->media == item && c->open) { - close_clip(c, true); - c->replaced = true; - } - } - } + // close any clips currently using this media + QVector all_sequences = panel_project->list_all_project_sequences(); + for (int i=0;ito_sequence(); + for (int j=0;jclips.size();j++) { + ClipPtr c = s->clips.at(j); + if (c != nullptr && c->media == item && c->open) { + close_clip(c, true); + c->replaced = true; + } + } + } - // replace media - QStringList files; - files.append(filename); - item->to_footage()->ready_lock.lock(); - panel_project->process_file_list(files, false, item, nullptr); + // replace media + QStringList files; + files.append(filename); + item->to_footage()->ready_lock.lock(); + panel_project->process_file_list(files, false, item, nullptr); } void ReplaceMediaCommand::doUndo() { - replace(old_filename); + replace(old_filename); + - } void ReplaceMediaCommand::doRedo() { - replace(new_filename); + replace(new_filename); } ReplaceClipMediaCommand::ReplaceClipMediaCommand(Media *a, Media *b, bool e) { - old_media = a; - new_media = b; - preserve_clip_ins = e; + old_media = a; + new_media = b; + preserve_clip_ins = e; } void ReplaceClipMediaCommand::replace(bool undo) { - if (!undo) { - old_clip_ins.clear(); - } + if (!undo) { + old_clip_ins.clear(); + } - for (int i=0;iopen) { - close_clip(c, true); - } + for (int i=0;iopen) { + close_clip(c, true); + } - if (undo) { - if (!preserve_clip_ins) { - c->clip_in = old_clip_ins.at(i); - } + if (undo) { + if (!preserve_clip_ins) { + c->clip_in = old_clip_ins.at(i); + } - c->media = old_media; - } else { - if (!preserve_clip_ins) { - old_clip_ins.append(c->clip_in); - c->clip_in = 0; - } + c->media = old_media; + } else { + if (!preserve_clip_ins) { + old_clip_ins.append(c->clip_in); + c->clip_in = 0; + } - c->media = new_media; - } + c->media = new_media; + } - c->replaced = true; - c->refresh(); - } + c->replaced = true; + c->refresh(); + } } void ReplaceClipMediaCommand::doUndo() { - replace(true); + replace(true); } void ReplaceClipMediaCommand::doRedo() { - replace(false); + replace(false); - update_ui(true); + update_ui(true); } EffectDeleteCommand::EffectDeleteCommand() { - done = false; + done = false; } EffectDeleteCommand::~EffectDeleteCommand() {} void EffectDeleteCommand::doUndo() { - for (int i=0;ieffects.insert(fx.at(i), deleted_objects.at(i)); - } - panel_effect_controls->reload_clips(); - done = false; - + for (int i=0;ieffects.insert(fx.at(i), deleted_objects.at(i)); + } + panel_effect_controls->reload_clips(); + done = false; + } void EffectDeleteCommand::doRedo() { - deleted_objects.clear(); - for (int i=0;ieffects.at(fx_id); - e->close(); - deleted_objects.append(e); - c->effects.removeAt(fx_id); - } - panel_effect_controls->reload_clips(); - done = true; + deleted_objects.clear(); + for (int i=0;ieffects.at(fx_id); + e->close(); + deleted_objects.append(e); + c->effects.removeAt(fx_id); + } + panel_effect_controls->reload_clips(); + done = true; } MediaMove::MediaMove() {} void MediaMove::doUndo() { - for (int i=0;iparentItem(); - froms[i] = parent; - olive::project_model.moveChild(items.at(i), to); - } + if (to == nullptr) to = olive::project_model.get_root(); + froms.resize(items.size()); + for (int i=0;iparentItem(); + froms[i] = parent; + olive::project_model.moveChild(items.at(i), to); + } } MediaRename::MediaRename(Media* iitem, QString ito) { - item = iitem; - from = iitem->get_name(); - to = ito; + item = iitem; + from = iitem->get_name(); + to = ito; } void MediaRename::doUndo() { - item->set_name(from); - + item->set_name(from); + } void MediaRename::doRedo() { - item->set_name(to); + item->set_name(to); } KeyframeDelete::KeyframeDelete(EffectField *ifield, int iindex) { - field = ifield; - index = iindex; + field = ifield; + index = iindex; } void KeyframeDelete::doUndo() { - field->keyframes.insert(index, deleted_key); + field->keyframes.insert(index, deleted_key); } void KeyframeDelete::doRedo() { - deleted_key = field->keyframes.at(index); - field->keyframes.removeAt(index); + deleted_key = field->keyframes.at(index); + field->keyframes.removeAt(index); } EffectFieldUndo::EffectFieldUndo(EffectField* f) { - field = f; - done = true; + field = f; + done = true; - old_val = field->get_previous_data(); - new_val = field->get_current_data(); + old_val = field->get_previous_data(); + new_val = field->get_current_data(); } void EffectFieldUndo::doUndo() { - field->set_current_data(old_val); - done = false; - + field->set_current_data(old_val); + done = false; + } void EffectFieldUndo::doRedo() { - if (!done) { - field->set_current_data(new_val); - } + if (!done) { + field->set_current_data(new_val); + } } SetAutoscaleAction::SetAutoscaleAction() {} void SetAutoscaleAction::doUndo() { - for (int i=0;iautoscale = !clips.at(i)->autoscale; - } - panel_sequence_viewer->viewer_widget->frame_update(); - + for (int i=0;iautoscale = !clips.at(i)->autoscale; + } + panel_sequence_viewer->viewer_widget->frame_update(); + } void SetAutoscaleAction::doRedo() { - for (int i=0;iautoscale = !clips.at(i)->autoscale; - } - panel_sequence_viewer->viewer_widget->frame_update(); + for (int i=0;iautoscale = !clips.at(i)->autoscale; + } + panel_sequence_viewer->viewer_widget->frame_update(); } AddMarkerAction::AddMarkerAction(QVector* m, long t, QString n) { - active_array = m; - time = t; - name = n; + active_array = m; + time = t; + name = n; } void AddMarkerAction::doUndo() { - if (index == -1) { - active_array->removeLast(); - } else { - active_array[0][index].name = old_name; - } + if (index == -1) { + active_array->removeLast(); + } else { + active_array[0][index].name = old_name; + } } void AddMarkerAction::doRedo() { - index = -1; + index = -1; - for (int i=0;isize();i++) { - if (active_array->at(i).frame == time) { - index = i; - break; - } - } + for (int i=0;isize();i++) { + if (active_array->at(i).frame == time) { + index = i; + break; + } + } - if (index == -1) { - Marker m; - m.frame = time; - m.name = name; - active_array->append(m); - } else { - old_name = active_array->at(index).name; - active_array[0][index].name = name; - } + if (index == -1) { + Marker m; + m.frame = time; + m.name = name; + active_array->append(m); + } else { + old_name = active_array->at(index).name; + active_array[0][index].name = name; + } } MoveMarkerAction::MoveMarkerAction(Marker* m, long o, long n) { - marker = m; - old_time = o; - new_time = n; + marker = m; + old_time = o; + new_time = n; } void MoveMarkerAction::doUndo() { - marker->frame = old_time; - + marker->frame = old_time; + } void MoveMarkerAction::doRedo() { - marker->frame = new_time; + marker->frame = new_time; } DeleteMarkerAction::DeleteMarkerAction(QVector *m) { - active_array = m; - sorted = false; + active_array = m; + sorted = false; } void DeleteMarkerAction::doUndo() { - for (int i=markers.size()-1;i>=0;i--) { - active_array->insert(markers.at(i), copies.at(i)); - } - + for (int i=markers.size()-1;i>=0;i--) { + active_array->insert(markers.at(i), copies.at(i)); + } + } void DeleteMarkerAction::doRedo() { - for (int i=0;iat(markers.at(i))); - for (int j=i+1;j markers.at(i)) { - markers[j]--; - } - } - } - active_array->removeAt(markers.at(i)); - } - sorted = true; + for (int i=0;iat(markers.at(i))); + for (int j=i+1;j markers.at(i)) { + markers[j]--; + } + } + } + active_array->removeAt(markers.at(i)); + } + sorted = true; } SetSpeedAction::SetSpeedAction(ClipPtr c, double speed) { - clip = c; - old_speed = c->speed; - new_speed = speed; + clip = c; + old_speed = c->speed; + new_speed = speed; } void SetSpeedAction::doUndo() { - clip->speed = old_speed; - clip->recalculateMaxLength(); - + clip->speed = old_speed; + clip->recalculateMaxLength(); + } void SetSpeedAction::doRedo() { - clip->speed = new_speed; - clip->recalculateMaxLength(); + clip->speed = new_speed; + clip->recalculateMaxLength(); } SetBool::SetBool(bool* b, bool setting) { - boolean = b; - old_setting = *b; - new_setting = setting; + boolean = b; + old_setting = *b; + new_setting = setting; } void SetBool::doUndo() { - *boolean = old_setting; + *boolean = old_setting; } void SetBool::doRedo() { - *boolean = new_setting; + *boolean = new_setting; } SetSelectionsCommand::SetSelectionsCommand(SequencePtr s) { - seq = s; - done = true; + seq = s; + done = true; } void SetSelectionsCommand::doUndo() { - seq->selections = old_data; - done = false; + seq->selections = old_data; + done = false; } void SetSelectionsCommand::doRedo() { - if (!done) { - seq->selections = new_data; - done = true; - } + if (!done) { + seq->selections = new_data; + done = true; + } } EditSequenceCommand::EditSequenceCommand(Media* i, SequencePtr s) { - item = i; - seq = s; - old_name = s->name; - old_width = s->width; - old_height = s->height; - old_frame_rate = s->frame_rate; - old_audio_frequency = s->audio_frequency; - old_audio_layout = s->audio_layout; + item = i; + seq = s; + old_name = s->name; + old_width = s->width; + old_height = s->height; + old_frame_rate = s->frame_rate; + old_audio_frequency = s->audio_frequency; + old_audio_layout = s->audio_layout; } void EditSequenceCommand::doUndo() { - seq->name = old_name; - seq->width = old_width; - seq->height = old_height; - seq->frame_rate = old_frame_rate; - seq->audio_frequency = old_audio_frequency; - seq->audio_layout = old_audio_layout; - update(); + seq->name = old_name; + seq->width = old_width; + seq->height = old_height; + seq->frame_rate = old_frame_rate; + seq->audio_frequency = old_audio_frequency; + seq->audio_layout = old_audio_layout; + update(); } void EditSequenceCommand::doRedo() { - seq->name = name; - seq->width = width; - seq->height = height; - seq->frame_rate = frame_rate; - seq->audio_frequency = audio_frequency; - seq->audio_layout = audio_layout; - update(); + seq->name = name; + seq->width = width; + seq->height = height; + seq->frame_rate = frame_rate; + seq->audio_frequency = audio_frequency; + seq->audio_layout = audio_layout; + update(); } void EditSequenceCommand::update() { - // update tooltip - item->set_sequence(seq); + // update tooltip + item->set_sequence(seq); - for (int i=0;iclips.size();i++) { - if (seq->clips.at(i) != nullptr) seq->clips.at(i)->refresh(); - } + for (int i=0;iclips.size();i++) { + if (seq->clips.at(i) != nullptr) seq->clips.at(i)->refresh(); + } - if (olive::ActiveSequence == seq) { - set_sequence(seq); - } + if (olive::ActiveSequence == seq) { + set_sequence(seq); + } } SetInt::SetInt(int* pointer, int new_value) { - p = pointer; - oldval = *pointer; - newval = new_value; + p = pointer; + oldval = *pointer; + newval = new_value; } void SetInt::doUndo() { - *p = oldval; - + *p = oldval; + } void SetInt::doRedo() { - *p = newval; + *p = newval; } SetString::SetString(QString* pointer, QString new_value) { - p = pointer; - oldval = *pointer; - newval = new_value; + p = pointer; + oldval = *pointer; + newval = new_value; } void SetString::doUndo() { - *p = oldval; - + *p = oldval; + } void SetString::doRedo() { - *p = newval; + *p = newval; } void CloseAllClipsCommand::doUndo() { - redo(); + redo(); } void CloseAllClipsCommand::doRedo() { - closeActiveClips(olive::ActiveSequence); + closeActiveClips(olive::ActiveSequence); } UpdateFootageTooltip::UpdateFootageTooltip(Media *i) { - item = i; + item = i; } void UpdateFootageTooltip::doUndo() { - redo(); + redo(); } void UpdateFootageTooltip::doRedo() { - item->update_tooltip(); + item->update_tooltip(); } MoveEffectCommand::MoveEffectCommand() {} void MoveEffectCommand::doUndo() { - clip->effects.move(to, from); - + clip->effects.move(to, from); + } void MoveEffectCommand::doRedo() { - clip->effects.move(from, to); + clip->effects.move(from, to); } RemoveClipsFromClipboard::RemoveClipsFromClipboard(int index) { - pos = index; - done = false; + pos = index; + done = false; } RemoveClipsFromClipboard::~RemoveClipsFromClipboard() {} void RemoveClipsFromClipboard::doUndo() { - clipboard.insert(pos, clip); - done = false; + clipboard.insert(pos, clip); + done = false; } void RemoveClipsFromClipboard::doRedo() { - clip = std::static_pointer_cast(clipboard.at(pos)); - clipboard.removeAt(pos); - done = true; + clip = std::static_pointer_cast(clipboard.at(pos)); + clipboard.removeAt(pos); + done = true; } RenameClipCommand::RenameClipCommand() {} void RenameClipCommand::doUndo() { - for (int i=0;iname = old_names.at(i); - } + for (int i=0;iname = old_names.at(i); + } } void RenameClipCommand::doRedo() { - old_names.resize(clips.size()); - for (int i=0;iname; - clips.at(i)->name = new_name; - } + old_names.resize(clips.size()); + for (int i=0;iname; + clips.at(i)->name = new_name; + } } SetPointer::SetPointer(void **pointer, void *data) { - p = pointer; - new_data = data; + p = pointer; + new_data = data; } void SetPointer::doUndo() { - *p = old_data; + *p = old_data; } void SetPointer::doRedo() { - old_data = *p; - *p = new_data; + old_data = *p; + *p = new_data; } void ReloadEffectsCommand::doUndo() { - redo(); + redo(); } void ReloadEffectsCommand::doRedo() { - panel_effect_controls->reload_clips(); + panel_effect_controls->reload_clips(); } RippleAction::RippleAction(SequencePtr is, long ipoint, long ilength, const QVector &iignore) { - s = is; - point = ipoint; - length = ilength; - ignore = iignore; + s = is; + point = ipoint; + length = ilength; + ignore = iignore; } void RippleAction::doUndo() { - ca->undo(); - delete ca; + ca->undo(); + delete ca; } void RippleAction::doRedo() { - ca = new ComboAction(); - for (int i=0;iclips.size();i++) { - if (!ignore.contains(i)) { - ClipPtr c = s->clips.at(i); - if (c != nullptr) { - if (c->timeline_in >= point) { - move_clip(ca, c, length, length, 0, 0, true, true); - } - } - } - } - ca->redo(); + ca = new ComboAction(); + for (int i=0;iclips.size();i++) { + if (!ignore.contains(i)) { + ClipPtr c = s->clips.at(i); + if (c != nullptr) { + if (c->timeline_in >= point) { + move_clip(ca, c, length, length, 0, 0, true, true); + } + } + } + } + ca->redo(); } SetDouble::SetDouble(double* pointer, double old_value, double new_value) { - p = pointer; - oldval = old_value; - newval = new_value; + p = pointer; + oldval = old_value; + newval = new_value; } void SetDouble::doUndo() { - *p = oldval; - + *p = oldval; + } void SetDouble::doRedo() { - *p = newval; + *p = newval; } SetQVariant::SetQVariant(QVariant *itarget, const QVariant &iold, const QVariant &inew) { - target = itarget; - old_val = iold; - new_val = inew; + target = itarget; + old_val = iold; + new_val = inew; } void SetQVariant::doUndo() { - *target = old_val; + *target = old_val; } void SetQVariant::doRedo() { - *target = new_val; + *target = new_val; } SetLong::SetLong(long *pointer, long old_value, long new_value) { - p = pointer; - oldval = old_value; - newval = new_value; + p = pointer; + oldval = old_value; + newval = new_value; } void SetLong::doUndo() { - *p = oldval; - + *p = oldval; + } void SetLong::doRedo() { - *p = newval; + *p = newval; } KeyframeFieldSet::KeyframeFieldSet(EffectField *ifield, int ii) { - field = ifield; - index = ii; - key = ifield->keyframes.at(ii); - done = true; + field = ifield; + index = ii; + key = ifield->keyframes.at(ii); + done = true; } void KeyframeFieldSet::doUndo() { - field->keyframes.removeAt(index); - - done = false; + field->keyframes.removeAt(index); + + done = false; } void KeyframeFieldSet::doRedo() { - if (!done) { - field->keyframes.insert(index, key); - } - done = true; + if (!done) { + field->keyframes.insert(index, key); + } + done = true; } SetKeyframing::SetKeyframing(EffectRow *irow, bool ib) { - row = irow; - b = ib; + row = irow; + b = ib; } void SetKeyframing::doUndo() { - row->setKeyframing(!b); + row->setKeyframing(!b); } void SetKeyframing::doRedo() { - row->setKeyframing(b); + row->setKeyframing(b); } RefreshClips::RefreshClips(Media *m) { - media = m; + media = m; } void RefreshClips::doUndo() { - redo(); + redo(); } void RefreshClips::doRedo() { - // close any clips currently using this media - QVector all_sequences = panel_project->list_all_project_sequences(); - for (int i=0;ito_sequence(); - for (int j=0;jclips.size();j++) { - ClipPtr c = s->clips.at(j); - if (c != nullptr && c->media == media) { - c->replaced = true; - c->refresh(); - } - } - } + // close any clips currently using this media + QVector all_sequences = panel_project->list_all_project_sequences(); + for (int i=0;ito_sequence(); + for (int j=0;jclips.size();j++) { + ClipPtr c = s->clips.at(j); + if (c != nullptr && c->media == media) { + c->replaced = true; + c->refresh(); + } + } + } } void UpdateViewer::doUndo() { - redo(); + redo(); } void UpdateViewer::doRedo() { - panel_sequence_viewer->viewer_widget->frame_update(); + panel_sequence_viewer->viewer_widget->frame_update(); } SetEffectData::SetEffectData(EffectPtr e, const QByteArray &s) { - effect = e; - data = s; + effect = e; + data = s; } void SetEffectData::doUndo() { - effect->load_from_string(old_data); + effect->load_from_string(old_data); - old_data.clear(); + old_data.clear(); } void SetEffectData::doRedo() { - old_data = effect->save_to_string(); + old_data = effect->save_to_string(); - effect->load_from_string(data); + effect->load_from_string(data); } OliveAction::OliveAction(bool iset_window_modified) { - set_window_modified = iset_window_modified; + set_window_modified = iset_window_modified; } OliveAction::~OliveAction() {} void OliveAction::undo() { - doUndo(); + doUndo(); - if (set_window_modified) { - olive::MainWindow->setWindowModified(old_window_modified); - } + if (set_window_modified) { + olive::MainWindow->setWindowModified(old_window_modified); + } } void OliveAction::redo() { - doRedo(); + doRedo(); - if (set_window_modified) { + if (set_window_modified) { - // store current modified state - old_window_modified = olive::MainWindow->isWindowModified(); + // store current modified state + old_window_modified = olive::MainWindow->isWindowModified(); - // set modified to true - olive::MainWindow->setWindowModified(true); + // set modified to true + olive::MainWindow->setWindowModified(true); - } + } } diff --git a/project/undo.h b/project/undo.h index 09d07dbad..830a9973f 100644 --- a/project/undo.h +++ b/project/undo.h @@ -36,594 +36,590 @@ #include namespace olive { - extern QUndoStack UndoStack; +extern QUndoStack UndoStack; } class OliveAction : public QUndoCommand { public: - OliveAction(bool iset_window_modified = true); - virtual ~OliveAction() override; + OliveAction(bool iset_window_modified = true); + virtual ~OliveAction() override; - virtual void undo() override; - virtual void redo() override; + virtual void undo() override; + virtual void redo() override; - virtual void doUndo() = 0; - virtual void doRedo() = 0; + virtual void doUndo() = 0; + virtual void doRedo() = 0; private: - /** + /** * @brief Setting whether to change the windowModified state of MainWindow */ - bool set_window_modified; + bool set_window_modified; - /** + /** * @brief Cache previous window modified value to return to if the user undoes this action */ - bool old_window_modified; + bool old_window_modified; }; class MoveClipAction : public OliveAction { public: - MoveClipAction(ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool irelative); - virtual void doUndo() override; - virtual void doRedo() override; + MoveClipAction(ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool irelative); + virtual void doUndo() override; + virtual void doRedo() override; private: - ClipPtr clip; + ClipPtr clip; - long old_in; - long old_out; - long old_clip_in; - int old_track; + long old_in; + long old_out; + long old_clip_in; + int old_track; - long new_in; - long new_out; - long new_clip_in; - int new_track; + long new_in; + long new_out; + long new_clip_in; + int new_track; - bool relative; + bool relative; }; class RippleAction : public OliveAction { public: - RippleAction(SequencePtr is, long ipoint, long ilength, const QVector& iignore); - virtual void doUndo() override; - virtual void doRedo() override; + RippleAction(SequencePtr is, long ipoint, long ilength, const QVector& iignore); + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr s; - long point; - long length; - QVector ignore; - ComboAction* ca; + SequencePtr s; + long point; + long length; + QVector ignore; + ComboAction* ca; }; class DeleteClipAction : public OliveAction { public: - DeleteClipAction(SequencePtr s, int clip); - virtual ~DeleteClipAction() override; - virtual void doUndo() override; - virtual void doRedo() override; + DeleteClipAction(SequencePtr s, int clip); + virtual ~DeleteClipAction() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr seq; - ClipPtr ref; - int index; + SequencePtr seq; + ClipPtr ref; + int index; - int opening_transition; - int closing_transition; + int opening_transition; + int closing_transition; - QVector linkClipIndex; - QVector linkLinkIndex; + QVector linkClipIndex; + QVector linkLinkIndex; }; class ChangeSequenceAction : public OliveAction { public: - ChangeSequenceAction(SequencePtr s); - virtual void doUndo() override; - virtual void doRedo() override; + ChangeSequenceAction(SequencePtr s); + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr old_sequence; - SequencePtr new_sequence; + SequencePtr old_sequence; + SequencePtr new_sequence; }; class AddEffectCommand : public OliveAction { public: - AddEffectCommand(ClipPtr c, EffectPtr e, const EffectMeta* m, int insert_pos = -1); - virtual void doUndo() override; - virtual void doRedo() override; + AddEffectCommand(ClipPtr c, EffectPtr e, const EffectMeta* m, int insert_pos = -1); + virtual void doUndo() override; + virtual void doRedo() override; private: - ClipPtr clip; - const EffectMeta* meta; - EffectPtr ref; - int pos; - bool done; + ClipPtr clip; + const EffectMeta* meta; + EffectPtr ref; + int pos; + bool done; }; class AddTransitionCommand : public OliveAction { public: - AddTransitionCommand(ClipPtr c, ClipPtr s, TransitionPtr copy, const EffectMeta* itransition, int itype, int ilength); - virtual void doUndo() override; - virtual void doRedo() override; + AddTransitionCommand(ClipPtr c, ClipPtr s, TransitionPtr copy, const EffectMeta* itransition, int itype, int ilength); + virtual void doUndo() override; + virtual void doRedo() override; private: - ClipPtr clip; - ClipPtr secondary; - TransitionPtr transition_to_copy; - const EffectMeta* transition; - int type; - int length; - int old_ptransition; - int old_stransition; + ClipPtr primary; + ClipPtr secondary; + TransitionPtr transition_to_copy; + const EffectMeta* transition_meta_; + int type; + int length; + TransitionPtr old_ptransition; + TransitionPtr old_stransition; }; class ModifyTransitionCommand : public OliveAction { public: - ModifyTransitionCommand(ClipPtr c, int itype, long ilength); - virtual void doUndo() override; - virtual void doRedo() override; + ModifyTransitionCommand(TransitionPtr t, long ilength); + virtual void doUndo() override; + virtual void doRedo() override; private: - ClipPtr clip; - int type; - long new_length; - long old_length; + TransitionPtr transition_ref_; + long new_length_; + long old_length_; }; class DeleteTransitionCommand : public OliveAction { public: - DeleteTransitionCommand(SequencePtr s, int transition_index); - virtual ~DeleteTransitionCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + DeleteTransitionCommand(TransitionPtr t); + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr seq; - int index; - TransitionPtr transition; - ClipPtr otc; - ClipPtr ctc; + TransitionPtr transition_ref_; + ClipPtr opened_clip_; + ClipPtr closed_clip_; }; class SetTimelineInOutCommand : public OliveAction { public: - SetTimelineInOutCommand(SequencePtr s, bool enabled, long in, long out); - virtual void doUndo() override; - virtual void doRedo() override; + SetTimelineInOutCommand(SequencePtr s, bool enabled, long in, long out); + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr seq; + SequencePtr seq; - bool old_enabled; - long old_in; - long old_out; + bool old_enabled; + long old_in; + long old_out; - bool new_enabled; - long new_in; - long new_out; + bool new_enabled; + long new_in; + long new_out; }; class NewSequenceCommand : public OliveAction { public: - NewSequenceCommand(Media* s, Media* iparent); - virtual ~NewSequenceCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + NewSequenceCommand(Media* s, Media* iparent); + virtual ~NewSequenceCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* seq; - Media* parent; - bool done; + Media* seq; + Media* parent; + bool done; }; class AddMediaCommand : public OliveAction { public: - AddMediaCommand(Media* iitem, Media* iparent); - virtual ~AddMediaCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + AddMediaCommand(Media* iitem, Media* iparent); + virtual ~AddMediaCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* item; - Media* parent; - bool done; + Media* item; + Media* parent; + bool done; }; class DeleteMediaCommand : public OliveAction { public: - DeleteMediaCommand(Media *i); - virtual ~DeleteMediaCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + DeleteMediaCommand(Media *i); + virtual ~DeleteMediaCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* item; - Media* parent; - bool done; + Media* item; + Media* parent; + bool done; }; class AddClipCommand : public OliveAction { public: - AddClipCommand(SequencePtr s, QVector& add); - virtual ~AddClipCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + AddClipCommand(SequencePtr s, QVector& add); + virtual ~AddClipCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - SequencePtr seq; - QVector clips; - QVector undone_clips; + SequencePtr seq; + QVector clips; + QVector undone_clips; }; class LinkCommand : public OliveAction { public: - LinkCommand(); - virtual void doUndo() override; - virtual void doRedo() override; - SequencePtr s; - QVector clips; - bool link; + LinkCommand(); + virtual void doUndo() override; + virtual void doRedo() override; + SequencePtr s; + QVector clips; + bool link; private: - QVector< QVector > old_links; + QVector< QVector > old_links; }; class CheckboxCommand : public OliveAction { public: - CheckboxCommand(QCheckBox* b); - virtual ~CheckboxCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; + CheckboxCommand(QCheckBox* b); + virtual ~CheckboxCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - QCheckBox* box; - bool checked; - bool done; + QCheckBox* box; + bool checked; + bool done; }; class ReplaceMediaCommand : public OliveAction { public: - ReplaceMediaCommand(Media*, QString); - virtual void doUndo() override; - virtual void doRedo() override; + ReplaceMediaCommand(Media*, QString); + virtual void doUndo() override; + virtual void doRedo() override; private: - Media *item; - QString old_filename; - QString new_filename; - void replace(QString& filename); + Media *item; + QString old_filename; + QString new_filename; + void replace(QString& filename); }; class ReplaceClipMediaCommand : public OliveAction { public: - ReplaceClipMediaCommand(Media *, Media *, bool); - virtual void doUndo() override; - virtual void doRedo() override; - QVector clips; + ReplaceClipMediaCommand(Media *, Media *, bool); + virtual void doUndo() override; + virtual void doRedo() override; + QVector clips; private: - Media* old_media; - Media* new_media; - bool preserve_clip_ins; - QVector old_clip_ins; - void replace(bool undo); + Media* old_media; + Media* new_media; + bool preserve_clip_ins; + QVector old_clip_ins; + void replace(bool undo); }; class EffectDeleteCommand : public OliveAction { public: - EffectDeleteCommand(); - virtual ~EffectDeleteCommand() override; - virtual void doUndo() override; - virtual void doRedo() override; - QVector clips; - QVector fx; + EffectDeleteCommand(); + virtual ~EffectDeleteCommand() override; + virtual void doUndo() override; + virtual void doRedo() override; + QVector clips; + QVector fx; private: - bool done; - QVector deleted_objects; + bool done; + QVector deleted_objects; }; class MediaMove : public OliveAction { public: - MediaMove(); - QVector items; - Media* to; - virtual void doUndo() override; - virtual void doRedo() override; + MediaMove(); + QVector items; + Media* to; + virtual void doUndo() override; + virtual void doRedo() override; private: - QVector froms; + QVector froms; }; class MediaRename : public OliveAction { public: - MediaRename(Media* iitem, QString to); - virtual void doUndo() override; - virtual void doRedo() override; + MediaRename(Media* iitem, QString to); + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* item; - QString from; - QString to; + Media* item; + QString from; + QString to; }; class KeyframeDelete : public OliveAction { public: - KeyframeDelete(EffectField* ifield, int iindex); - virtual void doUndo() override; - virtual void doRedo() override; + KeyframeDelete(EffectField* ifield, int iindex); + virtual void doUndo() override; + virtual void doRedo() override; private: - EffectField* field; - int index; - bool done; - EffectKeyframe deleted_key; + EffectField* field; + int index; + bool done; + EffectKeyframe deleted_key; }; // a more modern version of the above, could probably replace it // assumes the keyframe already exists class KeyframeFieldSet : public OliveAction { public: - KeyframeFieldSet(EffectField* ifield, int ii); - virtual void doUndo() override; - virtual void doRedo() override; + KeyframeFieldSet(EffectField* ifield, int ii); + virtual void doUndo() override; + virtual void doRedo() override; private: - EffectField* field; - int index; - EffectKeyframe key; - bool done; + EffectField* field; + int index; + EffectKeyframe key; + bool done; }; class EffectFieldUndo : public OliveAction { public: - EffectFieldUndo(EffectField* field); - virtual void doUndo() override; - virtual void doRedo() override; + EffectFieldUndo(EffectField* field); + virtual void doUndo() override; + virtual void doRedo() override; private: - EffectField* field; - QVariant old_val; - QVariant new_val; - bool done; + EffectField* field; + QVariant old_val; + QVariant new_val; + bool done; }; class SetAutoscaleAction : public OliveAction { public: - SetAutoscaleAction(); - virtual void doUndo() override; - virtual void doRedo() override; - QVector clips; + SetAutoscaleAction(); + virtual void doUndo() override; + virtual void doRedo() override; + QVector clips; }; class AddMarkerAction : public OliveAction { public: - AddMarkerAction(QVector* m, long t, QString n); - virtual void doUndo() override; - virtual void doRedo() override; + AddMarkerAction(QVector* m, long t, QString n); + virtual void doUndo() override; + virtual void doRedo() override; private: - QVector* active_array; - long time; - QString name; - QString old_name; - int index; + QVector* active_array; + long time; + QString name; + QString old_name; + int index; }; class MoveMarkerAction : public OliveAction { public: - MoveMarkerAction(Marker* m, long o, long n); - virtual void doUndo() override; - virtual void doRedo() override; + MoveMarkerAction(Marker* m, long o, long n); + virtual void doUndo() override; + virtual void doRedo() override; private: - Marker* marker; - long old_time; - long new_time; + Marker* marker; + long old_time; + long new_time; }; class DeleteMarkerAction : public OliveAction { public: - DeleteMarkerAction(QVector* m); - virtual void doUndo() override; - virtual void doRedo() override; - QVector markers; + DeleteMarkerAction(QVector* m); + virtual void doUndo() override; + virtual void doRedo() override; + QVector markers; private: - QVector* active_array; - QVector copies; - bool sorted; + QVector* active_array; + QVector copies; + bool sorted; }; class SetSpeedAction : public OliveAction { public: - SetSpeedAction(ClipPtr c, double speed); - virtual void doUndo() override; - virtual void doRedo() override; + SetSpeedAction(ClipPtr c, double speed); + virtual void doUndo() override; + virtual void doRedo() override; private: - ClipPtr clip; - double old_speed; - double new_speed; + ClipPtr clip; + double old_speed; + double new_speed; }; class SetBool : public OliveAction { public: - SetBool(bool* b, bool setting); - virtual void doUndo() override; - virtual void doRedo() override; + SetBool(bool* b, bool setting); + virtual void doUndo() override; + virtual void doRedo() override; private: - bool* boolean; - bool old_setting; - bool new_setting; + bool* boolean; + bool old_setting; + bool new_setting; }; class SetSelectionsCommand : public OliveAction { public: - SetSelectionsCommand(SequencePtr s); - virtual void doUndo() override; - virtual void doRedo() override; - QVector old_data; - QVector new_data; + SetSelectionsCommand(SequencePtr s); + virtual void doUndo() override; + virtual void doRedo() override; + QVector old_data; + QVector new_data; private: - SequencePtr seq; - bool done; + SequencePtr seq; + bool done; }; class EditSequenceCommand : public OliveAction { public: - EditSequenceCommand(Media *i, SequencePtr s); - virtual void doUndo() override; - virtual void doRedo() override; - void update(); + EditSequenceCommand(Media *i, SequencePtr s); + virtual void doUndo() override; + virtual void doRedo() override; + void update(); - QString name; - int width; - int height; - double frame_rate; - int audio_frequency; - int audio_layout; + QString name; + int width; + int height; + double frame_rate; + int audio_frequency; + int audio_layout; private: - Media* item; - SequencePtr seq; + Media* item; + SequencePtr seq; - QString old_name; - int old_width; - int old_height; - double old_frame_rate; - int old_audio_frequency; - int old_audio_layout; + QString old_name; + int old_width; + int old_height; + double old_frame_rate; + int old_audio_frequency; + int old_audio_layout; }; class SetInt : public OliveAction { public: - SetInt(int* pointer, int new_value); - virtual void doUndo() override; - virtual void doRedo() override; + SetInt(int* pointer, int new_value); + virtual void doUndo() override; + virtual void doRedo() override; private: - int* p; - int oldval; - int newval; + int* p; + int oldval; + int newval; }; class SetLong : public OliveAction { public: - SetLong(long* pointer, long old_value, long new_value); - virtual void doUndo() override; - virtual void doRedo() override; + SetLong(long* pointer, long old_value, long new_value); + virtual void doUndo() override; + virtual void doRedo() override; private: - long* p; - long oldval; - long newval; + long* p; + long oldval; + long newval; }; class SetDouble : public OliveAction { public: - SetDouble(double* pointer, double old_value, double new_value); - virtual void doUndo() override; - virtual void doRedo() override; + SetDouble(double* pointer, double old_value, double new_value); + virtual void doUndo() override; + virtual void doRedo() override; private: - double* p; - double oldval; - double newval; + double* p; + double oldval; + double newval; }; class SetString : public OliveAction { public: - SetString(QString* pointer, QString new_value); - virtual void doUndo() override; - virtual void doRedo() override; + SetString(QString* pointer, QString new_value); + virtual void doUndo() override; + virtual void doRedo() override; private: - QString* p; - QString oldval; - QString newval; + QString* p; + QString oldval; + QString newval; }; class CloseAllClipsCommand : public OliveAction { public: - virtual void doUndo() override; - virtual void doRedo() override; + virtual void doUndo() override; + virtual void doRedo() override; }; class UpdateFootageTooltip : public OliveAction { public: - UpdateFootageTooltip(Media* i); - virtual void doUndo() override; - virtual void doRedo() override; + UpdateFootageTooltip(Media* i); + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* item; + Media* item; }; class MoveEffectCommand : public OliveAction { public: - MoveEffectCommand(); - virtual void doUndo() override; - virtual void doRedo() override; - ClipPtr clip; - int from; - int to; + MoveEffectCommand(); + virtual void doUndo() override; + virtual void doRedo() override; + ClipPtr clip; + int from; + int to; }; class RemoveClipsFromClipboard : public OliveAction { public: - RemoveClipsFromClipboard(int index); - virtual ~RemoveClipsFromClipboard() override; - virtual void doUndo() override; - virtual void doRedo() override; + RemoveClipsFromClipboard(int index); + virtual ~RemoveClipsFromClipboard() override; + virtual void doUndo() override; + virtual void doRedo() override; private: - int pos; - ClipPtr clip; - bool done; + int pos; + ClipPtr clip; + bool done; }; class RenameClipCommand : public OliveAction { public: - RenameClipCommand(); - QVector clips; - QString new_name; - virtual void doUndo() override; - virtual void doRedo() override; + RenameClipCommand(); + QVector clips; + QString new_name; + virtual void doUndo() override; + virtual void doRedo() override; private: - QVector old_names; + QVector old_names; }; class SetPointer : public OliveAction { public: - SetPointer(void** pointer, void* data); - virtual void doUndo() override; - virtual void doRedo() override; + SetPointer(void** pointer, void* data); + virtual void doUndo() override; + virtual void doRedo() override; private: - bool old_changed; - void** p; - void* new_data; - void* old_data; + bool old_changed; + void** p; + void* new_data; + void* old_data; }; class ReloadEffectsCommand : public OliveAction { public: - virtual void doUndo() override; - virtual void doRedo() override; + virtual void doUndo() override; + virtual void doRedo() override; }; class SetQVariant : public OliveAction { public: - SetQVariant(QVariant* itarget, const QVariant& iold, const QVariant& inew); - virtual void doUndo() override; - virtual void doRedo() override; + SetQVariant(QVariant* itarget, const QVariant& iold, const QVariant& inew); + virtual void doUndo() override; + virtual void doRedo() override; private: - QVariant* target; - QVariant old_val; - QVariant new_val; + QVariant* target; + QVariant old_val; + QVariant new_val; }; class SetKeyframing : public OliveAction { public: - SetKeyframing(EffectRow* irow, bool ib); - virtual void doUndo() override; - virtual void doRedo() override; + SetKeyframing(EffectRow* irow, bool ib); + virtual void doUndo() override; + virtual void doRedo() override; private: - EffectRow* row; - bool b; + EffectRow* row; + bool b; }; class RefreshClips : public OliveAction { public: - RefreshClips(Media* m); - virtual void doUndo() override; - virtual void doRedo() override; + RefreshClips(Media* m); + virtual void doUndo() override; + virtual void doRedo() override; private: - Media* media; + Media* media; }; class UpdateViewer : public OliveAction { public: - virtual void doUndo() override; - virtual void doRedo() override; + virtual void doUndo() override; + virtual void doRedo() override; }; class SetEffectData : public OliveAction { public: - SetEffectData(EffectPtr e, const QByteArray &s); - virtual void doUndo() override; - virtual void doRedo() override; + SetEffectData(EffectPtr e, const QByteArray &s); + virtual void doUndo() override; + virtual void doRedo() override; private: - EffectPtr effect; - QByteArray data; - QByteArray old_data; + EffectPtr effect; + QByteArray data; + QByteArray old_data; }; #endif // UNDO_H diff --git a/ui/renderfunctions.cpp b/ui/renderfunctions.cpp index f00cc915e..d1c732f2a 100644 --- a/ui/renderfunctions.cpp +++ b/ui/renderfunctions.cpp @@ -401,7 +401,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { // run through all of the clip's effects for (int j=0;jeffects.size();j++) { EffectPtr e = c->effects.at(j); - process_effect(c, e, timecode, coords, textureID, fbo_switcher, params.texture_failed, TA_NO_TRANSITION); + process_effect(c, e, timecode, coords, textureID, fbo_switcher, params.texture_failed, kTransitionNone); // retrieve gizmo data from effect if (e->are_gizmos_enabled()) { @@ -421,7 +421,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { if (c->get_opening_transition() != nullptr) { int transition_progress = playhead - c->get_timeline_in_with_transition(); if (transition_progress < c->get_opening_transition()->get_length()) { - process_effect(c, c->get_opening_transition(), double(transition_progress)/double(c->get_opening_transition()->get_length()), coords, textureID, fbo_switcher, params.texture_failed, TA_OPENING_TRANSITION); + process_effect(c, c->get_opening_transition(), double(transition_progress)/double(c->get_opening_transition()->get_length()), coords, textureID, fbo_switcher, params.texture_failed, kTransitionOpening); } } @@ -429,7 +429,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { if (c->get_closing_transition() != nullptr) { int transition_progress = playhead - (c->get_timeline_out_with_transition() - c->get_closing_transition()->get_length()); if (transition_progress >= 0 && transition_progress < c->get_closing_transition()->get_length()) { - process_effect(c, c->get_closing_transition(), double(transition_progress)/double(c->get_closing_transition()->get_length()), coords, textureID, fbo_switcher, params.texture_failed, TA_CLOSING_TRANSITION); + process_effect(c, c->get_closing_transition(), double(transition_progress)/double(c->get_closing_transition()->get_length()), coords, textureID, fbo_switcher, params.texture_failed, kTransitionClosing); } } diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 1d8afcbac..bf3a48987 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -656,7 +656,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); } } - } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER && panel_timeline->transition_select != TA_NO_TRANSITION) { + } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER && panel_timeline->transition_select != kTransitionNone) { panel_timeline->deselect_area(clip->timeline_in, clip->timeline_out, clip->track); for (int i=0;ilinked.size();i++) { @@ -667,11 +667,11 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { Selection s; s.track = clip->track; - if (panel_timeline->transition_select == TA_OPENING_TRANSITION && clip->get_opening_transition() != nullptr) { + if (panel_timeline->transition_select == kTransitionOpening && clip->get_opening_transition() != nullptr) { s.in = clip->timeline_in; if (clip->get_opening_transition()->secondary_clip != nullptr) s.in -= clip->get_opening_transition()->get_true_length(); s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); - } else if (panel_timeline->transition_select == TA_CLOSING_TRANSITION && clip->get_closing_transition() != nullptr) { + } else if (panel_timeline->transition_select == kTransitionClosing && clip->get_closing_transition() != nullptr) { s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); s.out = clip->timeline_out; if (clip->get_closing_transition()->secondary_clip != nullptr) s.out += clip->get_closing_transition()->get_true_length(); @@ -690,12 +690,12 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { s.out = clip->timeline_out; if (panel_timeline->tool == TIMELINE_TOOL_POINTER) { - if (panel_timeline->transition_select == TA_OPENING_TRANSITION) { + if (panel_timeline->transition_select == kTransitionOpening) { s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); if (clip->get_opening_transition()->secondary_clip != nullptr) s.in -= clip->get_opening_transition()->get_true_length(); } - if (panel_timeline->transition_select == TA_CLOSING_TRANSITION) { + if (panel_timeline->transition_select == kTransitionClosing) { s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); if (clip->get_closing_transition()->secondary_clip != nullptr) s.out += clip->get_closing_transition()->get_true_length(); } @@ -709,7 +709,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { } // if alt is not down, select links - if (!alt && panel_timeline->transition_select == TA_NO_TRANSITION) { + if (!alt && panel_timeline->transition_select == kTransitionNone) { for (int i=0;ilinked.size();i++) { ClipPtr link = olive::ActiveSequence->clips.at(clip->linked.at(i)); if (!is_clip_selected(link, true)) { @@ -767,26 +767,26 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { void make_room_for_transition(ComboAction* ca, ClipPtr c, int type, long transition_start, long transition_end, bool delete_old_transitions) { // make room for transition - if (type == TA_OPENING_TRANSITION) { + if (type == kTransitionOpening) { if (delete_old_transitions && c->get_opening_transition() != nullptr) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + ca->append(new DeleteTransitionCommand(c->opening_transition)); } if (c->get_closing_transition() != nullptr) { if (transition_end >= c->timeline_out) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + ca->append(new DeleteTransitionCommand(c->closing_transition)); } else if (transition_end > c->timeline_out - c->get_closing_transition()->get_true_length()) { - ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, c->timeline_out - transition_end)); + ca->append(new ModifyTransitionCommand(c->closing_transition, c->timeline_out - transition_end)); } } } else { if (delete_old_transitions && c->get_closing_transition() != nullptr) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + ca->append(new DeleteTransitionCommand(c->closing_transition)); } if (c->get_opening_transition() != nullptr) { if (transition_start <= c->timeline_in) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + ca->append(new DeleteTransitionCommand(c->opening_transition)); } else if (transition_start < c->timeline_in + c->get_opening_transition()->get_true_length()) { - ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, transition_start - c->timeline_in)); + ca->append(new ModifyTransitionCommand(c->opening_transition, transition_start - c->timeline_in)); } } } @@ -1022,9 +1022,9 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { max_open_length -= c->get_closing_transition()->get_true_length(); } if (max_open_length <= 0) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + ca->append(new DeleteTransitionCommand(c->opening_transition)); } else if (c->get_opening_transition()->get_true_length() > max_open_length) { - ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, max_open_length)); + ca->append(new ModifyTransitionCommand(c->opening_transition, max_open_length)); } } if (c->get_closing_transition() != nullptr) { @@ -1033,16 +1033,16 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { max_open_length -= c->get_opening_transition()->get_true_length(); } if (max_open_length <= 0) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + ca->append(new DeleteTransitionCommand(c->closing_transition)); } else if (c->get_closing_transition()->get_true_length() > max_open_length) { - ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, max_open_length)); + ca->append(new ModifyTransitionCommand(c->closing_transition, max_open_length)); } } } else { bool is_opening_transition = (g.transition == c->get_opening_transition()); long new_transition_length = g.out - g.in; if (g.transition->secondary_clip != nullptr) new_transition_length >>= 1; - ca->append(new ModifyTransitionCommand(c, is_opening_transition ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION, new_transition_length)); + ca->append(new ModifyTransitionCommand(is_opening_transition ? c->opening_transition : c->closing_transition, new_transition_length)); long clip_length = c->getLength(); @@ -1059,7 +1059,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { clip_length -= (g.in - g.old_in); } - make_room_for_transition(ca, c, TA_OPENING_TRANSITION, g.in, g.out, false); + make_room_for_transition(ca, c, kTransitionOpening, g.in, g.out, false); } else { if (g.out != g.old_out) { // if transition is going to make the clip bigger, make the clip bigger @@ -1067,7 +1067,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { clip_length += (g.out - g.old_out); } - make_room_for_transition(ca, c, TA_CLOSING_TRANSITION, g.in, g.out, false); + make_room_for_transition(ca, c, kTransitionClosing, g.in, g.out, false); } } } @@ -1089,7 +1089,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { if (panel_timeline->transition_tool_post_clip > -1) { post = olive::ActiveSequence->clips.at(panel_timeline->transition_tool_post_clip); - int opposite_type = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? TA_CLOSING_TRANSITION : TA_OPENING_TRANSITION; + int opposite_type = (panel_timeline->transition_tool_type == kTransitionOpening) ? kTransitionClosing : kTransitionOpening; make_room_for_transition( ca, post, @@ -1099,7 +1099,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { true ); - if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { + if (panel_timeline->transition_tool_type == kTransitionClosing) { // swap ClipPtr temp = pre; pre = post; @@ -1136,7 +1136,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } if (panel_timeline->transition_tool_post_clip > -1) { - ca->append(new AddTransitionCommand(pre, post, nullptr, panel_timeline->transition_tool_meta, TA_OPENING_TRANSITION, transition_end - pre->timeline_in)); + ca->append(new AddTransitionCommand(pre, post, nullptr, panel_timeline->transition_tool_meta, kTransitionOpening, transition_end - pre->timeline_in)); } else { ca->append(new AddTransitionCommand(pre, nullptr, nullptr, panel_timeline->transition_tool_meta, panel_timeline->transition_tool_type, transition_end - transition_start)); } @@ -1241,7 +1241,7 @@ void TimelineWidget::init_ghosts() { void validate_transitions(ClipPtr c, int transition_type, long& frame_diff) { long validator; - if (transition_type == TA_OPENING_TRANSITION) { + if (transition_type == kTransitionOpening) { // prevent from going below 0 on the timeline validator = c->timeline_in + frame_diff; if (validator < 0) frame_diff -= validator; @@ -1274,7 +1274,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { int mouse_track = getTrackFromScreenPoint(mouse_pos.y()); long frame_diff = (lock_frame) ? 0 : panel_timeline->getTimelineFrameFromScreenPoint(mouse_pos.x()) - panel_timeline->drag_frame_start; - int track_diff = ((effective_tool == TIMELINE_TOOL_SLIDE || panel_timeline->transition_select != TA_NO_TRANSITION) && !panel_timeline->importing) ? 0 : mouse_track - panel_timeline->drag_track_start; + int track_diff = ((effective_tool == TIMELINE_TOOL_SLIDE || panel_timeline->transition_select != kTransitionNone) && !panel_timeline->importing) ? 0 : mouse_track - panel_timeline->drag_track_start; long validator; long earliest_in_point = LONG_MAX; @@ -1389,12 +1389,12 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { frame_diff += g.transition->get_true_length(); } - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + validate_transitions(otc, kTransitionOpening, frame_diff); + validate_transitions(ctc, kTransitionClosing, frame_diff); frame_diff = -frame_diff; - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + validate_transitions(otc, kTransitionOpening, frame_diff); + validate_transitions(ctc, kTransitionClosing, frame_diff); frame_diff = -frame_diff; if (g.trim_in) { @@ -1484,7 +1484,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { ClipPtr otc = c; // open transition clip ClipPtr ctc = olive::ActiveSequence->clips.at(panel_timeline->transition_tool_post_clip); // close transition clip - if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { + if (panel_timeline->transition_tool_type == kTransitionClosing) { // swap ClipPtr temp = otc; otc = ctc; @@ -1492,13 +1492,13 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } // always gets a positive frame_diff - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + validate_transitions(otc, kTransitionOpening, frame_diff); + validate_transitions(ctc, kTransitionClosing, frame_diff); // always gets a negative frame_diff frame_diff = -frame_diff; - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + validate_transitions(otc, kTransitionOpening, frame_diff); + validate_transitions(ctc, kTransitionClosing, frame_diff); frame_diff = -frame_diff; } } @@ -1566,7 +1566,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { if (panel_timeline->transition_tool_post_clip > -1) { g.in = g.old_in - frame_diff; g.out = g.old_out + frame_diff; - } else if (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) { + } else if (panel_timeline->transition_tool_type == kTransitionOpening) { g.out = g.old_out + frame_diff; } else { g.in = g.old_in + frame_diff; @@ -1750,11 +1750,11 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { for (int j=0;jselections.size();j++) { const Selection& s = olive::ActiveSequence->selections.at(j); if (s.track == c->track) { - if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { + if (selection_contains_transition(s, c, kTransitionOpening)) { g.transition = c->get_opening_transition(); add = true; break; - } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { + } else if (selection_contains_transition(s, c, kTransitionClosing)) { g.transition = c->get_closing_transition(); add = true; break; @@ -2049,7 +2049,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { int max_track = INT_MIN; // we default to selecting no transition, but set this accordingly if the cursor is on a transition - panel_timeline->transition_select = TA_NO_TRANSITION; + panel_timeline->transition_select = kTransitionNone; // set currently trimming clip to -1 (aka null) panel_timeline->trim_target = -1; @@ -2081,12 +2081,12 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { if (c->get_opening_transition() != nullptr && panel_timeline->cursor_frame <= c->timeline_in + c->get_opening_transition()->get_true_length()) { - panel_timeline->transition_select = TA_OPENING_TRANSITION; + panel_timeline->transition_select = kTransitionOpening; } else if (c->get_closing_transition() != nullptr && panel_timeline->cursor_frame >= c->timeline_out - c->get_closing_transition()->get_true_length()) { - panel_timeline->transition_select = TA_CLOSING_TRANSITION; + panel_timeline->transition_select = kTransitionClosing; } } @@ -2145,7 +2145,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { if (nc < closeness) { panel_timeline->trim_target = i; panel_timeline->trim_in_point = false; - panel_timeline->transition_select = TA_OPENING_TRANSITION; + panel_timeline->transition_select = kTransitionOpening; closeness = nc; found = true; } @@ -2166,7 +2166,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { if (nc < closeness) { panel_timeline->trim_target = i; panel_timeline->trim_in_point = true; - panel_timeline->transition_select = TA_CLOSING_TRANSITION; + panel_timeline->transition_select = kTransitionClosing; closeness = nc; found = true; } @@ -2234,7 +2234,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { Ghost g; - g.in = g.old_in = g.out = g.old_out = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? c->timeline_in : c->timeline_out; + g.in = g.old_in = g.out = g.old_out = (panel_timeline->transition_tool_type == kTransitionOpening) ? c->timeline_in : c->timeline_out; g.track = c->track; g.clip = panel_timeline->transition_tool_pre_clip; g.media_stream = panel_timeline->transition_tool_type; @@ -2254,9 +2254,9 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { long between_range = getFrameFromScreenPoint(panel_timeline->zoom, TRANSITION_BETWEEN_RANGE) + 1; if (panel_timeline->cursor_frame > halfway) { - panel_timeline->transition_tool_type = TA_CLOSING_TRANSITION; + panel_timeline->transition_tool_type = kTransitionClosing; } else { - panel_timeline->transition_tool_type = TA_OPENING_TRANSITION; + panel_timeline->transition_tool_type = kTransitionOpening; } panel_timeline->transition_tool_post_clip = -1; @@ -2334,14 +2334,14 @@ void draw_waveform(ClipPtr clip, const FootageStream* ms, long media_length, QPa } void draw_transition(QPainter& p, ClipPtr c, const QRect& clip_rect, QRect& text_rect, int transition_type) { - TransitionPtr t = (transition_type == TA_OPENING_TRANSITION) ? c->get_opening_transition() : c->get_closing_transition(); + TransitionPtr t = (transition_type == kTransitionOpening) ? c->get_opening_transition() : c->get_closing_transition(); if (t != nullptr) { QColor transition_color(255, 0, 0, 16); int transition_width = getScreenPointFromFrame(panel_timeline->zoom, t->get_true_length()); int transition_height = clip_rect.height(); int tr_y = clip_rect.y(); int tr_x = 0; - if (transition_type == TA_OPENING_TRANSITION) { + if (transition_type == kTransitionOpening) { tr_x = clip_rect.x(); text_rect.setX(text_rect.x()+transition_width); } else { @@ -2356,13 +2356,13 @@ void draw_transition(QPainter& p, ClipPtr c, const QRect& clip_rect, QRect& text p.setPen(QColor(0, 0, 0, 96)); if (t->secondary_clip == nullptr) { - if (transition_type == TA_OPENING_TRANSITION) { + if (transition_type == kTransitionOpening) { p.drawLine(transition_rect.bottomLeft(), transition_rect.topRight()); } else { p.drawLine(transition_rect.topLeft(), transition_rect.bottomRight()); } } else { - if (transition_type == TA_OPENING_TRANSITION) { + if (transition_type == kTransitionOpening) { p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.topRight()); p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.bottomRight()); draw_text = false; @@ -2577,8 +2577,8 @@ void TimelineWidget::paintEvent(QPaintEvent*) { p.setBrush(Qt::NoBrush); // draw clip transitions - draw_transition(p, clip, clip_rect, text_rect, TA_OPENING_TRANSITION); - draw_transition(p, clip, clip_rect, text_rect, TA_CLOSING_TRANSITION); + draw_transition(p, clip, clip_rect, text_rect, kTransitionOpening); + draw_transition(p, clip, clip_rect, text_rect, kTransitionClosing); // top left bevel p.setPen(Qt::white); @@ -2617,10 +2617,10 @@ void TimelineWidget::paintEvent(QPaintEvent*) { int type = panel_timeline->transition_tool_type; if (panel_timeline->transition_tool_post_clip == i) { // invert transition type - type = (type == TA_CLOSING_TRANSITION) ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION; + type = (type == kTransitionClosing) ? kTransitionOpening : kTransitionClosing; } QRect transition_tool_rect = clip_rect; - if (type == TA_CLOSING_TRANSITION) { + if (type == kTransitionClosing) { if (panel_timeline->transition_tool_post_clip > -1) { transition_tool_rect.setLeft(transition_tool_rect.right() - TRANSITION_BETWEEN_RANGE); } else {