• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 32260334846

19 Aug 2026 01:49PM UTC coverage: 20.843% (+0.2%) from 20.688%
32260334846

Pull #2212

github

web-flow
Merge 883c59e85 into 05abddc99
Pull Request #2212: test: make rendering testable from master

59 of 225 new or added lines in 15 files covered. (26.22%)

134 existing lines in 10 files now uncovered.

44621 of 214080 relevant lines covered (20.84%)

5844.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.74
/src/app/Application.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include "Application.hpp"
4

5
#include <score/application/ApplicationServices.hpp>
6
#include <score/command/Validity/ValidityChecker.hpp>
7
#include <score/model/Identifier.hpp>
8
#include <score/model/Skin.hpp>
9
#include <score/model/path/ObjectIdentifier.hpp>
10
#include <score/plugins/application/GUIApplicationPlugin.hpp>
11
#include <score/plugins/documentdelegate/DocumentDelegateFactory.hpp>
12
#include <score/plugins/settingsdelegate/SettingsDelegateModel.hpp>
13
#include <score/selection/Selection.hpp>
14
#include <score/tools/IdentifierGeneration.hpp>
15
#include <score/widgets/Pixmap.hpp>
16

17
#include <core/application/ApplicationRegistrar.hpp>
18
#include <core/application/OpenDocumentsFile.hpp>
19
#include <core/application/SafeQApplication.hpp>
20
#include <core/document/DocumentBackups.hpp>
21
#include <core/document/DocumentModel.hpp>
22
#include <core/presenter/DocumentManager.hpp>
23
#include <core/presenter/Presenter.hpp>
24
#include <core/view/Window.hpp>
25

26
#include <ossia/context.hpp>
27

28
#include <ossia-qt/qt_logger.hpp>
29

30
#include <QDesktopServices>
31
#include <QDir>
32
#include <QDirIterator>
33
#include <QFontDatabase>
34
#include <QKeyEvent>
35
#include <QLabel>
36
#include <QOpenGLContext>
37
#include <QPainter>
38
#include <QPushButton>
39
#include <QResource>
40
#include <QStandardPaths>
41
#include <QStyleHints>
42
#include <QUrl>
43
#include <qconfig.h>
44
#include <qobjectdefs.h>
45

46
#if defined(QT_FEATURE_thread)
47
#if QT_FEATURE_thread == 1
48
#include <QThreadPool>
49
#endif
50
#endif
51

52
#include <score/gfx/Vulkan.hpp>
53
#if QT_HAS_VULKAN && __has_include(<QVulkanInstance>)
54
#include <QVulkanInstance>
55
#endif
56

57
#include <spdlog/sinks/stdout_sinks.h>
58
#include <spdlog/spdlog.h>
59

60
#if defined(SCORE_STATIC_PLUGINS)
61
#include <score_static_plugins.hpp>
62
#endif
63

64
#include <wobjectimpl.h>
65
W_OBJECT_IMPL(Application)
×
66

67
#if defined(SCORE_SOURCE_DIR)
68
#include <QFileSystemWatcher>
69
#endif
70
#if defined(SCORE_STATIC_PLUGINS)
71
int qInitResources_score();
72
int qInitResources_qtconf();
73
#endif
74

75
#if !defined(SCORE_DEBUG) && !defined(__EMSCRIPTEN__)
76
#define SCORE_SPLASH_SCREEN 1
77
#endif
78
#include <phantom/phantomstyle.h>
79

80
#if defined(SCORE_SPLASH_SCREEN)
81
#include "StartScreen.hpp"
82
#else
83
namespace score
84
{
85
class StartScreen : public QWidget
86
{
87
};
88
}
89
#endif
90

91
static void loadResources()
×
92
{
93
// Note: Q_INIT_RESOURCE must be invoked outside of any namespace
94
#if defined(SCORE_STATIC_PLUGINS)
95
  Q_INIT_RESOURCE(score);
96
  Q_INIT_RESOURCE(qtconf);
97
  Q_INIT_RESOURCE(qcodeeditor_resources);
98
#if defined(__APPLE__)
99
  Q_INIT_RESOURCE(fonts_macos);
100
#else
101
  Q_INIT_RESOURCE(fonts);
102
#endif
103
#endif
104

105
  if(QString file = QCoreApplication::applicationDirPath() + "/resources.rcc";
×
106
     QFile::exists(file))
×
107
  {
108
    QResource::registerResource(file);
×
109
  }
×
110
}
×
111

112
namespace score
113
{
114
class DocumentModel;
115

116
static void loadApplicationResources()
×
117
{
118
  loadResources();
×
119

120
  // Register fonts
121
  {
122
    QDirIterator it(":/fonts", QDirIterator::Subdirectories);
×
123
    while (it.hasNext()) {
×
124
      auto font = it.next();
×
125
      if(font.endsWith("ttf", Qt::CaseInsensitive) || font.endsWith("bdf", Qt::CaseInsensitive) || font.endsWith("otf", Qt::CaseInsensitive))
×
126
      {
127
        QFontDatabase::addApplicationFont(font);
×
128
      }
×
129
    }
×
130
  }
×
131

132
#if defined(__APPLE__)
133
  constexpr const double defaultFontSize = 10. * 96. / 72.;
134
#else
135
  constexpr const double defaultFontSize = 10.;
×
136
#endif
137

138
  QFont f("Ubuntu", defaultFontSize);
×
139
  f.setHintingPreference(QFont::HintingPreference::PreferVerticalHinting);
×
140
  qGuiApp->setFont(f);
×
141
}
×
142

143
static void setQApplicationSettings(QApplication& m_app)
×
144
{
145
  // For release builds against a debug Qt, we build qt without any style plug-in.
146
  // Sadly Qt asserts so wh have to simulate the loading of a plugin (see above).
147
  // For older Qts we won't be debugging anyways and will be linking against distro Qt versions so we just set the style
148
  // manually
149
  m_app.setStyle(new PhantomStyle);
×
150

151
  auto pal = qApp->palette();
×
152
  pal.setBrush(QPalette::Window, QColor("#222222"));        //#1A2024"));
×
153
  pal.setBrush(QPalette::Base, QColor("#161514"));          //12171A"));
×
154
  pal.setBrush(QPalette::AlternateBase, QColor("#1e1d1c")); //1f2a30")); // alternate bg
×
155
  pal.setBrush(QPalette::Highlight, QColor{"#9062400a"});
×
156
  pal.setBrush(QPalette::HighlightedText, QColor("#FDFDFD"));
×
157
  pal.setBrush(QPalette::WindowText, QColor("silver"));
×
158
  pal.setBrush(QPalette::Text, QColor("#d0d0d0"));
×
159

160
  pal.setBrush(QPalette::Button, QColor("#1d1c1a"));
×
161
  pal.setBrush(QPalette::ButtonText, QColor("#f0f0f0"));
×
162
  pal.setBrush(QPalette::PlaceholderText, QColor("#80d0d0d0"));
×
163
  pal.setBrush(QPalette::ToolTipBase, QColor("#161514"));
×
164
  pal.setBrush(QPalette::ToolTipText, QColor("silver"));
×
165

166
  pal.setBrush(QPalette::Midlight, QColor{"#62400a"});
×
167
  pal.setBrush(QPalette::Light, QColor{"#c58014"});
×
168
  pal.setBrush(QPalette::Mid, QColor("#252930"));
×
169

170
  //  pal.setBrush(QPalette::Dark, QColor("#808080"));
171
  // pal.setBrush(QPalette::Shadow, QColor("#666666"));
172

173
  qGuiApp->setPalette(pal);
×
174
}
×
175

176
} // namespace score
177

178
namespace
179
{
180
bool runningUnderAnUISession() noexcept
5 ✔
181
{
182
  const auto platform = qgetenv("QT_QPA_PLATFORM");
5 ✔
183
  if(platform == "minimal")
5 ✔
184
  {
185
    return false;
×
186
  }
187

188
  // Win32 and macOS always have a graphical session
189
#if defined(WIN32) || defined(__APPLE__)
190
  return true;
191
#else
192
  if(!qEnvironmentVariableIsEmpty("DISPLAY"))
5 ✔
193
    return true;
×
194
  if(!qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY"))
5 ✔
195
    return true;
×
196
  if(qgetenv("XDG_SESSION_TYPE") != "tty")
5 ✔
197
    return true;
5 ✔
198
  if(platform.contains("gl") || platform.contains("vkkhr")
×
NEW
199
     || platform.contains("linuxfb") || platform.contains("vnc")
×
NEW
200
     || platform.contains("offscreen"))
×
201
    return true;
×
202
  return false;
×
203
#endif
204
}
5 ✔
205

206
QCoreApplication*
207
createApplication(const score::ApplicationSettings& set, int& argc, char** argv)
5 ✔
208
{
209
  if(set.gui || !set.ui.isEmpty())
5 ✔
210
  {
211
    return new SafeQApplication{argc, argv};
×
212
  }
213
  else
214
  {
215
    if(runningUnderAnUISession())
5 ✔
216
      return new QGuiApplication{argc, argv};
5 ✔
217
    else
218
      return new QCoreApplication{argc, argv};
×
219
  }
220
}
5 ✔
221
}
222

223
Application::Application(int& argc, char** argv)
10 ✔
224
    : QObject{nullptr}
5 ✔
225
{
5 ✔
226
  m_instance = this;
5 ✔
227

228
  QStringList l;
5 ✔
229
  for(int i = 0; i < argc; i++)
40 ✔
230
    l.append(QString::fromUtf8(argv[i]));
35 ✔
231
  appSettings.parse(l, argc, argv);
5 ✔
232

233
  score::setQApplicationMetadata();
5 ✔
234

235
  if(!qEnvironmentVariableIsSet("QT_SCALE_FACTOR"))
5 ✔
236
  {
237
    QSettings s;
5 ✔
238
    if(s.contains("Skin/Zoom"))
5 ✔
239
    {
240
      double zoom = s.value("Skin/Zoom").toDouble();
3 ✔
241
      if(zoom != 1.)
3 ✔
242
      {
243
        zoom = qBound(1.0, zoom, 10.);
×
244
        qputenv("QT_SCALE_FACTOR", QString("%1").arg(zoom).toLatin1());
×
245
        qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough");
×
246
      }
×
247
    }
3 ✔
248
  }
5 ✔
249

250
  m_app = createApplication(appSettings, argc, argv);
5 ✔
251

252
#if defined(QT_FEATURE_thread)
253
#if QT_FEATURE_thread == 1
254
  this->thread()->setPriority(QThread::Priority::TimeCriticalPriority);
5 ✔
255
  QThreadPool::globalInstance()->setMaxThreadCount(2);
5 ✔
256
  QThreadPool::globalInstance()->setThreadPriority(QThread::Priority::HighPriority);
5 ✔
257
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
258
  QThreadPool::globalInstance()->setServiceLevel(QThread::QualityOfService::High);
259
#endif
260
#endif
261
#endif
262
}
×
263

264
Application::Application(
×
265
    const score::ApplicationSettings& appSettings, int& argc, char** argv)
266
    : QObject{nullptr}
×
267
    , appSettings(appSettings)
×
268
{
×
269
  m_instance = this;
×
270
  score::setQApplicationMetadata();
×
271

272
  if(!qEnvironmentVariableIsSet("QT_SCALE_FACTOR"))
×
273
  {
274
    QSettings s;
×
275
    if(s.contains("Skin/Zoom"))
×
276
    {
277
      double zoom = s.value("Skin/Zoom").toDouble();
×
278
      if(zoom != 1.)
×
279
      {
280
        zoom = qBound(1.0, zoom, 10.);
×
281
        qputenv("QT_SCALE_FACTOR", QString("%1").arg(zoom).toLatin1());
×
282
        qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough");
×
283
      }
×
284
    }
×
285
  }
×
286

287
  m_app = createApplication(appSettings, argc, argv);
×
288
}
×
289

290
Application::~Application()
5 ✔
291
{
×
292
  this->setParent(nullptr);
5 ✔
293
  m_settings.teardownView();
5 ✔
294
  // FIXME projectSettings?
295
  delete m_view;
5 ✔
296
  delete m_presenter;
5 ✔
297
  delete m_startScreen;
5 ✔
298

299
  score::DocumentBackups::clear();
5 ✔
300
  QCoreApplication::processEvents();
5 ✔
301

302
  auto& svc = score::AppServices();
5 ✔
303
  svc.filewatch.reset();
5 ✔
304
  svc.taskpool.reset();
5 ✔
305
  svc.threadpool.reset();
5 ✔
306

307
#if QT_HAS_VULKAN
308
  if(auto vk = score::gfx::staticVulkanInstance(false))
5 ✔
309
  {
310
    delete vk;
×
311
  }
×
312

313
#endif
314
  for(auto& settings : m_settings.settings())
65 ✔
315
    settings->setParent(nullptr);
60 ✔
316
  delete m_app;
5 ✔
317
}
5 ✔
318

319
const score::GUIApplicationContext& Application::context() const
60 ✔
320
{
321
  return m_presenter->applicationContext();
60 ✔
322
}
323

324
const score::ApplicationComponents& Application::components() const
1,126 ✔
325
{
326
  return m_presenter->applicationComponents();
1,126 ✔
327
}
328

329
void Application::init()
5 ✔
330
{
331
  if(appSettings.gui && appSettings.opengl)
5 ✔
332
  {
333
    auto platform = QGuiApplication::platformName();
×
334
    if(platform.contains(QStringLiteral("wayland")))
×
335
    {
336
      appSettings.opengl = false;
×
337
    }
×
338
    else
339
    {
340
#if !((defined(__arm__) || defined(__aarch64__)))
341
      QOpenGLContext ctx;
×
342
      appSettings.opengl = ctx.create() && ctx.format().majorVersion() > 1;
×
343
#else
344
      appSettings.opengl = true;
345
#endif
346
    }
×
347
  }
×
348
#if defined(SCORE_STATIC_PLUGINS)
349
  score_init_static_plugins();
350
#endif
351

352
  std::vector<spdlog::sink_ptr> v;
5 ✔
353
  /*
354
  try {
355
    v.push_back(std::make_shared<spdlog::sinks::stderr_sink_mt>());
356
  } catch (...) { }
357
  */
358
  try
359
  {
360
    v.push_back(std::make_shared<ossia::qt::log_sink>());
5 ✔
361
  }
5 ✔
362
  catch(...)
363
  {
364
  }
×
365

366
  ossia::context context{std::move(v)};
5 ✔
367
  ossia::logger().set_level(spdlog::level::debug);
5 ✔
368

369
  this->setObjectName("Application");
5 ✔
370
  this->setParent(m_app);
5 ✔
371
#if !defined(__EMSCRIPTEN__)
372
#if QT_CONFIG(library)
373
  m_app->addLibraryPath(m_app->applicationDirPath() + "/plugins");
5 ✔
374
#endif
375
#endif
376
#if defined(_MSC_VER)
377
  QDir::setCurrent(qApp->applicationDirPath());
378
  auto path = qgetenv("PATH");
379
  path += ";" + QCoreApplication::applicationDirPath();
380
  path += ";" + QCoreApplication::applicationDirPath() + "/plugins";
381
  qputenv("PATH", path);
382
  SetDllDirectoryW((wchar_t*)QCoreApplication::applicationDirPath().utf16());
383
  const QString dir2 = (QCoreApplication::applicationDirPath() + "/plugins");
384
  SetDllDirectoryW((wchar_t*)dir2.utf16());
385
#endif
386

387
  if(appSettings.ui.isEmpty())
5 ✔
388
  {
389
    if(!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE"))
5 ✔
390
    {
391
      qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
5 ✔
392
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
393
      if(appSettings.gui)
394
        qGuiApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
395
#endif
396
    }
5 ✔
397
  }
5 ✔
398

399
  // MVP
400
  if(appSettings.gui)
5 ✔
401
  {
402
    score::loadApplicationResources();
×
403
    score::setQApplicationSettings(*qApp);
×
404
    m_settings.setupView();
×
405
    //m_projectSettings.setupView();
406
    m_view = new score::View{this};
×
407
  }
×
408
  else if(!appSettings.ui.isEmpty())
5 ✔
409
  {
410
    score::loadApplicationResources();
×
411
  }
×
412

413
  m_presenter
5 ✔
414
      = new score::Presenter{appSettings, m_settings, m_projectSettings, m_view, this};
5 ✔
415
  // Plugins
416
  GUIApplicationInterface::loadPluginData(m_settings, *m_presenter);
5 ✔
417

418
  // View
419
  if(appSettings.gui)
5 ✔
420
  {
421
    bool show_fullscreen = false;
×
422
#if defined(__EMSCRIPTEN__)
423
    show_fullscreen = true;
424
#else
425
    show_fullscreen = (qGuiApp->platformName() == "vnc");
×
426
#endif
427
    if(show_fullscreen)
×
428
    {
429
      m_view->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
×
430
      m_view->showFullScreen();
×
431
    }
×
432
    else
433
    {
434
      m_view->show();
×
435
    }
436
  }
×
437

438
#if defined(__APPLE__)
439
  {
440
    if(appSettings.gui)
441
    {
442
      auto sqa = safe_cast<SafeQApplication*>(m_app);
443
      if(auto file = sqa->fileToOpen; QFile::exists(file))
444
      {
445
        appSettings.loadList.push_back(file);
446
      }
447
    }
448
  }
449
#endif
450

451
#if defined(SCORE_SPLASH_SCREEN)
452
  if(appSettings.gui && !appSettings.forceRestore && appSettings.loadList.empty())
453
  {
454
    m_startScreen = new score::StartScreen{this->context().docManager.recentFiles()};
455
    m_startScreen->show();
456

457
    auto& ctx = m_presenter->applicationContext();
458
    connect(m_startScreen, &score::StartScreen::openNewDocument, this, [&]() {
459
      m_startScreen->close();
460
      openNewDocument();
461
    });
462
    connect(
463
        m_startScreen, &score::StartScreen::openFile, this, [&](const QString& file) {
464
          m_startScreen->close();
465
          m_presenter->documentManager().loadFile(ctx, file);
466
        });
467
    connect(m_startScreen, &score::StartScreen::openFileDialog, this, [&]() {
468
      m_startScreen->close();
469
      m_presenter->documentManager().loadFile(ctx);
470
    });
471
    connect(m_startScreen, &score::StartScreen::exitApp, this, [&]() { qApp->quit(); });
472
  }
473
#endif
474

475
  if(appSettings.gui)
5 ✔
476
  {
477
    m_view->sizeChanged(m_view->size());
×
478
    m_view->ready();
×
479

480
    auto sqa = safe_cast<SafeQApplication*>(m_app);
×
481
    connect(sqa, &SafeQApplication::fileOpened, this, [&](const QString& file) {
×
482
      auto& ctx = m_presenter->applicationContext();
×
483
      m_presenter->documentManager().loadFile(ctx, file);
×
484
    });
×
485
  }
×
486

487
  QTimer::singleShot(10, [&] {
10 ✔
488
    initDocuments();
5 ✔
489

490
#if defined(QT_FEATURE_thread)
491
#if QT_FEATURE_thread == 1
492
    this->thread()->setPriority(QThread::Priority::TimeCriticalPriority);
5 ✔
493
    QThreadPool::globalInstance()->setMaxThreadCount(2);
5 ✔
494
    QThreadPool::globalInstance()->setThreadPriority(QThread::Priority::HighPriority);
5 ✔
495
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
496
    QThreadPool::globalInstance()->setServiceLevel(QThread::QualityOfService::High);
497
#endif
498
#endif
499
#endif
500

501
    auto& ctx = m_presenter->applicationContext();
5 ✔
502
    // The plug-ins have the ability to override the boot process.
503
    for(auto plug : ctx.guiApplicationPlugins())
80 ✔
504
    {
505
      plug->afterStartup();
75 ✔
506
    }
507
  });
5 ✔
508
}
5 ✔
509

510
void Application::initDocuments()
5 ✔
511
{
512
  auto& ctx = m_presenter->applicationContext();
5 ✔
513
  // The plug-ins have the ability to override the boot process.
514
  for(auto plug : ctx.guiApplicationPlugins())
80 ✔
515
  {
516
    if(plug->handleLoading())
75 ✔
517
    {
518
      return;
×
519
    }
520
  }
521

522
  if(!appSettings.loadList.empty())
5 ✔
523
  {
524
    for(const auto& doc : appSettings.loadList)
8 ✔
525
      m_presenter->documentManager().loadFile(ctx, doc);
4 ✔
526
  }
4 ✔
527

528
  // Try to reload if there was a crash
529
  if(appSettings.forceRestore)
5 ✔
530
  {
531
    if(score::OpenDocumentsFile::exists())
×
532
    {
533
      m_presenter->documentManager().restoreDocuments(ctx);
×
534
    }
×
535
  }
×
536
  else if(appSettings.tryToRestore)
5 ✔
537
  {
538
#if defined(SCORE_SPLASH_SCREEN)
539
    if(m_startScreen && score::OpenDocumentsFile::exists())
540
    {
541
      m_startScreen->addLoadCrashedSession();
542
      connect(m_startScreen, &score::StartScreen::loadCrashedSession, this, [&]() {
543
        m_startScreen->close();
544
        m_presenter->documentManager().restoreDocuments(ctx);
545
      });
546
    }
547
#else
548
    if(score::DocumentBackups::canRestoreDocuments())
×
549
    {
550
      m_presenter->documentManager().restoreDocuments(ctx);
×
551
    }
×
552
#endif
553
  }
×
554

555
// If nothing was reloaded, open a normal document
556
  if(!appSettings.ui.isEmpty())
5 ✔
557
  {
558
    // Custom UI mode always expects a new document
559
    openNewDocument();
×
560
  }
×
561
  else
562
  {
563
    if(!m_startScreen)
5 ✔
564
      openNewDocument();
5 ✔
565
  }
566
}
5 ✔
567

568
void Application::openNewDocument()
5 ✔
569
{
570
  auto& ctx = m_presenter->applicationContext();
5 ✔
571
  if(m_presenter->documentManager().documents().empty())
5 ✔
572
  {
573
    auto& documentKinds
5 ✔
574
        = m_presenter->applicationComponents().interfaces<score::DocumentDelegateList>();
5 ✔
575
    if(!documentKinds.empty() && m_presenter->documentManager().documents().empty())
5 ✔
576
    {
577
      m_presenter->documentManager().newDocument(
10 ✔
578
          ctx, Id<score::DocumentModel>{score::random_id_generator::getRandomId()},
5 ✔
579
          *m_presenter->applicationComponents()
10 ✔
580
               .interfaces<score::DocumentDelegateList>()
5 ✔
581
               .begin());
5 ✔
582
    }
5 ✔
583
  }
5 ✔
584
}
5 ✔
585

586
int Application::exec()
5 ✔
587
{
588
  return m_app->exec();
5 ✔
589
}
590

591
#if defined(SCORE_SPLASH_SCREEN)
592

593
W_OBJECT_IMPL(score::StartScreen)
594
W_OBJECT_IMPL(score::InteractiveLabel)
595

596
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc