diff --git a/dialogs/mediapropertiesdialog.cpp b/dialogs/mediapropertiesdialog.cpp index b004e3fdf..591794cd4 100644 --- a/dialogs/mediapropertiesdialog.cpp +++ b/dialogs/mediapropertiesdialog.cpp @@ -47,7 +47,7 @@ MediaPropertiesDialog::MediaPropertiesDialog(QWidget *parent, Media *i) : int row = 0; - Footage* f = item->to_footage(); + FootagePtr f = item->to_footage(); grid->addWidget(new QLabel(tr("Tracks:"), this), row, 0, 1, 2); row++; @@ -143,7 +143,7 @@ MediaPropertiesDialog::MediaPropertiesDialog(QWidget *parent, Media *i) : } void MediaPropertiesDialog::accept() { - Footage* f = item->to_footage(); + FootagePtr f = item->to_footage(); ComboAction* ca = new ComboAction(); diff --git a/dialogs/mediapropertiesdialog.h b/dialogs/mediapropertiesdialog.h index a2e63da8b..8f24eee72 100644 --- a/dialogs/mediapropertiesdialog.h +++ b/dialogs/mediapropertiesdialog.h @@ -34,11 +34,11 @@ class MediaPropertiesDialog : public QDialog { Q_OBJECT public: - MediaPropertiesDialog(QWidget *parent, Media* i); + MediaPropertiesDialog(QWidget *parent, Media* i); private: QComboBox* interlacing_box; QLineEdit* name_box; - Media* item; + Media* item; QListWidget* track_list; QDoubleSpinBox* conform_fr; QCheckBox* premultiply_alpha_setting; diff --git a/dialogs/newsequencedialog.cpp b/dialogs/newsequencedialog.cpp index 3b4e48457..19ce423ac 100644 --- a/dialogs/newsequencedialog.cpp +++ b/dialogs/newsequencedialog.cpp @@ -85,7 +85,7 @@ void NewSequenceDialog::set_sequence_name(const QString& s) { void NewSequenceDialog::create() { if (existing_sequence == nullptr) { - Sequence* s = new Sequence(); + SequencePtr s(new Sequence()); s->name = sequence_name_edit->text(); s->width = width_numeric->value(); @@ -112,7 +112,7 @@ void NewSequenceDialog::create() { ca->append(esc); for (int i=0;iclips.size();i++) { - Clip* c = existing_sequence->clips.at(i); + ClipPtr c = existing_sequence->clips.at(i); if (c != nullptr) { c->refactor_frame_rate(ca, multiplier, true); } diff --git a/dialogs/newsequencedialog.h b/dialogs/newsequencedialog.h index f9d5164c6..8638b0e99 100644 --- a/dialogs/newsequencedialog.h +++ b/dialogs/newsequencedialog.h @@ -35,7 +35,7 @@ class NewSequenceDialog : public QDialog Q_OBJECT public: - explicit NewSequenceDialog(QWidget *parent = 0, Media* existing = 0); + explicit NewSequenceDialog(QWidget *parent = nullptr, Media* existing = nullptr); ~NewSequenceDialog(); void set_sequence_name(const QString& s); @@ -45,8 +45,8 @@ private slots: void preset_changed(int index); private: - Sequence* existing_sequence; - Media* existing_item; + SequencePtr existing_sequence; + Media* existing_item; void setup_ui(); diff --git a/dialogs/proxydialog.cpp b/dialogs/proxydialog.cpp index 4c989f466..033ee7256 100644 --- a/dialogs/proxydialog.cpp +++ b/dialogs/proxydialog.cpp @@ -32,7 +32,7 @@ #include "project/footage.h" #include "mainwindow.h" -ProxyDialog::ProxyDialog(QWidget *parent, const QVector &footage) : +ProxyDialog::ProxyDialog(QWidget *parent, const QVector &footage) : QDialog(parent), selected_footage(footage) { diff --git a/dialogs/proxydialog.h b/dialogs/proxydialog.h index d8917be54..3c283385b 100644 --- a/dialogs/proxydialog.h +++ b/dialogs/proxydialog.h @@ -30,7 +30,7 @@ class ProxyDialog : public QDialog { Q_OBJECT public: - ProxyDialog(QWidget* parent, const QVector& footage); + ProxyDialog(QWidget* parent, const QVector& footage); public slots: // called if user clicks "OK" on the dialog virtual void accept() override; @@ -51,7 +51,7 @@ private: QString proxy_folder_name; // list of footage to make proxies for - QVector selected_footage; + QVector selected_footage; private slots: // triggered when the user changes the index in the location combobox void location_changed(int i); diff --git a/dialogs/replaceclipmediadialog.cpp b/dialogs/replaceclipmediadialog.cpp index e9d5c2739..7a4cdc2c2 100644 --- a/dialogs/replaceclipmediadialog.cpp +++ b/dialogs/replaceclipmediadialog.cpp @@ -31,7 +31,7 @@ #include #include -ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, Media *old_media) : +ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, Media* old_media) : QDialog(parent), media(old_media) { @@ -80,7 +80,7 @@ void ReplaceClipMediaDialog::replace() { QMessageBox::Ok ); } else { - Media* new_item = static_cast(selected_items.at(0).internalPointer()); + Media* new_item = static_cast(selected_items.at(0).internalPointer()); if (media == new_item) { QMessageBox::critical( this, @@ -111,7 +111,7 @@ void ReplaceClipMediaDialog::replace() { ); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && c->media == media) { rcmc->clips.append(c); } diff --git a/dialogs/replaceclipmediadialog.h b/dialogs/replaceclipmediadialog.h index 1971579f4..7b1867a71 100644 --- a/dialogs/replaceclipmediadialog.h +++ b/dialogs/replaceclipmediadialog.h @@ -31,11 +31,11 @@ class ReplaceClipMediaDialog : public QDialog { Q_OBJECT public: - ReplaceClipMediaDialog(QWidget* parent, Media *old_media); + ReplaceClipMediaDialog(QWidget* parent, Media* old_media); private slots: void replace(); private: - Media* media; + Media* media; QTreeView* tree; QCheckBox* use_same_media_in_points; }; diff --git a/dialogs/speeddialog.cpp b/dialogs/speeddialog.cpp index 76dac52c8..cfa69f777 100644 --- a/dialogs/speeddialog.cpp +++ b/dialogs/speeddialog.cpp @@ -94,7 +94,7 @@ void SpeedDialog::run() { current_length = -1; for (int i=0;itrack < 0) { bool process_video = true; if (c->media != nullptr && c->media->get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* m = c->media->to_footage(); + FootagePtr m = c->media->to_footage(); FootageStream* ms = m->get_stream_from_file_index(true, c->media_stream); if (ms != nullptr && ms->infinite_length) { process_video = false; @@ -187,7 +187,7 @@ void SpeedDialog::percent_update() { long len_val = -1; for (int i=0;iisEnabled() && c->track < 0) { @@ -222,7 +222,7 @@ void SpeedDialog::duration_update() { double fr_val = qSNaN(); for (int i=0;igetLength() * c->speed); @@ -265,7 +265,7 @@ void SpeedDialog::frame_rate_update() { // analyze video clips for (int i=0;itrack >= 0) { long new_clip_len = (qIsNaN(old_pc_val) || qIsNaN(pc_val)) ? c->getLength() : ((c->getLength() * c->speed) / pc_val); @@ -312,7 +312,7 @@ void SpeedDialog::frame_rate_update() { duration->set_value((len_val == -1) ? qSNaN() : len_val, false); } -void set_speed(ComboAction* ca, Clip* c, double speed, bool ripple, long& ep, long& lr) { +void set_speed(ComboAction* ca, ClipPtr c, double speed, bool ripple, long& ep, long& lr) { panel_timeline->deselect_area(c->timeline_in, c->timeline_out, c->track); long proposed_out = c->timeline_out; @@ -321,7 +321,7 @@ void set_speed(ComboAction* ca, Clip* c, double speed, bool ripple, long& ep, lo ca->append(new SetSpeedAction(c, speed)); if (!ripple && proposed_out > c->timeline_out) { for (int i=0;isequence->clips.size();i++) { - Clip* compare = c->sequence->clips.at(i); + ClipPtr compare = c->sequence->clips.at(i); if (compare != nullptr && compare->track == c->track && compare->timeline_in >= c->timeline_out && compare->timeline_in < proposed_out) { @@ -352,7 +352,7 @@ void SpeedDialog::accept() { long longest_ripple = LONG_MIN; for (int i=0;iopen) close_clip(c, true); if (c->track >= 0 @@ -372,7 +372,7 @@ void SpeedDialog::accept() { if (!qIsNaN(percent->value())) { // simply set speed for (int i=0;ivalue(), ripple->isChecked(), earliest_point, longest_ripple); } } else if (!qIsNaN(frame_rate->value())) { @@ -382,7 +382,7 @@ void SpeedDialog::accept() { // see if we can use the frame rate to change all the speeds for (int i=0;ispeed; } else if (!qFuzzyCompare(cached_speed, c->speed)) { @@ -400,7 +400,7 @@ void SpeedDialog::accept() { // make changes for (int i=0;itrack < 0) { set_speed(ca, c, frame_rate->value() / c->getMediaFrameRate(), ripple->isChecked(), earliest_point, longest_ripple); } else if (can_change_all) { @@ -410,7 +410,7 @@ void SpeedDialog::accept() { } else if (!qIsNaN(duration->value())) { // simply set duration for (int i=0;igetLength() * c->speed) / duration->value(), ripple->isChecked(), earliest_point, longest_ripple); } } diff --git a/dialogs/speeddialog.h b/dialogs/speeddialog.h index 1da29af83..9f355377a 100644 --- a/dialogs/speeddialog.h +++ b/dialogs/speeddialog.h @@ -32,7 +32,7 @@ class SpeedDialog : public QDialog Q_OBJECT public: SpeedDialog(QWidget* parent = 0); - QVector clips; + QVector clips; void run(); private slots: diff --git a/effects/internal/audionoiseeffect.cpp b/effects/internal/audionoiseeffect.cpp index d43fd5545..00afe04c8 100644 --- a/effects/internal/audionoiseeffect.cpp +++ b/effects/internal/audionoiseeffect.cpp @@ -23,7 +23,7 @@ #include #include -AudioNoiseEffect::AudioNoiseEffect(Clip* c, const EffectMeta *em) : Effect(c, em) { +AudioNoiseEffect::AudioNoiseEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { amount_val = add_row(tr("Amount"))->add_field(EFFECT_FIELD_DOUBLE, "amount"); amount_val->set_double_minimum_value(0); amount_val->set_double_maximum_value(100); diff --git a/effects/internal/audionoiseeffect.h b/effects/internal/audionoiseeffect.h index e06789213..ea0e47dcb 100644 --- a/effects/internal/audionoiseeffect.h +++ b/effects/internal/audionoiseeffect.h @@ -26,7 +26,7 @@ class AudioNoiseEffect : public Effect { Q_OBJECT public: - AudioNoiseEffect(Clip* c, const EffectMeta* em); + AudioNoiseEffect(ClipPtr c, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); EffectField* amount_val; diff --git a/effects/internal/cornerpineffect.cpp b/effects/internal/cornerpineffect.cpp index c076e2313..baf8194ef 100644 --- a/effects/internal/cornerpineffect.cpp +++ b/effects/internal/cornerpineffect.cpp @@ -24,7 +24,7 @@ #include "project/clip.h" #include "debug.h" -CornerPinEffect::CornerPinEffect(Clip *c, const EffectMeta *em) : Effect(c, em) { +CornerPinEffect::CornerPinEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { enable_coords = true; enable_shader = true; diff --git a/effects/internal/cornerpineffect.h b/effects/internal/cornerpineffect.h index 61b38fef2..711571b96 100644 --- a/effects/internal/cornerpineffect.h +++ b/effects/internal/cornerpineffect.h @@ -26,7 +26,7 @@ class CornerPinEffect : public Effect { Q_OBJECT public: - CornerPinEffect(Clip* c, const EffectMeta* em); + CornerPinEffect(ClipPtr c, const EffectMeta* em); void process_coords(double timecode, GLTextureCoords& coords, int data); void process_shader(double timecode, GLTextureCoords& coords, int iterations); void gizmo_draw(double timecode, GLTextureCoords& coords); diff --git a/effects/internal/crossdissolvetransition.cpp b/effects/internal/crossdissolvetransition.cpp index 92e74f510..2e0a01600 100644 --- a/effects/internal/crossdissolvetransition.cpp +++ b/effects/internal/crossdissolvetransition.cpp @@ -22,7 +22,7 @@ #include -CrossDissolveTransition::CrossDissolveTransition(Clip* c, Clip* s, const EffectMeta* em) : Transition(c, s, em) { +CrossDissolveTransition::CrossDissolveTransition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Transition(c, s, em) { enable_coords = true; // add_row("Smooth")->add_field(EFFECT_FIELD_BOOL, "smooth"); diff --git a/effects/internal/crossdissolvetransition.h b/effects/internal/crossdissolvetransition.h index 3dd8e6e44..427b3e18b 100644 --- a/effects/internal/crossdissolvetransition.h +++ b/effects/internal/crossdissolvetransition.h @@ -25,7 +25,7 @@ class CrossDissolveTransition : public Transition { public: - CrossDissolveTransition(Clip* c, Clip* s, const EffectMeta* em); + CrossDissolveTransition(ClipPtr c, ClipPtr s, const EffectMeta* em); void process_coords(double timecode, GLTextureCoords &, int data); }; diff --git a/effects/internal/cubetransition.cpp b/effects/internal/cubetransition.cpp index 829ad820d..74b79d780 100644 --- a/effects/internal/cubetransition.cpp +++ b/effects/internal/cubetransition.cpp @@ -22,7 +22,7 @@ #include "debug.h" -CubeTransition::CubeTransition(Clip* c, Clip* s, const EffectMeta* em) : Transition(c, s, em) { +CubeTransition::CubeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Transition(c, s, em) { enable_coords = true; } diff --git a/effects/internal/cubetransition.h b/effects/internal/cubetransition.h index 82519ad03..05f23b306 100644 --- a/effects/internal/cubetransition.h +++ b/effects/internal/cubetransition.h @@ -25,7 +25,7 @@ class CubeTransition : public Transition { public: - CubeTransition(Clip* c, Clip* s, const EffectMeta* em); + CubeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em); void process_coords(double timecode, GLTextureCoords &, int data); }; diff --git a/effects/internal/exponentialfadetransition.cpp b/effects/internal/exponentialfadetransition.cpp index 7c71d5bfc..be558d7cd 100644 --- a/effects/internal/exponentialfadetransition.cpp +++ b/effects/internal/exponentialfadetransition.cpp @@ -22,7 +22,7 @@ #include -ExponentialFadeTransition::ExponentialFadeTransition(Clip* c, Clip* s, const EffectMeta* em) : Transition(c, s, em) {} +ExponentialFadeTransition::ExponentialFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Transition(c, s, em) {} void ExponentialFadeTransition::process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int type) { double interval = (timecode_end-timecode_start)/nb_bytes; diff --git a/effects/internal/exponentialfadetransition.h b/effects/internal/exponentialfadetransition.h index 36ec7f6f1..1fcca50bb 100644 --- a/effects/internal/exponentialfadetransition.h +++ b/effects/internal/exponentialfadetransition.h @@ -25,7 +25,7 @@ class ExponentialFadeTransition : public Transition { public: - ExponentialFadeTransition(Clip* c, Clip* s, const EffectMeta* em); + ExponentialFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); }; diff --git a/effects/internal/fillleftrighteffect.cpp b/effects/internal/fillleftrighteffect.cpp index e6e687839..8d0326042 100644 --- a/effects/internal/fillleftrighteffect.cpp +++ b/effects/internal/fillleftrighteffect.cpp @@ -23,7 +23,7 @@ #define FILL_TYPE_LEFT 0 #define FILL_TYPE_RIGHT 1 -FillLeftRightEffect::FillLeftRightEffect(Clip* c, const EffectMeta *em) : Effect(c, em) { +FillLeftRightEffect::FillLeftRightEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { EffectRow* type_row = add_row(tr("Type")); fill_type = type_row->add_field(EFFECT_FIELD_COMBO, "type"); fill_type->add_combo_item(tr("Fill Left with Right"), FILL_TYPE_LEFT); diff --git a/effects/internal/fillleftrighteffect.h b/effects/internal/fillleftrighteffect.h index 49e72c44a..d37f0d3e2 100644 --- a/effects/internal/fillleftrighteffect.h +++ b/effects/internal/fillleftrighteffect.h @@ -26,7 +26,7 @@ class FillLeftRightEffect : public Effect { Q_OBJECT public: - FillLeftRightEffect(Clip* c, const EffectMeta* em); + FillLeftRightEffect(ClipPtr c, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); private: EffectField* fill_type; diff --git a/effects/internal/frei0reffect.cpp b/effects/internal/frei0reffect.cpp index efa393bb0..b2cf0c1a7 100644 --- a/effects/internal/frei0reffect.cpp +++ b/effects/internal/frei0reffect.cpp @@ -37,7 +37,7 @@ typedef void (*f0rGetPluginInfo)(f0r_plugin_info_t* info); typedef void (*f0rSetParamValue) (f0r_instance_t instance, f0r_param_t param, int param_index); -Frei0rEffect::Frei0rEffect(Clip *c, const EffectMeta *em) : +Frei0rEffect::Frei0rEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em), open(false) { diff --git a/effects/internal/frei0reffect.h b/effects/internal/frei0reffect.h index daa546622..b197fff5a 100644 --- a/effects/internal/frei0reffect.h +++ b/effects/internal/frei0reffect.h @@ -35,7 +35,7 @@ typedef void (*f0rGetParamInfo)(f0r_param_info_t * info, class Frei0rEffect : public Effect { Q_OBJECT public: - Frei0rEffect(Clip* c, const EffectMeta* em); + Frei0rEffect(ClipPtr c, const EffectMeta* em); ~Frei0rEffect(); virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size); diff --git a/effects/internal/linearfadetransition.cpp b/effects/internal/linearfadetransition.cpp index 73ab8a44b..5cfb5edb7 100644 --- a/effects/internal/linearfadetransition.cpp +++ b/effects/internal/linearfadetransition.cpp @@ -20,7 +20,7 @@ #include "linearfadetransition.h" -LinearFadeTransition::LinearFadeTransition(Clip* c, Clip* s, const EffectMeta* em) : Transition(c, s, em) {} +LinearFadeTransition::LinearFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Transition(c, s, em) {} void LinearFadeTransition::process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int type) { double interval = (timecode_end-timecode_start)/nb_bytes; diff --git a/effects/internal/linearfadetransition.h b/effects/internal/linearfadetransition.h index f3716753a..b4d2bbae3 100644 --- a/effects/internal/linearfadetransition.h +++ b/effects/internal/linearfadetransition.h @@ -25,7 +25,7 @@ class LinearFadeTransition : public Transition { public: - LinearFadeTransition(Clip* c, Clip* s, const EffectMeta* em); + LinearFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); }; diff --git a/effects/internal/logarithmicfadetransition.cpp b/effects/internal/logarithmicfadetransition.cpp index 53cd4934c..4da914e9f 100644 --- a/effects/internal/logarithmicfadetransition.cpp +++ b/effects/internal/logarithmicfadetransition.cpp @@ -22,7 +22,7 @@ #include -LogarithmicFadeTransition::LogarithmicFadeTransition(Clip* c, Clip* s, const EffectMeta* em) : Transition(c, s, em) {} +LogarithmicFadeTransition::LogarithmicFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Transition(c, s, em) {} void LogarithmicFadeTransition::process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int type) { double interval = (timecode_end-timecode_start)/nb_bytes; diff --git a/effects/internal/logarithmicfadetransition.h b/effects/internal/logarithmicfadetransition.h index a476351d1..66ac0014a 100644 --- a/effects/internal/logarithmicfadetransition.h +++ b/effects/internal/logarithmicfadetransition.h @@ -25,7 +25,7 @@ class LogarithmicFadeTransition : public Transition { public: - LogarithmicFadeTransition(Clip* c, Clip* s, const EffectMeta* em); + LogarithmicFadeTransition(ClipPtr c, ClipPtr s, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); }; diff --git a/effects/internal/paneffect.cpp b/effects/internal/paneffect.cpp index babb0b01b..d3318838e 100644 --- a/effects/internal/paneffect.cpp +++ b/effects/internal/paneffect.cpp @@ -28,7 +28,7 @@ #include "ui/labelslider.h" #include "ui/collapsiblewidget.h" -PanEffect::PanEffect(Clip* c, const EffectMeta *em) : Effect(c, em) { +PanEffect::PanEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { EffectRow* pan_row = add_row(tr("Pan")); pan_val = pan_row->add_field(EFFECT_FIELD_DOUBLE, "pan"); pan_val->set_double_minimum_value(-100); diff --git a/effects/internal/paneffect.h b/effects/internal/paneffect.h index f5cee94e0..8ac4c3903 100644 --- a/effects/internal/paneffect.h +++ b/effects/internal/paneffect.h @@ -26,7 +26,7 @@ class PanEffect : public Effect { Q_OBJECT public: - PanEffect(Clip* c, const EffectMeta* em); + PanEffect(ClipPtr c, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); EffectField* pan_val; diff --git a/effects/internal/shakeeffect.cpp b/effects/internal/shakeeffect.cpp index 0960a0e74..275eabeea 100644 --- a/effects/internal/shakeeffect.cpp +++ b/effects/internal/shakeeffect.cpp @@ -33,7 +33,7 @@ #include "debug.h" -ShakeEffect::ShakeEffect(Clip *c, const EffectMeta *em) : Effect(c, em) { +ShakeEffect::ShakeEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { enable_coords = true; EffectRow* intensity_row = add_row(tr("Intensity")); diff --git a/effects/internal/shakeeffect.h b/effects/internal/shakeeffect.h index ff969754a..b162ab3bf 100644 --- a/effects/internal/shakeeffect.h +++ b/effects/internal/shakeeffect.h @@ -28,7 +28,7 @@ class ShakeEffect : public Effect { Q_OBJECT public: - ShakeEffect(Clip* c, const EffectMeta* em); + ShakeEffect(ClipPtr c, const EffectMeta* em); void process_coords(double timecode, GLTextureCoords& coords, int data); EffectField* intensity_val; diff --git a/effects/internal/solideffect.cpp b/effects/internal/solideffect.cpp index a3077852b..cf09eee63 100644 --- a/effects/internal/solideffect.cpp +++ b/effects/internal/solideffect.cpp @@ -38,7 +38,7 @@ #define SMPTE_STRIP_COUNT 3 #define SMPTE_LOWER_BARS 4 -SolidEffect::SolidEffect(Clip* c, const EffectMeta* em) : Effect(c, em) { +SolidEffect::SolidEffect(ClipPtr c, const EffectMeta* em) : Effect(c, em) { enable_superimpose = true; solid_type = add_row(tr("Type"))->add_field(EFFECT_FIELD_COMBO, "type"); diff --git a/effects/internal/solideffect.h b/effects/internal/solideffect.h index 309098c58..66ad89a58 100644 --- a/effects/internal/solideffect.h +++ b/effects/internal/solideffect.h @@ -28,7 +28,7 @@ class SolidEffect : public Effect { Q_OBJECT public: - SolidEffect(Clip* c, const EffectMeta *em); + SolidEffect(ClipPtr c, const EffectMeta *em); void redraw(double timecode); private slots: void ui_update(int); diff --git a/effects/internal/texteffect.cpp b/effects/internal/texteffect.cpp index 3c4a88504..871a8b4c8 100644 --- a/effects/internal/texteffect.cpp +++ b/effects/internal/texteffect.cpp @@ -44,7 +44,7 @@ #include "io/config.h" #include "mainwindow.h" -TextEffect::TextEffect(Clip *c, const EffectMeta* em) : +TextEffect::TextEffect(ClipPtr c, const EffectMeta* em) : Effect(c, em) { enable_superimpose = true; diff --git a/effects/internal/texteffect.h b/effects/internal/texteffect.h index e07ea1695..0d6c89237 100644 --- a/effects/internal/texteffect.h +++ b/effects/internal/texteffect.h @@ -29,7 +29,7 @@ class TextEffect : public Effect { Q_OBJECT public: - TextEffect(Clip* c, const EffectMeta *em); + TextEffect(ClipPtr c, const EffectMeta *em); void redraw(double timecode); EffectField* text_val; diff --git a/effects/internal/timecodeeffect.cpp b/effects/internal/timecodeeffect.cpp index 16e012741..e8ba340f0 100644 --- a/effects/internal/timecodeeffect.cpp +++ b/effects/internal/timecodeeffect.cpp @@ -44,7 +44,7 @@ #include "io/config.h" #include "playback/playback.h" -TimecodeEffect::TimecodeEffect(Clip *c, const EffectMeta* em) : +TimecodeEffect::TimecodeEffect(ClipPtr c, const EffectMeta* em) : Effect(c, em) { enable_always_update = true; diff --git a/effects/internal/timecodeeffect.h b/effects/internal/timecodeeffect.h index 2caeb3276..8cae99a8b 100644 --- a/effects/internal/timecodeeffect.h +++ b/effects/internal/timecodeeffect.h @@ -29,7 +29,7 @@ class TimecodeEffect : public Effect { Q_OBJECT public: - TimecodeEffect(Clip* c, const EffectMeta *em); + TimecodeEffect(ClipPtr c, const EffectMeta *em); void redraw(double timecode); EffectField * scale_val; EffectField * color_val; diff --git a/effects/internal/toneeffect.cpp b/effects/internal/toneeffect.cpp index 777c3e878..112a700e4 100644 --- a/effects/internal/toneeffect.cpp +++ b/effects/internal/toneeffect.cpp @@ -28,7 +28,7 @@ #include "project/sequence.h" #include "debug.h" -ToneEffect::ToneEffect(Clip* c, const EffectMeta *em) : Effect(c, em), sinX(INT_MIN) { +ToneEffect::ToneEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em), sinX(INT_MIN) { type_val = add_row(tr("Type"))->add_field(EFFECT_FIELD_COMBO, "type"); type_val->add_combo_item("Sine", TONE_TYPE_SINE); diff --git a/effects/internal/toneeffect.h b/effects/internal/toneeffect.h index fecef2c97..ec4e17622 100644 --- a/effects/internal/toneeffect.h +++ b/effects/internal/toneeffect.h @@ -26,7 +26,7 @@ class ToneEffect : public Effect { Q_OBJECT public: - ToneEffect(Clip *c, const EffectMeta* em); + ToneEffect(ClipPtr c, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); EffectField* type_val; diff --git a/effects/internal/transformeffect.cpp b/effects/internal/transformeffect.cpp index 07dd08d3f..458d03e31 100644 --- a/effects/internal/transformeffect.cpp +++ b/effects/internal/transformeffect.cpp @@ -43,7 +43,7 @@ #include "panels/viewer.h" #include "ui/viewerwidget.h" -TransformEffect::TransformEffect(Clip* c, const EffectMeta* em) : Effect(c, em) { +TransformEffect::TransformEffect(ClipPtr c, const EffectMeta* em) : Effect(c, em) { enable_coords = true; EffectRow* position_row = add_row(tr("Position")); diff --git a/effects/internal/transformeffect.h b/effects/internal/transformeffect.h index 6a7d483f9..969f76fc6 100644 --- a/effects/internal/transformeffect.h +++ b/effects/internal/transformeffect.h @@ -26,7 +26,7 @@ class TransformEffect : public Effect { Q_OBJECT public: - TransformEffect(Clip* c, const EffectMeta* em); + TransformEffect(ClipPtr c, const EffectMeta* em); void refresh(); void process_coords(double timecode, GLTextureCoords& coords, int data); diff --git a/effects/internal/voideffect.cpp b/effects/internal/voideffect.cpp index 95acc9442..8a898d772 100644 --- a/effects/internal/voideffect.cpp +++ b/effects/internal/voideffect.cpp @@ -27,7 +27,7 @@ #include "ui/collapsiblewidget.h" #include "debug.h" -VoidEffect::VoidEffect(Clip *c, const QString& n) : Effect(c, nullptr) { +VoidEffect::VoidEffect(ClipPtr c, const QString& n) : Effect(c, nullptr) { name = n; QString display_name; if (n.isEmpty()) { @@ -43,8 +43,8 @@ VoidEffect::VoidEffect(Clip *c, const QString& n) : Effect(c, nullptr) { meta = &void_meta; } -Effect *VoidEffect::copy(Clip *c) { - Effect* copy = new VoidEffect(c, name); +EffectPtr VoidEffect::copy(ClipPtr c) { + EffectPtr copy(new VoidEffect(c, name)); copy->set_enabled(is_enabled()); copy_field_keyframes(copy); return copy; diff --git a/effects/internal/voideffect.h b/effects/internal/voideffect.h index 668713740..b30dd9a59 100644 --- a/effects/internal/voideffect.h +++ b/effects/internal/voideffect.h @@ -32,9 +32,9 @@ class VoidEffect : public Effect { Q_OBJECT public: - VoidEffect(Clip* c, const QString& n); + VoidEffect(ClipPtr c, const QString& n); - virtual Effect* copy(Clip* c) override; + virtual EffectPtr copy(ClipPtr c) override; virtual void load(QXmlStreamReader &stream) override; virtual void save(QXmlStreamWriter &stream) override; private: diff --git a/effects/internal/volumeeffect.cpp b/effects/internal/volumeeffect.cpp index 23cf1a45f..17caa6e36 100644 --- a/effects/internal/volumeeffect.cpp +++ b/effects/internal/volumeeffect.cpp @@ -28,7 +28,7 @@ #include "ui/labelslider.h" #include "ui/collapsiblewidget.h" -VolumeEffect::VolumeEffect(Clip* c, const EffectMeta *em) : Effect(c, em) { +VolumeEffect::VolumeEffect(ClipPtr c, const EffectMeta *em) : Effect(c, em) { EffectRow* volume_row = add_row(tr("Volume")); volume_val = volume_row->add_field(EFFECT_FIELD_DOUBLE, "volume"); diff --git a/effects/internal/volumeeffect.h b/effects/internal/volumeeffect.h index c5ca0ae93..c1e67b667 100644 --- a/effects/internal/volumeeffect.h +++ b/effects/internal/volumeeffect.h @@ -26,7 +26,7 @@ class VolumeEffect : public Effect { Q_OBJECT public: - VolumeEffect(Clip* c, const EffectMeta* em); + VolumeEffect(ClipPtr c, const EffectMeta* em); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); EffectField* volume_val; diff --git a/effects/internal/vsthost.cpp b/effects/internal/vsthost.cpp index 02ecd3fdd..cecf6b0ee 100644 --- a/effects/internal/vsthost.cpp +++ b/effects/internal/vsthost.cpp @@ -252,7 +252,7 @@ void VSTHost::processAudio(long numFrames) { plugin->processReplacing(plugin, inputs, outputs, numFrames); } -VSTHost::VSTHost(Clip* c, const EffectMeta *em) : Effect(c, em) { +VSTHost::VSTHost(ClipPtr c, const EffectMeta *em) : Effect(c, em) { plugin = nullptr; inputs = new float* [CHANNEL_COUNT]; diff --git a/effects/internal/vsthost.h b/effects/internal/vsthost.h index 752f0b7b3..4bcd6e818 100644 --- a/effects/internal/vsthost.h +++ b/effects/internal/vsthost.h @@ -37,7 +37,7 @@ typedef intptr_t (*dispatcherFuncPtr)(AEffect *effect, int32_t opCode, int32_t i class VSTHost : public Effect { Q_OBJECT public: - VSTHost(Clip* c, const EffectMeta* em); + VSTHost(ClipPtr c, const EffectMeta* em); ~VSTHost(); void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count); diff --git a/io/clipboard.cpp b/io/clipboard.cpp index 3af4db829..cd5de7902 100644 --- a/io/clipboard.cpp +++ b/io/clipboard.cpp @@ -25,21 +25,10 @@ #include "project/transition.h" int clipboard_type = CLIPBOARD_TYPE_CLIP; -QVector clipboard; -QVector clipboard_transitions; +QVector clipboard; +QVector clipboard_transitions; void clear_clipboard() { - int clipboard_size = clipboard.size(); - for (int i=0;i(clipboard.at(i)); - } else if (clipboard_type == CLIPBOARD_TYPE_EFFECT) { - delete static_cast(clipboard.at(i)); - } - } - clipboard_size = clipboard_transitions.size(); - for (int i=0;i; + extern int clipboard_type; -extern QVector clipboard_transitions; -extern QVector clipboard; +extern QVector clipboard_transitions; +extern QVector clipboard; void clear_clipboard(); #endif // CLIPBOARD_H diff --git a/io/loadthread.cpp b/io/loadthread.cpp index 906d8af41..741453853 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -41,12 +41,12 @@ LoadThread::LoadThread(bool a) : autorecovery(a), cancelled(false) { connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); connect(this, SIGNAL(success()), this, SLOT(success_func())); connect(this, SIGNAL(error()), this, SLOT(error_func())); - connect(this, SIGNAL(start_create_dual_transition(const TransitionData*,Clip*,Clip*,const EffectMeta*)), this, SLOT(create_dual_transition(const TransitionData*,Clip*,Clip*,const EffectMeta*))); - connect(this, SIGNAL(start_create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)), this, SLOT(create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool))); + connect(this, SIGNAL(start_create_dual_transition(const TransitionData*,ClipPtr,ClipPtr,const EffectMeta*)), this, SLOT(create_dual_transition(const TransitionData*,ClipPtr,ClipPtr,const EffectMeta*))); + connect(this, SIGNAL(start_create_effect_ui(QXmlStreamReader*, ClipPtr, int, const QString*, const EffectMeta*, long, bool)), this, SLOT(create_effect_ui(QXmlStreamReader*, ClipPtr, int, const QString*, const EffectMeta*, long, bool))); connect(this, SIGNAL(start_question(const QString&, const QString &, int)), this, SLOT(question_func(const QString &, const QString &, int))); } -void LoadThread::load_effect(QXmlStreamReader& stream, Clip* c) { +void LoadThread::load_effect(QXmlStreamReader& stream, ClipPtr c) { int effect_id = -1; QString effect_name; bool effect_enabled = true; @@ -194,7 +194,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { int folder = 0; Media* item = new Media(0); - Footage* f = new Footage(); + FootagePtr f(new Footage()); f->using_inout = false; @@ -300,7 +300,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { case MEDIA_TYPE_SEQUENCE: { Media* parent = nullptr; - Sequence* s = new Sequence(); + SequencePtr s(new Sequence()); // load attributes about sequence for (int j=0;jautoscale = false; @@ -428,7 +428,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { case MEDIA_TYPE_FOOTAGE: if (media_id >= 0) { for (int j=0;jto_footage(); + FootagePtr m = loaded_media_items.at(j)->to_footage(); if (m->save_id == media_id) { c->media = loaded_media_items.at(j); c->media_stream = stream_id; @@ -487,7 +487,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { // correct links, clip IDs, transitions for (int i=0;iclips.size();i++) { // correct links - Clip* correct_clip = s->clips.at(i); + ClipPtr correct_clip = s->clips.at(i); for (int j=0;jlinked.size();j++) { bool found = false; for (int k=0;kclips.size();k++) { @@ -508,7 +508,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { ); waitCond.wait(&mutex); if (question_btn == QMessageBox::No) { - delete s; + s.reset(); return false; } } @@ -534,8 +534,8 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { // create transitions for (int i=0;iset_enabled(effect_enabled); ve->load(*stream); c->effects.append(ve); } else { - Effect* e = create_effect(c, meta); + EffectPtr e(create_effect(c, meta)); e->set_enabled(effect_enabled); e->load(*stream); @@ -808,7 +808,7 @@ void LoadThread::create_effect_ui( } } else { int transition_index = create_transition(c, nullptr, meta); - Transition* t = c->sequence->transitions.at(transition_index); + 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); @@ -825,7 +825,7 @@ void LoadThread::create_effect_ui( waitCond.wakeAll(); } -void LoadThread::create_dual_transition(const TransitionData* td, Clip* primary, Clip* secondary, const EffectMeta* meta) { +void LoadThread::create_dual_transition(const TransitionData* td, ClipPtr primary, ClipPtr secondary, const EffectMeta* meta) { // lock mutex - ensures the load thread is suspended while this happens mutex.lock(); diff --git a/io/loadthread.h b/io/loadthread.h index 3b51715e9..73ea66951 100644 --- a/io/loadthread.h +++ b/io/loadthread.h @@ -34,8 +34,8 @@ struct TransitionData { int id; QString name; long length; - Clip* otc; - Clip* ctc; + ClipPtr otc; + ClipPtr ctc; }; class LoadThread : public QThread @@ -49,26 +49,26 @@ signals: void start_question(const QString &title, const QString &text, int buttons); void success(); void error(); - void start_create_effect_ui(QXmlStreamReader* stream, Clip* c, int type, const QString *effect_name, const EffectMeta* meta, long effect_length, bool effect_enabled); - void start_create_dual_transition(const TransitionData* td, Clip* primary, Clip* secondary, const EffectMeta* meta); + void start_create_effect_ui(QXmlStreamReader* stream, ClipPtr c, int type, const QString *effect_name, const EffectMeta* meta, long effect_length, bool effect_enabled); + void start_create_dual_transition(const TransitionData* td, ClipPtr primary, ClipPtr secondary, const EffectMeta* meta); void report_progress(int p); private slots: void question_func(const QString &title, const QString &text, int buttons); void error_func(); void success_func(); - void create_effect_ui(QXmlStreamReader* stream, Clip* c, int type, const QString *effect_name, const EffectMeta* meta, long effect_length, bool effect_enabled); - void create_dual_transition(const TransitionData* td, Clip* primary, Clip* secondary, const EffectMeta* meta); + void create_effect_ui(QXmlStreamReader* stream, ClipPtr c, int type, const QString *effect_name, const EffectMeta* meta, long effect_length, bool effect_enabled); + void create_dual_transition(const TransitionData* td, ClipPtr primary, ClipPtr secondary, const EffectMeta* meta); private: bool autorecovery; bool load_worker(QFile& f, QXmlStreamReader& stream, int type); - void load_effect(QXmlStreamReader& stream, Clip* c); + void load_effect(QXmlStreamReader& stream, ClipPtr c); void read_next(QXmlStreamReader& stream); void read_next_start_element(QXmlStreamReader& stream); void update_current_element_count(QXmlStreamReader& stream); - Sequence* open_seq; + SequencePtr open_seq; QVector loaded_media_items; QDir proj_dir; QDir internal_proj_dir; @@ -79,7 +79,7 @@ private: bool is_element(QXmlStreamReader& stream); QVector loaded_folders; - QVector loaded_clips; + QVector loaded_clips; QVector loaded_sequences; Media* find_loaded_folder_by_id(int id); diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index 8569af840..36c0e644c 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -38,7 +38,7 @@ QSemaphore sem(5); // only 5 preview generators can run at one time -PreviewGenerator::PreviewGenerator(Media* i, Footage* m, bool r) : +PreviewGenerator::PreviewGenerator(Media* i, FootagePtr m, bool r) : QThread(nullptr), fmt_ctx(nullptr), media(i), @@ -48,8 +48,7 @@ PreviewGenerator::PreviewGenerator(Media* i, Footage* m, bool r) : replace(r), cancelled(false) { - data_path = get_data_path() + "/previews"; - QDir data_dir(data_path); + data_dir = QDir(get_data_dir().filePath("previews")); if (!data_dir.exists()) { data_dir.mkpath("."); } @@ -506,11 +505,11 @@ void PreviewGenerator::generate_waveform() { } QString PreviewGenerator::get_thumbnail_path(const QString& hash, const FootageStream& ms) { - return data_path + "/" + hash + "t" + 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_path + "/" + hash + "w" + QString::number(ms.file_index); + return data_dir.filePath(QString("%1w%2").arg(hash, QString::number(ms.file_index))); } void PreviewGenerator::run() { diff --git a/io/previewgenerator.h b/io/previewgenerator.h index a1b5d5252..40af8f64d 100644 --- a/io/previewgenerator.h +++ b/io/previewgenerator.h @@ -23,6 +23,7 @@ #include #include +#include enum IconType { ICON_TYPE_VIDEO, @@ -45,7 +46,7 @@ class PreviewGenerator : public QThread { Q_OBJECT public: - PreviewGenerator(Media*, Footage*, bool); + PreviewGenerator(Media*, FootagePtr, bool); void run(); void cancel(); signals: @@ -57,12 +58,12 @@ private: void finalize_media(); AVFormatContext* fmt_ctx; Media* media; - Footage* footage; + FootagePtr footage; bool retrieve_duration; bool contains_still_image; bool replace; - bool cancelled; - QString data_path; + 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); }; diff --git a/io/proxygenerator.cpp b/io/proxygenerator.cpp index 640433e42..f59be37c2 100644 --- a/io/proxygenerator.cpp +++ b/io/proxygenerator.cpp @@ -399,7 +399,7 @@ void ProxyGenerator::cancel() { wait(); } -double ProxyGenerator::get_proxy_progress(Footage *f) { +double ProxyGenerator::get_proxy_progress(FootagePtr f) { if (proxy_queue.first().footage == f) { return current_progress; } diff --git a/io/proxygenerator.h b/io/proxygenerator.h index b8afeb379..a85e8c9ed 100644 --- a/io/proxygenerator.h +++ b/io/proxygenerator.h @@ -29,7 +29,7 @@ #include "project/footage.h" struct ProxyInfo { - Footage* footage; + FootagePtr footage; double size_multiplier; int codec_type; QString path; @@ -42,7 +42,7 @@ public: void run(); void queue(const ProxyInfo& info); void cancel(); - double get_proxy_progress(Footage* f); + double get_proxy_progress(FootagePtr f); private: // queue of footage to process proxies for QVector proxy_queue; diff --git a/main.cpp b/main.cpp index 3e2307b24..2976ef578 100644 --- a/main.cpp +++ b/main.cpp @@ -32,7 +32,7 @@ extern "C" { #include } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { olive::Global = std::unique_ptr(new OliveGlobal); bool launch_fullscreen = false; diff --git a/mainwindow.cpp b/mainwindow.cpp index c2d6124ee..6eedb0426 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -64,6 +64,8 @@ #include #include +Q_DECLARE_METATYPE(ClipPtr); + MainWindow* olive::MainWindow; #define DEFAULT_CSS "QPushButton::checked { background: rgb(25, 25, 25); }" @@ -100,6 +102,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), first_show(true) { + qRegisterMetaType(); + init_custom_cursors(); open_debug_file(); diff --git a/olive.pro b/olive.pro index f75aacc71..dc68ad4ef 100644 --- a/olive.pro +++ b/olive.pro @@ -148,7 +148,8 @@ SOURCES += \ ui/cursors.cpp \ ui/menuhelper.cpp \ oliveglobal.cpp \ - ui/focusfilter.cpp + ui/focusfilter.cpp \ + project/comboaction.cpp HEADERS += \ mainwindow.h \ @@ -254,7 +255,8 @@ HEADERS += \ ui/menuhelper.h \ oliveglobal.h \ project/projectelements.h \ - ui/focusfilter.h + ui/focusfilter.h \ + project/comboaction.h FORMS += diff --git a/oliveglobal.cpp b/oliveglobal.cpp index c49f26da2..26c686899 100644 --- a/oliveglobal.cpp +++ b/oliveglobal.cpp @@ -295,7 +295,7 @@ void OliveGlobal::open_speed_dialog() { if (olive::ActiveSequence != nullptr) { SpeedDialog s(olive::MainWindow); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { s.clips.append(c); } diff --git a/panels/effectcontrols.cpp b/panels/effectcontrols.cpp index 4c4e3875d..c052daed2 100644 --- a/panels/effectcontrols.cpp +++ b/panels/effectcontrols.cpp @@ -100,7 +100,7 @@ void EffectControls::set_zoom(bool in) { void EffectControls::menu_select(QAction* q) { ComboAction* ca = new ComboAction(); for (int i=0;iclips.at(selected_clips.at(i)); + const ClipPtr& c = olive::ActiveSequence->clips.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) { @@ -140,9 +140,9 @@ void EffectControls::copy(bool del) { ComboAction* ca = new ComboAction(); EffectDeleteCommand* del_com = (del) ? new EffectDeleteCommand() : nullptr; for (int i=0;iclips.at(selected_clips.at(i)); + const ClipPtr& c = olive::ActiveSequence->clips.at(selected_clips.at(i)); for (int j=0;jeffects.size();j++) { - Effect* effect = c->effects.at(j); + EffectPtr effect = c->effects.at(j); if (effect->container->selected) { if (!cleared) { clear_clipboard(); @@ -150,7 +150,7 @@ void EffectControls::copy(bool del) { clipboard_type = CLIPBOARD_TYPE_EFFECT; } - clipboard.append(effect->copy(nullptr)); + clipboard.append(EffectPtr(effect->copy(nullptr))); if (del_com != nullptr) { del_com->clips.append(c); @@ -176,7 +176,7 @@ void EffectControls::scroll_to_frame(long frame) { 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); + paste_action->setEnabled(clipboard.size() > 0 && clipboard_type == CLIPBOARD_TYPE_EFFECT); } void EffectControls::cut() { @@ -282,7 +282,7 @@ void EffectControls::clear_effects(bool clear_cache) { void EffectControls::deselect_all_effects(QWidget* sender) { for (int i=0;iclips.at(selected_clips.at(i)); + const ClipPtr& c = olive::ActiveSequence->clips.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); @@ -292,7 +292,7 @@ void EffectControls::deselect_all_effects(QWidget* sender) { panel_sequence_viewer->viewer_widget->update(); } -void EffectControls::open_effect(QVBoxLayout* layout, Effect* e) { +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*))); @@ -505,7 +505,7 @@ void EffectControls::load_effects() { if (!multiple) { // load in new clips for (int i=0;iclips.at(selected_clips.at(i)); + ClipPtr c = olive::ActiveSequence->clips.at(selected_clips.at(i)); QVBoxLayout* layout; if (c->track < 0) { vcontainer->setVisible(true); @@ -539,9 +539,9 @@ void EffectControls::delete_effects() { if (mode == TA_NO_TRANSITION) { EffectDeleteCommand* command = new EffectDeleteCommand(); for (int i=0;iclips.at(selected_clips.at(i)); + ClipPtr c = olive::ActiveSequence->clips.at(selected_clips.at(i)); for (int j=0;jeffects.size();j++) { - Effect* effect = c->effects.at(j); + EffectPtr effect = c->effects.at(j); if (effect->container->selected) { command->clips.append(c); command->fx.append(j); @@ -595,7 +595,7 @@ void EffectControls::resizeEvent(QResizeEvent*) { bool EffectControls::is_focused() { if (this->hasFocus()) return true; for (int i=0;iclips.at(selected_clips.at(i)); + ClipPtr c = olive::ActiveSequence->clips.at(selected_clips.at(i)); if (c != nullptr) { for (int j=0;jeffects.size();j++) { if (c->effects.at(j)->container->is_focused()) { diff --git a/panels/effectcontrols.h b/panels/effectcontrols.h index dc2156264..aee0c8f73 100644 --- a/panels/effectcontrols.h +++ b/panels/effectcontrols.h @@ -100,7 +100,7 @@ private: void show_effect_menu(int type, int subtype); void load_effects(); void load_keyframes(); - void open_effect(QVBoxLayout* hlayout, Effect* e); + void open_effect(QVBoxLayout* hlayout, EffectPtr e); void setup_ui(); diff --git a/panels/panels.cpp b/panels/panels.cpp index 5b3d81059..4f8e3e0f2 100644 --- a/panels/panels.cpp +++ b/panels/panels.cpp @@ -50,7 +50,7 @@ void update_effect_controls() { int mode = TA_NO_TRANSITION; if (olive::ActiveSequence != nullptr) { for (int i=0;iclips.size();i++) { - Clip* clip = olive::ActiveSequence->clips.at(i); + ClipPtr clip = olive::ActiveSequence->clips.at(i); if (clip != nullptr) { for (int j=0;jselections.size();j++) { const Selection& s = olive::ActiveSequence->selections.at(j); @@ -88,7 +88,7 @@ void update_effect_controls() { if (aclip >= 0) selected_clips.append(aclip); if (vclip >= 0 && aclip >= 0) { bool found = false; - Clip* vclip_ref = olive::ActiveSequence->clips.at(vclip); + ClipPtr vclip_ref = olive::ActiveSequence->clips.at(vclip); for (int i=0;ilinked.size();i++) { if (vclip_ref->linked.at(i) == aclip) { found = true; diff --git a/panels/project.cpp b/panels/project.cpp index 7b7cc3f27..c95a0f5ed 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -22,6 +22,7 @@ #include "oliveglobal.h" +#include "panels.h" #include "playback/playback.h" #include "io/previewgenerator.h" #include "project/undo.h" @@ -257,10 +258,10 @@ QString Project::get_next_sequence_name(QString start) { return name; } -Sequence* create_sequence_from_media(QVector& media_list) { - Sequence* s = new Sequence(); +SequencePtr create_sequence_from_media(QVector& media_list) { + SequencePtr s(new Sequence()); - s->name = panel_project->get_next_sequence_name(); + s->name = panel_project->get_next_sequence_name(); // shitty hardcoded default values s->width = 1920; @@ -272,11 +273,11 @@ Sequence* create_sequence_from_media(QVector& media_list) { bool got_video_values = false; bool got_audio_values = false; for (int i=0;iget_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* m = media->to_footage(); + FootagePtr m = media->to_footage(); if (m->ready) { if (!got_video_values) { for (int j=0;jvideo_tracks.size();j++) { @@ -304,7 +305,7 @@ Sequence* create_sequence_from_media(QVector& media_list) { break; case MEDIA_TYPE_SEQUENCE: { - Sequence* seq = media->to_sequence(); + SequencePtr seq = media->to_sequence(); s->width = seq->width; s->height = seq->height; s->frame_rate = seq->frame_rate; @@ -327,7 +328,7 @@ void Project::duplicate_selected() { bool duped = false; ComboAction* ca = new ComboAction(); for (int j=0;jget_type() == MEDIA_TYPE_SEQUENCE) { create_sequence_internal(ca, i->to_sequence()->copy(), false, item_to_media(items.at(j).parent())); duped = true; @@ -343,7 +344,7 @@ void Project::duplicate_selected() { void Project::replace_selected_file() { QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); + Media* item = item_to_media(selected_items.at(0)); if (item->get_type() == MEDIA_TYPE_FOOTAGE) { replace_media(item, nullptr); } @@ -373,7 +374,7 @@ void Project::replace_clip_media() { } else { QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); + Media* item = item_to_media(selected_items.at(0)); if (item->get_type() == MEDIA_TYPE_SEQUENCE && olive::ActiveSequence == item->to_sequence()) { QMessageBox::critical(this, tr("Active sequence selected"), @@ -390,7 +391,7 @@ void Project::replace_clip_media() { void Project::open_properties() { QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); + Media* item = item_to_media(selected_items.at(0)); switch (item->get_type()) { case MEDIA_TYPE_FOOTAGE: { @@ -438,13 +439,16 @@ void Project::new_folder() { void Project::new_sequence() { NewSequenceDialog nsd(this); - nsd.set_sequence_name(panel_project->get_next_sequence_name()); + nsd.set_sequence_name(get_next_sequence_name()); nsd.exec(); } -Media* Project::create_sequence_internal(ComboAction *ca, Sequence *s, bool open, Media* parent) { - if (parent == nullptr) parent = project_model.get_root(); - Media* item = new Media(parent); +Media* Project::create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent) { + if (parent == nullptr) { + parent = project_model.get_root(); + } + + Media* item(new Media(parent)); item->set_sequence(s); if (ca != nullptr) { @@ -466,7 +470,7 @@ QString Project::get_file_name_from_path(const QString& path) { } /*Media* Project::new_item() { - Media* item = new Media(0); + Media* item = new Media(0); //item->setFlags(item->flags() | Qt::ItemIsEditable); return item; }*/ @@ -476,22 +480,22 @@ bool Project::is_focused() { } Media* Project::create_folder_internal(QString name) { - Media* item = new Media(nullptr); + Media* item = new Media(nullptr); item->set_folder(); item->set_name(name); return item; } Media *Project::item_to_media(const QModelIndex &index) { - return static_cast(sorter->mapToSource(index).internalPointer()); + return static_cast(sorter->mapToSource(index).internalPointer()); // return static_cast(index.internalPointer()); } void Project::get_all_media_from_table(QList& items, QList& list, int search_type) { for (int i=0;iget_type() == MEDIA_TYPE_FOLDER) { - QList children; + QList children; for (int j=0;jchildCount();j++) { children.append(item->child(j)); } @@ -505,8 +509,8 @@ void Project::get_all_media_from_table(QList& items, QList& list bool delete_clips_in_clipboard_with_media(ComboAction* ca, Media* m) { int delete_count = 0; if (clipboard_type == CLIPBOARD_TYPE_CLIP) { - for (int i=0;i(clipboard.at(i)); + for (int i=0;i(clipboard.at(i)); if (c->media == m) { ca->append(new RemoveClipsFromClipboard(i-delete_count)); delete_count++; @@ -519,7 +523,7 @@ bool delete_clips_in_clipboard_with_media(ComboAction* ca, Media* m) { void Project::delete_selected_media() { ComboAction* ca = new ComboAction(); QModelIndexList selected_items = get_current_selected(); - QList items; + QList items; for (int i=0;i parents; - QList sequence_items; - QList all_top_level_items; + QVector parents; + QList sequence_items; + QList all_top_level_items; for (int i=0;i 0) { - QList media_items; + QList media_items; get_all_media_from_table(items, media_items, MEDIA_TYPE_FOOTAGE); for (int i=0;ito_footage(); + Media* item = media_items.at(i); + FootagePtr media = item->to_footage(); bool confirm_delete = false; for (int j=0;jto_sequence(); + SequencePtr s = sequence_items.at(j)->to_sequence(); for (int k=0;kclips.size();k++) { - Clip* c = s->clips.at(k); - if (c != nullptr && c->media == item) { + ClipPtr c = s->clips.at(k); + if (c != nullptr && c->media == item) { if (!confirm_delete) { // we found a reference, so we know we'll need to ask if the user wants to delete it QMessageBox confirm(this); @@ -562,13 +566,13 @@ void Project::delete_selected_media() { redraw = true; } else if (confirm.clickedButton() == skip_button) { // remove media item and any folders containing it from the remove list - Media* parent = item; + Media* parent = item; while (parent != nullptr) { parents.append(parent); // re-add item's siblings for (int m=0;mchildCount();m++) { - Media* child = parent->child(m); + Media* child = parent->child(m); bool found = false; for (int n=0;nget_type() == MEDIA_TYPE_SEQUENCE) { redraw = true; - Sequence* s = items.at(i)->to_sequence(); + SequencePtr s = items.at(i)->to_sequence(); if (s == olive::ActiveSequence) { ca->append(new ChangeSequenceAction(nullptr)); @@ -640,8 +644,8 @@ void Project::delete_selected_media() { } else if (items.at(i)->get_type() == MEDIA_TYPE_FOOTAGE) { if (panel_footage_viewer->seq != nullptr) { for (int j=0;jseq->clips.size();j++) { - Clip* c = panel_footage_viewer->seq->clips.at(j); - if (c != nullptr && c->media == items.at(i)) { + ClipPtr c = panel_footage_viewer->seq->clips.at(j); + if (c != nullptr && c->media == items.at(i)) { panel_footage_viewer->set_media(nullptr); break; } @@ -689,7 +693,7 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla for (int i=0;ireset(); } else { item = new Media(parent); - m = new Footage(); + m = FootagePtr(new Footage()); } m->using_inout = false; @@ -842,7 +846,7 @@ Media* Project::get_selected_folder() { // if one item is selected and it's a folder, return it QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* m = item_to_media(selected_items.at(0)); + Media* m = item_to_media(selected_items.at(0)); if (m->get_type() == MEDIA_TYPE_FOLDER) return m; } return nullptr; @@ -851,7 +855,7 @@ Media* Project::get_selected_folder() { bool Project::reveal_media(Media *media, QModelIndex parent) { for (int i=0;iget_type() == MEDIA_TYPE_FOLDER) { @@ -923,10 +927,10 @@ void Project::delete_clips_using_selected_media() { bool deleted = false; QModelIndexList items = get_current_selected(); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + const ClipPtr& c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { for (int j=0;jmedia == m) { ca->append(new DeleteClipAction(olive::ActiveSequence, i)); deleted = true; @@ -935,7 +939,7 @@ void Project::delete_clips_using_selected_media() { } } for (int j=0;jclear_effects(true); // delete sequences first because it's important to close all the clips before deleting the media - QVector sequences = list_all_project_sequences(); + QVector sequences = list_all_project_sequences(); for (int i=0;ito_sequence(); + sequences.at(i)->to_sequence().reset(); sequences.at(i)->set_sequence(nullptr); } @@ -962,7 +966,7 @@ void Project::clear() { project_model.clear(); // update tree view (sometimes this doesn't seem to update reliably) - panel_project->tree_view->update(); + tree_view->update(); } void Project::new_project() { @@ -990,7 +994,7 @@ void save_marker(QXmlStreamWriter& stream, const Marker& m) { void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, const QModelIndex& parent) { for (int i=0;iget_type()) { if (m->get_type() == MEDIA_TYPE_FOLDER) { @@ -1013,7 +1017,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, } else { int folder = m->parentItem()->temp_id; if (type == MEDIA_TYPE_FOOTAGE) { - Footage* f = m->to_footage(); + FootagePtr f = m->to_footage(); f->save_id = media_id; stream.writeStartElement("footage"); stream.writeAttribute("id", QString::number(media_id)); @@ -1061,7 +1065,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeEndElement(); // footage media_id++; } else if (type == MEDIA_TYPE_SEQUENCE) { - Sequence* s = m->to_sequence(); + SequencePtr s = m->to_sequence(); if (set_ids_only) { s->save_id = sequence_id; sequence_id++; @@ -1083,7 +1087,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeAttribute("workareaOut", QString::number(s->workarea_out)); for (int j=0;jtransitions.size();j++) { - Transition* t = s->transitions.at(j); + TransitionPtr t = s->transitions.at(j); if (t != nullptr) { stream.writeStartElement("transition"); stream.writeAttribute("id", QString::number(j)); @@ -1094,7 +1098,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, } for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); + const ClipPtr& c = s->clips.at(j); if (c != nullptr) { stream.writeStartElement("clip"); // clip stream.writeAttribute("id", QString::number(j)); @@ -1305,7 +1309,7 @@ void Project::add_recent_project(QString url) { void Project::list_all_sequences_worker(QVector* list, Media* parent) { for (int i=0;iget_type()) { case MEDIA_TYPE_SEQUENCE: list->append(item); @@ -1318,16 +1322,16 @@ void Project::list_all_sequences_worker(QVector* list, Media* parent) { } QVector Project::list_all_project_sequences() { - QVector list; + QVector list; list_all_sequences_worker(&list, nullptr); return list; } QModelIndexList Project::get_current_selected() { if (olive::CurrentConfig.project_view_type == PROJECT_VIEW_TREE) { - return panel_project->tree_view->selectionModel()->selectedRows(); + return tree_view->selectionModel()->selectedRows(); } - return panel_project->icon_view->selectionModel()->selectedIndexes(); + return icon_view->selectionModel()->selectedIndexes(); } #define THROBBER_LIMIT 20 @@ -1366,11 +1370,11 @@ void MediaThrobber::stop(int icon_type, bool replace) { } // refresh all clips - QVector sequences = panel_project->list_all_project_sequences(); + QVector sequences = panel_project->list_all_project_sequences(); for (int i=0;ito_sequence(); + SequencePtr s = sequences.at(i)->to_sequence(); for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); + const ClipPtr& c = s->clips.at(j); if (c != nullptr) { c->refresh(); } @@ -1380,7 +1384,7 @@ void MediaThrobber::stop(int icon_type, bool replace) { // redraw clips update_ui(replace); - panel_project->tree_view->viewport()->update(); + panel_project->tree_view->viewport()->update(); item->throbber = nullptr; deleteLater(); } diff --git a/panels/project.h b/panels/project.h index 581fa1780..5a073f455 100644 --- a/panels/project.h +++ b/panels/project.h @@ -37,8 +37,6 @@ #include "project/sourcescommon.h" #include "ui/sourceiconview.h" -#include "panels.h" - #include "ui/sourcetable.h" #define LOAD_TYPE_VERSION 69 @@ -48,7 +46,7 @@ extern QString autorecovery_filename; extern QStringList recent_projects; extern ProjectModel project_model; -Sequence* create_sequence_from_media(QVector &media_list); +SequencePtr create_sequence_from_media(QVector &media_list); QString get_channel_layout_name(int channels, uint64_t layout); QString get_interlacing_name(int interlacing); @@ -56,15 +54,15 @@ QString get_interlacing_name(int interlacing); class Project : public QDockWidget { Q_OBJECT public: - explicit Project(QWidget *parent = 0); + explicit Project(QWidget *parent = nullptr); ~Project(); bool is_focused(); void clear(); - Media* create_sequence_internal(ComboAction *ca, Sequence* s, bool open, Media* parent); - QString get_next_sequence_name(QString start = 0); - void process_file_list(QStringList& files, bool recursive = false, Media* replace = nullptr, Media *parent = nullptr); - void replace_media(Media* item, QString filename); - Media *get_selected_folder(); + Media* create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent); + QString get_next_sequence_name(QString start = nullptr); + void process_file_list(QStringList& files, bool recursive = false, Media* replace = nullptr, Media *parent = nullptr); + void replace_media(Media* item, QString filename); + Media* get_selected_folder(); bool reveal_media(Media *media, QModelIndex parent = QModelIndex()); void add_recent_project(QString url); @@ -72,12 +70,12 @@ public: void load_project(bool autorecovery); void save_project(bool autorecovery); - Media* create_folder_internal(QString name); - Media* item_to_media(const QModelIndex& index); + Media* create_folder_internal(QString name); + Media* item_to_media(const QModelIndex& index); void save_recent_projects(); - QVector list_all_project_sequences(); + QVector list_all_project_sequences(); SourceTable* tree_view; SourceIconView* icon_view; @@ -85,11 +83,11 @@ public: ProjectFilter* sorter; - QVector last_imported_media; + QVector last_imported_media; QModelIndexList get_current_selected(); - void start_preview_generator(Media* item, bool replacing); + void start_preview_generator(Media* item, bool replacing); void get_all_media_from_table(QList &items, QList &list, int type = -1); QWidget* toolbar_widget; @@ -108,7 +106,7 @@ private: int folder_id; int media_id; int sequence_id; - void list_all_sequences_worker(QVector *list, Media* parent); + void list_all_sequences_worker(QVector *list, Media* parent); QString get_file_name_from_path(const QString &path); QDir proj_dir; QWidget* icon_view_container; @@ -127,7 +125,7 @@ private slots: class MediaThrobber : public QObject { Q_OBJECT public: - MediaThrobber(Media*); + MediaThrobber(Media*); public slots: void start(); void stop(int, bool replace); @@ -136,7 +134,7 @@ private slots: private: QPixmap pixmap; int animation; - Media* item; + Media* item; QTimer* animator; }; diff --git a/panels/timeline.cpp b/panels/timeline.cpp index c1decbdd8..c8349a387 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -122,7 +122,7 @@ void Timeline::previous_cut() { && olive::ActiveSequence->playhead > 0) { long p_cut = 0; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { if (c->timeline_out > p_cut && c->timeline_out < olive::ActiveSequence->playhead) { p_cut = c->timeline_out; @@ -140,7 +140,7 @@ void Timeline::next_cut() { bool seek_enabled = false; long n_cut = LONG_MAX; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { if (c->timeline_in < n_cut && c->timeline_in > olive::ActiveSequence->playhead) { n_cut = c->timeline_in; @@ -155,7 +155,7 @@ void Timeline::next_cut() { } } -void ripple_clips(ComboAction* ca, Sequence *s, long point, long length, const QVector& ignore) { +void ripple_clips(ComboAction* ca, SequencePtr s, long point, long length, const QVector& ignore) { ca->append(new RippleAction(s, point, length, ignore)); } @@ -171,7 +171,7 @@ void Timeline::toggle_show_all() { } } -void Timeline::create_ghosts_from_media(Sequence* seq, long entry_point, QVector& media_list) { +void Timeline::create_ghosts_from_media(SequencePtr seq, long entry_point, QVector& media_list) { video_ghosts = false; audio_ghosts = false; @@ -179,8 +179,8 @@ void Timeline::create_ghosts_from_media(Sequence* seq, long entry_point, QVector bool can_import = true; Media* medium = media_list.at(i); - Footage* m = nullptr; - Sequence* s = nullptr; + FootagePtr m = nullptr; + SequencePtr s = nullptr; long sequence_length = 0; long default_clip_in = 0; long default_clip_out = 0; @@ -276,16 +276,16 @@ void Timeline::create_ghosts_from_media(Sequence* seq, long entry_point, QVector } } -void Timeline::add_clips_from_ghosts(ComboAction* ca, Sequence* s) { +void Timeline::add_clips_from_ghosts(ComboAction* ca, SequencePtr s) { // add clips long earliest_point = LONG_MAX; - QVector added_clips; + QVector added_clips; for (int i=0;imedia = g.media; c->media_stream = g.media_stream; c->timeline_in = g.in; @@ -293,7 +293,7 @@ void Timeline::add_clips_from_ghosts(ComboAction* ca, Sequence* s) { c->clip_in = g.clip_in; c->track = g.track; if (c->media->get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* m = c->media->to_footage(); + FootagePtr m = c->media->to_footage(); if (m->video_tracks.size() == 0) { // audio only (greenish) c->color_r = 128; @@ -317,7 +317,7 @@ void Timeline::add_clips_from_ghosts(ComboAction* ca, Sequence* s) { c->color_g = 128; c->color_b = 128; - Sequence* media = c->media->to_sequence(); + SequencePtr media = c->media->to_sequence(); c->name = media->name; } c->recalculateMaxLength(); @@ -327,9 +327,9 @@ void Timeline::add_clips_from_ghosts(ComboAction* ca, Sequence* s) { // link clips from the same media for (int i=0;imedia == cc->media) { c->linked.append(j); } @@ -367,7 +367,7 @@ void Timeline::add_transition() { bool adding = false; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); 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) { @@ -397,7 +397,7 @@ void Timeline::nest() { // get selected clips for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { selected_clips.append(i); earliest_point = qMin(c->timeline_in, earliest_point); @@ -408,7 +408,7 @@ void Timeline::nest() { if (!selected_clips.isEmpty()) { ComboAction* ca = new ComboAction(); - Sequence* s = new Sequence(); + SequencePtr s(new Sequence()); // create "nest" sequence s->name = panel_project->get_next_sequence_name(tr("Nested Sequence")); @@ -424,7 +424,7 @@ void Timeline::nest() { ca->append(new DeleteClipAction(olive::ActiveSequence, selected_clips.at(i))); // copy to new - Clip* copy = olive::ActiveSequence->clips.at(selected_clips.at(i))->copy(s); + ClipPtr copy(olive::ActiveSequence->clips.at(selected_clips.at(i))->copy(s)); copy->timeline_in -= earliest_point; copy->timeline_out -= earliest_point; s->clips.append(copy); @@ -536,7 +536,7 @@ void Timeline::select_all() { if (olive::ActiveSequence != nullptr) { olive::ActiveSequence->selections.clear(); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { Selection s; s.in = c->timeline_in; @@ -556,7 +556,7 @@ void Timeline::scroll_to_frame(long frame) { void Timeline::select_from_playhead() { olive::ActiveSequence->selections.clear(); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && c->timeline_in <= olive::ActiveSequence->playhead && c->timeline_out > olive::ActiveSequence->playhead) { @@ -576,7 +576,7 @@ bool Timeline::can_ripple_empty_space(long frame, int track) { rc_ripple_max = LONG_MAX; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { if (c->timeline_in > frame || c->timeline_out > frame) { at_end_of_sequence = false; @@ -667,7 +667,7 @@ void Timeline::toggle_enable_on_selected_clips() { ComboAction* ca = new ComboAction(); bool push_undo = false; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { ca->append(new SetBool(&c->enabled, !c->enabled)); push_undo = true; @@ -706,7 +706,7 @@ void Timeline::delete_selection(QVector& selections, bool ripple_dele bool can_ripple = true; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && c->timeline_in < ripple_point && c->timeline_out > ripple_point) { // conflict detected, but this clip may be getting deleted so let's check bool deleted = false; @@ -721,7 +721,7 @@ void Timeline::delete_selection(QVector& selections, bool ripple_dele } if (!deleted) { for (int j=0;jclips.size();j++) { - Clip* cc = olive::ActiveSequence->clips.at(j); + ClipPtr cc = olive::ActiveSequence->clips.at(j); if (cc != nullptr && cc->track == c->track && cc->timeline_in > c->timeline_out @@ -781,7 +781,7 @@ void Timeline::decheck_tool_buttons(QObject* sender) { QVector Timeline::get_tracks_of_linked_clips(int i) { QVector tracks; - Clip* clip = olive::ActiveSequence->clips.at(i); + ClipPtr clip = olive::ActiveSequence->clips.at(i); for (int j=0;jlinked.size();j++) { tracks.append(olive::ActiveSequence->clips.at(clip->linked.at(j))->track); } @@ -796,7 +796,7 @@ void Timeline::zoom_out() { multiply_zoom(0.5); } -bool is_clip_selected(Clip* clip, bool containing) { +bool is_clip_selected(ClipPtr clip, bool containing) { for (int i=0;isequence->selections.size();i++) { const Selection& s = clip->sequence->selections.at(i); if (clip->track == s.track && ((clip->timeline_in >= s.in && clip->timeline_out <= s.out && containing) || @@ -811,12 +811,12 @@ void Timeline::snapping_clicked(bool checked) { snapping = checked; } -Clip* Timeline::split_clip(ComboAction* ca, bool transitions, int p, long frame) { +ClipPtr Timeline::split_clip(ComboAction* ca, bool transitions, int p, long frame) { return split_clip(ca, transitions, p, frame, frame); } -Clip* Timeline::split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in) { - Clip* pre = olive::ActiveSequence->clips.at(p); +ClipPtr Timeline::split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in) { + ClipPtr pre = olive::ActiveSequence->clips.at(p); if (pre != nullptr && pre->timeline_in < frame && pre->timeline_out > frame) { // guard against attempts to split at in/out points bool splitting_closing_dual_transition = false; @@ -826,7 +826,7 @@ Clip* Timeline::split_clip(ComboAction* ca, bool transitions, int p, long frame, splitting_closing_dual_transition = true; } - Clip* post = pre->copy(olive::ActiveSequence, transitions && !splitting_closing_dual_transition); + ClipPtr post = ClipPtr(pre->copy(olive::ActiveSequence, transitions && !splitting_closing_dual_transition)); long new_clip_length = frame - pre->timeline_in; @@ -891,12 +891,12 @@ bool Timeline::split_clip_and_relink(ComboAction *ca, int clip, long frame, bool split_cache.append(clip); - Clip* c = olive::ActiveSequence->clips.at(clip); + ClipPtr c = olive::ActiveSequence->clips.at(clip); if (c != nullptr) { QVector pre_clips; - QVector post_clips; + QVector post_clips; - Clip* post = split_clip(ca, true, clip, frame); + ClipPtr post = split_clip(ca, true, clip, frame); // if alt is not down, split clips links too if (post == nullptr) { @@ -912,10 +912,10 @@ bool Timeline::split_clip_and_relink(ComboAction *ca, int clip, long frame, bool for (int i=0;ilinked.size();i++) { int l = c->linked.at(i); if (!has_clip_been_split(l)) { - Clip* link = olive::ActiveSequence->clips.at(l); + ClipPtr link = olive::ActiveSequence->clips.at(l); if ((original_clip_is_selected && is_clip_selected(link, true)) || !original_clip_is_selected) { split_cache.append(l); - Clip* s = split_clip(ca, true, l, frame); + ClipPtr s = split_clip(ca, true, l, frame); if (s != nullptr) { pre_clips.append(l); post_clips.append(s); @@ -963,7 +963,7 @@ void Timeline::clean_up_selections(QVector& areas) { } } -bool selection_contains_transition(const Selection& s, Clip* c, int type) { +bool selection_contains_transition(const Selection& s, ClipPtr c, int type) { if (type == TA_OPENING_TRANSITION) { return c->get_opening_transition() != nullptr && s.out == c->timeline_in + c->get_opening_transition()->get_true_length() @@ -982,12 +982,12 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area panel_effect_controls->clear_effects(true); QVector pre_clips; - QVector post_clips; + QVector post_clips; for (int i=0;iclips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(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)) { // delete opening transition @@ -1002,7 +1002,7 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area // middle of clip is within deletion area // duplicate clip - Clip* post = split_clip(ca, true, j, s.in, s.out); + ClipPtr post = split_clip(ca, true, j, s.in, s.out); pre_clips.append(j); post_clips.append(post); @@ -1053,7 +1053,7 @@ void Timeline::copy(bool del) { long min_in = 0; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { for (int j=0;jselections.size();j++) { const Selection& s = olive::ActiveSequence->selections.at(j); @@ -1064,7 +1064,7 @@ void Timeline::copy(bool del) { clipboard_type = CLIPBOARD_TYPE_CLIP; } - Clip* copied_clip = c->copy(nullptr); + ClipPtr copied_clip = c->copy(nullptr); // copy linked IDs (we correct these later in paste()) copied_clip->linked = c->linked; @@ -1087,16 +1087,16 @@ void Timeline::copy(bool del) { copied_clip->load_id = i; - clipboard.append(copied_clip); + clipboard.append(copied_clip); } } } } - for (int i=0;i(clipboard.at(i))->timeline_in -= min_in; - static_cast(clipboard.at(i))->timeline_out -= min_in; + std::static_pointer_cast(clipboard.at(i))->timeline_in -= min_in; + std::static_pointer_cast(clipboard.at(i))->timeline_out -= min_in; } if (del && copied) { @@ -1104,11 +1104,11 @@ void Timeline::copy(bool del) { } } -void Timeline::relink_clips_using_ids(QVector& old_clips, QVector& new_clips) { +void Timeline::relink_clips_using_ids(QVector& old_clips, QVector& new_clips) { // relink pasted clips for (int i=0;iclips.at(old_clips.at(i)); + ClipPtr oc = olive::ActiveSequence->clips.at(old_clips.at(i)); for (int j=0;jlinked.size();j++) { for (int k=0;klinked.at(j) == old_clips.at(k)) { @@ -1123,19 +1123,19 @@ void Timeline::relink_clips_using_ids(QVector& old_clips, QVector& n void Timeline::paste(bool insert) { if (clipboard.size() > 0) { - if (clipboard_type == CLIPBOARD_TYPE_CLIP) { + if (clipboard_type == CLIPBOARD_TYPE_CLIP) { ComboAction* ca = new ComboAction(); // create copies and delete areas that we'll be pasting to QVector delete_areas; - QVector pasted_clips; + QVector pasted_clips; long paste_start = LONG_MAX; long paste_end = LONG_MIN; - for (int i=0;i(clipboard.at(i)); + for (int i=0;i(clipboard.at(i)); // create copy of clip and offset by playhead - Clip* cc = c->copy(olive::ActiveSequence); + ClipPtr cc(c->copy(olive::ActiveSequence)); // convert frame rates cc->timeline_in = refactor_frame_number(cc->timeline_in, c->cached_fr, olive::ActiveSequence->frame_rate); @@ -1168,13 +1168,13 @@ void Timeline::paste(bool insert) { } // correct linked clips - for (int i=0;i(clipboard.at(i)); + ClipPtr oc = std::static_pointer_cast(clipboard.at(i)); for (int j=0;jlinked.size();j++) { - for (int k=0;k(clipboard.at(k)); + for (int k=0;k(clipboard.at(k)); if (comp->load_id == oc->linked.at(j)) { pasted_clips.at(i)->linked.append(k); } @@ -1200,10 +1200,10 @@ void Timeline::paste(bool insert) { bool ask_conflict = true; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { - for (int j=0;j(clipboard.at(j)); + for (int j=0;j(clipboard.at(j)); if ((c->track < 0) == (e->meta->subtype == EFFECT_TYPE_VIDEO)) { int found = -1; if (ask_conflict) { @@ -1283,7 +1283,7 @@ void Timeline::edit_to_point_internal(bool in, bool ripple) { // find closest in point to playhead for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { track_min = qMin(track_min, c->track); track_max = qMax(track_max, c->track); @@ -1382,18 +1382,18 @@ bool Timeline::split_selection(ComboAction* ca) { // temporary relinking vectors QVector pre_splits; - QVector post_splits; - QVector secondary_post_splits; + QVector post_splits; + QVector secondary_post_splits; // find clips within selection and split for (int j=0;jclips.size();j++) { - Clip* clip = olive::ActiveSequence->clips.at(j); + ClipPtr clip = olive::ActiveSequence->clips.at(j); if (clip != nullptr) { for (int i=0;iselections.size();i++) { const Selection& s = olive::ActiveSequence->selections.at(i); if (s.track == clip->track) { - Clip* post_b = split_clip(ca, true, j, s.out); - Clip* post_a = split_clip(ca, post_b == nullptr, j, s.in); + ClipPtr post_b = split_clip(ca, true, j, s.out); + ClipPtr post_a = split_clip(ca, post_b == nullptr, j, s.in); pre_splits.append(j); post_splits.append(post_a); secondary_post_splits.append(post_b); @@ -1424,7 +1424,7 @@ bool Timeline::split_selection(ComboAction* ca) { bool Timeline::split_all_clips_at_point(ComboAction* ca, long point) { bool split = false; for (int j=0;jclips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(j); + ClipPtr c = olive::ActiveSequence->clips.at(j); if (c != nullptr) { // always relinks if (split_clip_and_relink(ca, j, point, true)) { @@ -1443,11 +1443,11 @@ void Timeline::split_at_playhead() { if (olive::ActiveSequence->selections.size() > 0) { // see if whole clips are selected QVector pre_clips; - QVector post_clips; + QVector post_clips; for (int j=0;jclips.size();j++) { - Clip* clip = olive::ActiveSequence->clips.at(j); + ClipPtr clip = olive::ActiveSequence->clips.at(j); if (clip != nullptr && is_clip_selected(clip, true)) { - Clip* s = split_clip(ca, true, j, olive::ActiveSequence->playhead); + ClipPtr s = split_clip(ca, true, j, olive::ActiveSequence->playhead); if (s != nullptr) { pre_clips.append(j); post_clips.append(s); @@ -1555,7 +1555,7 @@ bool Timeline::snap_to_timeline(long* l, bool use_playhead, bool use_markers, bo // snap to clip/transition for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { if (snap_to_point(c->timeline_in, l)) { return true; @@ -1587,7 +1587,7 @@ void Timeline::set_marker() { bool clip_mode = false; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { @@ -1642,7 +1642,7 @@ void Timeline::toggle_links() { LinkCommand* command = new LinkCommand(); command->s = olive::ActiveSequence; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { if (!command->clips.contains(i)) command->clips.append(i); @@ -1665,22 +1665,26 @@ void Timeline::toggle_links() { void Timeline::increase_track_height() { for (int i=0;iappend(new MoveClipAction(c, iin, iout, iclip_in, itrack, relative)); if (verify_transitions) { diff --git a/panels/timeline.h b/panels/timeline.h index a9c77f780..2cacaad7d 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -23,10 +23,17 @@ #include "ui/timelinetools.h" #include "project/selection.h" +#include "project/clip.h" +#include "project/undo.h" +#include "ui/timelineheader.h" +#include "ui/resizablescrollbar.h" +#include "ui/audiomonitor.h" +#include "ui/timelinewidget.h" #include #include #include +#include #define TRACK_DEFAULT_HEIGHT 40 @@ -37,30 +44,12 @@ #define ADD_OBJ_NOISE 4 #define ADD_OBJ_AUDIO 5 -class QPushButton; -class SourceTable; -class ViewerWidget; -class ComboAction; -class Effect; -class Media; -class Transition; -class TimelineHeader; -class TimelineWidget; -class ResizableScrollBar; -class AudioMonitor; -class QScrollBar; -struct EffectMeta; -struct Sequence; -class Clip; -struct Footage; -struct FootageStream; - -bool is_clip_selected(Clip* clip, bool containing); +bool is_clip_selected(ClipPtr clip, bool containing); int getScreenPointFromFrame(double zoom, long frame); long getFrameFromScreenPoint(double zoom, int x); -bool selection_contains_transition(const Selection& s, Clip* c, int type); -void move_clip(ComboAction *ca, Clip *c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions = true, bool relative = false); -void ripple_clips(ComboAction *ca, Sequence* s, long point, long length, const QVector& ignore = QVector()); +bool selection_contains_transition(const Selection& s, ClipPtr c, int type); +void move_clip(ComboAction *ca, ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions = true, bool relative = false); +void ripple_clips(ComboAction *ca, SequencePtr s, long point, long length, const QVector& ignore = QVector()); struct Ghost { int clip; @@ -85,7 +74,7 @@ struct Ghost { bool trimming; // transition trimming - Transition* transition; + TransitionPtr transition; }; class Timeline : public QDockWidget @@ -98,15 +87,15 @@ public: bool focused(); void multiply_zoom(double m); void copy(bool del); - Clip* split_clip(ComboAction* ca, bool transitions, int p, long frame); - Clip* split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in); + ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame); + ClipPtr split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in); bool split_selection(ComboAction* ca); bool split_all_clips_at_point(ComboAction *ca, long point); bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink); void clean_up_selections(QVector& areas); void deselect_area(long in, long out, int track); void delete_areas_and_relink(ComboAction *ca, QVector& areas, bool deselect_areas); - void relink_clips_using_ids(QVector& old_clips, QVector& new_clips); + void relink_clips_using_ids(QVector& old_clips, QVector& new_clips); void update_sequence(); QVector get_tracks_of_linked_clips(int i); @@ -114,8 +103,8 @@ public: void edit_to_point_internal(bool in, bool ripple); void delete_in_out_internal(bool ripple); - void create_ghosts_from_media(Sequence *seq, long entry_point, QVector &media_list); - void add_clips_from_ghosts(ComboAction *ca, Sequence *s); + void create_ghosts_from_media(SequencePtr seq, long entry_point, QVector &media_list); + void add_clips_from_ghosts(ComboAction *ca, SequencePtr s); int getTimelineScreenPointFromFrame(long frame); long getTimelineFrameFromScreenPoint(int x); diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 76c9103f5..037a3b735 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -123,7 +123,7 @@ void Viewer::reset_all_audio() { if (seq != nullptr) { long last_frame = 0; for (int i=0;iclips.size();i++) { - Clip* c = seq->clips.at(i); + ClipPtr c = seq->clips.at(i); if (c != nullptr) { c->reset_audio(); last_frame = qMax(last_frame, c->timeline_out); @@ -438,9 +438,9 @@ void Viewer::pause() { panel_project->process_file_list(file_list); // add it to the sequence - Clip* c = new Clip(seq); + ClipPtr c = ClipPtr(new Clip(seq)); Media* m = panel_project->last_imported_media.at(0); - Footage* f = m->to_footage(); + FootagePtr f = m->to_footage(); f->ready_lock.lock(); @@ -457,7 +457,7 @@ void Viewer::pause() { f->ready_lock.unlock(); - QVector add_clips; + QVector add_clips; add_clips.append(c); olive::UndoStack.push(new AddClipCommand(seq, add_clips)); // add clip } @@ -720,11 +720,11 @@ void Viewer::set_media(Media* m) { switch (media->get_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* footage = media->to_footage(); + FootagePtr footage = media->to_footage(); marker_ref = &footage->markers; - seq = new Sequence(); + seq = SequencePtr(new Sequence()); created_sequence = true; seq->wrapper_sequence = true; seq->name = footage->name; @@ -743,7 +743,7 @@ void Viewer::set_media(Media* m) { seq->height = video_stream.video_height; if (video_stream.video_frame_rate > 0 && !video_stream.infinite_length) seq->frame_rate = video_stream.video_frame_rate * footage->speed; - Clip* c = new Clip(seq); + ClipPtr c = ClipPtr(new Clip(seq)); c->media = media; c->media_stream = video_stream.file_index; c->timeline_in = 0; @@ -762,7 +762,7 @@ void Viewer::set_media(Media* m) { const FootageStream& audio_stream = footage->audio_tracks.at(0); seq->audio_frequency = audio_stream.audio_frequency; - Clip* c = new Clip(seq); + ClipPtr c = ClipPtr(new Clip(seq)); c->media = media; c->media_stream = audio_stream.file_index; c->timeline_in = 0; @@ -848,13 +848,12 @@ void Viewer::clean_created_seq() { undo_stack.command(i) }*/ - delete seq; - seq = nullptr; + seq.reset(); created_sequence = false; } } -void Viewer::set_sequence(bool main, Sequence *s) { +void Viewer::set_sequence(bool main, SequencePtr s) { pause(); reset_all_audio(); diff --git a/panels/viewer.h b/panels/viewer.h index 08c049d4a..c69791199 100644 --- a/panels/viewer.h +++ b/panels/viewer.h @@ -24,19 +24,17 @@ #include #include #include - -class Timeline; -class Media; -struct Sequence; -class TimelineHeader; -class ResizableScrollBar; -class ViewerContainer; -class LabelSlider; -class QPushButton; -class QLabel; +#include +#include #include "project/marker.h" +#include "project/media.h" + #include "ui/viewerwidget.h" +#include "ui/timelinewidget.h" +#include "ui/timelineheader.h" +#include "ui/labelslider.h" +#include "ui/resizablescrollbar.h" bool frame_rate_is_droppable(float rate); long timecode_to_frame(const QString& s, int view, double frame_rate); @@ -92,7 +90,7 @@ public: ViewerWidget* viewer_widget; Media* media; - Sequence* seq; + SequencePtr seq; QVector* marker_ref; void set_marker(); @@ -124,7 +122,7 @@ private slots: private: void update_window_title(); void clean_created_seq(); - void set_sequence(bool main, Sequence* s); + void set_sequence(bool main, SequencePtr s); bool main_sequence; bool created_sequence; long cached_end_frame; diff --git a/playback/audio.h b/playback/audio.h index 55cafbcca..ba6aba7b5 100644 --- a/playback/audio.h +++ b/playback/audio.h @@ -25,15 +25,11 @@ #include #include #include +#include +#include +#include -//#define INT16_MAX 0x7fff -//#define INT16_MIN (-INT16_MAX-1) - -class QIODevice; -class QAudioOutput; -class QComboBox; - -struct Sequence; +#include "project/sequence.h" class AudioSenderThread : public QThread { Q_OBJECT diff --git a/playback/cacher.cpp b/playback/cacher.cpp index f05145bfa..3c36f2f5f 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -62,13 +62,13 @@ double bytes_to_seconds(int nb_bytes, int nb_channels, int sample_rate) { return ((double) (nb_bytes >> 1) / nb_channels / sample_rate); } -void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_bytes, QVector nests) { +void apply_audio_effects(ClipPtr c, double timecode_start, AVFrame* frame, int nb_bytes, QVector nests) { // perform all audio effects double timecode_end; timecode_end = timecode_start + bytes_to_seconds(nb_bytes, frame->channels, frame->sample_rate); for (int j=0;jeffects.size();j++) { - Effect* e = c->effects.at(j); + EffectPtr e = c->effects.at(j); if (e->is_enabled()) e->process_audio(timecode_start, timecode_end, frame->data[0], nb_bytes, 2); } if (c->get_opening_transition() != nullptr) { @@ -98,7 +98,7 @@ void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_ } if (!nests.isEmpty()) { - Clip* next_nest = nests.last(); + ClipPtr next_nest = nests.last(); nests.removeLast(); apply_audio_effects(next_nest, timecode_start + (((double)c->get_timeline_in_with_transition()-c->get_clip_in_with_transition())/c->sequence->frame_rate), frame, nb_bytes, nests); } @@ -106,7 +106,7 @@ void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_ #define AUDIO_BUFFER_PADDING 2048 -void cache_audio_worker(Clip* c, bool scrubbing, QVector& nests, int playback_speed) { +void cache_audio_worker(ClipPtr c, bool scrubbing, QVector& nests, int playback_speed) { long timeline_in = c->get_timeline_in_with_transition(); long timeline_out = c->get_timeline_out_with_transition(); long target_frame = c->audio_target_frame; @@ -460,7 +460,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector& nests, int play QMetaObject::invokeMethod(panel_sequence_viewer, "play_wake", Qt::QueuedConnection); } -void cache_video_worker(Clip* c, long playhead) { +void cache_video_worker(ClipPtr c, long playhead) { int read_ret, send_ret, retr_ret; int64_t target_pts = seconds_to_timestamp(c, playhead_to_clip_seconds(c, playhead)); @@ -498,7 +498,7 @@ void cache_video_worker(Clip* c, long playhead) { while (true) { AVFrame* frame = av_frame_alloc(); - Footage* media = c->media->to_footage(); + FootagePtr media = c->media->to_footage(); const FootageStream* ms = media->get_stream_from_file_index(true, c->media_stream); while ((retr_ret = av_buffersink_get_frame(c->buffersink_ctx, frame)) == AVERROR(EAGAIN)) { @@ -585,7 +585,7 @@ void cache_video_worker(Clip* c, long playhead) { } } -void reset_cache(Clip* c, long target_frame, int playback_speed) { +void reset_cache(ClipPtr c, long target_frame, int playback_speed) { // if we seek to a whole other place in the timeline, we'll need to reset the cache with new values if (c->media == nullptr) { if (c->track >= 0) { @@ -671,11 +671,11 @@ void reset_cache(Clip* c, long target_frame, int playback_speed) { } } -Cacher::Cacher(Clip* c) : clip(c) {} +Cacher::Cacher(ClipPtr c) : clip(c) {} AVSampleFormat sample_format = AV_SAMPLE_FMT_S16; -void open_clip_worker(Clip* clip) { +void open_clip_worker(ClipPtr clip) { qint64 time_start = QDateTime::currentMSecsSinceEpoch(); if (clip->media == nullptr) { @@ -694,7 +694,7 @@ void open_clip_worker(Clip* clip) { } } else if (clip->media->get_type() == MEDIA_TYPE_FOOTAGE) { // opens file resource for FFmpeg and prepares Clip struct for playback - Footage* m = clip->media->to_footage(); + FootagePtr m = clip->media->to_footage(); // byte array for retriving raw bytes from QString URL QByteArray ba; @@ -947,7 +947,7 @@ void open_clip_worker(Clip* clip) { qInfo() << "Clip opened on track" << clip->track << "(took" << (QDateTime::currentMSecsSinceEpoch() - time_start) << "ms)"; } -void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector nests, int playback_speed) { +void cache_clip_worker(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector nests, int playback_speed) { if (reset) { // note: for video, playhead is in "internal clip" frames - for audio, it's the timeline playhead reset_cache(clip, playhead, playback_speed); @@ -967,7 +967,7 @@ void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QV } } -void close_clip_worker(Clip* clip) { +void close_clip_worker(ClipPtr clip) { clip->finished_opening = false; if (clip->media != nullptr && clip->media->get_type() == MEDIA_TYPE_FOOTAGE) { diff --git a/playback/cacher.h b/playback/cacher.h index d6fc01e76..02d58fd75 100644 --- a/playback/cacher.h +++ b/playback/cacher.h @@ -25,12 +25,13 @@ #include class Clip; +using ClipPtr = std::shared_ptr; class Cacher : public QThread { // Q_OBJECT public: - Cacher(Clip* c); + Cacher(ClipPtr c); void run(); bool caching; @@ -42,14 +43,14 @@ public: bool interrupt; bool queued; int playback_speed; - QVector nests; + QVector nests; private: - Clip* clip; + ClipPtr clip; }; -void open_clip_worker(Clip* clip); -void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector nest, int playback_speed); -void close_clip_worker(Clip* clip); +void open_clip_worker(ClipPtr clip); +void cache_clip_worker(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector nest, int playback_speed); +void close_clip_worker(ClipPtr clip); #endif // CACHER_H diff --git a/playback/playback.cpp b/playback/playback.cpp index 7f8a95066..e8225625a 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -36,7 +36,6 @@ #include "debug.h" extern "C" { - #include #include #include #include @@ -59,11 +58,11 @@ long refactor_frame_number(long framenumber, double source_frame_rate, double ta return qRound((double(framenumber)/source_frame_rate)*target_frame_rate); } -bool clip_uses_cacher(Clip* clip) { +bool clip_uses_cacher(ClipPtr clip) { return (clip->media == nullptr && clip->track >= 0) || (clip->media != nullptr && clip->media->get_type() == MEDIA_TYPE_FOOTAGE); } -void open_clip(Clip* clip, bool multithreaded) { +void open_clip(ClipPtr clip, bool multithreaded) { if (clip_uses_cacher(clip)) { clip->multithreaded = multithreaded; if (multithreaded) { @@ -85,7 +84,7 @@ void open_clip(Clip* clip, bool multithreaded) { } } -void close_clip(Clip* clip, bool wait) { +void close_clip(ClipPtr clip, bool wait) { clip->finished_opening = false; // destroy opengl texture in main thread @@ -129,7 +128,7 @@ void close_clip(Clip* clip, bool wait) { } } -void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector& nests, int playback_speed) { +void cache_clip(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector& nests, int playback_speed) { if (clip_uses_cacher(clip)) { if (clip->multithreaded) { clip->cacher->playhead = playhead; @@ -147,11 +146,11 @@ void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVectorget_timeline_in_with_transition()+c->get_clip_in_with_transition())/(double)c->sequence->frame_rate); } -void get_clip_frame(Clip* c, long playhead, bool& texture_failed) { +void get_clip_frame(ClipPtr c, long playhead, bool& texture_failed) { if (c->finished_opening) { const FootageStream* ms = c->media->to_footage()->get_stream_from_file_index(c->track < 0, c->media_stream); @@ -336,7 +335,7 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) { } for (int i=0;ieffects.size();i++) { - Effect* e = c->effects.at(i); + EffectPtr e = c->effects.at(i); if (e->enable_image && e->is_enabled()) { if (data_buffer_1 == target_frame->data[0]) { data_buffer_1 = new uint8_t[frame_size]; @@ -366,16 +365,16 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) { c->queue_lock.unlock(); // get more frames - QVector empty; + QVector empty; if (cache) cache_clip(c, playhead, reset, false, empty, false); } } -long playhead_to_clip_frame(Clip* c, long playhead) { +long playhead_to_clip_frame(ClipPtr c, long playhead) { return (qMax(0L, playhead - c->get_timeline_in_with_transition()) + c->get_clip_in_with_transition()); } -double playhead_to_clip_seconds(Clip* c, long playhead) { +double playhead_to_clip_seconds(ClipPtr c, long playhead) { // returns time in seconds long clip_frame = playhead_to_clip_frame(c, playhead); if (c->reverse) clip_frame = c->getMaximumLength() - clip_frame - 1; @@ -384,15 +383,15 @@ double playhead_to_clip_seconds(Clip* c, long playhead) { return secs; } -int64_t seconds_to_timestamp(Clip* c, double seconds) { +int64_t seconds_to_timestamp(ClipPtr c, double seconds) { return qRound64(seconds * av_q2d(av_inv_q(c->stream->time_base))) + qMax((int64_t) 0, c->stream->start_time); } -int64_t playhead_to_timestamp(Clip* c, long playhead) { +int64_t playhead_to_timestamp(ClipPtr c, long playhead) { return seconds_to_timestamp(c, playhead_to_clip_seconds(c, playhead)); } -int retrieve_next_frame(Clip* c, AVFrame* f) { +int retrieve_next_frame(ClipPtr c, AVFrame* f) { int result = 0; int receive_ret; @@ -438,7 +437,7 @@ int retrieve_next_frame(Clip* c, AVFrame* f) { return result; } -bool is_clip_active(Clip* c, long playhead) { +bool is_clip_active(ClipPtr c, long playhead) { // these buffers allow clips to be opened and prepared well before they're displayed // as well as closed a little after they're not needed anymore int open_buffer = qCeil(c->sequence->frame_rate*2); @@ -451,7 +450,7 @@ bool is_clip_active(Clip* c, long playhead) { && playhead - c->get_timeline_in_with_transition() + c->get_clip_in_with_transition() < c->getMaximumLength(); } -void set_sequence(Sequence* s) { +void set_sequence(SequencePtr s) { panel_effect_controls->clear_effects(true); olive::ActiveSequence = s; panel_sequence_viewer->set_main_sequence(); @@ -459,10 +458,10 @@ void set_sequence(Sequence* s) { panel_timeline->setFocus(); } -void closeActiveClips(Sequence *s) { +void closeActiveClips(SequencePtr s) { if (s != nullptr) { for (int i=0;iclips.size();i++) { - Clip* c = s->clips.at(i); + ClipPtr c = s->clips.at(i); if (c != nullptr) { if (c->media != nullptr && c->media->get_type() == MEDIA_TYPE_SEQUENCE) { closeActiveClips(c->media->to_sequence()); diff --git a/playback/playback.h b/playback/playback.h index 7c1d1c0bc..ab460e00c 100644 --- a/playback/playback.h +++ b/playback/playback.h @@ -24,30 +24,32 @@ #include #include -class Clip; -struct ClipCache; -struct Sequence; -struct AVFrame; +#include "project/clip.h" +#include "project/sequence.h" + +extern "C" { + #include +} long refactor_frame_number(long framenumber, double source_frame_rate, double target_frame_rate); -bool clip_uses_cacher(Clip* clip); -void open_clip(Clip* clip, bool multithreaded); -void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector &nests, int playback_speed); -void close_clip(Clip* clip, bool wait); -void handle_media(Sequence* sequence, long playhead, bool multithreaded); -void reset_cache(Clip* c, long target_frame, int playback_speed); -void get_clip_frame(Clip* c, long playhead, bool &texture_failed); -double get_timecode(Clip* c, long playhead); +bool clip_uses_cacher(ClipPtr clip); +void open_clip(ClipPtr clip, bool multithreaded); +void cache_clip(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector &nests, int playback_speed); +void close_clip(ClipPtr clip, bool wait); +void handle_media(SequencePtr sequence, long playhead, bool multithreaded); +void reset_cache(ClipPtr c, long target_frame, int playback_speed); +void get_clip_frame(ClipPtr c, long playhead, bool &texture_failed); +double get_timecode(ClipPtr c, long playhead); -long playhead_to_clip_frame(Clip* c, long playhead); -double playhead_to_clip_seconds(Clip* c, long playhead); -int64_t seconds_to_timestamp(Clip* c, double seconds); -int64_t playhead_to_timestamp(Clip* c, long playhead); +long playhead_to_clip_frame(ClipPtr c, long playhead); +double playhead_to_clip_seconds(ClipPtr c, long playhead); +int64_t seconds_to_timestamp(ClipPtr c, double seconds); +int64_t playhead_to_timestamp(ClipPtr c, long playhead); -int retrieve_next_frame(Clip* c, AVFrame* f); -bool is_clip_active(Clip* c, long playhead); -void get_next_audio(Clip* c, bool mix); -void set_sequence(Sequence* s); -void closeActiveClips(Sequence* s); +int retrieve_next_frame(ClipPtr c, AVFrame* f); +bool is_clip_active(ClipPtr c, long playhead); +void get_next_audio(ClipPtr c, bool mix); +void set_sequence(SequencePtr s); +void closeActiveClips(SequencePtr s); #endif // PLAYBACK_H diff --git a/project/clip.cpp b/project/clip.cpp index 53aefdaec..bcfa76d35 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -34,11 +34,7 @@ #include "undo.h" #include "debug.h" -extern "C" { - #include -} - -Clip::Clip(Sequence* s) : +Clip::Clip(SequencePtr s) : sequence(s), enabled(true), clip_in(0), @@ -64,8 +60,8 @@ Clip::Clip(Sequence* s) : reset(); } -Clip* Clip::copy(Sequence* s, bool duplicate_transitions) { - Clip* copy = new Clip(s); +ClipPtr Clip::copy(SequencePtr s, bool duplicate_transitions) { + ClipPtr copy(new Clip(s)); copy->enabled = enabled; copy->name = QString(name); @@ -122,9 +118,9 @@ void Clip::reset_audio() { frame_sample_index = -1; audio_buffer_write = 0; } else if (media->get_type() == MEDIA_TYPE_SEQUENCE) { - Sequence* nested_sequence = media->to_sequence(); + SequencePtr nested_sequence = media->to_sequence(); for (int i=0;iclips.size();i++) { - Clip* c = nested_sequence->clips.at(i); + ClipPtr c = nested_sequence->clips.at(i); if (c != nullptr) c->reset_audio(); } } @@ -133,7 +129,7 @@ void Clip::reset_audio() { void Clip::refresh() { // validates media if it was replaced if (replaced && media != nullptr && media->get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* m = media->to_footage(); + FootagePtr m = media->to_footage(); if (track < 0 && m->video_tracks.size() > 0) { media_stream = m->video_tracks.at(0).file_index; @@ -177,7 +173,7 @@ QVector &Clip::get_markers() { return markers; } -Transition* Clip::get_opening_transition() { +TransitionPtr Clip::get_opening_transition() { if (opening_transition > -1) { if (this->sequence == nullptr) { return clipboard_transitions.at(opening_transition); @@ -188,7 +184,7 @@ Transition* Clip::get_opening_transition() { return nullptr; } -Transition* Clip::get_closing_transition() { +TransitionPtr Clip::get_closing_transition() { if (closing_transition > -1) { if (this->sequence == nullptr) { return clipboard_transitions.at(closing_transition); @@ -201,15 +197,13 @@ Transition* Clip::get_closing_transition() { Clip::~Clip() { if (open) { - close_clip(this, true); + close_clip(ClipPtr(this), true); } - if (opening_transition != -1) this->sequence->hard_delete_transition(this, TA_OPENING_TRANSITION); - if (closing_transition != -1) this->sequence->hard_delete_transition(this, TA_CLOSING_TRANSITION); + 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); - for (int i=0;iget_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* m = media->to_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; @@ -276,7 +270,7 @@ void Clip::recalculateMaxLength() { break; case MEDIA_TYPE_SEQUENCE: { - Sequence* s = media->to_sequence(); + SequencePtr s = media->to_sequence(); calculated_length = refactor_frame_number(s->getEndFrame(), s->frame_rate, fr); } break; @@ -301,7 +295,7 @@ int Clip::getWidth() { } case MEDIA_TYPE_SEQUENCE: { - Sequence* s = media->to_sequence(); + SequencePtr s = media->to_sequence(); return s->width; break; } @@ -320,7 +314,7 @@ int Clip::getHeight() { } case MEDIA_TYPE_SEQUENCE: { - Sequence* s = media->to_sequence(); + SequencePtr s = media->to_sequence(); return s->height; } } @@ -329,7 +323,7 @@ int Clip::getHeight() { void Clip::refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points) { if (change_timeline_points) { - move_clip(ca, this, + move_clip(ca, ClipPtr(this), qRound((double) timeline_in * multiplier), qRound((double) timeline_out * multiplier), qRound((double) clip_in * multiplier), @@ -338,7 +332,7 @@ void Clip::refactor_frame_rate(ComboAction* ca, double multiplier, bool change_t // move keyframes for (int i=0;irow_count();j++) { EffectRow* r = e->row(j); for (int l=0;lfieldCount();l++) { diff --git a/project/clip.h b/project/clip.h index 620542092..ab6eb934a 100644 --- a/project/clip.h +++ b/project/clip.h @@ -24,37 +24,34 @@ #include #include #include +#include +#include + +#include "playback/cacher.h" + +#include "project/effect.h" +#include "project/transition.h" +#include "project/comboaction.h" +#include "project/media.h" +#include "footage.h" #include "marker.h" -class Cacher; -class Effect; -class Transition; -class QOpenGLFramebufferObject; -class ComboAction; -class Media; -struct Sequence; -struct Footage; -struct FootageStream; +extern "C" { + #include + #include +} -struct AVFormatContext; -struct AVStream; -struct AVCodec; -struct AVCodecContext; -struct AVFrame; -struct AVPacket; -struct SwsContext; -struct SwrContext; -struct AVFilterGraph; -struct AVFilterContext; -struct AVDictionary; -class QOpenGLTexture; +using ClipPtr = std::shared_ptr; + +class Sequence; +using SequencePtr = std::shared_ptr; class Clip { public: - Clip(Sequence* s); + Clip(SequencePtr s); ~Clip(); - Clip* copy(Sequence* s, bool duplicate_transitions = true); + ClipPtr copy(SequencePtr s, bool duplicate_transitions = true); void reset_audio(); void reset(); void refresh(); @@ -68,7 +65,7 @@ public: int getWidth(); int getHeight(); void refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points); - Sequence* sequence; + SequencePtr sequence; // queue functions void queue_clear(); @@ -84,7 +81,7 @@ public: quint8 color_r; quint8 color_g; quint8 color_b; - Media* media; + Media* media; int media_stream; double speed; double cached_fr; @@ -96,12 +93,12 @@ public: QVector& get_markers(); // other variables (should be deep copied/duplicated in copy()) - QList effects; + QList effects; QVector linked; int opening_transition; - Transition* get_opening_transition(); + TransitionPtr get_opening_transition(); int closing_transition; - Transition* get_closing_transition(); + TransitionPtr get_closing_transition(); // media handling AVFormatContext* formatCtx; diff --git a/project/comboaction.cpp b/project/comboaction.cpp new file mode 100644 index 000000000..825c28262 --- /dev/null +++ b/project/comboaction.cpp @@ -0,0 +1,35 @@ +#include "comboaction.h" + +ComboAction::ComboAction() {} + +ComboAction::~ComboAction() { + for (int i=0;i=0;i--) { + commands.at(i)->undo(); + } + for (int i=0;iundo(); + } +} + +void ComboAction::redo() { + for (int i=0;iredo(); + } + for (int i=0;iredo(); + } +} + +void ComboAction::append(QUndoCommand* u) { + commands.append(u); +} + +void ComboAction::appendPost(QUndoCommand* u) { + post_commands.append(u); +} diff --git a/project/comboaction.h b/project/comboaction.h new file mode 100644 index 000000000..7d3edbf65 --- /dev/null +++ b/project/comboaction.h @@ -0,0 +1,88 @@ +#ifndef COMBOACTION_H +#define COMBOACTION_H + +#include +#include + +/** + * @brief The ComboAction class + * + * The Undo/Redo system works by stacking an action that knows how to "do" and also "undo" itself. As Olive is + * a very complex program, there are many actions that can in one "user action". For example, moving a clip over + * another will delete the clip under it, which is at least two actions that need to be undone if the user clicks + * undo, however the user only (knowingly) did one thing and would find it confusing if this one user action required + * to undos to complete undo. + * + * To address this, ComboAction is an undo action that simply compiles several possible actions into one, doing them + * all on every redo, and undoing them all on every undo. + */ +class ComboAction : public QUndoCommand { +public: + /** + * @brief ComboAction Constructor. Currently empty. + */ + ComboAction(); + + /** + * @brief ~ComboAction Destructor. Cleans up all QUndoCommand classes that have been added to it. + */ + virtual ~ComboAction() override; + + /** + * @brief Undo Function + * + * Called by the QUndoStack to undo. + * + * Calls QUndoCommand::undo() on all QUndoCommand objects added by append() + * in REVERSE order to how they were added. Then calls QUndoCommand::redo() on every action added by appendPost() + * in the order they were added (not in reverse). + */ + virtual void undo() override; + + /** + * @brief Redo Function + * + * Called by the QUndoStack to redo. + * + * Calls QUndoCommand::redo() on all QUndoCommand objects added by append() + * in the order they were added. Then calls QUndoCommand::redo() on every action added by appendPost() in + * the order they were added. + */ + virtual void redo() override; + + /** + * @brief Add an undo action + * + * Add an action to be done/undone. ComboAction takes ownership of this QUndoCommand and will delete it when + * it is deleted. + * + * @param u + * + * The QUndoCommand to add. + */ + void append(QUndoCommand* u); + + /** + * @brief Add a post-undo PostAction + * + * Sometimes the results of all the actions require another function to be called (e.g. repainting the Viewer). + * QUndoCommand objects added by appendPost() will run after EVERY QUndoCommand added by append() has been run. + * + * @param u + * + * The PostAction to add + */ + void appendPost(QUndoCommand* u); +private: + /** + * @brief Internal array of QUndoCommand objects + */ + QVector commands; + + /** + * @brief Internal array of PostAction objects + */ + QVector post_commands; +}; + +#endif // COMBOACTION_H diff --git a/project/effect.cpp b/project/effect.cpp index cdafc379a..aa85b95af 100644 --- a/project/effect.cpp +++ b/project/effect.cpp @@ -69,31 +69,31 @@ QVector effects; -Effect* create_effect(Clip* c, const EffectMeta* em) { +EffectPtr create_effect(ClipPtr c, const EffectMeta* em) { if (em->internal >= 0 && em->internal < EFFECT_INTERNAL_COUNT) { // must be an internal effect switch (em->internal) { - case EFFECT_INTERNAL_TRANSFORM: return new TransformEffect(c, em); - case EFFECT_INTERNAL_TEXT: return new TextEffect(c, em); - case EFFECT_INTERNAL_TIMECODE: return new TimecodeEffect(c, em); - case EFFECT_INTERNAL_SOLID: return new SolidEffect(c, em); - case EFFECT_INTERNAL_NOISE: return new AudioNoiseEffect(c, em); - case EFFECT_INTERNAL_VOLUME: return new VolumeEffect(c, em); - case EFFECT_INTERNAL_PAN: return new PanEffect(c, em); - case EFFECT_INTERNAL_TONE: return new ToneEffect(c, em); - case EFFECT_INTERNAL_SHAKE: return new ShakeEffect(c, em); - case EFFECT_INTERNAL_CORNERPIN: return new CornerPinEffect(c, em); - case EFFECT_INTERNAL_FILLLEFTRIGHT: return new FillLeftRightEffect(c, em); + case EFFECT_INTERNAL_TRANSFORM: return EffectPtr(new TransformEffect(c, em)); + case EFFECT_INTERNAL_TEXT: return EffectPtr(new TextEffect(c, em)); + case EFFECT_INTERNAL_TIMECODE: return EffectPtr(new TimecodeEffect(c, em)); + case EFFECT_INTERNAL_SOLID: return EffectPtr(new SolidEffect(c, em)); + case EFFECT_INTERNAL_NOISE: return EffectPtr(new AudioNoiseEffect(c, em)); + case EFFECT_INTERNAL_VOLUME: return EffectPtr(new VolumeEffect(c, em)); + case EFFECT_INTERNAL_PAN: return EffectPtr(new PanEffect(c, em)); + case EFFECT_INTERNAL_TONE: return EffectPtr(new ToneEffect(c, em)); + case EFFECT_INTERNAL_SHAKE: return EffectPtr(new ShakeEffect(c, em)); + case EFFECT_INTERNAL_CORNERPIN: return EffectPtr(new CornerPinEffect(c, em)); + case EFFECT_INTERNAL_FILLLEFTRIGHT: return EffectPtr(new FillLeftRightEffect(c, em)); #ifndef NOVST - case EFFECT_INTERNAL_VST: return new VSTHost(c, em); + case EFFECT_INTERNAL_VST: return EffectPtr(new VSTHost(c, em)); #endif #ifndef NOFREI0R - case EFFECT_INTERNAL_FREI0R: return new Frei0rEffect(c, em); + case EFFECT_INTERNAL_FREI0R: return EffectPtr(new Frei0rEffect(c, em)); #endif } } else if (!em->filename.isEmpty()) { // load effect from file - return new Effect(c, em); + return EffectPtr(new Effect(c, em)); } else { qCritical() << "Invalid effect data"; QMessageBox::critical(olive::MainWindow, @@ -112,7 +112,7 @@ const EffectMeta* get_internal_meta(int internal_id, int type) { return nullptr; } -Effect::Effect(Clip* c, const EffectMeta *em) : +Effect::Effect(ClipPtr c, const EffectMeta *em) : parent_clip(c), meta(em), enable_shader(false), @@ -344,7 +344,7 @@ Effect::~Effect() { } } -void Effect::copy_field_keyframes(Effect* e) { +void Effect::copy_field_keyframes(EffectPtr e) { for (int i=0;irows.at(i); @@ -498,7 +498,7 @@ void Effect::load_from_file() { QFile file_handle(file); if (file_handle.open(QFile::ReadOnly)) { - olive::UndoStack.push(new SetEffectData(this, file_handle.readAll())); + olive::UndoStack.push(new SetEffectData(EffectPtr(this), file_handle.readAll())); file_handle.close(); @@ -515,7 +515,7 @@ void Effect::load_from_file() { int Effect::get_index_in_clip() { if (parent_clip != nullptr) { for (int i=0;ieffects.size();i++) { - if (parent_clip->effects.at(i) == this) { + if (parent_clip->effects.at(i).get() == this) { return i; } } @@ -854,8 +854,8 @@ void Effect::setIterations(int i) { void Effect::process_image(double, uint8_t *, uint8_t *, int){} -Effect* Effect::copy(Clip* c) { - Effect* copy = create_effect(c, meta); +EffectPtr Effect::copy(ClipPtr c) { + EffectPtr copy = create_effect(c, meta); copy->set_enabled(is_enabled()); copy_field_keyframes(copy); return copy; diff --git a/project/effect.h b/project/effect.h index e27e99fbb..b3cb88990 100644 --- a/project/effect.h +++ b/project/effect.h @@ -30,19 +30,22 @@ #include #include #include -class QLabel; -class QWidget; -class CollapsibleWidget; -class QGridLayout; -class QPushButton; -class QMouseEvent; +#include +#include +#include +#include +#include +#include +#include + +#include "ui/collapsiblewidget.h" +#include "ui/checkboxex.h" class Clip; -class QXmlStreamReader; -class QXmlStreamWriter; +using ClipPtr = std::shared_ptr; + class Effect; -class EffectRow; -class CheckboxEx; +using EffectPtr = std::shared_ptr; struct EffectMeta { QString name; @@ -57,7 +60,7 @@ struct EffectMeta { extern QVector effects; double log_volume(double linear); -Effect* create_effect(Clip* c, const EffectMeta *em); +EffectPtr create_effect(ClipPtr c, const EffectMeta *em); const EffectMeta* get_internal_meta(int internal_id, int type); enum EffectType { @@ -166,9 +169,9 @@ qint16 mix_audio_sample(qint16 a, qint16 b); class Effect : public QObject { Q_OBJECT public: - Effect(Clip* c, const EffectMeta* em); + Effect(ClipPtr c, const EffectMeta* em); ~Effect(); - Clip* parent_clip; + ClipPtr parent_clip; const EffectMeta* meta; int id; QString name; @@ -187,8 +190,8 @@ public: virtual void refresh(); - virtual Effect* copy(Clip* c); - void copy_field_keyframes(Effect *e); + virtual EffectPtr copy(ClipPtr c); + void copy_field_keyframes(EffectPtr e); virtual void load(QXmlStreamReader& stream); virtual void custom_load(QXmlStreamReader& stream); diff --git a/project/effectrow.cpp b/project/effectrow.cpp index 9ad98d67f..0d9577d27 100644 --- a/project/effectrow.cpp +++ b/project/effectrow.cpp @@ -116,7 +116,7 @@ void EffectRow::set_keyframe_enabled(bool enabled) { void EffectRow::goto_previous_key() { long key = LONG_MIN; - Clip* c = parent_effect->parent_clip; + ClipPtr c = parent_effect->parent_clip; for (int i=0;ikeyframes.size();j++) { @@ -132,7 +132,7 @@ void EffectRow::goto_previous_key() { void EffectRow::toggle_key() { QVector key_fields; QVector key_field_index; - Clip* c = parent_effect->parent_clip; + ClipPtr c = parent_effect->parent_clip; for (int j=0;jkeyframes.size();i++) { @@ -159,7 +159,7 @@ void EffectRow::toggle_key() { void EffectRow::goto_next_key() { long key = LONG_MAX; - Clip* c = parent_effect->parent_clip; + ClipPtr c = parent_effect->parent_clip; for (int i=0;ikeyframes.size();j++) { diff --git a/project/footage.h b/project/footage.h index 30db89b2b..9c99c2a87 100644 --- a/project/footage.h +++ b/project/footage.h @@ -37,7 +37,7 @@ enum VideoInterlacingMode { VIDEO_BOTTOM_FIELD_FIRST }; -struct Sequence; +class Sequence; class Clip; class PreviewGenerator; class MediaThrobber; @@ -101,4 +101,6 @@ struct Footage { void reset(); }; +using FootagePtr = std::shared_ptr; + #endif // FOOTAGE_H diff --git a/project/marker.cpp b/project/marker.cpp index e6a4d3927..ca8de8492 100644 --- a/project/marker.cpp +++ b/project/marker.cpp @@ -48,7 +48,7 @@ void draw_marker(QPainter &p, int x, int y, int bottom, bool selected) { p.drawPolygon(points, 5); } -void set_marker_internal(Sequence* seq, const QVector& clips) { +void set_marker_internal(SequencePtr seq, const QVector& clips) { // if clips is empty, the marker is being added to the sequence // add_marker is used to determine whether we're adding a marker, depending on whether the user input a marker name @@ -78,7 +78,7 @@ void set_marker_internal(Sequence* seq, const QVector& clips) { // add a marker action for each clip foreach (int i, clips) { - Clip* c = seq->clips.at(i); + ClipPtr c = seq->clips.at(i); ca->append(new AddMarkerAction(&c->get_markers(), seq->playhead - c->timeline_in + c->clip_in, marker_name)); @@ -119,7 +119,7 @@ void set_marker_internal(Sequence* seq, const QVector& clips) { } } -void set_marker_internal(Sequence* seq) { +void set_marker_internal(SequencePtr seq) { // create empty clip array QVector clips; diff --git a/project/marker.h b/project/marker.h index 59de65f3e..5678660d1 100644 --- a/project/marker.h +++ b/project/marker.h @@ -26,7 +26,8 @@ #include #include -struct Sequence; +class Sequence; +using SequencePtr = std::shared_ptr; struct Marker { long frame; @@ -35,7 +36,7 @@ struct Marker { void draw_marker(QPainter& p, int x, int y, int bottom, bool selected); -void set_marker_internal(Sequence* seq, const QVector& clips); -void set_marker_internal(Sequence* seq); +void set_marker_internal(SequencePtr seq, const QVector& clips); +void set_marker_internal(SequencePtr seq); #endif // MARKER_H diff --git a/project/media.cpp b/project/media.cpp index f0de8274f..118d9c960 100644 --- a/project/media.cpp +++ b/project/media.cpp @@ -68,30 +68,29 @@ Media::Media(Media* iparent) : {} Media::~Media() { - switch (get_type()) { - case MEDIA_TYPE_FOOTAGE: delete to_footage(); break; - case MEDIA_TYPE_SEQUENCE: if (object != nullptr) delete to_sequence(); break; - } + for (int i=0;i(object); +FootagePtr Media::to_footage() { + return std::static_pointer_cast(object); } -Sequence *Media::to_sequence() { - return static_cast(object); +SequencePtr Media::to_sequence() { + return std::static_pointer_cast(object); } -void Media::set_footage(Footage *f) { +void Media::set_footage(FootagePtr f) { type = MEDIA_TYPE_FOOTAGE; - object = f; + object = VoidPtr(f); } -void Media::set_sequence(Sequence *s) { +void Media::set_sequence(SequencePtr s) { set_icon(QIcon(":/icons/sequence.png")); type = MEDIA_TYPE_SEQUENCE; - object = s; + object = VoidPtr(s); if (s != nullptr) update_tooltip(); } @@ -114,7 +113,7 @@ void Media::update_tooltip(const QString& error) { switch (type) { case MEDIA_TYPE_FOOTAGE: { - Footage* f = to_footage(); + FootagePtr f = to_footage(); tooltip = QCoreApplication::translate("Media", "Name:") + " " + f->name + "\n" + QCoreApplication::translate("Media", "Filename:") + " " + f->url + "\n"; if (error.isEmpty()) { @@ -185,7 +184,7 @@ void Media::update_tooltip(const QString& error) { break; case MEDIA_TYPE_SEQUENCE: { - Sequence* s = to_sequence(); + SequencePtr s = to_sequence(); tooltip = QCoreApplication::translate("Media", "Name: %1" "\nVideo Dimensions: %2x%3" @@ -205,7 +204,7 @@ void Media::update_tooltip(const QString& error) { } -void *Media::to_object() { +VoidPtr Media::to_object() { return object; } @@ -233,7 +232,7 @@ double Media::get_frame_rate(int stream) { switch (get_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* f = to_footage(); + FootagePtr f = to_footage(); if (stream < 0) return f->video_tracks.at(0).video_frame_rate * f->speed; return f->get_stream_from_file_index(true, stream)->video_frame_rate * f->speed; } @@ -246,7 +245,7 @@ int Media::get_sampling_rate(int stream) { switch (get_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* f = to_footage(); + FootagePtr f = to_footage(); if (stream < 0) return f->audio_tracks.at(0).audio_frequency * f->speed; return to_footage()->get_stream_from_file_index(false, stream)->audio_frequency * f->speed; } @@ -288,7 +287,7 @@ QVariant Media::data(int column, int role) { case Qt::DecorationRole: if (column == 0) { if (get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* f = to_footage(); + FootagePtr f = to_footage(); if (f->video_tracks.size() > 0 && f->video_tracks.at(0).preview_done) { return f->video_tracks.at(0).video_preview_square; @@ -304,11 +303,11 @@ QVariant Media::data(int column, int role) { case 1: if (root) return QCoreApplication::translate("Media", "Duration"); if (get_type() == MEDIA_TYPE_SEQUENCE) { - Sequence* s = to_sequence(); + SequencePtr s = to_sequence(); return frame_to_timecode(s->getEndFrame(), olive::CurrentConfig.timecode_view, s->frame_rate); } if (get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* f = to_footage(); + FootagePtr f = to_footage(); double r = 30; if (f->video_tracks.size() > 0 && !qIsNull(f->video_tracks.at(0).video_frame_rate)) @@ -322,7 +321,7 @@ QVariant Media::data(int column, int role) { if (root) return QCoreApplication::translate("Media", "Rate"); if (get_type() == MEDIA_TYPE_SEQUENCE) return QString::number(get_frame_rate()) + " FPS"; if (get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* f = to_footage(); + FootagePtr f = to_footage(); double r; if (f->video_tracks.size() > 0 && !qIsNull(r = get_frame_rate())) { return QString::number(get_frame_rate()) + " FPS"; diff --git a/project/media.h b/project/media.h index ed99c2ad5..fb782e8a8 100644 --- a/project/media.h +++ b/project/media.h @@ -23,8 +23,10 @@ #include #include +#include #include "project/marker.h" +#include "project/footage.h" enum MediaType { MEDIA_TYPE_FOOTAGE, @@ -32,25 +34,27 @@ enum MediaType { MEDIA_TYPE_FOLDER }; -struct Footage; +class Sequence; +using SequencePtr = std::shared_ptr; + +using VoidPtr = std::shared_ptr; + class MediaThrobber; -struct Sequence; -#include class Media { public: Media(Media* iparent); ~Media(); - Footage *to_footage(); - Sequence* to_sequence(); - void set_footage(Footage* f); - void set_sequence(Sequence* s); + FootagePtr to_footage(); + SequencePtr to_sequence(); + void set_footage(FootagePtr f); + void set_sequence(SequencePtr s); void set_folder(); void set_icon(const QIcon &ico); void set_parent(Media* p); void update_tooltip(const QString& error = 0); - void *to_object(); + VoidPtr to_object(); int get_type(); const QString& get_name(); void set_name(const QString& n); @@ -78,7 +82,7 @@ public: int temp_id2; private: int type; - void* object; + VoidPtr object; // item functions QList children; diff --git a/project/projectmodel.cpp b/project/projectmodel.cpp index 5fdae2184..177eaa0fc 100644 --- a/project/projectmodel.cpp +++ b/project/projectmodel.cpp @@ -99,8 +99,8 @@ QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) return QModelIndex(); } -QModelIndex ProjectModel::create_index(int arow, int acolumn, void* aid) { - return createIndex(arow, acolumn, aid); +QModelIndex ProjectModel::create_index(int arow, int acolumn, void* adata) { + return createIndex(arow, acolumn, adata); } QModelIndex ProjectModel::parent(const QModelIndex &index) const { diff --git a/project/projectmodel.h b/project/projectmodel.h index 08788d08f..a875dfb51 100644 --- a/project/projectmodel.h +++ b/project/projectmodel.h @@ -23,7 +23,7 @@ #include -class Media; +#include "project/media.h" class ProjectModel : public QAbstractItemModel { @@ -35,29 +35,29 @@ public: void make_root(); void destroy_root(); void clear(); - Media* get_root(); + Media* get_root(); QVariant data(const QModelIndex &index, int role) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - QModelIndex create_index(int arow, int acolumn, void *aid); + QModelIndex create_index(int arow, int acolumn, void *adata); QModelIndex parent(const QModelIndex &index) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; - Media *getItem(const QModelIndex &index) const; + Media* getItem(const QModelIndex &index) const; - void appendChild(Media* parent, Media* child); - void moveChild(Media *child, Media *to); - void removeChild(Media *parent, Media* m); - Media *child(int i, Media* parent = nullptr); - int childCount(Media* parent = nullptr); - void set_icon(Media* m, const QIcon &ico); + void appendChild(Media* parent, Media* child); + void moveChild(Media* child, Media* to); + void removeChild(Media* parent, Media* m); + Media* child(int i, Media* parent = nullptr); + int childCount(Media* parent = nullptr); + void set_icon(Media* m, const QIcon &ico); private: - Media* root_item; + Media* root_item; }; #endif // PROJECTMODEL_H diff --git a/project/sequence.cpp b/project/sequence.cpp index b2b489b55..9c01b5b07 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -20,9 +20,6 @@ #include "sequence.h" -#include "clip.h" -#include "transition.h" - #include #include "debug.h" @@ -36,15 +33,10 @@ Sequence::Sequence() : { } -Sequence::~Sequence() { - // dealloc all clips - for (int i=0;iname = QCoreApplication::translate("Sequence", "%1 (copy)").arg(name); s->width = width; s->height = height; @@ -53,11 +45,11 @@ Sequence* Sequence::copy() { s->audio_layout = audio_layout; s->clips.resize(clips.size()); for (int i=0;iclips[i] = nullptr; } else { - Clip* copy = c->copy(s); + ClipPtr copy = c->copy(s); copy->linked = c->linked; s->clips[i] = copy; } @@ -68,7 +60,7 @@ Sequence* Sequence::copy() { long Sequence::getEndFrame() { long end = 0; for (int j=0;jtimeline_out > end) { end = c->timeline_out; } @@ -76,15 +68,15 @@ long Sequence::getEndFrame() { return end; } -void Sequence::hard_delete_transition(Clip *c, int type) { +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; - Transition* t = transitions.at(transition_index); + TransitionPtr t = transitions.at(transition_index); if (t->secondary_clip != nullptr) { for (int i=0;iopening_transition == transition_index @@ -100,9 +92,8 @@ void Sequence::hard_delete_transition(Clip *c, int type) { } } - if (del) { - delete transitions.at(transition_index); - transitions[transition_index] = nullptr; + if (del) { + transitions[transition_index].reset(); } if (type == TA_OPENING_TRANSITION) { @@ -117,7 +108,7 @@ void Sequence::getTrackLimits(int* video_tracks, int* audio_tracks) { int vt = 0; int at = 0; for (int j=0;jtrack < 0 && c->track < vt) { // video clip vt = c->track; @@ -131,4 +122,4 @@ void Sequence::getTrackLimits(int* video_tracks, int* audio_tracks) { } // static variable for the currently active sequence -Sequence* olive::ActiveSequence = nullptr; +SequencePtr olive::ActiveSequence = nullptr; diff --git a/project/sequence.h b/project/sequence.h index 0adbe9dc3..60ac73192 100644 --- a/project/sequence.h +++ b/project/sequence.h @@ -23,21 +23,20 @@ #include +#include "project/clip.h" #include "project/marker.h" +#include "project/transition.h" #include "project/selection.h" -class Clip; -class Transition; -class Media; - -struct Sequence { +class Sequence { +public: Sequence(); ~Sequence(); - Sequence* copy(); + SequencePtr copy(); QString name; void getTrackLimits(int* video_tracks, int* audio_tracks); long getEndFrame(); - void hard_delete_transition(Clip *c, int type); + void hard_delete_transition(ClipPtr c, int type); int width; int height; double frame_rate; @@ -56,13 +55,15 @@ struct Sequence { int save_id; QVector markers; - QVector clips; - QVector transitions; + QVector clips; + QVector transitions; }; +using SequencePtr = std::shared_ptr; + // static variable for the currently active sequence namespace olive { - extern Sequence* ActiveSequence; + extern SequencePtr ActiveSequence; } #endif // SEQUENCE_H diff --git a/project/sourcescommon.cpp b/project/sourcescommon.cpp index 995d78855..339a7a386 100644 --- a/project/sourcescommon.cpp +++ b/project/sourcescommon.cpp @@ -62,7 +62,7 @@ void SourcesCommon::create_seq_from_selected() { } ComboAction* ca = new ComboAction(); - Sequence* s = create_sequence_from_media(media_list); + SequencePtr s = create_sequence_from_media(media_list); // add clips to it panel_timeline->create_ghosts_from_media(s, 0, media_list); @@ -334,7 +334,7 @@ void SourcesCommon::dropEvent(QWidget* parent, QDropEvent *event, const QModelIn void SourcesCommon::reveal_in_browser() { Media* media = project_parent->item_to_media(selected_items.at(0)); - Footage* m = media->to_footage(); + FootagePtr m = media->to_footage(); #if defined(Q_OS_WIN) QStringList args; @@ -385,7 +385,7 @@ void SourcesCommon::clear_proxies_from_selected() { QList delete_list; for (int i=0;iproxy && !f->proxy_path.isEmpty()) { if (QFileInfo::exists(f->proxy_path)) { diff --git a/project/sourcescommon.h b/project/sourcescommon.h index 0fa1c015a..152f1b159 100644 --- a/project/sourcescommon.h +++ b/project/sourcescommon.h @@ -25,6 +25,8 @@ #include #include +#include "project/footage.h" + class Project; class QMouseEvent; class Media; @@ -63,7 +65,7 @@ private: QTimer rename_timer; // we cache the selected footage items for open_create_proxy_dialog() - QVector cached_selected_footage; + QVector cached_selected_footage; }; #endif // SOURCESCOMMON_H diff --git a/project/transition.cpp b/project/transition.cpp index 6c9cf6b15..b11b00f15 100644 --- a/project/transition.cpp +++ b/project/transition.cpp @@ -41,7 +41,7 @@ #include #include -Transition::Transition(Clip* c, Clip* s, const EffectMeta* em) : +Transition::Transition(ClipPtr c, ClipPtr s, const EffectMeta* em) : Effect(c, em), secondary_clip(s), length(30) { @@ -55,7 +55,7 @@ Transition::Transition(Clip* c, Clip* s, const EffectMeta* em) : length_ui_ele->set_frame_rate(parent_clip->sequence == nullptr ? parent_clip->cached_fr : parent_clip->sequence->frame_rate); } -int Transition::copy(Clip *c, Clip* s) { +int Transition::copy(ClipPtr c, ClipPtr s) { return create_transition(c, s, meta, length); } @@ -80,18 +80,18 @@ void Transition::set_length_from_slider() { update_ui(false); } -Transition* get_transition_from_meta(Clip* c, Clip* s, const EffectMeta* em) { +TransitionPtr get_transition_from_meta(ClipPtr c, ClipPtr s, const EffectMeta* em) { if (!em->filename.isEmpty()) { // load effect from file - return new Transition(c, s, em); + 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 new CrossDissolveTransition(c, s, em); - case TRANSITION_INTERNAL_LINEARFADE: return new LinearFadeTransition(c, s, em); - case TRANSITION_INTERNAL_EXPONENTIALFADE: return new ExponentialFadeTransition(c, s, em); - case TRANSITION_INTERNAL_LOGARITHMICFADE: return new LogarithmicFadeTransition(c, s, em); - case TRANSITION_INTERNAL_CUBE: return new CubeTransition(c, s, em); + 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"; @@ -103,11 +103,11 @@ Transition* get_transition_from_meta(Clip* c, Clip* s, const EffectMeta* em) { return nullptr; } -int create_transition(Clip* c, Clip* s, const EffectMeta* em, long length) { - Transition* t = get_transition_from_meta(c, s, em); +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; + QVector& transition_list = (c->sequence == nullptr) ? clipboard_transitions : c->sequence->transitions; transition_list.append(t); return transition_list.size() - 1; } diff --git a/project/transition.h b/project/transition.h index bd8c4ffa7..2677fb332 100644 --- a/project/transition.h +++ b/project/transition.h @@ -34,14 +34,14 @@ #define TRANSITION_INTERNAL_CUBE 4 #define TRANSITION_INTERNAL_COUNT 5 -int create_transition(Clip* c, Clip* s, const EffectMeta* em, long length = -1); +int create_transition(ClipPtr c, ClipPtr s, const EffectMeta* em, long length = -1); class Transition : public Effect { Q_OBJECT public: - Transition(Clip* c, Clip* s, const EffectMeta* em); - int copy(Clip* c, Clip* s); - Clip* secondary_clip; + 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(); @@ -52,4 +52,6 @@ private: EffectField* length_field; }; +using TransitionPtr = std::shared_ptr; + #endif // TRANSITION_H diff --git a/project/undo.cpp b/project/undo.cpp index b87e248fa..17dfe6474 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -48,41 +48,7 @@ QUndoStack olive::UndoStack; -ComboAction::ComboAction() {} - -ComboAction::~ComboAction() { - for (int i=0;i=0;i--) { - commands.at(i)->undo(); - } - for (int i=0;iundo(); - } -} - -void ComboAction::redo() { - for (int i=0;iredo(); - } - for (int i=0;iredo(); - } -} - -void ComboAction::append(QUndoCommand* u) { - commands.append(u); -} - -void ComboAction::appendPost(QUndoCommand* u) { - post_commands.append(u); -} - -MoveClipAction::MoveClipAction(Clip *c, long iin, long iout, long iclip_in, int itrack, bool irelative) { +MoveClipAction::MoveClipAction(ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool irelative) { clip = c; old_in = c->timeline_in; @@ -126,16 +92,14 @@ void MoveClipAction::doRedo() { } } -DeleteClipAction::DeleteClipAction(Sequence* s, int clip) { +DeleteClipAction::DeleteClipAction(SequencePtr s, int clip) { seq = s; index = clip; opening_transition = -1; closing_transition = -1; } -DeleteClipAction::~DeleteClipAction() { - if (ref != nullptr) delete ref; -} +DeleteClipAction::~DeleteClipAction() {} void DeleteClipAction::doUndo() { // restore ref to clip @@ -187,7 +151,7 @@ void DeleteClipAction::doRedo() { linkClipIndex.clear(); linkLinkIndex.clear(); for (int i=0;iclips.size();i++) { - Clip* c = seq->clips.at(i); + ClipPtr c = seq->clips.at(i); if (c != nullptr) { for (int j=0;jlinked.size();j++) { if (c->linked.at(j) == index) { @@ -200,7 +164,7 @@ void DeleteClipAction::doRedo() { } } -ChangeSequenceAction::ChangeSequenceAction(Sequence* s) { +ChangeSequenceAction::ChangeSequenceAction(SequencePtr s) { new_sequence = s; } @@ -213,7 +177,7 @@ void ChangeSequenceAction::doRedo() { set_sequence(new_sequence); } -SetTimelineInOutCommand::SetTimelineInOutCommand(Sequence *s, bool enabled, long in, long out) { +SetTimelineInOutCommand::SetTimelineInOutCommand(SequencePtr s, bool enabled, long in, long out) { seq = s; new_enabled = enabled; new_in = in; @@ -227,7 +191,7 @@ void SetTimelineInOutCommand::doUndo() { // footage viewer functions if (seq->wrapper_sequence) { - Footage* m = seq->clips.at(0)->media->to_footage(); + FootagePtr m = seq->clips.at(0)->media->to_footage(); m->using_inout = old_enabled; m->in = old_in; m->out = old_out; @@ -245,14 +209,14 @@ void SetTimelineInOutCommand::doRedo() { // footage viewer functions if (seq->wrapper_sequence) { - Footage* m = seq->clips.at(0)->media->to_footage(); + FootagePtr m = seq->clips.at(0)->media->to_footage(); m->using_inout = new_enabled; m->in = new_in; m->out = new_out; } } -AddEffectCommand::AddEffectCommand(Clip* c, Effect* e, const EffectMeta *m, int insert_pos) { +AddEffectCommand::AddEffectCommand(ClipPtr c, EffectPtr e, const EffectMeta *m, int insert_pos) { clip = c; ref = e; meta = m; @@ -260,10 +224,6 @@ AddEffectCommand::AddEffectCommand(Clip* c, Effect* e, const EffectMeta *m, int done = false; } -AddEffectCommand::~AddEffectCommand() { - if (!done && ref != nullptr) delete ref; -} - void AddEffectCommand::doUndo() { clip->effects.last()->close(); if (pos < 0) { @@ -286,9 +246,9 @@ void AddEffectCommand::doRedo() { done = true; } -AddTransitionCommand::AddTransitionCommand(Clip* c, - Clip *s, - Transition* copy, +AddTransitionCommand::AddTransitionCommand(ClipPtr c, + ClipPtr s, + TransitionPtr copy, const EffectMeta *itransition, int itype, int ilength) { @@ -337,24 +297,24 @@ void AddTransitionCommand::doRedo() { } } -ModifyTransitionCommand::ModifyTransitionCommand(Clip* c, int itype, long ilength) { +ModifyTransitionCommand::ModifyTransitionCommand(ClipPtr c, int itype, long ilength) { clip = c; type = itype; new_length = ilength; } void ModifyTransitionCommand::doUndo() { - Transition* t = (type == TA_OPENING_TRANSITION) ? clip->get_opening_transition() : clip->get_closing_transition(); + TransitionPtr t = (type == TA_OPENING_TRANSITION) ? clip->get_opening_transition() : clip->get_closing_transition(); t->set_length(old_length); } void ModifyTransitionCommand::doRedo() { - Transition* t = (type == TA_OPENING_TRANSITION) ? clip->get_opening_transition() : clip->get_closing_transition(); + 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); } -DeleteTransitionCommand::DeleteTransitionCommand(Sequence* s, int transition_index) { +DeleteTransitionCommand::DeleteTransitionCommand(SequencePtr s, int transition_index) { seq = s; index = transition_index; transition = nullptr; @@ -362,9 +322,7 @@ DeleteTransitionCommand::DeleteTransitionCommand(Sequence* s, int transition_ind ctc = nullptr; } -DeleteTransitionCommand::~DeleteTransitionCommand() { - if (transition != nullptr) delete transition; -} +DeleteTransitionCommand::~DeleteTransitionCommand() {} void DeleteTransitionCommand::doUndo() { seq->transitions[index] = transition; @@ -377,7 +335,7 @@ void DeleteTransitionCommand::doUndo() { void DeleteTransitionCommand::doRedo() { for (int i=0;iclips.size();i++) { - Clip* c = seq->clips.at(i); + ClipPtr c = seq->clips.at(i); if (c != nullptr) { if (c->opening_transition == index) { otc = c; @@ -466,24 +424,17 @@ void DeleteMediaCommand::doRedo() { done = true; } -AddClipCommand::AddClipCommand(Sequence* s, QVector& add) { +AddClipCommand::AddClipCommand(SequencePtr s, QVector& add) { seq = s; clips = add; } -AddClipCommand::~AddClipCommand() { - for (int i=0;iclear_effects(true); for (int i=0;iclips.last(); + ClipPtr c = seq->clips.last(); panel_timeline->deselect_area(c->timeline_in, c->timeline_out, c->track); undone_clips.prepend(c); if (c->open) close_clip(c, true); @@ -501,9 +452,9 @@ void AddClipCommand::doRedo() { } else { int linkOffset = seq->clips.size(); for (int i=0;icopy(seq); + ClipPtr copy = original->copy(seq); copy->linked.resize(original->linked.size()); for (int j=0;jlinked.size();j++) { copy->linked[j] = original->linked.at(j) + linkOffset; @@ -524,7 +475,7 @@ LinkCommand::LinkCommand() { void LinkCommand::doUndo() { for (int i=0;iclips.at(clips.at(i)); + ClipPtr c = s->clips.at(clips.at(i)); if (link) { c->linked.clear(); } else { @@ -538,7 +489,7 @@ void LinkCommand::doRedo() { old_links.clear(); for (int i=0;iclips.at(clips.at(i)); + ClipPtr c = s->clips.at(clips.at(i)); if (link) { for (int j=0;j all_sequences = panel_project->list_all_project_sequences(); + QVector all_sequences = panel_project->list_all_project_sequences(); for (int i=0;ito_sequence(); + SequencePtr s = all_sequences.at(i)->to_sequence(); for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); + ClipPtr c = s->clips.at(j); if (c != nullptr && c->media == item && c->open) { close_clip(c, true); c->replaced = true; @@ -621,7 +572,7 @@ void ReplaceClipMediaCommand::replace(bool undo) { } for (int i=0;iopen) { close_clip(c, true); } @@ -660,17 +611,11 @@ EffectDeleteCommand::EffectDeleteCommand() { done = false; } -EffectDeleteCommand::~EffectDeleteCommand() { - if (done) { - for (int i=0;ieffects.insert(fx.at(i), deleted_objects.at(i)); } panel_effect_controls->reload_clips(); @@ -681,9 +626,9 @@ void EffectDeleteCommand::doUndo() { void EffectDeleteCommand::doRedo() { deleted_objects.clear(); for (int i=0;ieffects.at(fx_id); + EffectPtr e = c->effects.at(fx_id); e->close(); deleted_objects.append(e); c->effects.removeAt(fx_id); @@ -705,7 +650,7 @@ void MediaMove::doRedo() { if (to == nullptr) to = project_model.get_root(); froms.resize(items.size()); for (int i=0;iparentItem(); + Media* parent = items.at(i)->parentItem(); froms[i] = parent; project_model.moveChild(items.at(i), to); } @@ -855,7 +800,7 @@ void DeleteMarkerAction::doRedo() { sorted = true; } -SetSpeedAction::SetSpeedAction(Clip* c, double speed) { +SetSpeedAction::SetSpeedAction(ClipPtr c, double speed) { clip = c; old_speed = c->speed; new_speed = speed; @@ -886,7 +831,7 @@ void SetBool::doRedo() { *boolean = new_setting; } -SetSelectionsCommand::SetSelectionsCommand(Sequence* s) { +SetSelectionsCommand::SetSelectionsCommand(SequencePtr s) { seq = s; done = true; } @@ -903,7 +848,7 @@ void SetSelectionsCommand::doRedo() { } } -EditSequenceCommand::EditSequenceCommand(Media* i, Sequence *s) { +EditSequenceCommand::EditSequenceCommand(Media* i, SequencePtr s) { item = i; seq = s; old_name = s->name; @@ -1013,11 +958,7 @@ RemoveClipsFromClipboard::RemoveClipsFromClipboard(int index) { done = false; } -RemoveClipsFromClipboard::~RemoveClipsFromClipboard() { - if (done) { - delete clip; - } -} +RemoveClipsFromClipboard::~RemoveClipsFromClipboard() {} void RemoveClipsFromClipboard::doUndo() { clipboard.insert(pos, clip); @@ -1025,7 +966,7 @@ void RemoveClipsFromClipboard::doUndo() { } void RemoveClipsFromClipboard::doRedo() { - clip = static_cast(clipboard.at(pos)); + clip = std::static_pointer_cast(clipboard.at(pos)); clipboard.removeAt(pos); done = true; } @@ -1068,7 +1009,7 @@ void ReloadEffectsCommand::doRedo() { panel_effect_controls->reload_clips(); } -RippleAction::RippleAction(Sequence *is, long ipoint, long ilength, const QVector &iignore) { +RippleAction::RippleAction(SequencePtr is, long ipoint, long ilength, const QVector &iignore) { s = is; point = ipoint; length = ilength; @@ -1084,7 +1025,7 @@ void RippleAction::doRedo() { ca = new ComboAction(); for (int i=0;iclips.size();i++) { if (!ignore.contains(i)) { - Clip* c = s->clips.at(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); @@ -1182,11 +1123,11 @@ void RefreshClips::doUndo() { void RefreshClips::doRedo() { // close any clips currently using this media - QVector all_sequences = panel_project->list_all_project_sequences(); + QVector all_sequences = panel_project->list_all_project_sequences(); for (int i=0;ito_sequence(); + SequencePtr s = all_sequences.at(i)->to_sequence(); for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); + ClipPtr c = s->clips.at(j); if (c != nullptr && c->media == media) { c->replaced = true; c->refresh(); @@ -1203,7 +1144,7 @@ void UpdateViewer::doRedo() { panel_sequence_viewer->viewer_widget->frame_update(); } -SetEffectData::SetEffectData(Effect *e, const QByteArray &s) { +SetEffectData::SetEffectData(EffectPtr e, const QByteArray &s) { effect = e; data = s; } diff --git a/project/undo.h b/project/undo.h index 1edf1b159..09d07dbad 100644 --- a/project/undo.h +++ b/project/undo.h @@ -21,24 +21,14 @@ #ifndef UNDO_H #define UNDO_H -class Media; -class QCheckBox; -class LabelSlider; -class Effect; -class SourceTable; -class EffectRow; -class EffectField; -class Transition; -class EffectGizmo; -class Clip; -struct Sequence; -struct Footage; -struct EffectMeta; - -#include "project/marker.h" +#include "project/projectelements.h" #include "project/selection.h" #include "project/effectfield.h" +#include "ui/labelslider.h" +#include "ui/sourcetable.h" + +#include #include #include #include @@ -49,19 +39,6 @@ namespace olive { extern QUndoStack UndoStack; } -class ComboAction : public QUndoCommand { -public: - ComboAction(); - virtual ~ComboAction() override; - virtual void undo() override; - virtual void redo() override; - void append(QUndoCommand* u); - void appendPost(QUndoCommand* u); -private: - QVector commands; - QVector post_commands; -}; - class OliveAction : public QUndoCommand { public: OliveAction(bool iset_window_modified = true); @@ -86,11 +63,11 @@ private: class MoveClipAction : public OliveAction { public: - MoveClipAction(Clip* c, long iin, long iout, long iclip_in, int itrack, bool irelative); + MoveClipAction(ClipPtr c, long iin, long iout, long iclip_in, int itrack, bool irelative); virtual void doUndo() override; virtual void doRedo() override; private: - Clip* clip; + ClipPtr clip; long old_in; long old_out; @@ -107,11 +84,11 @@ private: class RippleAction : public OliveAction { public: - RippleAction(Sequence *is, long ipoint, long ilength, const QVector& iignore); + RippleAction(SequencePtr is, long ipoint, long ilength, const QVector& iignore); virtual void doUndo() override; virtual void doRedo() override; private: - Sequence *s; + SequencePtr s; long point; long length; QVector ignore; @@ -120,13 +97,13 @@ private: class DeleteClipAction : public OliveAction { public: - DeleteClipAction(Sequence* s, int clip); + DeleteClipAction(SequencePtr s, int clip); virtual ~DeleteClipAction() override; virtual void doUndo() override; virtual void doRedo() override; private: - Sequence* seq; - Clip* ref; + SequencePtr seq; + ClipPtr ref; int index; int opening_transition; @@ -138,37 +115,36 @@ private: class ChangeSequenceAction : public OliveAction { public: - ChangeSequenceAction(Sequence* s); + ChangeSequenceAction(SequencePtr s); virtual void doUndo() override; virtual void doRedo() override; private: - Sequence* old_sequence; - Sequence* new_sequence; + SequencePtr old_sequence; + SequencePtr new_sequence; }; class AddEffectCommand : public OliveAction { public: - AddEffectCommand(Clip* c, Effect *e, const EffectMeta* m, int insert_pos = -1); - virtual ~AddEffectCommand() override; + AddEffectCommand(ClipPtr c, EffectPtr e, const EffectMeta* m, int insert_pos = -1); virtual void doUndo() override; virtual void doRedo() override; private: - Clip* clip; + ClipPtr clip; const EffectMeta* meta; - Effect* ref; + EffectPtr ref; int pos; bool done; }; class AddTransitionCommand : public OliveAction { public: - AddTransitionCommand(Clip* c, Clip* s, Transition *copy, const EffectMeta* itransition, int itype, int ilength); + AddTransitionCommand(ClipPtr c, ClipPtr s, TransitionPtr copy, const EffectMeta* itransition, int itype, int ilength); virtual void doUndo() override; virtual void doRedo() override; private: - Clip* clip; - Clip* secondary; - Transition* transition_to_copy; + ClipPtr clip; + ClipPtr secondary; + TransitionPtr transition_to_copy; const EffectMeta* transition; int type; int length; @@ -178,11 +154,11 @@ private: class ModifyTransitionCommand : public OliveAction { public: - ModifyTransitionCommand(Clip* c, int itype, long ilength); + ModifyTransitionCommand(ClipPtr c, int itype, long ilength); virtual void doUndo() override; virtual void doRedo() override; private: - Clip* clip; + ClipPtr clip; int type; long new_length; long old_length; @@ -190,25 +166,25 @@ private: class DeleteTransitionCommand : public OliveAction { public: - DeleteTransitionCommand(Sequence* s, int transition_index); + DeleteTransitionCommand(SequencePtr s, int transition_index); virtual ~DeleteTransitionCommand() override; virtual void doUndo() override; virtual void doRedo() override; private: - Sequence* seq; + SequencePtr seq; int index; - Transition* transition; - Clip* otc; - Clip* ctc; + TransitionPtr transition; + ClipPtr otc; + ClipPtr ctc; }; class SetTimelineInOutCommand : public OliveAction { public: - SetTimelineInOutCommand(Sequence* s, bool enabled, long in, long out); + SetTimelineInOutCommand(SequencePtr s, bool enabled, long in, long out); virtual void doUndo() override; virtual void doRedo() override; private: - Sequence* seq; + SequencePtr seq; bool old_enabled; long old_in; @@ -221,25 +197,25 @@ private: class NewSequenceCommand : public OliveAction { public: - NewSequenceCommand(Media *s, Media* iparent); + NewSequenceCommand(Media* s, Media* iparent); virtual ~NewSequenceCommand() override; virtual void doUndo() override; virtual void doRedo() override; private: - Media* seq; - Media* parent; + Media* seq; + Media* parent; bool done; }; class AddMediaCommand : public OliveAction { public: - AddMediaCommand(Media* iitem, Media* iparent); + AddMediaCommand(Media* iitem, Media* iparent); virtual ~AddMediaCommand() override; virtual void doUndo() override; virtual void doRedo() override; private: - Media* item; - Media* parent; + Media* item; + Media* parent; bool done; }; @@ -250,21 +226,21 @@ public: virtual void doUndo() override; virtual void doRedo() override; private: - Media* item; + Media* item; Media* parent; bool done; }; class AddClipCommand : public OliveAction { public: - AddClipCommand(Sequence* s, QVector& add); + AddClipCommand(SequencePtr s, QVector& add); virtual ~AddClipCommand() override; virtual void doUndo() override; virtual void doRedo() override; private: - Sequence* seq; - QVector clips; - QVector undone_clips; + SequencePtr seq; + QVector clips; + QVector undone_clips; }; class LinkCommand : public OliveAction { @@ -272,7 +248,7 @@ public: LinkCommand(); virtual void doUndo() override; virtual void doRedo() override; - Sequence* s; + SequencePtr s; QVector clips; bool link; private: @@ -293,7 +269,7 @@ private: class ReplaceMediaCommand : public OliveAction { public: - ReplaceMediaCommand(Media*, QString); + ReplaceMediaCommand(Media*, QString); virtual void doUndo() override; virtual void doRedo() override; private: @@ -308,10 +284,10 @@ public: ReplaceClipMediaCommand(Media *, Media *, bool); virtual void doUndo() override; virtual void doRedo() override; - QVector clips; + QVector clips; private: - Media* old_media; - Media* new_media; + Media* old_media; + Media* new_media; bool preserve_clip_ins; QVector old_clip_ins; void replace(bool undo); @@ -323,18 +299,18 @@ public: virtual ~EffectDeleteCommand() override; virtual void doUndo() override; virtual void doRedo() override; - QVector clips; + QVector clips; QVector fx; private: bool done; - QVector deleted_objects; + QVector deleted_objects; }; class MediaMove : public OliveAction { public: MediaMove(); - QVector items; - Media* to; + QVector items; + Media* to; virtual void doUndo() override; virtual void doRedo() override; private: @@ -343,11 +319,11 @@ private: class MediaRename : public OliveAction { public: - MediaRename(Media* iitem, QString to); + MediaRename(Media* iitem, QString to); virtual void doUndo() override; virtual void doRedo() override; private: - Media* item; + Media* item; QString from; QString to; }; @@ -395,7 +371,7 @@ public: SetAutoscaleAction(); virtual void doUndo() override; virtual void doRedo() override; - QVector clips; + QVector clips; }; class AddMarkerAction : public OliveAction { @@ -436,11 +412,11 @@ private: class SetSpeedAction : public OliveAction { public: - SetSpeedAction(Clip* c, double speed); + SetSpeedAction(ClipPtr c, double speed); virtual void doUndo() override; virtual void doRedo() override; private: - Clip* clip; + ClipPtr clip; double old_speed; double new_speed; }; @@ -458,19 +434,19 @@ private: class SetSelectionsCommand : public OliveAction { public: - SetSelectionsCommand(Sequence *s); + SetSelectionsCommand(SequencePtr s); virtual void doUndo() override; virtual void doRedo() override; QVector old_data; QVector new_data; private: - Sequence* seq; + SequencePtr seq; bool done; }; class EditSequenceCommand : public OliveAction { public: - EditSequenceCommand(Media *i, Sequence* s); + EditSequenceCommand(Media *i, SequencePtr s); virtual void doUndo() override; virtual void doRedo() override; void update(); @@ -482,8 +458,8 @@ public: int audio_frequency; int audio_layout; private: - Media* item; - Sequence* seq; + Media* item; + SequencePtr seq; QString old_name; int old_width; @@ -545,11 +521,11 @@ public: class UpdateFootageTooltip : public OliveAction { public: - UpdateFootageTooltip(Media* i); + UpdateFootageTooltip(Media* i); virtual void doUndo() override; virtual void doRedo() override; private: - Media* item; + Media* item; }; class MoveEffectCommand : public OliveAction { @@ -557,7 +533,7 @@ public: MoveEffectCommand(); virtual void doUndo() override; virtual void doRedo() override; - Clip* clip; + ClipPtr clip; int from; int to; }; @@ -570,14 +546,14 @@ public: virtual void doRedo() override; private: int pos; - Clip* clip; + ClipPtr clip; bool done; }; class RenameClipCommand : public OliveAction { public: RenameClipCommand(); - QVector clips; + QVector clips; QString new_name; virtual void doUndo() override; virtual void doRedo() override; @@ -626,11 +602,11 @@ private: class RefreshClips : public OliveAction { public: - RefreshClips(Media* m); + RefreshClips(Media* m); virtual void doUndo() override; virtual void doRedo() override; private: - Media* media; + Media* media; }; class UpdateViewer : public OliveAction { @@ -641,11 +617,11 @@ public: class SetEffectData : public OliveAction { public: - SetEffectData(Effect* e, const QByteArray &s); + SetEffectData(EffectPtr e, const QByteArray &s); virtual void doUndo() override; virtual void doRedo() override; private: - Effect* effect; + EffectPtr effect; QByteArray data; QByteArray old_data; }; diff --git a/ui/keyframeview.cpp b/ui/keyframeview.cpp index eb448b9e2..5d494673d 100644 --- a/ui/keyframeview.cpp +++ b/ui/keyframeview.cpp @@ -106,15 +106,15 @@ void KeyframeView::paintEvent(QPaintEvent*) { visible_out = 0; for (int j=0;jselected_clips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j)); + ClipPtr c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j)); visible_in = qMin(visible_in, c->timeline_in); visible_out = qMax(visible_out, c->timeline_out); } for (int j=0;jselected_clips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j)); + ClipPtr c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j)); for (int i=0;ieffects.size();i++) { - Effect* e = c->effects.at(i); + EffectPtr e = c->effects.at(i); if (e->container->is_expanded()) { for (int j=0;jrow_count();j++) { EffectRow* row = e->row(j); @@ -373,7 +373,7 @@ void KeyframeView::mouseMoveEvent(QMouseEvent* event) { if (panel_timeline->snapping) { for (int i=0;iparent_row->parent_effect->parent_clip; + ClipPtr c = field->parent_row->parent_effect->parent_clip; long key_time = old_key_vals.at(i) + frame_diff - c->clip_in + c->timeline_in; long key_eval = key_time; if (panel_timeline->snap_to_point(olive::ActiveSequence->playhead, &key_eval)) { diff --git a/ui/renderfunctions.cpp b/ui/renderfunctions.cpp index a8a0adaf8..f00cc915e 100644 --- a/ui/renderfunctions.cpp +++ b/ui/renderfunctions.cpp @@ -100,8 +100,8 @@ GLuint draw_clip(QOpenGLFramebufferObject* fbo, GLuint texture, bool clear) { return fbo->texture(); } -void process_effect(Clip* c, - Effect* e, +void process_effect(ClipPtr c, + EffectPtr e, double timecode, GLTextureCoords& coords, GLuint& composite_texture, @@ -151,7 +151,7 @@ void process_effect(Clip* c, GLuint compose_sequence(ComposeSequenceParams ¶ms) { GLuint final_fbo = params.main_buffer; - Sequence* s = params.seq; + SequencePtr s = params.seq; long playhead = s->playhead; if (!params.nests.isEmpty()) { @@ -170,12 +170,12 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { int audio_track_count = 0; - QVector current_clips; + QVector current_clips; // loop through clips, find currently active, and sort by track for (int i=0;iclips.size();i++) { - Clip* c = s->clips.at(i); + ClipPtr c = s->clips.at(i); if (c != nullptr) { @@ -186,7 +186,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { // is the clip a "footage" clip? if (c->media != nullptr && c->media->get_type() == MEDIA_TYPE_FOOTAGE) { - Footage* m = c->media->to_footage(); + FootagePtr m = c->media->to_footage(); // does the clip have a valid media source? if (!m->invalid && !(c->track >= 0 && !is_audio_device_set())) { @@ -273,7 +273,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { // loop through current clips for (int i=0;imedia != nullptr && c->media->get_type() == MEDIA_TYPE_FOOTAGE && !c->finished_opening) { @@ -395,12 +395,12 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { double timecode = get_timecode(c, playhead); // set up variables for gizmos later - Effect* first_gizmo_effect = nullptr; - Effect* selected_effect = nullptr; + EffectPtr first_gizmo_effect = nullptr; + EffectPtr selected_effect = nullptr; // run through all of the clip's effects for (int j=0;jeffects.size();j++) { - Effect* e = c->effects.at(j); + EffectPtr e = c->effects.at(j); process_effect(c, e, timecode, coords, textureID, fbo_switcher, params.texture_failed, TA_NO_TRANSITION); // retrieve gizmo data from effect @@ -601,7 +601,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { if (c->sequence == params.seq) { // only if you can currently see them double ts = (playhead - c->get_timeline_in_with_transition() + c->get_clip_in_with_transition())/s->frame_rate; for (int i=0;ieffects.size();i++) { - Effect* e = c->effects.at(i); + EffectPtr e = c->effects.at(i); for (int j=0;jrow_count();j++) { EffectRow* r = e->row(j); for (int k=0;kfieldCount();k++) { @@ -630,7 +630,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { return 0; } -void compose_audio(Viewer* viewer, Sequence* seq, int playback_speed) { +void compose_audio(Viewer* viewer, SequencePtr seq, int playback_speed) { ComposeSequenceParams params; params.viewer = viewer; params.ctx = nullptr; diff --git a/ui/renderfunctions.h b/ui/renderfunctions.h index 2197a59ee..a5f11e588 100644 --- a/ui/renderfunctions.h +++ b/ui/renderfunctions.h @@ -23,12 +23,12 @@ #include #include +#include -class Effect; -class Viewer; -class QOpenGLShaderProgram; -struct Sequence; -class Clip; +#include "project/sequence.h" +#include "project/effect.h" + +#include "panels/viewer.h" /** * @brief The ComposeSequenceParams struct @@ -59,7 +59,7 @@ struct ComposeSequenceParams { * In addition to clips, sequences also contain the playhead position so compose_sequence() knows which frame * to render. */ - Sequence* seq; + SequencePtr seq; /** * @brief Array to store the nested sequence hierarchy @@ -67,7 +67,7 @@ struct ComposeSequenceParams { * Should be left empty. This array gets passed around compose_sequence() as it calls itself recursively to * handle nested sequences. */ - QVector nests; + QVector nests; /** * @brief Set compose mode to video or audio @@ -82,7 +82,7 @@ struct ComposeSequenceParams { * A pointer to a pointer that will be set to the Effect whose gizmos are being rendered and should therefore * be interacted with if the user uses them. */ - Effect** gizmos; + EffectPtr* gizmos; /** * @brief A variable that compose_sequence() will set to **TRUE** if any of the clips couldn't be shown. @@ -260,6 +260,6 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms); * * The current playback speed (controlled by Shuttle Left/Right) */ -void compose_audio(Viewer* viewer, Sequence* seq, int playback_speed); +void compose_audio(Viewer* viewer, SequencePtr seq, int playback_speed); #endif // RENDERFUNCTIONS_H diff --git a/ui/renderthread.cpp b/ui/renderthread.cpp index d5136b59b..29da93012 100644 --- a/ui/renderthread.cpp +++ b/ui/renderthread.cpp @@ -235,7 +235,7 @@ void RenderThread::paint() { glDisable(GL_TEXTURE_2D); } -void RenderThread::start_render(QOpenGLContext *share, Sequence *s, const QString& save, GLvoid* pixels, int pixel_linesize, int idivider) { +void RenderThread::start_render(QOpenGLContext *share, SequencePtr s, const QString& save, GLvoid* pixels, int pixel_linesize, int idivider) { Q_UNUSED(idivider); seq = s; diff --git a/ui/renderthread.h b/ui/renderthread.h index 4c2288098..192d6f1f7 100644 --- a/ui/renderthread.h +++ b/ui/renderthread.h @@ -29,14 +29,14 @@ #include #include +#include "project/sequence.h" +#include "project/effect.h" + // copied from source code to OCIODisplay -#define LUT3D_EDGE_SIZE 32 +const int LUT3D_EDGE_SIZE = 32; // copied from source code to OCIODisplay, expanded from 3*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE*LUT3D_EDGE_SIZE -#define NUM_3D_ENTRIES 98304 - -struct Sequence; -class Effect; +const int NUM_3D_ENTRIES = 98304; class RenderThread : public QThread { Q_OBJECT @@ -47,9 +47,9 @@ public: QMutex mutex; GLuint front_buffer; GLuint front_texture; - Effect* gizmos; + EffectPtr gizmos; void paint(); - void start_render(QOpenGLContext* share, Sequence* s, const QString &save = nullptr, GLvoid *pixels = nullptr, int pixel_linesize = 0, int idivider = 0); + void start_render(QOpenGLContext* share, SequencePtr s, const QString &save = nullptr, GLvoid *pixels = nullptr, int pixel_linesize = 0, int idivider = 0); bool did_texture_fail(); void cancel(); @@ -78,7 +78,7 @@ private: float ocio_lut_data[NUM_3D_ENTRIES]; - Sequence* seq; + SequencePtr seq; int divider; int tex_width; int tex_height; diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index e01a41fee..d18c45ecf 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -100,9 +100,9 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { menu.addSeparator(); // collect all the selected clips - QVector selected_clips; + QVector selected_clips; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { selected_clips.append(c); } @@ -186,7 +186,7 @@ void TimelineWidget::show_context_menu(const QPoint& pos) { void TimelineWidget::toggle_autoscale() { SetAutoscaleAction* action = new SetAutoscaleAction(); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { action->clips.append(c); } @@ -201,7 +201,7 @@ void TimelineWidget::toggle_autoscale() { void TimelineWidget::tooltip_timer_timeout() { if (olive::ActiveSequence != nullptr) { if (tooltip_clip < olive::ActiveSequence->clips.size()) { - Clip* c = olive::ActiveSequence->clips.at(tooltip_clip); + ClipPtr c = olive::ActiveSequence->clips.at(tooltip_clip); if (c != nullptr) { QToolTip::showText(QCursor::pos(), tr("%1\nStart: %2\nEnd: %3\nDuration: %4").arg( @@ -217,9 +217,9 @@ void TimelineWidget::tooltip_timer_timeout() { } void TimelineWidget::rename_clip() { - QVector selected_clips; + QVector selected_clips; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && is_clip_selected(c, true)) { selected_clips.append(c); } @@ -278,7 +278,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { } if (event->source() == panel_footage_viewer->viewer_widget) { - Sequence* proposed_seq = panel_footage_viewer->seq; + SequencePtr proposed_seq = panel_footage_viewer->seq; if (proposed_seq != olive::ActiveSequence) { // don't allow nesting the same sequence media_list.append(panel_footage_viewer->media); import_init = true; @@ -299,7 +299,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { for (int i=0;ilast_imported_media.size();i++) { // waits for media to have a duration // TODO would be much nicer if this was multithreaded - Footage* f = panel_project->last_imported_media.at(i)->to_footage(); + FootagePtr f = panel_project->last_imported_media.at(i)->to_footage(); f->ready_lock.lock(); f->ready_lock.unlock(); @@ -321,7 +321,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { event->acceptProposedAction(); long entry_point; - Sequence* seq = olive::ActiveSequence; + SequencePtr seq = olive::ActiveSequence; if (seq == nullptr) { // if no sequence, we're going to create a new one using the clips as a reference @@ -413,7 +413,7 @@ void TimelineWidget::dragLeaveEvent(QDragLeaveEvent* event) { update_ui(false); } if (self_created_sequence != nullptr) { - delete self_created_sequence; + self_created_sequence.reset(); self_created_sequence = nullptr; } } @@ -461,7 +461,7 @@ void insert_clips(ComboAction* ca) { panel_timeline->split_cache.clear(); for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { // don't split any clips that are moving bool found = false; @@ -517,7 +517,7 @@ void TimelineWidget::dropEvent(QDropEvent* event) { ComboAction* ca = new ComboAction(); - Sequence* s = olive::ActiveSequence; + SequencePtr s = olive::ActiveSequence; // if we're dropping into nothing, create a new sequences based on the clip being dragged if (s == nullptr) { @@ -545,7 +545,7 @@ void TimelineWidget::mouseDoubleClickEvent(QMouseEvent *event) { if (panel_timeline->tool == TIMELINE_TOOL_EDIT) { int clip_index = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); if (clip_index >= 0) { - Clip* clip = olive::ActiveSequence->clips.at(clip_index); + ClipPtr clip = olive::ActiveSequence->clips.at(clip_index); if (!(event->modifiers() & Qt::ShiftModifier)) olive::ActiveSequence->selections.clear(); Selection s; s.in = clip->timeline_in; @@ -557,7 +557,7 @@ void TimelineWidget::mouseDoubleClickEvent(QMouseEvent *event) { } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER) { int clip_index = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); if (clip_index >= 0) { - Clip* c = olive::ActiveSequence->clips.at(clip_index); + ClipPtr c = olive::ActiveSequence->clips.at(clip_index); if (c->media != nullptr && c->media->get_type() == MEDIA_TYPE_SEQUENCE) { set_sequence(c->media->to_sequence()); } @@ -644,7 +644,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { panel_timeline->moving_init = true; } else { if (clip_index >= 0) { - Clip* clip = olive::ActiveSequence->clips.at(clip_index); + ClipPtr clip = olive::ActiveSequence->clips.at(clip_index); if (clip != nullptr) { if (is_clip_selected(clip, true)) { if (shift) { @@ -652,7 +652,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { if (!alt) { for (int i=0;ilinked.size();i++) { - Clip* link = olive::ActiveSequence->clips.at(clip->linked.at(i)); + ClipPtr link = olive::ActiveSequence->clips.at(clip->linked.at(i)); panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); } } @@ -660,7 +660,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { panel_timeline->deselect_area(clip->timeline_in, clip->timeline_out, clip->track); for (int i=0;ilinked.size();i++) { - Clip* link = olive::ActiveSequence->clips.at(clip->linked.at(i)); + ClipPtr link = olive::ActiveSequence->clips.at(clip->linked.at(i)); panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); } @@ -711,7 +711,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { // if alt is not down, select links if (!alt && panel_timeline->transition_select == TA_NO_TRANSITION) { for (int i=0;ilinked.size();i++) { - Clip* link = olive::ActiveSequence->clips.at(clip->linked.at(i)); + ClipPtr link = olive::ActiveSequence->clips.at(clip->linked.at(i)); if (!is_clip_selected(link, true)) { Selection ss; ss.in = link->timeline_in; @@ -765,7 +765,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { } } -void make_room_for_transition(ComboAction* ca, Clip* c, int type, long transition_start, long transition_end, bool delete_old_transitions) { +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 (delete_old_transitions && c->get_opening_transition() != nullptr) { @@ -812,7 +812,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { panel_sequence_viewer->cue_recording(qMin(g.in, g.out), qMax(g.in, g.out), g.track); panel_timeline->creating = false; } else if (g.in != g.out) { - Clip* c = new Clip(olive::ActiveSequence); + ClipPtr c = ClipPtr(new Clip(olive::ActiveSequence)); c->media = nullptr; c->timeline_in = qMin(g.in, g.out); c->timeline_out = qMax(g.in, g.out); @@ -834,7 +834,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { panel_timeline->delete_areas_and_relink(ca, areas, false); } - QVector add; + QVector add; add.append(c); ca->append(new AddClipCommand(olive::ActiveSequence, add)); @@ -855,7 +855,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { case ADD_OBJ_BARS: { c->name = tr("Bars"); - Effect* e = create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT)); + EffectPtr e = create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT)); e->row(0)->field(0)->set_combo_index(1); c->effects.append(e); } @@ -943,13 +943,13 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { && panel_timeline->trim_target == -1) { // if holding alt (and not trimming), duplicate rather than move // duplicate clips QVector old_clips; - QVector new_clips; + QVector new_clips; QVector delete_areas; for (int i=0;ighosts.size();i++) { const Ghost& g = panel_timeline->ghosts.at(i); if (g.old_in != g.in || g.old_out != g.out || g.track != g.old_track || g.clip_in != g.old_clip_in) { // create copy of clip - Clip* c = olive::ActiveSequence->clips.at(g.clip)->copy(olive::ActiveSequence); + ClipPtr c(olive::ActiveSequence->clips.at(g.clip)->copy(olive::ActiveSequence)); c->timeline_in = g.in; c->timeline_out = g.out; @@ -1010,7 +1010,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { Ghost& g = panel_timeline->ghosts[i]; // step 3 - move clips - Clip* c = olive::ActiveSequence->clips.at(g.clip); + ClipPtr c = olive::ActiveSequence->clips.at(g.clip); if (g.transition == nullptr) { move_clip(ca, c, (g.in - g.old_in), (g.out - g.old_out), (g.clip_in - g.old_clip_in), (g.track - g.old_track), true, true); @@ -1082,8 +1082,8 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { long transition_start = qMin(g.in, g.out); long transition_end = qMax(g.in, g.out); - Clip* pre = olive::ActiveSequence->clips.at(g.clip); - Clip* post = pre; + ClipPtr pre = olive::ActiveSequence->clips.at(g.clip); + ClipPtr post = pre; make_room_for_transition(ca, pre, panel_timeline->transition_tool_type, transition_start, transition_end, true); @@ -1101,7 +1101,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { // swap - Clip* temp = pre; + ClipPtr temp = pre; pre = post; post = temp; } @@ -1200,7 +1200,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { void TimelineWidget::init_ghosts() { for (int i=0;ighosts.size();i++) { Ghost& g = panel_timeline->ghosts[i]; - Clip* c = olive::ActiveSequence->clips.at(g.clip); + ClipPtr c = olive::ActiveSequence->clips.at(g.clip); g.track = g.old_track = c->track; g.clip_in = g.old_clip_in = c->clip_in; @@ -1238,7 +1238,7 @@ void TimelineWidget::init_ghosts() { } } -void validate_transitions(Clip* c, int transition_type, long& frame_diff) { +void validate_transitions(ClipPtr c, int transition_type, long& frame_diff) { long validator; if (transition_type == TA_OPENING_TRANSITION) { @@ -1306,7 +1306,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { // if the ghost is attached to a clip, snap its markers too if (panel_timeline->trim_target == -1 && g.clip >= 0) { - Clip* c = olive::ActiveSequence->clips.at(g.clip); + ClipPtr c = olive::ActiveSequence->clips.at(g.clip); for (int j=0;jget_markers().size();j++) { long marker_real_time = c->get_markers().at(j).frame + c->timeline_in - c->clip_in; fm = marker_real_time + frame_diff; @@ -1325,7 +1325,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { long temp_frame_diff = frame_diff; // cache to see if we change it (thus cancelling any snap) for (int i=0;ighosts.size();i++) { const Ghost& g = panel_timeline->ghosts.at(i); - Clip* c = nullptr; + ClipPtr c = nullptr; if (g.clip != -1) c = olive::ActiveSequence->clips.at(g.clip); const FootageStream* ms = nullptr; @@ -1380,8 +1380,8 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { // prevent dual transition from going below 0 on the primary or media length on the secondary if (g.transition != nullptr && g.transition->secondary_clip != nullptr) { - Clip* otc = g.transition->parent_clip; - Clip* ctc = g.transition->secondary_clip; + ClipPtr otc = g.transition->parent_clip; + ClipPtr ctc = g.transition->secondary_clip; if (g.trim_in) { frame_diff -= g.transition->get_true_length(); @@ -1407,7 +1407,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { // ripple ops if (effective_tool == TIMELINE_TOOL_RIPPLE) { for (int j=0;jtrim_in_point) { @@ -1417,7 +1417,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { // prevent any post-clips colliding with pre-clips for (int k=0;ktrack == post->track) { if (panel_timeline->trim_in_point) { validator = post->timeline_in - frame_diff - pre->timeline_out; @@ -1481,12 +1481,12 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { if (panel_timeline->transition_tool_post_clip == -1) { validate_transitions(c, panel_timeline->transition_tool_type, frame_diff); } else { - Clip* otc = c; // open transition clip - Clip* ctc = olive::ActiveSequence->clips.at(panel_timeline->transition_tool_post_clip); // close transition clip + 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) { // swap - Clip* temp = otc; + ClipPtr temp = otc; otc = ctc; ctc = temp; } @@ -1670,7 +1670,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { // select linked clips too if (olive::CurrentConfig.edit_tool_selects_links) { for (int j=0;jclips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(j); + ClipPtr c = olive::ActiveSequence->clips.at(j); for (int k=0;kselections.size();k++) { const Selection& s = olive::ActiveSequence->selections.at(k); if (!(c->timeline_in < s.in && c->timeline_out < s.in) && @@ -1728,7 +1728,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } else { new_height -= diff; } - if (new_height < TRACK_MIN_HEIGHT) new_height = TRACK_MIN_HEIGHT; + new_height = qMax(new_height, olive::timeline::kTrackMinHeight); panel_timeline->calculate_track_height(track_target, new_height); update(); } else if (panel_timeline->moving_proc) { @@ -1737,7 +1737,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { // set up movement // create ghosts for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { Ghost g; g.transition = nullptr; @@ -1785,11 +1785,11 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { int size = panel_timeline->ghosts.size(); if (panel_timeline->tool == TIMELINE_TOOL_ROLLING) { for (int i=0;iclips.at(panel_timeline->ghosts.at(i).clip); + ClipPtr ghost_clip = olive::ActiveSequence->clips.at(panel_timeline->ghosts.at(i).clip); // see if any ghosts are touching, in which case flip them for (int k=0;kclips.at(panel_timeline->ghosts.at(k).clip); + ClipPtr comp_clip = olive::ActiveSequence->clips.at(panel_timeline->ghosts.at(k).clip); if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { panel_timeline->ghosts[k].trim_in = !panel_timeline->trim_in_point; @@ -1800,9 +1800,9 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { // then look for other clips we're touching for (int i=0;ighosts.at(i); - Clip* ghost_clip = olive::ActiveSequence->clips.at(g.clip); + ClipPtr ghost_clip = olive::ActiveSequence->clips.at(g.clip); for (int j=0;jclips.size();j++) { - Clip* comp_clip = olive::ActiveSequence->clips.at(j); + ClipPtr comp_clip = olive::ActiveSequence->clips.at(j); if (comp_clip->track == ghost_clip->track) { if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { @@ -1839,10 +1839,10 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } else if (panel_timeline->tool == TIMELINE_TOOL_SLIDE) { for (int i=0;ighosts.at(i); - Clip* ghost_clip = olive::ActiveSequence->clips.at(g.clip); + ClipPtr ghost_clip = olive::ActiveSequence->clips.at(g.clip); panel_timeline->ghosts[i].trimming = false; for (int j=0;jclips.size();j++) { - Clip* c = olive::ActiveSequence->clips.at(j); + ClipPtr c = olive::ActiveSequence->clips.at(j); if (c != nullptr && c->track == ghost_clip->track) { bool found = false; for (int k=0;kghosts.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(panel_timeline->ghosts.at(i).clip); + ClipPtr c = olive::ActiveSequence->clips.at(panel_timeline->ghosts.at(i).clip); if (panel_timeline->trim_in_point) { axis = qMin(axis, c->timeline_in); } else { @@ -1883,15 +1883,15 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && !is_clip_selected(c, true)) { bool clip_is_post = (c->timeline_in >= axis); // see if this a clip on this track is already in the list, and if it's closer bool found = false; - QVector& clip_list = clip_is_post ? post_clips : pre_clips; + QVector& clip_list = clip_is_post ? post_clips : pre_clips; for (int j=0;jtrack == c->track) { if ((!clip_is_post && compare->timeline_out < c->timeline_out) || (clip_is_post && compare->timeline_in > c->timeline_in)) { @@ -1957,15 +1957,15 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { int track_min = qMin(track_start, track_end); int track_max = qMax(track_start, track_end); - QVector selected_clips; + QVector selected_clips; for (int i=0;iclips.size();i++) { - Clip* clip = olive::ActiveSequence->clips.at(i); + ClipPtr clip = olive::ActiveSequence->clips.at(i); if (clip != nullptr && clip->track >= track_min && clip->track <= track_max && !(clip->timeline_in < frame_min && clip->timeline_out < frame_min) && !(clip->timeline_in > frame_max && clip->timeline_out > frame_max)) { - QVector session_clips; + QVector session_clips; session_clips.append(clip); if (!alt) { @@ -1977,7 +1977,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { for (int j=0;jselections.resize(selected_clips.size() + panel_timeline->selection_offset); for (int i=0;iselections[i+panel_timeline->selection_offset]; - Clip* clip = selected_clips.at(i); + ClipPtr clip = selected_clips.at(i); s.old_in = s.in = clip->timeline_in; s.old_out = s.out = clip->timeline_out; s.old_track = s.track = clip->track; @@ -2056,7 +2056,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { // loop through current clips in the sequence for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr) { // cache track range @@ -2230,7 +2230,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { if (panel_timeline->transition_tool_proc) { update_ghosts(event->pos(), event->modifiers() & Qt::ShiftModifier); } else { - Clip* c = olive::ActiveSequence->clips.at(panel_timeline->transition_tool_pre_clip); + ClipPtr c = olive::ActiveSequence->clips.at(panel_timeline->transition_tool_pre_clip); Ghost g; @@ -2247,7 +2247,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } else { int mouse_clip = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); if (mouse_clip > -1) { - Clip* c = olive::ActiveSequence->clips.at(mouse_clip); + ClipPtr c = olive::ActiveSequence->clips.at(mouse_clip); if (same_sign(c->track, panel_timeline->transition_tool_side)) { panel_timeline->transition_tool_pre_clip = mouse_clip; long halfway = c->timeline_in + (c->getLength()/2); @@ -2285,7 +2285,7 @@ int color_brightness(int r, int g, int b) { return qRound(0.2126*r + 0.7152*g + 0.0722*b); } -void draw_waveform(Clip* clip, const FootageStream* ms, long media_length, QPainter *p, const QRect& clip_rect, int waveform_start, int waveform_limit, double zoom) { +void draw_waveform(ClipPtr clip, const FootageStream* ms, long media_length, QPainter *p, const QRect& clip_rect, int waveform_start, int waveform_limit, double zoom) { int divider = ms->audio_channels*2; int channel_height = clip_rect.height()/ms->audio_channels; @@ -2333,8 +2333,8 @@ void draw_waveform(Clip* clip, const FootageStream* ms, long media_length, QPain } } -void draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, QRect& text_rect, int transition_type) { - Transition* t = (transition_type == TA_OPENING_TRANSITION) ? c->get_opening_transition() : c->get_closing_transition(); +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(); if (t != nullptr) { QColor transition_color(255, 0, 0, 16); int transition_width = getScreenPointFromFrame(panel_timeline->zoom, t->get_true_length()); @@ -2350,7 +2350,7 @@ void draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, QRect& text_r } QRect transition_rect = QRect(tr_x, tr_y, transition_width, transition_height); p.fillRect(transition_rect, transition_color); - QRect transition_text_rect(transition_rect.x() + CLIP_TEXT_PADDING, transition_rect.y() + CLIP_TEXT_PADDING, transition_rect.width() - CLIP_TEXT_PADDING, transition_rect.height() - CLIP_TEXT_PADDING); + QRect transition_text_rect(transition_rect.x() + olive::timeline::kClipTextPadding, transition_rect.y() + olive::timeline::kClipTextPadding, transition_rect.width() - olive::timeline::kClipTextPadding, transition_rect.height() - olive::timeline::kClipTextPadding); if (transition_text_rect.width() > MAX_TEXT_WIDTH) { bool draw_text = true; @@ -2392,7 +2392,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { int video_track_limit = 0; int audio_track_limit = 0; for (int i=0;iclips.size();i++) { - Clip* clip = olive::ActiveSequence->clips.at(i); + ClipPtr clip = olive::ActiveSequence->clips.at(i); if (clip != nullptr) { video_track_limit = qMin(video_track_limit, clip->track); audio_track_limit = qMax(audio_track_limit, clip->track); @@ -2416,10 +2416,10 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } for (int i=0;iclips.size();i++) { - Clip* clip = olive::ActiveSequence->clips.at(i); + ClipPtr clip = olive::ActiveSequence->clips.at(i); if (clip != nullptr && is_track_visible(clip->track)) { QRect clip_rect(panel_timeline->getTimelineScreenPointFromFrame(clip->timeline_in), getScreenPointFromTrack(clip->track), getScreenPointFromFrame(panel_timeline->zoom, clip->getLength()), panel_timeline->calculate_track_height(clip->track, -1)); - QRect text_rect(clip_rect.left() + CLIP_TEXT_PADDING, clip_rect.top() + CLIP_TEXT_PADDING, clip_rect.width() - CLIP_TEXT_PADDING - 1, clip_rect.height() - CLIP_TEXT_PADDING - 1); + QRect text_rect(clip_rect.left() + olive::timeline::kClipTextPadding, clip_rect.top() + olive::timeline::kClipTextPadding, clip_rect.width() - olive::timeline::kClipTextPadding - 1, clip_rect.height() - olive::timeline::kClipTextPadding - 1); if (clip_rect.left() < width() && clip_rect.right() >= 0 && clip_rect.top() < height() && clip_rect.bottom() >= 0) { QRect actual_clip_rect = clip_rect; if (actual_clip_rect.x() < 0) actual_clip_rect.setX(0); @@ -2433,13 +2433,13 @@ void TimelineWidget::paintEvent(QPaintEvent*) { if (clip->media != nullptr && clip->media->get_type() == MEDIA_TYPE_FOOTAGE) { bool draw_checkerboard = false; QRect checkerboard_rect(clip_rect); - Footage* m = clip->media->to_footage(); + FootagePtr m = clip->media->to_footage(); FootageStream* ms = m->get_stream_from_file_index(clip->track < 0, clip->media_stream); if (ms == nullptr) { draw_checkerboard = true; } else if (ms->preview_done) { // draw top and tail triangles - int triangle_size = TRACK_MIN_HEIGHT >> 2; + int triangle_size = olive::timeline::kTrackMinHeight >> 2; if (!ms->infinite_length && clip_rect.width() > triangle_size) { p.setPen(Qt::NoPen); p.setBrush(QColor(80, 80, 80)); @@ -2478,7 +2478,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { if (clip->track < 0) { // draw thumbnail - int thumb_y = p.fontMetrics().height()+CLIP_TEXT_PADDING+CLIP_TEXT_PADDING; + int thumb_y = p.fontMetrics().height()+olive::timeline::kClipTextPadding+olive::timeline::kClipTextPadding; if (thumb_x < width() && thumb_y < height()) { int space_for_thumb = clip_rect.width()-1; if (clip->get_opening_transition() != nullptr) { @@ -2513,7 +2513,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { draw_checkerboard = true; checkerboard_rect.setLeft(panel_timeline->getTimelineScreenPointFromFrame(clip->getMaximumLength() + clip->timeline_in - clip->clip_in)); } - } else if (clip_rect.height() > TRACK_MIN_HEIGHT) { + } else if (clip_rect.height() > olive::timeline::kTrackMinHeight) { // draw waveform p.setPen(QColor(80, 80, 80)); @@ -2594,7 +2594,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { p.setPen(Qt::black); } if (clip->linked.size() > 0) { - int underline_y = CLIP_TEXT_PADDING + p.fontMetrics().height() + clip_rect.top(); + int underline_y = olive::timeline::kClipTextPadding + p.fontMetrics().height() + clip_rect.top(); int underline_width = qMin(text_rect.width() - 1, p.fontMetrics().width(clip->name)); p.drawLine(text_rect.x(), underline_y, text_rect.x() + underline_width, underline_y); } @@ -2748,7 +2748,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { insert_points.append(ghost_y + (ghost_height>>1)); p.setPen(QColor(255, 255, 0)); - for (int j=0;jgetTimelineScreenPointFromFrame(first_ghost); - int tri_size = TRACK_MIN_HEIGHT>>2; + int tri_size = olive::timeline::kTrackMinHeight>>2; for (int i=0;iclips.size();i++) { - Clip* c = olive::ActiveSequence->clips.at(i); + ClipPtr c = olive::ActiveSequence->clips.at(i); if (c != nullptr && c->track == track && frame >= c->timeline_in && frame < c->timeline_out) { return i; } diff --git a/ui/timelinewidget.h b/ui/timelinewidget.h index 3fc352a6a..9a25a88dc 100644 --- a/ui/timelinewidget.h +++ b/ui/timelinewidget.h @@ -23,26 +23,30 @@ #include #include +#include +#include + +#include "project/sequence.h" +#include "project/clip.h" +#include "project/footage.h" +#include "project/media.h" +#include "project/undo.h" #include "timelinetools.h" -#define GHOST_THICKNESS 2 // thiccccc -#define CLIP_TEXT_PADDING 3 - -#define TRACK_MIN_HEIGHT 30 -#define TRACK_HEIGHT_INCREMENT 10 - -struct Sequence; -class Clip; -struct FootageStream; class Timeline; -class TimelineAction; -class QScrollBar; -class SetSelectionsCommand; -class QPainter; -class Media; + +namespace olive { + namespace timeline { + const int kGhostThickness = 2; + const int kClipTextPadding = 3; + + const int kTrackMinHeight = 30; + const int kTrackHeightIncrement = 10; + } +} bool same_sign(int a, int b); -void draw_waveform(Clip* clip, const FootageStream *ms, long media_length, QPainter* p, const QRect& clip_rect, int waveform_start, int waveform_limit, double zoom); +void draw_waveform(ClipPtr clip, const FootageStream *ms, long media_length, QPainter* p, const QRect& clip_rect, int waveform_start, int waveform_limit, double zoom); class TimelineWidget : public QWidget { Q_OBJECT @@ -80,12 +84,12 @@ private: bool track_resizing; int track_target; - QVector pre_clips; - QVector post_clips; + QVector pre_clips; + QVector post_clips; Media* rc_reveal_media; - Sequence* self_created_sequence; + SequencePtr self_created_sequence; QTimer tooltip_timer; int tooltip_clip; diff --git a/ui/viewerwidget.h b/ui/viewerwidget.h index 8af8c91a0..34c8f9d5d 100644 --- a/ui/viewerwidget.h +++ b/ui/viewerwidget.h @@ -30,16 +30,16 @@ #include #include +#include "project/clip.h" +#include "project/footage.h" +#include "project/effect.h" +#include "ui/viewerwindow.h" +#include "ui/viewercontainer.h" +#include "ui/renderthread.h" + class Viewer; -class Clip; -struct FootageStream; class QOpenGLFramebufferObject; -class Effect; -class EffectGizmo; -class ViewerContainer; struct GLTextureCoords; -class RenderThread; -class ViewerWindow; class ViewerWidget : public QOpenGLWidget, QOpenGLFunctions { @@ -57,7 +57,7 @@ public: ViewerContainer* container; bool waveform; - Clip* waveform_clip; + ClipPtr waveform_clip; const FootageStream* waveform_ms; double waveform_zoom; int waveform_scroll; @@ -81,7 +81,7 @@ private: void move_gizmos(QMouseEvent *event, bool done); bool dragging; void seek_from_click(int x); - Effect* gizmos; + EffectPtr gizmos; int drag_start_x; int drag_start_y; int gizmo_x_mvmt;