diff --git a/.clang-format b/.clang-format index f292a0f219069123dea60222d9fc5c4b6e9e7efd..f24513acc97d596d6d78f3dbf9b8e62d579f41b4 100644 --- a/.clang-format +++ b/.clang-format @@ -44,7 +44,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: false -ColumnLimit: 120 +ColumnLimit: 100 CompactNamespaces: true ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 diff --git a/src/Ass/AssFactory.cc b/src/Ass/AssFactory.cc index 28f1322ef50e3cb0063c3a6163cc27aab38af386..179eae8f2197536a0ec17fd7152ad124984d057b 100644 --- a/src/Ass/AssFactory.cc +++ b/src/Ass/AssFactory.cc @@ -36,8 +36,11 @@ AssFactory::initFromStorage() noexcept const int baseValueIndex = separatorIndex + 2; if (separatorIndex < 0) { qWarning() << "Invalid line #" << lineIndex << ":" << line; + } else { + assContent[currentSection].insert(line.mid(0, separatorIndex), + line.mid(baseValueIndex)); + qDebug() << "Got line #" << lineIndex << ":" << line; } - assContent[currentSection].insert(line.mid(0, separatorIndex), line.mid(baseValueIndex)); } lineIndex++; diff --git a/src/Ass/AssFactory.hh b/src/Ass/AssFactory.hh index 74a0976661a81cdec642f341bafe612875553657..ff483150ee24e5069f74662b798203bf6a7a6bb8 100644 --- a/src/Ass/AssFactory.hh +++ b/src/Ass/AssFactory.hh @@ -44,13 +44,16 @@ private: static inline const QString sectionScriptInfo = "Script Info"; static inline const QString sectionStyles = "V4+ Styles"; static inline const QString sectionEvents = "Events"; - static inline const QStringList validSections = { sectionEvents, sectionScriptInfo, sectionStyles }; + static inline const QStringList validSections = { sectionEvents, sectionScriptInfo, + sectionStyles }; - static inline const QStringList intTypeFields = { "PlayResX", "PlayResY", "WrapStyle" }; - static inline const QList<QPair<QString, QString>> checkedValues = { { "ScriptType", "v4.00+" }, - { "WrapStyle", "0" }, - { "YCbCr Matrix", "TV.601" }, - { "ScaledBorderAndShadow", "yes" } }; + static inline const QStringList intTypeFields = { "PlayResX", "PlayResY", "WrapStyle" }; + static inline const QList<QPair<QString, QString>> checkedValues = { + { "ScriptType", "v4.00+" }, + { "WrapStyle", "0" }, + { "YCbCr Matrix", "TV.601" }, + { "ScaledBorderAndShadow", "yes" } + }; bool initFromStorage() noexcept; bool checkValidity() const noexcept; diff --git a/src/Ass/Style.cc b/src/Ass/Style.cc index 0ced674c9d1ac94bb7f3665810177f46aead1d4c..58d247a43074935f369c7c469fdb524255d052a7 100644 --- a/src/Ass/Style.cc +++ b/src/Ass/Style.cc @@ -74,17 +74,19 @@ Style::Style(const QString &styleString) underline = decodeLineToBoolean(content[StyleIndex::Underline], "Underline is not a boolean"); strikeOut = decodeLineToBoolean(content[StyleIndex::StrikeOut], "StrikeOut is not a boolean"); - scaleX = decodeLineToFloating(content[StyleIndex::ScaleX], "ScaleX is not a floating"); - scaleY = decodeLineToFloating(content[StyleIndex::ScaleY], "ScaleY is not a floating"); - spacing = decodeLineToFloating(content[StyleIndex::ScaleY], "Spacing is not a floating"); - angle = decodeLineToFloating(content[StyleIndex::Angle], "Angle is not a floating"); - borderStyle = decodeLineToFloating(content[StyleIndex::BorderStyle], "BorderStyle is not a floating"); - outline = decodeLineToFloating(content[StyleIndex::Outline], "Outline is not a floating"); - shadow = decodeLineToFloating(content[StyleIndex::Shadow], "Shadow is not a floating"); + scaleX = decodeLineToFloating(content[StyleIndex::ScaleX], "ScaleX is not a floating"); + scaleY = decodeLineToFloating(content[StyleIndex::ScaleY], "ScaleY is not a floating"); + spacing = decodeLineToFloating(content[StyleIndex::ScaleY], "Spacing is not a floating"); + angle = decodeLineToFloating(content[StyleIndex::Angle], "Angle is not a floating"); + borderStyle = + decodeLineToFloating(content[StyleIndex::BorderStyle], "BorderStyle is not a floating"); + outline = decodeLineToFloating(content[StyleIndex::Outline], "Outline is not a floating"); + shadow = decodeLineToFloating(content[StyleIndex::Shadow], "Shadow is not a floating"); alignment = decodeLineToInteger(content[StyleIndex::Shadow], "Alignement is not an integer"); if (alignment < 1 || alignment > 9) - throw std::runtime_error("invalid line content: Alignement must be between 1 and 9 included"); + throw std::runtime_error( + "invalid line content: Alignement must be between 1 and 9 included"); marginL = decodeLineToInteger(content[StyleIndex::MarginL], "MarginL is not an integer"); marginR = decodeLineToInteger(content[StyleIndex::MarginR], "MarginR is not an integer"); diff --git a/src/AudioUtils.c b/src/AudioUtils.c index d7a73aa10c5756970b152fc5cd882d6322565f1a..92b6303676e7b8e73bb72185ce0c5bf7787210f7 100644 --- a/src/AudioUtils.c +++ b/src/AudioUtils.c @@ -58,12 +58,14 @@ decodeAudioFile(const char *path, const int sample_rate, double **const data, si codec = avcodec_find_decoder(codec_par->codec_id); if (codec == NULL) { - fprintf(stderr, "Failed to find decoder for stream #%zu in file '%s'\n", stream_index, path); + fprintf(stderr, "Failed to find decoder for stream #%zu in file '%s'\n", stream_index, + path); goto exit_error; } if (avcodec_open2(codec_ctx, codec, NULL) < 0) { - fprintf(stderr, "Failed to open decoder for stream #%zu in file '%s'\n", stream_index, path); + fprintf(stderr, "Failed to open decoder for stream #%zu in file '%s'\n", stream_index, + path); goto exit_error; } @@ -101,8 +103,8 @@ decodeAudioFile(const char *path, const int sample_rate, double **const data, si /* Resample frames */ double *buffer; av_samples_alloc((uint8_t **)&buffer, NULL, 1, frame->nb_samples, AV_SAMPLE_FMT_DBL, 0); - const int frame_count_int = - swr_convert(swr, (uint8_t **)&buffer, frame->nb_samples, (const uint8_t **)frame->data, frame->nb_samples); + const int frame_count_int = swr_convert(swr, (uint8_t **)&buffer, frame->nb_samples, + (const uint8_t **)frame->data, frame->nb_samples); assert(frame_count_int >= 0); const size_t frame_count = (size_t)frame_count_int; @@ -169,13 +171,13 @@ RawImageDataDuplicatePixels(RawImageData *const ptr) return ret; } -#define CAP_VALUE(_value, _lower, _upper) \ - { \ - if (_value > _upper) { \ - _value = _upper; \ - } else if (_value < _lower) { \ - _value = _lower; \ - } \ +#define CAP_VALUE(_value, _lower, _upper) \ + { \ + if (_value > _upper) { \ + _value = _upper; \ + } else if (_value < _lower) { \ + _value = _lower; \ + } \ } RawImageData * @@ -186,9 +188,9 @@ RawImageDataNewFromData(const double *const data, const size_t size) const unsigned int decal = chunk_size - overlap; const size_t width = (size - chunk_size) / decal; const size_t height = chunk_size; - unsigned char *pixs = (unsigned char *)malloc(sizeof(unsigned char) * width * height / 2); - FFTSample *chunk_data = (FFTSample *)av_malloc_array(2 * chunk_size, sizeof(FFTSample)); - RDFTContext *ctx = av_rdft_init((int)log2(chunk_size), DFT_R2C); + unsigned char *pixs = (unsigned char *)malloc(sizeof(unsigned char) * width * height / 2); + FFTSample *chunk_data = (FFTSample *)av_malloc_array(2 * chunk_size, sizeof(FFTSample)); + RDFTContext *ctx = av_rdft_init((int)log2(chunk_size), DFT_R2C); if (!(pixs && chunk_data && ctx)) { if (pixs) diff --git a/src/AudioUtils.h b/src/AudioUtils.h index 62e1f83b82bee7468c79bfbec83fa67e6fef6f3a..41f36a3cf0fc2c6dcb5fd76bd14be8fd8a88fca0 100644 --- a/src/AudioUtils.h +++ b/src/AudioUtils.h @@ -7,7 +7,8 @@ extern "C" { #include <libavcodec/avcodec.h> -int decodeAudioFile(const char *path, const int sample_rate, double **const data, size_t *const size); +int decodeAudioFile(const char *path, const int sample_rate, double **const data, + size_t *const size); typedef struct ___RawImageData RawImageData; RawImageData *RawImageDataNewFromData(const double *const data, const size_t size); diff --git a/src/AudioVisualizer.cc b/src/AudioVisualizer.cc index 840d770aa44f99d2ac31eafe89279ede49a8da91..79ac7a9333e12ab834aa950c5bfe8496ab55df16 100644 --- a/src/AudioVisualizer.cc +++ b/src/AudioVisualizer.cc @@ -34,8 +34,8 @@ AudioVisualizer::fromFile(const QString &filename) const int sample_rate = 44100; double *data = nullptr; size_t size = 0; - int rc = decodeAudioFile(filename.toStdString().c_str(), sample_rate, &data, &size); - auto data_deleter = [](double *ptr) -> void { + int rc = decodeAudioFile(filename.toStdString().c_str(), sample_rate, &data, &size); + auto data_deleter = [](double *ptr) -> void { if (ptr != nullptr) { av_free(ptr); } @@ -49,14 +49,16 @@ AudioVisualizer::fromFile(const QString &filename) auto raw_image_deleter = [](RawImageData *ptr) -> void { RawImageDataFree(ptr); }; RawImageData *raw_image = RawImageDataNewFromData(data, size); - std::unique_ptr<RawImageData, decltype(raw_image_deleter)> raw_image_holder(raw_image, raw_image_deleter); + std::unique_ptr<RawImageData, decltype(raw_image_deleter)> raw_image_holder(raw_image, + raw_image_deleter); auto pixs_deleter = [](void *ptr) -> void { free(ptr); }; const int width = RawImageDataGetWidth(raw_image); const int height = RawImageDataGetHeight(raw_image); uchar *pixs = RawImageDataDuplicatePixels(raw_image); QImage img = - QImage(pixs, width, height / 2, width, QImage::Format_Grayscale8, pixs_deleter, pixs).mirrored(false, true); + QImage(pixs, width, height / 2, width, QImage::Format_Grayscale8, pixs_deleter, pixs) + .mirrored(false, true); auto *audioVisualizer = new AudioVisualizer; audioVisualizer->printSpectrum(img); diff --git a/src/Document/VivyDocument.cc b/src/Document/VivyDocument.cc index caf5b2850fa0d63148a203197f31377bbff573ab..4d8ceaed542e0a921f111cf64818f21a22290e71 100644 --- a/src/Document/VivyDocument.cc +++ b/src/Document/VivyDocument.cc @@ -24,17 +24,20 @@ VivyDocument::loadSubDocument(const QString &name) noexcept switch (type) { case Capabilities::AudioAble: qDebug() << "Create an audio subDocument from " << name; - audioDocument = std::unique_ptr<AudioSubDocument>(AudioSubDocument::fromFile(file.absoluteFilePath())); + audioDocument = std::unique_ptr<AudioSubDocument>( + AudioSubDocument::fromFile(file.absoluteFilePath())); return true; case Capabilities::VideoAble: qDebug() << "Create a video subDocument from " << name; - videoDocument = std::unique_ptr<VideoSubDocument>(VideoSubDocument::fromFile(file.absoluteFilePath())); + videoDocument = std::unique_ptr<VideoSubDocument>( + VideoSubDocument::fromFile(file.absoluteFilePath())); return true; case Capabilities::AssAble: qDebug() << "Create an ass subDocument from " << name; - assDocument = std::unique_ptr<AssSubDocument>(AssSubDocument::fromFile(file.absoluteFilePath())); + assDocument = + std::unique_ptr<AssSubDocument>(AssSubDocument::fromFile(file.absoluteFilePath())); return true; } } @@ -54,18 +57,22 @@ VivyDocument::loadSubDocument(const QString &name, VivyDocument::Capabilities as if (type == Capabilities::AssAble && asType == Capabilities::AssAble) { qDebug() << "Create an ass subDocument from " << name; - assDocument = std::unique_ptr<AssSubDocument>(AssSubDocument::fromFile(file.absoluteFilePath())); + assDocument = + std::unique_ptr<AssSubDocument>(AssSubDocument::fromFile(file.absoluteFilePath())); } else if (type == Capabilities::VideoAble && asType == Capabilities::VideoAble) { qDebug() << "Create a video subDocument from " << name; - videoDocument = std::unique_ptr<VideoSubDocument>(VideoSubDocument::fromFile(file.absoluteFilePath())); + videoDocument = + std::unique_ptr<VideoSubDocument>(VideoSubDocument::fromFile(file.absoluteFilePath())); } else if (const bool requestAudio = (asType == Capabilities::AudioAble); - (type == Capabilities::VideoAble && requestAudio) || (type == Capabilities::AudioAble && requestAudio)) { + (type == Capabilities::VideoAble && requestAudio) || + (type == Capabilities::AudioAble && requestAudio)) { qDebug() << "Create an audio subDocument from " << name; - audioDocument = std::unique_ptr<AudioSubDocument>(AudioSubDocument::fromFile(file.absoluteFilePath())); + audioDocument = + std::unique_ptr<AudioSubDocument>(AudioSubDocument::fromFile(file.absoluteFilePath())); } return true; @@ -98,7 +105,8 @@ bool VivyDocument::rename(const QString &name) noexcept { /* Compute new paths */ - const QString newNameWithExtension = name.right(filePrefix.size()) == filePrefix ? name : name + "." + filePrefix; + const QString newNameWithExtension = + name.right(filePrefix.size()) == filePrefix ? name : name + "." + filePrefix; QFileInfo oldPath(documentLocation, documentName + "." + filePrefix); QFileInfo newPath(documentLocation, newNameWithExtension); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index a028ff88bb56e0c35af7db33808981351373af9e..4a6a4045ced783301ca9ac711856b0d21e552698 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -19,14 +19,14 @@ #define DCL_MENU(menu, name) [[maybe_unused]] QMenu *menu##Menu = menuBar()->addMenu(name); -#define DCL_TOOLBAR(method, name) \ - [[maybe_unused]] QToolBar *method##ToolBar = new QToolBar(tr(name), this); \ +#define DCL_TOOLBAR(method, name) \ + [[maybe_unused]] QToolBar *method##ToolBar = new QToolBar(tr(name), this); \ addToolBar(method##ToolBar); -#define DCL_ACTION(method, name, tip, menu) \ - [[maybe_unused]] QAction *method##Act = new QAction(tr(name), this); \ - method##Act->setStatusTip(tr(tip)); \ - menu##Menu->addAction(method##Act); \ +#define DCL_ACTION(method, name, tip, menu) \ + [[maybe_unused]] QAction *method##Act = new QAction(tr(name), this); \ + method##Act->setStatusTip(tr(tip)); \ + menu##Menu->addAction(method##Act); \ connect(method##Act, &QAction::triggered, this, &MainWindow::method); #define TOOLBAR_ADD_ACTION(toolbar, action) toolbar##ToolBar->addAction(action##Act); @@ -96,10 +96,14 @@ MainWindow::MainWindow(QWidget *parent) noexcept loadSubDocumentVideoAct->setEnabled(false); loadSubDocumentAudioAct->setEnabled(false); - auto enableOnDocument = [](auto *widget, int index) noexcept -> void { widget->setEnabled(index >= 0); }; + auto enableOnDocument = [](auto *widget, int index) noexcept -> void { + widget->setEnabled(index >= 0); + }; - connect(documents, &QTabWidget::currentChanged, saveFileAct, std::bind_front(enableOnDocument, saveFileAct)); - connect(documents, &QTabWidget::currentChanged, saveFileAsAct, std::bind_front(enableOnDocument, saveFileAsAct)); + connect(documents, &QTabWidget::currentChanged, saveFileAct, + std::bind_front(enableOnDocument, saveFileAct)); + connect(documents, &QTabWidget::currentChanged, saveFileAsAct, + std::bind_front(enableOnDocument, saveFileAsAct)); connect(documents, &QTabWidget::currentChanged, loadSubDocumentAudioAct, std::bind_front(enableOnDocument, loadSubDocumentAudioAct)); @@ -119,7 +123,8 @@ MainWindow::MainWindow(QWidget *parent) noexcept std::weak_ptr<VivyDocument> MainWindow::getCurrentDocument() const { - VivyDocumentView *currentView = reinterpret_cast<VivyDocumentView *>(documents->currentWidget()); + VivyDocumentView *currentView = + reinterpret_cast<VivyDocumentView *>(documents->currentWidget()); if (currentView) return currentView->getDocument(); else @@ -160,8 +165,9 @@ MainWindow::saveFileAs() noexcept void MainWindow::closeDocument(int index) noexcept { - const QWidget *widgetToClose = documents->widget(index); - const VivyDocumentView *documentToClose = reinterpret_cast<const VivyDocumentView *>(widgetToClose); + const QWidget *widgetToClose = documents->widget(index); + const VivyDocumentView *documentToClose = + reinterpret_cast<const VivyDocumentView *>(widgetToClose); if (auto doc = documentToClose->getDocument().lock()) { const QString documentName = doc->getName(); @@ -210,13 +216,16 @@ MainWindow::openDocument() noexcept if (auto document = vivyApp->documentStore.loadDocument(filename).lock()) { try { addTab(new VivyDocumentView(document)); - if (auto doc = reinterpret_cast<const VivyDocumentView *>(documents->widget(0))->getDocument().lock()) { + if (auto doc = reinterpret_cast<const VivyDocumentView *>(documents->widget(0)) + ->getDocument() + .lock()) { if (doc->isUntouchedDefault() && documents->count() == 2) { closeDocument(0); } } } catch (const std::runtime_error &e) { - qCritical() << "Failed to create the document view for" << baseName << "with path" << filename; + qCritical() + << "Failed to create the document view for" << baseName << "with path" << filename; vivyApp->documentStore.closeDocument(baseName); } } diff --git a/src/TimingView.cc b/src/TimingView.cc index b176c3d2f879f4ac5f67f098cb7ced74f10abf95..25f859d3dda9af16b58ebc910f9ee4ebe1a276bf 100644 --- a/src/TimingView.cc +++ b/src/TimingView.cc @@ -37,8 +37,8 @@ TimingView::mousePressEvent(QMouseEvent *event) noexcept QGraphicsItem *got; if ((got = scene->itemAt(pos, QTransform())) == nullptr || got == scene->bg()) { const int height = static_cast<int>(scene->height()); - scene->addItem( - new TimingBar(QLine(x, 0, x, height), event->button() == Qt::LeftButton ? startColour : endColour)); + scene->addItem(new TimingBar(QLine(x, 0, x, height), + event->button() == Qt::LeftButton ? startColour : endColour)); } QGraphicsView::mousePressEvent(event); diff --git a/src/Utils.hh b/src/Utils.hh index cfe0d3ed88a011dea7f1d505ecd213f6a691dc6f..97bfa1f57e5e1f86d8dafa6646808cc499aa7689 100644 --- a/src/Utils.hh +++ b/src/Utils.hh @@ -9,11 +9,11 @@ #include <QtGlobal> #include <type_traits> -#define VIVY_UNMOVABLE_OBJECT(classname) \ - /* Don't move this object around */ \ - classname(const classname &) = delete; /* Copy */ \ - classname(classname &&) = delete; /* Move */ \ - classname &operator=(const classname &) = delete; /* Copy assign */ \ +#define VIVY_UNMOVABLE_OBJECT(classname) \ + /* Don't move this object around */ \ + classname(const classname &) = delete; /* Copy */ \ + classname(classname &&) = delete; /* Move */ \ + classname &operator=(const classname &) = delete; /* Copy assign */ \ classname &operator=(classname &&) = delete; /* Move assign */ namespace Vivy::Utils diff --git a/src/VivyDocumentView.cc b/src/VivyDocumentView.cc index 368468f9c2372dce029917c81ffeb4b936968808..31e2b0c16c0b9b4c61fd4a78e2dec5225bfe4d4f 100644 --- a/src/VivyDocumentView.cc +++ b/src/VivyDocumentView.cc @@ -27,7 +27,8 @@ VivyDocumentView::loadAudioView(std::shared_ptr<VivyDocument> doc) noexcept if (doc->checkDocumentCapabilities(VivyDocument::AudioAble)) { std::weak_ptr<AudioSubDocument> audioDocumentWeak = doc->getAudioSubDocument(); if (auto audioDocument = audioDocumentWeak.lock()) { - qDebug() << "Create an audio vizualizer for the audio sub document" << audioDocument->getFilePath(); + qDebug() << "Create an audio vizualizer for the audio sub document" + << audioDocument->getFilePath(); visualizer = AudioVisualizer::fromFile(audioDocument->getFilePath()); if (visualizer == nullptr) { qCritical() << "Failed to create visualizer for" << audioDocument->getFilePath();