From aff3acb94ed698a94b28d953aed653651a7f055d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 25 Mar 2019 02:49:58 +1100 Subject: [PATCH] implemented default sequence settings --- dialogs/newsequencedialog.cpp | 54 ++++++++++++++++++++++++++++------- dialogs/newsequencedialog.h | 35 +++++++++++++++++++---- dialogs/preferencesdialog.cpp | 23 +++++++++++++++ dialogs/preferencesdialog.h | 13 +++++++++ global/config.cpp | 27 +++++++++++++++++- global/config.h | 25 ++++++++++++++++ panels/project.cpp | 19 ++++-------- panels/viewer.cpp | 11 +++---- 8 files changed, 170 insertions(+), 37 deletions(-) diff --git a/dialogs/newsequencedialog.cpp b/dialogs/newsequencedialog.cpp index f852e5253..67b3537c0 100644 --- a/dialogs/newsequencedialog.cpp +++ b/dialogs/newsequencedialog.cpp @@ -39,19 +39,26 @@ #include "panels/timeline.h" #include "project/media.h" #include "rendering/audio.h" +#include "global/config.h" extern "C" { #include } -NewSequenceDialog::NewSequenceDialog(QWidget *parent, Media *existing) : +NewSequenceDialog::NewSequenceDialog(QWidget *parent, Media *existing, Sequence* iexisting_sequence) : QDialog(parent), - existing_item(existing) + existing_item(existing), + existing_sequence(iexisting_sequence) { + Q_ASSERT(!(existing != nullptr && iexisting_sequence != nullptr)); + setup_ui(); if (existing != nullptr) { - existing_sequence = existing->to_sequence(); + existing_sequence = existing->to_sequence().get(); + } + + if (existing_sequence != nullptr) { setWindowTitle(tr("Editing \"%1\"").arg(existing_sequence->name)); width_numeric->setValue(existing_sequence->width); @@ -80,6 +87,12 @@ void NewSequenceDialog::set_sequence_name(const QString& s) { sequence_name_edit->setText(s); } +void NewSequenceDialog::SetNameEditable(bool enabled) +{ + sequence_name_edit->setVisible(enabled); + sequence_name_label->setVisible(enabled); +} + void NewSequenceDialog::accept() { if (existing_sequence == nullptr) { @@ -98,7 +111,7 @@ void NewSequenceDialog::accept() { panel_project->create_sequence_internal(ca, s, true, nullptr); olive::UndoStack.push(ca); - } else { + } else if (existing_item != nullptr) { // The dialog was given an existing Sequence object, so we'll apply the changes to it @@ -106,7 +119,7 @@ void NewSequenceDialog::accept() { double multiplier = frame_rate_combobox->currentData().toDouble() / existing_sequence->frame_rate; - EditSequenceCommand* esc = new EditSequenceCommand(existing_item, existing_sequence); + EditSequenceCommand* esc = new EditSequenceCommand(existing_item, existing_item->to_sequence()); esc->name = sequence_name_edit->text(); esc->width = width_numeric->value(); esc->height = height_numeric->value(); @@ -123,6 +136,18 @@ void NewSequenceDialog::accept() { } olive::UndoStack.push(ca); + + } else if (existing_sequence != nullptr) { + + // This dialog was given an existing Sequence without a Media wrapper - therefore just directly apply the settings + + existing_sequence->name = sequence_name_edit->text(); + existing_sequence->width = width_numeric->value(); + existing_sequence->height = height_numeric->value(); + existing_sequence->frame_rate = frame_rate_combobox->currentData().toDouble(); + existing_sequence->audio_frequency = audio_frequency_combobox->currentData().toInt(); + existing_sequence->audio_layout = AV_CH_LAYOUT_STEREO; + } QDialog::accept(); @@ -210,13 +235,13 @@ void NewSequenceDialog::setup_ui() { videoLayout->addWidget(new QLabel(tr("Width:"), this), 0, 0, 1, 1); width_numeric = new QSpinBox(videoGroupBox); width_numeric->setMaximum(9999); - width_numeric->setValue(1920); + width_numeric->setValue(olive::CurrentConfig.default_sequence_width); videoLayout->addWidget(width_numeric, 0, 2, 1, 2); videoLayout->addWidget(new QLabel(tr("Height:"), this), 1, 0, 1, 2); height_numeric = new QSpinBox(videoGroupBox); height_numeric->setMaximum(9999); - height_numeric->setValue(1080); + height_numeric->setValue(olive::CurrentConfig.default_sequence_height); videoLayout->addWidget(height_numeric, 1, 2, 1, 2); videoLayout->addWidget(new QLabel(tr("Frame Rate:"), this), 2, 0, 1, 1); @@ -232,7 +257,11 @@ void NewSequenceDialog::setup_ui() { frame_rate_combobox->addItem("50 FPS", 50.0); frame_rate_combobox->addItem("59.94 FPS", 59.94); frame_rate_combobox->addItem("60 FPS", 60.0); - frame_rate_combobox->setCurrentIndex(6); + for (int i=0;icount();i++) { + if (qFuzzyCompare(frame_rate_combobox->itemData(i).toDouble(), olive::CurrentConfig.default_sequence_framerate)) { + frame_rate_combobox->setCurrentIndex(i); + } + } videoLayout->addWidget(frame_rate_combobox, 2, 2, 1, 2); videoLayout->addWidget(new QLabel(tr("Pixel Aspect Ratio:"), this), 4, 0, 1, 1); @@ -258,7 +287,11 @@ void NewSequenceDialog::setup_ui() { audio_frequency_combobox = new QComboBox(audioGroupBox); combobox_audio_sample_rates(audio_frequency_combobox); - audio_frequency_combobox->setCurrentIndex(4); + for (int i=0;icount();i++) { + if (audio_frequency_combobox->itemData(i) == olive::CurrentConfig.default_sequence_audio_frequency) { + audio_frequency_combobox->setCurrentIndex(i); + } + } audioLayout->addWidget(audio_frequency_combobox, 0, 1, 1, 1); @@ -268,7 +301,8 @@ void NewSequenceDialog::setup_ui() { QHBoxLayout* nameLayout = new QHBoxLayout(nameWidget); nameLayout->setContentsMargins(0, 0, 0, 0); - nameLayout->addWidget(new QLabel(tr("Name:"), this)); + sequence_name_label = new QLabel(tr("Name:")); + nameLayout->addWidget(sequence_name_label); sequence_name_edit = new QLineEdit(nameWidget); diff --git a/dialogs/newsequencedialog.h b/dialogs/newsequencedialog.h index 631923647..4e5ad8c34 100644 --- a/dialogs/newsequencedialog.h +++ b/dialogs/newsequencedialog.h @@ -50,8 +50,13 @@ public: * * Set this to a Sequence object (wrapped in a Media object) to edit an existing Sequence, * or leave as nullptr to create a new one. + * + * @param existing_sequence + * + * If your Sequence object is not wrapped in a Media object, use this to reference a raw Sequence pointer. You must + * not use both existing_sequence AND existing - one must be nullptr. */ - explicit NewSequenceDialog(QWidget *parent = nullptr, Media* existing = nullptr); + explicit NewSequenceDialog(QWidget *parent = nullptr, Media* existing = nullptr, Sequence* iexisting_sequence = nullptr); /** * @brief Set the name for the new Sequence @@ -68,6 +73,17 @@ public: */ void set_sequence_name(const QString& s); + /** + * @brief Set whether the Sequence's name can be edited + * + * This defaults to TRUE. + * + * @param enabled + * + * TRUE to allow the user to edit the Sequence's name. FALSE if not. + */ + void SetNameEditable(bool enabled); + private slots: /** * @brief Override accept function to create/edit a Sequence @@ -86,16 +102,16 @@ private slots: void preset_changed(int index); private: - /** - * @brief Internal reference to an existing Sequence (if one was provided to the constructor) - */ - SequencePtr existing_sequence; - /** * @brief Internal reference to an existing Media wrapper (if one was provided to the constructor) */ Media* existing_item; + /** + * @brief Internal reference to an existing Sequence (if one was provided to the constructor) + */ + Sequence* existing_sequence; + /** * @brief Internal function to create the dialog's UI */ @@ -136,6 +152,13 @@ private: */ QComboBox* audio_frequency_combobox; + /** + * @brief Label marker for setting the Sequence's name + * + * Primarily a persistent class reference so it can be hidden with SetNameEditable() alongside sequence_name_edit. + */ + QLabel* sequence_name_label; + /** * @brief Line edit to set the Sequence's name */ diff --git a/dialogs/preferencesdialog.cpp b/dialogs/preferencesdialog.cpp index e304f06b4..3fc27bdfb 100644 --- a/dialogs/preferencesdialog.cpp +++ b/dialogs/preferencesdialog.cpp @@ -51,6 +51,7 @@ #include "panels/panels.h" #include "ui/columnedgridlayout.h" #include "ui/mainwindow.h" +#include "dialogs/newsequencedialog.h" KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a) : QKeySequenceEdit(parent), action(a) { @@ -86,6 +87,14 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : setup_ui(); setup_kbd_shortcuts(olive::MainWindow->menuBar()); + + // set up default sequence + default_sequence.name = tr("Default Sequence"); + default_sequence.width = olive::CurrentConfig.default_sequence_width; + default_sequence.height = olive::CurrentConfig.default_sequence_height; + default_sequence.frame_rate = olive::CurrentConfig.default_sequence_framerate; + default_sequence.audio_frequency = olive::CurrentConfig.default_sequence_audio_frequency; + default_sequence.audio_layout = olive::CurrentConfig.default_sequence_audio_channel_layout; } void PreferencesDialog::setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* parent) { @@ -265,6 +274,12 @@ void PreferencesDialog::accept() { olive::CurrentConfig.effect_textbox_lines = effect_textbox_lines_field->value(); olive::CurrentConfig.language_file = language_combobox->currentData().toString(); + olive::CurrentConfig.default_sequence_width = default_sequence.width; + olive::CurrentConfig.default_sequence_height = default_sequence.height; + olive::CurrentConfig.default_sequence_framerate = default_sequence.frame_rate; + olive::CurrentConfig.default_sequence_audio_frequency = default_sequence.audio_frequency; + olive::CurrentConfig.default_sequence_audio_channel_layout = default_sequence.audio_layout; + for (int i=0;iisChecked(); } @@ -470,6 +485,13 @@ void PreferencesDialog::delete_all_previews() { } } +void PreferencesDialog::edit_default_sequence_settings() +{ + NewSequenceDialog nsd(this, nullptr, &default_sequence); + nsd.SetNameEditable(false); + nsd.exec(); +} + void PreferencesDialog::setup_ui() { QVBoxLayout* verticalLayout = new QVBoxLayout(this); QTabWidget* tabWidget = new QTabWidget(this); @@ -560,6 +582,7 @@ void PreferencesDialog::setup_ui() { // General -> Default Sequence Settings QPushButton* default_sequence_settings = new QPushButton(tr("Default Sequence Settings")); + connect(default_sequence_settings, SIGNAL(clicked(bool)), this, SLOT(edit_default_sequence_settings())); general_layout->addWidget(default_sequence_settings); tabWidget->addTab(general_tab, tr("General")); diff --git a/dialogs/preferencesdialog.h b/dialogs/preferencesdialog.h index 38efcdf7e..f360284ea 100644 --- a/dialogs/preferencesdialog.h +++ b/dialogs/preferencesdialog.h @@ -118,6 +118,11 @@ private slots: */ void delete_all_previews(); + /** + * @brief Shows a NewSequenceDialog attached to default_sequence + */ + void edit_default_sequence_settings(); + private: /** @@ -243,6 +248,14 @@ private: */ QComboBox* ui_style; + /** + * @brief Stored default Sequence object + * + * Default Sequence settings are loaded into an actual Sequence object that can be loaded into NewSequenceDialog + * for the sake of familiarity with the user. + */ + Sequence default_sequence; + /** * @brief List of keyboard shortcut actions that can be triggered (links with key_shortcut_items and * key_shortcut_fields) diff --git a/global/config.cpp b/global/config.cpp index cc2e2b441..5ab9a2293 100644 --- a/global/config.cpp +++ b/global/config.cpp @@ -73,7 +73,12 @@ Config::Config() add_default_effects_to_clips(true), invert_timeline_scroll_axes(true), style(olive::styling::kOliveDefaultDark), - use_native_menu_styling(true) + use_native_menu_styling(true), + default_sequence_width(1920), + default_sequence_height(1080), + default_sequence_framerate(29.97), + default_sequence_audio_frequency(48000), + default_sequence_audio_channel_layout(3) {} void Config::load(QString path) { @@ -219,6 +224,21 @@ void Config::load(QString path) { } else if (stream.name() == "NativeMenuStyling") { stream.readNext(); use_native_menu_styling = (stream.text() == "1"); + } else if (stream.name() == "DefaultSequenceWidth") { + stream.readNext(); + default_sequence_width = stream.text().toInt(); + } else if (stream.name() == "DefaultSequenceHeight") { + stream.readNext(); + default_sequence_height = stream.text().toInt(); + } else if (stream.name() == "DefaultSequenceFrameRate") { + stream.readNext(); + default_sequence_framerate = stream.text().toDouble(); + } else if (stream.name() == "DefaultSequenceAudioFrequency") { + stream.readNext(); + default_sequence_audio_frequency = stream.text().toInt(); + } else if (stream.name() == "DefaultSequenceAudioLayout") { + stream.readNext(); + default_sequence_audio_channel_layout = stream.text().toInt(); } } } @@ -288,6 +308,11 @@ void Config::save(QString path) { stream.writeTextElement("AddDefaultEffectsToClips", QString::number(add_default_effects_to_clips)); stream.writeTextElement("Style", QString::number(style)); stream.writeTextElement("NativeMenuStyling", QString::number(use_native_menu_styling)); + stream.writeTextElement("DefaultSequenceWidth", QString::number(default_sequence_width)); + stream.writeTextElement("DefaultSequenceHeight", QString::number(default_sequence_height)); + stream.writeTextElement("DefaultSequenceFrameRate", QString::number(default_sequence_framerate)); + stream.writeTextElement("DefaultSequenceAudioFrequency", QString::number(default_sequence_audio_frequency)); + stream.writeTextElement("DefaultSequenceAudioLayout", QString::number(default_sequence_audio_channel_layout)); stream.writeEndElement(); // configuration stream.writeEndDocument(); // doc diff --git a/global/config.h b/global/config.h index c72b52077..498a9895c 100644 --- a/global/config.h +++ b/global/config.h @@ -533,6 +533,31 @@ struct Config { */ bool use_native_menu_styling; + /** + * @brief Default Sequence video width + */ + int default_sequence_width; + + /** + * @brief Default Sequence video height + */ + int default_sequence_height; + + /** + * @brief Default Sequence video frame rate + */ + double default_sequence_framerate; + + /** + * @brief Default Sequence audio frequency + */ + int default_sequence_audio_frequency; + + /** + * @brief Default Sequence audio channel layout + */ + int default_sequence_audio_channel_layout; + /** * @brief Load config from file * diff --git a/panels/project.cpp b/panels/project.cpp index fb609a114..e4781a160 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -65,13 +65,6 @@ extern "C" { #include "global/debug.h" #include "ui/menu.h" -// TODO make these configurable -const int kDefaultSequenceWidth = 1920; -const int kDefaultSequenceHeight = 1080; -const double kDefaultSequenceFrameRate = 29.97; -const int kDefaultSequenceFrequency = 48000; -const int kDefaultSequenceChannelLayout = 3; - #define MAXIMUM_RECENT_PROJECTS 10 // FIXME: should be configurable QString autorecovery_filename; @@ -261,12 +254,12 @@ SequencePtr create_sequence_from_media(QVector s->name = panel_project->get_next_sequence_name(); - // shitty hardcoded default values - s->width = kDefaultSequenceWidth; - s->height = kDefaultSequenceHeight; - s->frame_rate = kDefaultSequenceFrameRate; - s->audio_frequency = kDefaultSequenceFrequency; - s->audio_layout = kDefaultSequenceChannelLayout; + // Retrieve default Sequence settings from Config + s->width = olive::CurrentConfig.default_sequence_width; + s->height = olive::CurrentConfig.default_sequence_height; + s->frame_rate = olive::CurrentConfig.default_sequence_framerate; + s->audio_frequency = olive::CurrentConfig.default_sequence_audio_frequency; + s->audio_layout = olive::CurrentConfig.default_sequence_audio_channel_layout; bool got_video_values = false; bool got_audio_values = false; diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 7e17bb583..b91c00d07 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -802,8 +802,7 @@ void Viewer::set_media(Media* m) { new_sequence->workarea_out = footage->out; } - // FIXME: Move this magic number to Config - new_sequence->frame_rate = 30; + new_sequence->frame_rate = olive::CurrentConfig.default_sequence_framerate; if (footage->video_tracks.size() > 0) { const FootageStream& video_stream = footage->video_tracks.at(0); @@ -826,9 +825,8 @@ void Viewer::set_media(Media* m) { c->refresh(); new_sequence->clips.append(c); } else { - // FIXME: Move this magic number to Config - new_sequence->width = 1920; - new_sequence->height = 1080; + new_sequence->width = olive::CurrentConfig.default_sequence_width; + new_sequence->height = olive::CurrentConfig.default_sequence_height; } if (footage->audio_tracks.size() > 0) { @@ -851,8 +849,7 @@ void Viewer::set_media(Media* m) { viewer_widget->frame_update(); } } else { - // FIXME: Move this magic number to Config - new_sequence->audio_frequency = 48000; + new_sequence->audio_frequency = olive::CurrentConfig.default_sequence_audio_frequency; } new_sequence->audio_layout = AV_CH_LAYOUT_STEREO;