improvements and moved many behavioral tools menu items to preferences

This commit is contained in:
itsmattkc
2019-03-24 18:28:01 +11:00
15 changed files with 609 additions and 161 deletions
+222
View File
@@ -0,0 +1,222 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "autocutsilencedialog.h"
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QDialogButtonBox>
#include "timeline/sequence.h"
#include "rendering/renderfunctions.h"
#include "panels/panels.h"
#include "panels/timeline.h"
AutoCutSilenceDialog::AutoCutSilenceDialog(QWidget *parent, QVector<Clip*> clips) :
QDialog(parent),
clips_(clips)
{
setWindowTitle(tr("Cut Silence"));
QVBoxLayout* main_layout = new QVBoxLayout(this);
QGridLayout* grid = new QGridLayout();
grid->setSpacing(6);
grid->addWidget(new QLabel(tr("Attack Threshold:"), this), 0, 0);
attack_threshold = new LabelSlider(this);
attack_threshold->SetDecimalPlaces(0);
grid->addWidget(attack_threshold, 0, 1);
grid->addWidget(new QLabel(tr("Attack Time:"), this), 1, 0);
attack_time = new LabelSlider(this);
attack_time->SetDecimalPlaces(0);
grid->addWidget(attack_time, 1, 1);
grid->addWidget(new QLabel(tr("Release Threshold:"), this), 2, 0);
release_threshold = new LabelSlider(this);
release_threshold->SetDecimalPlaces(0);
grid->addWidget(release_threshold, 2, 1);
grid->addWidget(new QLabel(tr("Release Time:"), this), 3, 0);
release_time = new LabelSlider(this);
release_time->SetDecimalPlaces(0);
grid->addWidget(release_time, 3, 1);
main_layout->addLayout(grid);
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttonBox->setCenterButtons(true);
main_layout->addWidget(buttonBox);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
}
int AutoCutSilenceDialog::exec()
{
default_attack_threshold = 5;
current_attack_threshold = 5;
default_attack_time = 2;
current_attack_time = 2;
default_release_threshold = 2;
current_release_threshold = 2;
default_release_time = 5;
current_release_time = 5;
attack_threshold->SetMinimum(1);
attack_threshold->setEnabled(true);
attack_threshold->SetDefault(default_attack_threshold);
attack_threshold->SetValue(current_attack_threshold);
attack_time->SetMinimum(1);
attack_time->setEnabled(true);
attack_time->SetDefault(default_attack_time);
attack_time->SetValue(current_attack_time);
release_threshold->SetMinimum(1);
release_threshold->setEnabled(true);
release_threshold->SetDefault(default_release_threshold);
release_threshold->SetValue(current_release_threshold);
release_time->SetMinimum(1);
release_time->setEnabled(true);
release_time->SetDefault(default_release_time);
release_time->SetValue(current_release_time);
return QDialog::exec();
}
void AutoCutSilenceDialog::accept() {
current_attack_threshold = attack_threshold->value();
current_attack_time = attack_time->value();
current_release_threshold = release_threshold->value();
current_release_time = release_time->value();
cut_silence();
update_ui(true);
QDialog::accept();
}
void AutoCutSilenceDialog::cut_silence() {
// Loop over clips provided to this dialog
for (int j=0;j<clips_.size();j++) {
Clip* clip = clips_.at(j);
// Check if this clip is an audio footage clip
if (clip->track() >= 0
&& clip->media() != nullptr
&& clip->media_stream()->preview_done) { // TODO provide warning for preview not being done
QVector<long> split_positions;
int clip_start = clip->timeline_in();
const FootageStream* ms = clip->media_stream();
long media_length = clip->media_length();
int preview_size = ms->audio_preview.length();
float chunk_size = (float)preview_size/media_length; // how many audio samples to read for each fotogram
int sample_size = qMax(current_attack_time, current_release_time)+1;
bool attack = false; // status flags
bool release = false;
QVector<qint8> vols;
vols.resize(sample_size);
vols.fill(0);
// loop through the entire sequence
for (long i=clip_start;i<media_length+clip_start;i++) {
long start = ((i-clip_start)*chunk_size); //audio samples are read relative to the clip, not absolute to the timeline
int circular_index = i%sample_size;
// read the current sample into the circular array
qint8 tmp = 0;
for (int k=start; k<start+chunk_size; k++){
tmp = qMax(tmp, qint8(qRound(double(ms->audio_preview.at(k)))));
}
vols[circular_index] = tmp;
//for debug:
//qInfo() << "i:" << i <<" - "<< i/30 <<":"<< i%30 << " - volume:" << vols[circular_index] <<"\n";
int overthreshold = 0;
int cut_idx = 0; //how much to cut (backwards)
// if current volume value is above threshold
if (vols[circular_index] >= current_attack_threshold && !attack){ // if we get one sample over the threshold
for(int k=0; k<sample_size; k++){ // count how many times this happened before within sample_size range (avoid false activations)
int back_idx = (((circular_index-k)%sample_size)+sample_size)%sample_size; // positive modulus
if(vols[back_idx] > current_attack_threshold){
overthreshold++;
cut_idx = k+1;
}
}
// if we reached threshold over the set tolerance
if(overthreshold >= current_attack_time){
split_positions.append(i-cut_idx);
attack = true;
release = false;
//qInfo() << "\n\n Current vol: "<<vols[circular_index]<<" attack at " << i-cut_idx << "\n\n";
}
overthreshold = 0;
cut_idx = 0;
}else if (vols[circular_index] < current_release_threshold && !release){ // if we get one sample under the threshold
for(int k=0; k<sample_size; k++){ // count how many times this happened before within sample_size range
int back_idx = (((circular_index-k)%sample_size)+sample_size)%sample_size; // positive modulus
if(vols[back_idx] < current_release_threshold)
overthreshold++;
}
// if we reached threshold over the set tolerance
if(overthreshold >= current_release_time){ // must be <= sample_size
attack = false;
release = true;
split_positions.append(i);
//qInfo() << "\n\n Current vol: "<<vols[circular_index]<<" release at " << i << "\n\n";
}
overthreshold = 0;
}
}
ComboAction* ca = new ComboAction();
// NO GOOD VERY BAD TEST CODE
int clip_index = -1;
for (int i=0;i<olive::ActiveSequence->clips.size();i++) {
if (olive::ActiveSequence->clips.at(i).get() == clip) {
clip_index = i;
break;
}
}
Q_ASSERT(clip_index > -1);
panel_timeline->split_clip_at_positions(ca, clip_index, split_positions);
olive::UndoStack.push(ca);
}
}
}
+59
View File
@@ -0,0 +1,59 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef SILENCEDIALOG_H
#define SILENCEDIALOG_H
#include <QDialog>
#include <QCheckBox>
#include "timeline/clip.h"
#include "ui/labelslider.h"
class AutoCutSilenceDialog : public QDialog
{
Q_OBJECT
public:
AutoCutSilenceDialog(QWidget* parent, QVector<Clip*> clips);
public slots:
virtual int exec() override;
private slots:
virtual void accept() override;
private:
void cut_silence();
QVector<Clip*> clips_;
LabelSlider* attack_threshold;
LabelSlider* release_threshold;
LabelSlider* attack_time;
LabelSlider* release_time;
int default_attack_threshold;
int current_attack_threshold;
int default_release_threshold;
int current_release_threshold;
int default_attack_time;
int current_attack_time;
int default_release_time;
int current_release_time;
};
#endif // SILENCEDIALOG_H
+99 -30
View File
@@ -20,13 +20,6 @@
#include "preferencesdialog.h"
#include "global/global.h"
#include "global/config.h"
#include "global/path.h"
#include "rendering/audio.h"
#include "panels/panels.h"
#include "ui/mainwindow.h"
#include <QMenuBar>
#include <QAction>
#include <QVBoxLayout>
@@ -51,6 +44,14 @@
#include <QProcess>
#include <QDebug>
#include "global/global.h"
#include "global/config.h"
#include "global/path.h"
#include "rendering/audio.h"
#include "panels/panels.h"
#include "ui/columnedgridlayout.h"
#include "ui/mainwindow.h"
KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
: QKeySequenceEdit(parent), action(a) {
setKeySequence(action->shortcut());
@@ -142,6 +143,15 @@ void PreferencesDialog::delete_previews(char type) {
}
}
void PreferencesDialog::AddBoolPair(QCheckBox *ui, bool *value, bool restart_required)
{
bool_ui.append(ui);
bool_value.append(value);
bool_restart_required.append(restart_required);
ui->setChecked(*value);
}
void PreferencesDialog::setup_kbd_shortcuts(QMenuBar* menubar) {
QList<QAction*> menus = menubar->actions();
@@ -186,14 +196,20 @@ void PreferencesDialog::accept() {
reload_effects = true;
}
bool bool_requires_restart = false;
for (int i=0;i<bool_restart_required.size();i++) {
if (bool_restart_required.at(i)
&& bool_ui.at(i)->isChecked() != *bool_value.at(i)) {
bool_requires_restart = true;
break;
}
}
// Check if any settings will require a restart of Olive
if (olive::CurrentConfig.use_software_fallback != use_software_fallbacks_checkbox->isChecked()
if (bool_requires_restart
|| olive::CurrentConfig.thumbnail_resolution != thumbnail_res_spinbox->value()
|| olive::CurrentConfig.waveform_resolution != waveform_res_spinbox->value()
|| olive::CurrentConfig.css_path != custom_css_fn->text()
#ifdef Q_OS_WIN32
|| olive::CurrentConfig.use_native_menu_styling != native_menus->isChecked()
#endif
|| olive::CurrentConfig.style != static_cast<olive::styling::Style>(ui_style->currentData().toInt())) {
// any changes to these settings will require a restart - ask the user if we should do one now or later
@@ -241,22 +257,19 @@ void PreferencesDialog::accept() {
olive::CurrentConfig.upcoming_queue_type = upcoming_queue_type->currentIndex();
olive::CurrentConfig.previous_queue_size = previous_queue_spinbox->value();
olive::CurrentConfig.previous_queue_type = previous_queue_type->currentIndex();
olive::CurrentConfig.add_default_effects_to_clips = add_default_effects_to_clips->isChecked();
olive::CurrentConfig.preferred_audio_output = audio_output_devices->currentData().toString();
olive::CurrentConfig.preferred_audio_input = audio_input_devices->currentData().toString();
olive::CurrentConfig.audio_rate = audio_sample_rate->currentData().toInt();
olive::CurrentConfig.effect_textbox_lines = effect_textbox_lines_field->value();
olive::CurrentConfig.use_software_fallback = use_software_fallbacks_checkbox->isChecked();
olive::CurrentConfig.language_file = language_combobox->currentData().toString();
olive::CurrentConfig.style = static_cast<olive::styling::Style>(ui_style->currentData().toInt());
#ifdef Q_OS_WIN
olive::CurrentConfig.use_native_menu_styling = native_menus->isChecked();
#endif
for (int i=0;i<bool_ui.size();i++) {
*bool_value[i] = bool_ui.at(i)->isChecked();
}
olive::CurrentConfig.auto_seek_to_beginning = auto_seek_to_beginning->isChecked();
olive::CurrentConfig.style = static_cast<olive::styling::Style>(ui_style->currentData().toInt());
// Check if the thumbnail or waveform icon
if (olive::CurrentConfig.thumbnail_resolution != thumbnail_res_spinbox->value()
@@ -539,9 +552,8 @@ void PreferencesDialog::setup_ui() {
row++;
// General -> Use Software Fallbacks When Possible
use_software_fallbacks_checkbox = new QCheckBox(general_tab);
use_software_fallbacks_checkbox->setText(tr("Use Software Fallbacks When Possible"));
use_software_fallbacks_checkbox->setChecked(olive::CurrentConfig.use_software_fallback);
QCheckBox* use_software_fallbacks_checkbox = new QCheckBox(tr("Use Software Fallbacks When Possible"));
AddBoolPair(use_software_fallbacks_checkbox, &olive::CurrentConfig.use_software_fallback, true);
general_layout->addWidget(use_software_fallbacks_checkbox, row, 0, 1, 4);
row++;
@@ -556,15 +568,72 @@ void PreferencesDialog::setup_ui() {
QWidget* behavior_tab = new QWidget(this);
tabWidget->addTab(behavior_tab, tr("Behavior"));
QVBoxLayout* behavior_tab_layout = new QVBoxLayout(behavior_tab);
ColumnedGridLayout* behavior_tab_layout = new ColumnedGridLayout(behavior_tab, 2);
add_default_effects_to_clips = new QCheckBox(tr("Add Default Effects to New Clips"));
add_default_effects_to_clips->setChecked(olive::CurrentConfig.add_default_effects_to_clips);
behavior_tab_layout->addWidget(add_default_effects_to_clips);
QCheckBox* add_default_effects_to_clips = new QCheckBox(tr("Add Default Effects to New Clips"));
AddBoolPair(add_default_effects_to_clips, &olive::CurrentConfig.add_default_effects_to_clips);
behavior_tab_layout->Add(add_default_effects_to_clips);
auto_seek_to_beginning = new QCheckBox(tr("Automatically Seek to the Beginning When Playing at the End of a Sequence"));
auto_seek_to_beginning->setChecked(olive::CurrentConfig.auto_seek_to_beginning);
behavior_tab_layout->addWidget(auto_seek_to_beginning);
QCheckBox* auto_seek_to_beginning = new QCheckBox(tr("Automatically Seek to the Beginning When Playing at the End of a Sequence"));
AddBoolPair(auto_seek_to_beginning, &olive::CurrentConfig.auto_seek_to_beginning);
behavior_tab_layout->Add(auto_seek_to_beginning);
QCheckBox* selecting_also_seeks = new QCheckBox(tr("Selecting Also Seeks"));
AddBoolPair(selecting_also_seeks, &olive::CurrentConfig.select_also_seeks);
behavior_tab_layout->Add(selecting_also_seeks);
QCheckBox* edit_tool_also_seeks = new QCheckBox(tr("Edit Tool Also Seeks"));
AddBoolPair(edit_tool_also_seeks, &olive::CurrentConfig.edit_tool_also_seeks);
behavior_tab_layout->Add(edit_tool_also_seeks);
QCheckBox* edit_tool_selects_links = new QCheckBox(tr("Edit Tool Selects Links"));
AddBoolPair(edit_tool_selects_links, &olive::CurrentConfig.edit_tool_selects_links);
behavior_tab_layout->Add(edit_tool_selects_links);
QCheckBox* seek_also_selects = new QCheckBox(tr("Seek Also Selects"));
AddBoolPair(seek_also_selects, &olive::CurrentConfig.seek_also_selects);
behavior_tab_layout->Add(seek_also_selects);
QCheckBox* seek_to_end_of_pastes = new QCheckBox(tr("Seek to the End of Pastes"));
AddBoolPair(seek_to_end_of_pastes, &olive::CurrentConfig.paste_seeks);
behavior_tab_layout->Add(seek_to_end_of_pastes);
QCheckBox* scroll_wheel_zooms = new QCheckBox(tr("Scroll Wheel Zooms"));
scroll_wheel_zooms->setToolTip(tr("Hold CTRL to toggle this setting"));
AddBoolPair(scroll_wheel_zooms, &olive::CurrentConfig.scroll_zooms);
behavior_tab_layout->Add(scroll_wheel_zooms);
QCheckBox* invert_timeline_scroll_axes = new QCheckBox(tr("Invert Timeline Scroll Axes"));
AddBoolPair(invert_timeline_scroll_axes, &olive::CurrentConfig.invert_timeline_scroll_axes);
behavior_tab_layout->Add(invert_timeline_scroll_axes);
QCheckBox* enable_drag_files_to_timeline = new QCheckBox(tr("Enable Drag Files to Timeline"));
AddBoolPair(enable_drag_files_to_timeline, &olive::CurrentConfig.enable_drag_files_to_timeline);
behavior_tab_layout->Add(enable_drag_files_to_timeline);
QCheckBox* autoscale_by_default = new QCheckBox(tr("Auto-Scale By Default"));
AddBoolPair(autoscale_by_default, &olive::CurrentConfig.autoscale_by_default);
behavior_tab_layout->Add(autoscale_by_default);
QCheckBox* enable_seek_to_import = new QCheckBox(tr("Auto-Seek to Imported Clips"));
AddBoolPair(enable_seek_to_import, &olive::CurrentConfig.enable_seek_to_import);
behavior_tab_layout->Add(enable_seek_to_import);
QCheckBox* enable_audio_scrubbing = new QCheckBox(tr("Audio Scrubbing"));
AddBoolPair(enable_audio_scrubbing, &olive::CurrentConfig.enable_audio_scrubbing);
behavior_tab_layout->Add(enable_audio_scrubbing);
QCheckBox* enable_drop_on_media_to_replace = new QCheckBox(tr("Drop Files on Media to Replace"));
AddBoolPair(enable_drop_on_media_to_replace, &olive::CurrentConfig.drop_on_media_to_replace);
behavior_tab_layout->Add(enable_drop_on_media_to_replace);
QCheckBox* enable_hover_focus = new QCheckBox(tr("Enable Hover Focus"));
AddBoolPair(enable_hover_focus, &olive::CurrentConfig.hover_focus);
behavior_tab_layout->Add(enable_hover_focus);
QCheckBox* set_name_and_marker = new QCheckBox(tr("Ask For Name When Setting Marker"));
AddBoolPair(set_name_and_marker, &olive::CurrentConfig.set_name_with_marker);
behavior_tab_layout->Add(set_name_and_marker);
// Appearance
QWidget* appearance_tab = new QWidget(this);
@@ -590,8 +659,8 @@ void PreferencesDialog::setup_ui() {
#ifdef Q_OS_WIN
// Native menu styling is only available on Windows. Environments like Ubuntu and Mac use the native menu system by
// default
native_menus = new QCheckBox(tr("Use Native Menu Styling"));
native_menus->setChecked(olive::CurrentConfig.use_native_menu_styling);
QCheckBox* native_menus = new QCheckBox(tr("Use Native Menu Styling"));
AddBoolPair(native_menus, &olive::CurrentConfig.use_native_menu_styling);
appearance_layout->addWidget(native_menus, row, 0, 1, 3);
row++;
+39 -21
View File
@@ -208,11 +208,6 @@ private:
*/
QSpinBox* effect_textbox_lines_field;
/**
* @brief UI widget for enabling/disabling software fallbacks
*/
QCheckBox* use_software_fallbacks_checkbox;
/**
* @brief UI widget for selecting the output audio device
*/
@@ -243,26 +238,10 @@ private:
*/
QSpinBox* waveform_res_spinbox;
/**
* @brief UI widget for enabling/disabling default effects
*/
QCheckBox* add_default_effects_to_clips;
/**
* @brief UI widget for enabling/disabling Config::auto_seek_to_beginning
*/
QCheckBox* auto_seek_to_beginning;
/**
* @brief UI widget for selecting the current UI style
*/
QComboBox* ui_style;
#ifdef Q_OS_WIN
/**
* @brief UI widget for forcing native menu styling on Windows
*/
QCheckBox* native_menus;
#endif
/**
* @brief List of keyboard shortcut actions that can be triggered (links with key_shortcut_items and
@@ -281,6 +260,45 @@ private:
* key_shortcut_actions and key_shortcut_fields)
*/
QVector<KeySequenceEditor*> key_shortcut_fields;
/**
* @brief Add an automated QCheckBox+boolean value pair
*
* Many preferences are simple true/false (or on/off) options. Rather than adding a QCheckBox for each one and
* manually setting its checked value to the configuration setting (and vice versa when saving), this convenience
* function will add it to an automated set of checkboxes, automatically setting the checked state to the current
* setting, and then saving the new checked state back to the setting when the user accepts the changes (clicks OK).
*
* @param ui
*
* A valid QCheckBox item. This function does not take ownership of the QWidget or place it in a layout anywhere.
*
* @param value
*
* A pointer to the Boolean value this QCheckBox should be shared with. The QCheckBox widget's checked state will be
* set to the value of this pointer.
*
* @param restart_required
*
* Defaults to FALSE, set this to TRUE if changing this setting should prompt the user for a restart of Olive before
* the setting change takes effect.
*/
void AddBoolPair(QCheckBox* ui, bool* value, bool restart_required = false);
/**
* @brief Internal array managed by AddBoolPair(). Do not access this directly.
*/
QVector<QCheckBox*> bool_ui;
/**
* @brief Internal array managed by AddBoolPair(). Do not access this directly.
*/
QVector<bool*> bool_value;
/**
* @brief Internal array managed by AddBoolPair(). Do not access this directly.
*/
QVector<bool> bool_restart_required;
};
/**