From 3969be087521c39333504d8437840242579883e6 Mon Sep 17 00:00:00 2001 From: SeleDreams Date: Tue, 7 Jul 2020 04:58:53 +0200 Subject: [PATCH] Changed the system to use a file named portable_mode.txt instead of a define and fixed the indentation type --- include/ConfigManager.h | 102 +++++--- src/core/ConfigManager.cpp | 361 ++++++++++++++-------------- src/core/FxMixer.cpp | 465 ++++++++++++++++++------------------- 3 files changed, 467 insertions(+), 461 deletions(-) diff --git a/include/ConfigManager.h b/include/ConfigManager.h index 30ae1a09cb5..edd516246a7 100644 --- a/include/ConfigManager.h +++ b/include/ConfigManager.h @@ -46,18 +46,19 @@ const QString PRESETS_PATH = "presets/"; const QString SAMPLES_PATH = "samples/"; const QString GIG_PATH = "samples/gig/"; const QString SF2_PATH = "samples/soundfonts/"; -const QString LADSPA_PATH ="plugins/ladspa/"; +const QString LADSPA_PATH = "plugins/ladspa/"; const QString DEFAULT_THEME_PATH = "themes/default/"; const QString TRACK_ICON_PATH = "track_icons/"; const QString LOCALE_PATH = "locale/"; +const QString PORTABLE_MODE_FILE = "/portable_mode.txt"; class LMMS_EXPORT ConfigManager : public QObject { - Q_OBJECT +Q_OBJECT public: - static inline ConfigManager * inst() + static inline ConfigManager *inst() { - if(s_instanceOfMe == NULL ) + if (s_instanceOfMe == NULL) { s_instanceOfMe = new ConfigManager(); } @@ -65,12 +66,12 @@ class LMMS_EXPORT ConfigManager : public QObject } - const QString & workingDir() const + const QString &workingDir() const { return m_workingDir; } - const QString & dataDir() const + const QString &dataDir() const { return m_dataDir; } @@ -117,36 +118,40 @@ class LMMS_EXPORT ConfigManager : public QObject } - const QString & vstDir() const + const QString &vstDir() const { return m_vstDir; } - const QString & ladspaDir() const + const QString &ladspaDir() const { return m_ladspaDir; } - const QString & sf2Dir() const + const QString &sf2Dir() const { return m_sf2Dir; } #ifdef LMMS_HAVE_FLUIDSYNTH - const QString & sf2File() const + + const QString &sf2File() const { return m_sf2File; } + #endif #ifdef LMMS_HAVE_STK - const QString & stkDir() const + + const QString &stkDir() const { return m_stkDir; } + #endif - const QString & gigDir() const + const QString &gigDir() const { return m_gigDir; } @@ -182,7 +187,7 @@ class LMMS_EXPORT ConfigManager : public QObject return m_themeDir; } - const QString & backgroundPicFile() const + const QString &backgroundPicFile() const { return m_backgroundPicFile; } @@ -197,7 +202,7 @@ class LMMS_EXPORT ConfigManager : public QObject return m_workingDir + "recover.mmp"; } - inline const QStringList & recentlyOpenedProjects() const + inline const QStringList &recentlyOpenedProjects() const { return m_recentlyOpenedProjects; } @@ -207,7 +212,7 @@ class LMMS_EXPORT ConfigManager : public QObject return m_dataDir + LOCALE_PATH; } - const QString & version() const + const QString &version() const { return m_version; } @@ -216,54 +221,74 @@ class LMMS_EXPORT ConfigManager : public QObject static QStringList availableVstEmbedMethods(); + QString vstEmbedMethod() const; void InitializePortableWorkingDir(); + void InitializeInstalledWorkingDir(); - void InitializeDevelopmentDirs(); + + void InitializeDevelopmentDirs(); // Returns true if the working dir (e.g. ~/lmms) exists on disk. bool hasWorkingDir() const; - void addRecentlyOpenedProject(const QString & _file); + void addRecentlyOpenedProject(const QString &_file); - const QString & value(const QString & cls, - const QString & attribute) const; - const QString & value(const QString & cls, - const QString & attribute, - const QString & defaultVal) const; - void setValue(const QString & cls, const QString & attribute, - const QString & value); - void deleteValue(const QString & cls, const QString & attribute); + const QString &value(const QString &cls, + const QString &attribute) const; + + const QString &value(const QString &cls, + const QString &attribute, + const QString &defaultVal) const; + + void setValue(const QString &cls, const QString &attribute, + const QString &value); + + void deleteValue(const QString &cls, const QString &attribute); + + void loadConfigFile(const QString &configFile = ""); - void loadConfigFile(const QString & configFile = ""); void saveConfigFile(); - void setWorkingDir(const QString & workingDir); - void setVSTDir(const QString & vstDir); - void setLADSPADir(const QString & ladspaDir); - void setSF2Dir(const QString & sf2Dir); - void setSF2File(const QString & sf2File); - void setSTKDir(const QString & stkDir); - void setGIGDir(const QString & gigDir); - void setThemeDir(const QString & themeDir); - void setBackgroundPicFile(const QString & backgroundPicFile); + void setWorkingDir(const QString &workingDir); + + void setVSTDir(const QString &vstDir); + + void setLADSPADir(const QString &ladspaDir); + + void setSF2Dir(const QString &sf2Dir); + + void setSF2File(const QString &sf2File); + + void setSTKDir(const QString &stkDir); + + void setGIGDir(const QString &gigDir); + + void setThemeDir(const QString &themeDir); + + void setBackgroundPicFile(const QString &backgroundPicFile); // Creates the working directory & subdirectories on disk. void createWorkingDir(); signals: - void valueChanged( QString cls, QString attribute, QString value ); + + void valueChanged(QString cls, QString attribute, QString value); private: - static ConfigManager * s_instanceOfMe; + static ConfigManager *s_instanceOfMe; ConfigManager(); - ConfigManager(const ConfigManager & _c); + + ConfigManager(const ConfigManager &_c); + ~ConfigManager(); void upgrade_1_1_90(); + void upgrade_1_1_91(); + void upgrade(); QString m_workingDir; @@ -291,4 +316,5 @@ class LMMS_EXPORT ConfigManager : public QObject friend class LmmsCore; }; + #endif diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index 316b465dcf7..46c259e9b71 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -38,9 +38,9 @@ #include "lmmsversion.h" -static inline QString ensureTrailingSlash(const QString & s ) +static inline QString ensureTrailingSlash(const QString &s) { - if(! s.isEmpty() && !s.endsWith('/') && !s.endsWith('\\')) + if (!s.isEmpty() && !s.endsWith('/') && !s.endsWith('\\')) { return s + '/'; } @@ -48,23 +48,27 @@ static inline QString ensureTrailingSlash(const QString & s ) } -ConfigManager * ConfigManager::s_instanceOfMe = NULL; +ConfigManager *ConfigManager::s_instanceOfMe = NULL; ConfigManager::ConfigManager() : m_version(defaultVersion()) { -#ifdef PORTABLE_MODE - InitializePortableWorkingDir(); -#else - InitializeInstalledWorkingDir(); -#endif - InitializeDevelopmentDirs(); - m_themeDir = defaultThemeDir(); - m_dataDir = "data:/"; - m_vstDir = m_workingDir + "vst/"; - m_sf2Dir = m_workingDir + SF2_PATH; - m_gigDir = m_workingDir + GIG_PATH; - if (! qgetenv("LMMS_DATA_DIR").isEmpty()) - QDir::addSearchPath("data", QString::fromLocal8Bit(qgetenv("LMMS_DATA_DIR"))); + bool is_portable = QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE); + if (is_portable) + { + InitializePortableWorkingDir(); + } + else + { + InitializeInstalledWorkingDir(); + } + InitializeDevelopmentDirs(); + m_themeDir = defaultThemeDir(); + m_dataDir = "data:/"; + m_vstDir = m_workingDir + "vst/"; + m_sf2Dir = m_workingDir + SF2_PATH; + m_gigDir = m_workingDir + GIG_PATH; + if (!qgetenv("LMMS_DATA_DIR").isEmpty()) + QDir::addSearchPath("data", QString::fromLocal8Bit(qgetenv("LMMS_DATA_DIR"))); #ifdef LMMS_BUILD_WIN32 QDir::addSearchPath("data", qApp->applicationDirPath() + "/data/"); #else @@ -84,7 +88,7 @@ ConfigManager::~ConfigManager() void ConfigManager::upgrade_1_1_90() { // Remove trailing " (bad latency!)" string which was once saved with PulseAudio - if(value("mixer", "audiodev").startsWith("PulseAudio (")) + if (value("mixer", "audiodev").startsWith("PulseAudio (")) { setValue("mixer", "audiodev", "PulseAudio"); } @@ -104,11 +108,12 @@ void ConfigManager::upgrade_1_1_90() } } - + void ConfigManager::upgrade_1_1_91() -{ +{ // rename displaydbv to displaydbfs - if (!value("app", "displaydbv").isNull()) { + if (!value("app", "displaydbv").isNull()) + { setValue("app", "displaydbfs", value("app", "displaydbv")); deleteValue("app", "displaydbv"); } @@ -124,17 +129,17 @@ void ConfigManager::upgrade() } ProjectVersion createdWith = m_version; - + if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.90") { upgrade_1_1_90(); } - + if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.91") { upgrade_1_1_91(); } - + // Don't use old themes as they break the UI (i.e. 0.4 != 1.0, etc) if (createdWith.setCompareType(ProjectVersion::Minor) != LMMS_VERSION) { @@ -151,56 +156,63 @@ QString ConfigManager::defaultVersion() const } -void ConfigManager::InitializeInstalledWorkingDir() { - m_workingDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/lmms/"; - m_lmmsRcFile = QDir::home().absolutePath() +"/.lmmsrc.xml"; - // Detect < 1.2.0 working directory as a courtesy - if ( QFileInfo( QDir::home().absolutePath() + "/lmms/projects/" ).exists() ) - m_workingDir = QDir::home().absolutePath() + "/lmms/"; +void ConfigManager::InitializeInstalledWorkingDir() +{ + m_workingDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/lmms/"; + m_lmmsRcFile = QDir::home().absolutePath() + "/.lmmsrc.xml"; + // Detect < 1.2.0 working directory as a courtesy + if (QFileInfo(QDir::home().absolutePath() + "/lmms/projects/").exists()) + m_workingDir = QDir::home().absolutePath() + "/lmms/"; } -void ConfigManager::InitializePortableWorkingDir() { - m_workingDir = qApp->applicationDirPath() + "/lmms-workspace/"; - m_lmmsRcFile = qApp->applicationDirPath() + "/.lmmsrc.xml"; +void ConfigManager::InitializePortableWorkingDir() +{ + m_workingDir = qApp->applicationDirPath() + "/lmms-workspace/"; + m_lmmsRcFile = qApp->applicationDirPath() + "/.lmmsrc.xml"; } -void ConfigManager::InitializeDevelopmentDirs() { - // If we're in development (lmms is not installed) let's get the source and - // binary directories by reading the CMake Cache - QDir appPath = qApp->applicationDirPath(); - // If in tests, get parent directory - if (appPath.dirName() == "tests") { - appPath.cdUp(); - } - QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt")); - if (cmakeCache.exists()) { - cmakeCache.open(QFile::ReadOnly); - QTextStream stream(&cmakeCache); - - // Find the lines containing something like lmms_SOURCE_DIR:static= - // and lmms_BINARY_DIR:static= - int done = 0; - while(! stream.atEnd()) - { - QString line = stream.readLine(); - - if (line.startsWith("lmms_SOURCE_DIR:")) { - QString srcDir = line.section('=', -1).trimmed(); - QDir::addSearchPath("data", srcDir + "/data/"); - done++; - } - if (line.startsWith("lmms_BINARY_DIR:")) { - m_lmmsRcFile = line.section('=', -1).trimmed() + QDir::separator() + - ".lmmsrc.xml"; - done++; - } - if (done == 2) - { - break; - } - } - cmakeCache.close(); - } +void ConfigManager::InitializeDevelopmentDirs() +{ + // If we're in development (lmms is not installed) let's get the source and + // binary directories by reading the CMake Cache + QDir appPath = qApp->applicationDirPath(); + // If in tests, get parent directory + if (appPath.dirName() == "tests") + { + appPath.cdUp(); + } + QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt")); + if (cmakeCache.exists()) + { + cmakeCache.open(QFile::ReadOnly); + QTextStream stream(&cmakeCache); + + // Find the lines containing something like lmms_SOURCE_DIR:static= + // and lmms_BINARY_DIR:static= + int done = 0; + while (!stream.atEnd()) + { + QString line = stream.readLine(); + + if (line.startsWith("lmms_SOURCE_DIR:")) + { + QString srcDir = line.section('=', -1).trimmed(); + QDir::addSearchPath("data", srcDir + "/data/"); + done++; + } + if (line.startsWith("lmms_BINARY_DIR:")) + { + m_lmmsRcFile = line.section('=', -1).trimmed() + QDir::separator() + + ".lmmsrc.xml"; + done++; + } + if (done == 2) + { + break; + } + } + cmakeCache.close(); + } } QStringList ConfigManager::availableVstEmbedMethods() @@ -214,8 +226,8 @@ QStringList ConfigManager::availableVstEmbedMethods() methods.append("win32"); #endif #ifdef LMMS_BUILD_LINUX - if (static_cast(QApplication::instance())-> - platformName() == "xcb") + if (static_cast(QApplication::instance())-> + platformName() == "xcb") { methods.append("xembed"); } @@ -227,7 +239,7 @@ QString ConfigManager::vstEmbedMethod() const { QStringList methods = availableVstEmbedMethods(); QString defaultMethod = *(methods.end() - 1); - QString currentMethod = value( "ui", "vstembedmethod", defaultMethod ); + QString currentMethod = value("ui", "vstembedmethod", defaultMethod); return methods.contains(currentMethod) ? currentMethod : defaultMethod; } @@ -237,31 +249,25 @@ bool ConfigManager::hasWorkingDir() const } -void ConfigManager::setWorkingDir(const QString & workingDir) +void ConfigManager::setWorkingDir(const QString &workingDir) { m_workingDir = ensureTrailingSlash(QDir::cleanPath(workingDir)); } - - -void ConfigManager::setVSTDir(const QString & vstDir) +void ConfigManager::setVSTDir(const QString &vstDir) { m_vstDir = ensureTrailingSlash(vstDir); } - - -void ConfigManager::setLADSPADir(const QString & ladspaDir) +void ConfigManager::setLADSPADir(const QString &ladspaDir) { m_ladspaDir = ladspaDir; } - - -void ConfigManager::setSTKDir(const QString & stkDir) +void ConfigManager::setSTKDir(const QString &stkDir) { #ifdef LMMS_HAVE_STK m_stkDir = ensureTrailingSlash(stkDir); @@ -269,17 +275,13 @@ void ConfigManager::setSTKDir(const QString & stkDir) } - - -void ConfigManager::setSF2Dir(const QString & sf2Dir) +void ConfigManager::setSF2Dir(const QString &sf2Dir) { m_sf2Dir = sf2Dir; } - - -void ConfigManager::setSF2File(const QString & sf2File) +void ConfigManager::setSF2File(const QString &sf2File) { #ifdef LMMS_HAVE_FLUIDSYNTH m_sf2File = sf2File; @@ -287,32 +289,24 @@ void ConfigManager::setSF2File(const QString & sf2File) } - - -void ConfigManager::setGIGDir(const QString & gigDir) +void ConfigManager::setGIGDir(const QString &gigDir) { m_gigDir = gigDir; } - - -void ConfigManager::setThemeDir(const QString & themeDir) +void ConfigManager::setThemeDir(const QString &themeDir) { m_themeDir = ensureTrailingSlash(themeDir); } - - -void ConfigManager::setBackgroundPicFile(const QString & backgroundPicFile) +void ConfigManager::setBackgroundPicFile(const QString &backgroundPicFile) { m_backgroundPicFile = backgroundPicFile; } - - void ConfigManager::createWorkingDir() { QDir().mkpath(m_workingDir); @@ -328,16 +322,15 @@ void ConfigManager::createWorkingDir() } - -void ConfigManager::addRecentlyOpenedProject(const QString & file) +void ConfigManager::addRecentlyOpenedProject(const QString &file) { QFileInfo recentFile(file); - if(recentFile.suffix().toLower() == "mmp" || + if (recentFile.suffix().toLower() == "mmp" || recentFile.suffix().toLower() == "mmpz" || recentFile.suffix().toLower() == "mpt") { m_recentlyOpenedProjects.removeAll(file); - if(m_recentlyOpenedProjects.size() > 50) + if (m_recentlyOpenedProjects.size() > 50) { m_recentlyOpenedProjects.removeLast(); } @@ -347,20 +340,18 @@ void ConfigManager::addRecentlyOpenedProject(const QString & file) } - - -const QString & ConfigManager::value(const QString & cls, - const QString & attribute) const +const QString &ConfigManager::value(const QString &cls, + const QString &attribute) const { - if(m_settings.contains(cls)) + if (m_settings.contains(cls)) { - for(stringPairVector::const_iterator it = - m_settings[cls].begin(); - it != m_settings[cls].end(); ++it) + for (stringPairVector::const_iterator it = + m_settings[cls].begin(); + it != m_settings[cls].end(); ++it) { - if((*it).first == attribute) + if ((*it).first == attribute) { - return (*it).second ; + return (*it).second; } } } @@ -369,27 +360,24 @@ const QString & ConfigManager::value(const QString & cls, } - -const QString & ConfigManager::value(const QString & cls, - const QString & attribute, - const QString & defaultVal) const +const QString &ConfigManager::value(const QString &cls, + const QString &attribute, + const QString &defaultVal) const { - const QString & val = value(cls, attribute); + const QString &val = value(cls, attribute); return val.isEmpty() ? defaultVal : val; } - - -void ConfigManager::setValue(const QString & cls, - const QString & attribute, - const QString & value) +void ConfigManager::setValue(const QString &cls, + const QString &attribute, + const QString &value) { - if(m_settings.contains(cls)) + if (m_settings.contains(cls)) { - for(QPair& pair : m_settings[cls]) + for (QPair &pair : m_settings[cls]) { - if(pair.first == attribute) + if (pair.first == attribute) { if (pair.second != value) { @@ -405,14 +393,14 @@ void ConfigManager::setValue(const QString & cls, } -void ConfigManager::deleteValue(const QString & cls, const QString & attribute) +void ConfigManager::deleteValue(const QString &cls, const QString &attribute) { - if(m_settings.contains(cls)) + if (m_settings.contains(cls)) { - for(stringPairVector::iterator it = m_settings[cls].begin(); - it != m_settings[cls].end(); ++it) + for (stringPairVector::iterator it = m_settings[cls].begin(); + it != m_settings[cls].end(); ++it) { - if((*it).first == attribute) + if ((*it).first == attribute) { m_settings[cls].erase(it); return; @@ -422,7 +410,7 @@ void ConfigManager::deleteValue(const QString & cls, const QString & attribute) } -void ConfigManager::loadConfigFile(const QString & configFile) +void ConfigManager::loadConfigFile(const QString &configFile) { // read the XML file and create DOM tree // Allow configuration file override through --config commandline option @@ -434,11 +422,11 @@ void ConfigManager::loadConfigFile(const QString & configFile) QFile cfg_file(m_lmmsRcFile); QDomDocument dom_tree; - if(cfg_file.open(QIODevice::ReadOnly)) + if (cfg_file.open(QIODevice::ReadOnly)) { QString errorString; int errorLine, errorCol; - if(dom_tree.setContent(&cfg_file, false, &errorString, &errorLine, &errorCol)) + if (dom_tree.setContent(&cfg_file, false, &errorString, &errorLine, &errorCol)) { // get the head information from the DOM QDomElement root = dom_tree.documentElement(); @@ -446,41 +434,42 @@ void ConfigManager::loadConfigFile(const QString & configFile) QDomNode node = root.firstChild(); // Cache the config version for upgrade() - if (!root.attribute("version").isNull()) { + if (!root.attribute("version").isNull()) + { m_version = root.attribute("version"); } // create the settings-map out of the DOM - while(!node.isNull()) + while (!node.isNull()) { - if(node.isElement() && - node.toElement().hasAttributes ()) + if (node.isElement() && + node.toElement().hasAttributes()) { stringPairVector attr; QDomNamedNodeMap node_attr = - node.toElement().attributes(); - for(int i = 0; i < node_attr.count(); - ++i) + node.toElement().attributes(); + for (int i = 0; i < node_attr.count(); + ++i) { QDomNode n = node_attr.item(i); - if(n.isAttr()) + if (n.isAttr()) { attr.push_back(qMakePair(n.toAttr().name(), - n.toAttr().value())); + n.toAttr().value())); } } m_settings[node.nodeName()] = attr; } - else if(node.nodeName() == "recentfiles") + else if (node.nodeName() == "recentfiles") { m_recentlyOpenedProjects.clear(); QDomNode n = node.firstChild(); - while(!n.isNull()) + while (!n.isNull()) { - if(n.isElement() && n.toElement().hasAttributes()) + if (n.isElement() && n.toElement().hasAttributes()) { m_recentlyOpenedProjects << - n.toElement().attribute("path"); + n.toElement().attribute("path"); } n = n.nextSibling(); } @@ -488,7 +477,7 @@ void ConfigManager::loadConfigFile(const QString & configFile) node = node.nextSibling(); } - if(value("paths", "theme") != "") + if (value("paths", "theme") != "") { m_themeDir = value("paths", "theme"); #ifdef LMMS_BUILD_WIN32 @@ -499,8 +488,8 @@ void ConfigManager::loadConfigFile(const QString & configFile) bool badPath = false; #endif - if(badPath || !QDir(m_themeDir).exists() || - !QFile(m_themeDir + "/style.css").exists()) + if (badPath || !QDir(m_themeDir).exists() || + !QFile(m_themeDir + "/style.css").exists()) { m_themeDir = defaultThemeDir(); } @@ -512,53 +501,53 @@ void ConfigManager::loadConfigFile(const QString & configFile) setSF2Dir(value("paths", "sf2dir") == "" ? sf2Dir() : value("paths", "sf2dir")); setVSTDir(value("paths", "vstdir")); setLADSPADir(value("paths", "ladspadir")); - #ifdef LMMS_HAVE_STK +#ifdef LMMS_HAVE_STK setSTKDir(value("paths", "stkdir")); - #endif - #ifdef LMMS_HAVE_FLUIDSYNTH +#endif +#ifdef LMMS_HAVE_FLUIDSYNTH setSF2File(value("paths", "defaultsf2")); - #endif +#endif setBackgroundPicFile(value("paths", "backgroundtheme")); } - else if(gui) + else if (gui) { QMessageBox::warning(NULL, MainWindow::tr("Configuration file"), - MainWindow::tr("Error while parsing configuration file at line %1:%2: %3"). - arg(errorLine). - arg(errorCol). - arg(errorString)); + MainWindow::tr("Error while parsing configuration file at line %1:%2: %3"). + arg(errorLine). + arg(errorCol). + arg(errorString)); } cfg_file.close(); } // Plugins are searched recursively, blacklist problematic locations - if( m_vstDir.isEmpty() || m_vstDir == QDir::separator() || m_vstDir == "/" || - m_vstDir == ensureTrailingSlash( QDir::homePath() ) || - !QDir( m_vstDir ).exists() ) + if (m_vstDir.isEmpty() || m_vstDir == QDir::separator() || m_vstDir == "/" || + m_vstDir == ensureTrailingSlash(QDir::homePath()) || + !QDir(m_vstDir).exists()) { #ifdef LMMS_BUILD_WIN32 QString programFiles = QString::fromLocal8Bit(getenv("ProgramFiles")); m_vstDir = programFiles + "/VstPlugins/"; #else - m_vstDir = m_workingDir + "plugins/vst/"; + m_vstDir = m_workingDir + "plugins/vst/"; #endif } - if(m_ladspaDir.isEmpty() ) + if (m_ladspaDir.isEmpty()) { m_ladspaDir = userLadspaDir(); } #ifdef LMMS_HAVE_STK - if(m_stkDir.isEmpty() || m_stkDir == QDir::separator() || m_stkDir == "/" || - !QDir(m_stkDir).exists()) + if (m_stkDir.isEmpty() || m_stkDir == QDir::separator() || m_stkDir == "/" || + !QDir(m_stkDir).exists()) { #if defined(LMMS_BUILD_WIN32) m_stkDir = m_dataDir + "stk/rawwaves/"; #elif defined(LMMS_BUILD_APPLE) m_stkDir = qApp->applicationDirPath() + "/../share/stk/rawwaves/"; #else - if ( qApp->applicationDirPath().startsWith("/tmp/") ) + if (qApp->applicationDirPath().startsWith("/tmp/")) { // Assume AppImage bundle m_stkDir = qApp->applicationDirPath() + "/../share/stk/rawwaves/"; @@ -575,21 +564,19 @@ void ConfigManager::loadConfigFile(const QString & configFile) upgrade(); QStringList searchPaths; - if(! qgetenv("LMMS_THEME_PATH").isNull()) + if (!qgetenv("LMMS_THEME_PATH").isNull()) searchPaths << qgetenv("LMMS_THEME_PATH"); searchPaths << themeDir() << defaultThemeDir(); QDir::setSearchPaths("resources", searchPaths); // Create any missing subdirectories in the working dir, but only if the working dir exists - if(hasWorkingDir()) + if (hasWorkingDir()) { createWorkingDir(); } } - - void ConfigManager::saveConfigFile() { setValue("paths", "theme", m_themeDir); @@ -612,12 +599,12 @@ void ConfigManager::saveConfigFile() lmms_config.setAttribute("version", m_version); doc.appendChild(lmms_config); - for(settingsMap::iterator it = m_settings.begin(); - it != m_settings.end(); ++it) + for (settingsMap::iterator it = m_settings.begin(); + it != m_settings.end(); ++it) { QDomElement n = doc.createElement(it.key()); - for(stringPairVector::iterator it2 = (*it).begin(); - it2 != (*it).end(); ++it2) + for (stringPairVector::iterator it2 = (*it).begin(); + it2 != (*it).end(); ++it2) { n.setAttribute((*it2).first, (*it2).second); } @@ -626,8 +613,8 @@ void ConfigManager::saveConfigFile() QDomElement recent_files = doc.createElement("recentfiles"); - for(QStringList::iterator it = m_recentlyOpenedProjects.begin(); - it != m_recentlyOpenedProjects.end(); ++it) + for (QStringList::iterator it = m_recentlyOpenedProjects.begin(); + it != m_recentlyOpenedProjects.end(); ++it) { QDomElement n = doc.createElement("file"); n.setAttribute("path", *it); @@ -638,22 +625,22 @@ void ConfigManager::saveConfigFile() QString xml = "\n" + doc.toString(2); QFile outfile(m_lmmsRcFile); - if(!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) + if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { QString title, message; title = MainWindow::tr("Could not open file"); message = MainWindow::tr("Could not open file %1 " - "for writing.\nPlease make " - "sure you have write " - "permission to the file and " - "the directory containing the " - "file and try again!" - ).arg(m_lmmsRcFile); - if(gui) + "for writing.\nPlease make " + "sure you have write " + "permission to the file and " + "the directory containing the " + "file and try again!" + ).arg(m_lmmsRcFile); + if (gui) { QMessageBox::critical(NULL, title, message, - QMessageBox::Ok, - QMessageBox::NoButton); + QMessageBox::Ok, + QMessageBox::NoButton); } return; } diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 523e3a5f4f1..9aec6bd27b2 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -35,11 +35,12 @@ #include "SampleTrack.h" #include "BBTrackContainer.h" -FxRoute::FxRoute( FxChannel * from, FxChannel * to, float amount ) : - m_from( from ), - m_to( to ), - m_amount( amount, 0, 1, 0.001, NULL, - tr( "Amount to send from channel %1 to channel %2" ).arg( m_from->m_channelIndex ).arg( m_to->m_channelIndex ) ) +FxRoute::FxRoute(FxChannel *from, FxChannel *to, float amount) : + m_from(from), + m_to(to), + m_amount(amount, 0, 1, 0.001, NULL, + tr("Amount to send from channel %1 to channel %2").arg(m_from->m_channelIndex).arg( + m_to->m_channelIndex)) { //qDebug( "created: %d to %d", m_from->m_channelIndex, m_to->m_channelIndex ); // create send amount model @@ -54,45 +55,44 @@ FxRoute::~FxRoute() void FxRoute::updateName() { m_amount.setDisplayName( - tr( "Amount to send from channel %1 to channel %2" ).arg( m_from->m_channelIndex ).arg( m_to->m_channelIndex ) ); + tr("Amount to send from channel %1 to channel %2").arg(m_from->m_channelIndex).arg(m_to->m_channelIndex)); } -FxChannel::FxChannel( int idx, Model * _parent ) : - m_fxChain( NULL ), - m_hasInput( false ), - m_stillRunning( false ), - m_peakLeft( 0.0f ), - m_peakRight( 0.0f ), - m_buffer( new sampleFrame[Engine::mixer()->framesPerPeriod()] ), - m_muteModel( false, _parent ), - m_soloModel( false, _parent ), - m_volumeModel( 1.0, 0.0, 2.0, 0.001, _parent ), - m_name(), - m_lock(), - m_channelIndex( idx ), - m_queued( false ), - m_dependenciesMet(0) +FxChannel::FxChannel(int idx, Model *_parent) : + m_fxChain(NULL), + m_hasInput(false), + m_stillRunning(false), + m_peakLeft(0.0f), + m_peakRight(0.0f), + m_buffer(new sampleFrame[Engine::mixer()->framesPerPeriod()]), + m_muteModel(false, _parent), + m_soloModel(false, _parent), + m_volumeModel(1.0, 0.0, 2.0, 0.001, _parent), + m_name(), + m_lock(), + m_channelIndex(idx), + m_queued(false), + m_dependenciesMet(0) { - BufferManager::clear( m_buffer, Engine::mixer()->framesPerPeriod() ); + BufferManager::clear(m_buffer, Engine::mixer()->framesPerPeriod()); } - - FxChannel::~FxChannel() { - if (m_buffer != nullptr){ - delete[] m_buffer; - } + if (m_buffer != nullptr) + { + delete[] m_buffer; + } } inline void FxChannel::processed() { - for( const FxRoute * receiverRoute : m_sends ) + for (const FxRoute *receiverRoute : m_sends) { - if( receiverRoute->receiver()->m_muted == false ) + if (receiverRoute->receiver()->m_muted == false) { receiverRoute->receiver()->incrementDeps(); } @@ -102,10 +102,10 @@ inline void FxChannel::processed() void FxChannel::incrementDeps() { int i = m_dependenciesMet++ + 1; - if( i >= m_receives.size() && ! m_queued ) + if (i >= m_receives.size() && !m_queued) { m_queued = true; - MixerWorkerThread::addJob( this ); + MixerWorkerThread::addJob(this); } } @@ -116,47 +116,47 @@ void FxChannel::unmuteForSolo() } - void FxChannel::doProcessing() { const fpp_t fpp = Engine::mixer()->framesPerPeriod(); - if( m_muted == false ) + if (m_muted == false) { - for( FxRoute * senderRoute : m_receives ) + for (FxRoute *senderRoute : m_receives) { - FxChannel * sender = senderRoute->sender(); - FloatModel * sendModel = senderRoute->amount(); - if( ! sendModel ) qFatal( "Error: no send model found from %d to %d", senderRoute->senderIndex(), m_channelIndex ); + FxChannel *sender = senderRoute->sender(); + FloatModel *sendModel = senderRoute->amount(); + if (!sendModel) + qFatal("Error: no send model found from %d to %d", senderRoute->senderIndex(), m_channelIndex); - if( sender->m_hasInput || sender->m_stillRunning ) + if (sender->m_hasInput || sender->m_stillRunning) { // figure out if we're getting sample-exact input - ValueBuffer * sendBuf = sendModel->valueBuffer(); - ValueBuffer * volBuf = sender->m_volumeModel.valueBuffer(); + ValueBuffer *sendBuf = sendModel->valueBuffer(); + ValueBuffer *volBuf = sender->m_volumeModel.valueBuffer(); // mix it's output with this one's output - sampleFrame * ch_buf = sender->m_buffer; + sampleFrame *ch_buf = sender->m_buffer; // use sample-exact mixing if sample-exact values are available - if( ! volBuf && ! sendBuf ) // neither volume nor send has sample-exact data... + if (!volBuf && !sendBuf) // neither volume nor send has sample-exact data... { const float v = sender->m_volumeModel.value() * sendModel->value(); - MixHelpers::addSanitizedMultiplied( m_buffer, ch_buf, v, fpp ); + MixHelpers::addSanitizedMultiplied(m_buffer, ch_buf, v, fpp); } - else if( volBuf && sendBuf ) // both volume and send have sample-exact data + else if (volBuf && sendBuf) // both volume and send have sample-exact data { - MixHelpers::addSanitizedMultipliedByBuffers( m_buffer, ch_buf, volBuf, sendBuf, fpp ); + MixHelpers::addSanitizedMultipliedByBuffers(m_buffer, ch_buf, volBuf, sendBuf, fpp); } - else if( volBuf ) // volume has sample-exact data but send does not + else if (volBuf) // volume has sample-exact data but send does not { const float v = sendModel->value(); - MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, volBuf, fpp ); + MixHelpers::addSanitizedMultipliedByBuffer(m_buffer, ch_buf, v, volBuf, fpp); } else // vice versa { const float v = sender->m_volumeModel.value(); - MixHelpers::addSanitizedMultipliedByBuffer( m_buffer, ch_buf, v, sendBuf, fpp ); + MixHelpers::addSanitizedMultipliedByBuffer(m_buffer, ch_buf, v, sendBuf, fpp); } m_hasInput = true; } @@ -165,17 +165,17 @@ void FxChannel::doProcessing() const float v = m_volumeModel.value(); - if( m_hasInput ) + if (m_hasInput) { // only start fxchain when we have input... m_fxChain.startRunning(); } - m_stillRunning = m_fxChain.processAudioBuffer( m_buffer, fpp, m_hasInput ); + m_stillRunning = m_fxChain.processAudioBuffer(m_buffer, fpp, m_hasInput); Mixer::StereoSample peakSamples = Engine::mixer()->getPeakValues(m_buffer, fpp); - m_peakLeft = qMax( m_peakLeft, peakSamples.left * v ); - m_peakRight = qMax( m_peakRight, peakSamples.right * v ); + m_peakLeft = qMax(m_peakLeft, peakSamples.left * v); + m_peakRight = qMax(m_peakRight, peakSamples.right * v); } else { @@ -187,11 +187,10 @@ void FxChannel::doProcessing() } - FxMixer::FxMixer() : - Model( NULL ), - JournallingObject(), - m_fxChannels() + Model(NULL), + JournallingObject(), + m_fxChannels() { // create master channel createChannel(); @@ -199,31 +198,29 @@ FxMixer::FxMixer() : } - FxMixer::~FxMixer() { - while( ! m_fxRoutes.isEmpty() ) + while (!m_fxRoutes.isEmpty()) { - deleteChannelSend( m_fxRoutes.first() ); + deleteChannelSend(m_fxRoutes.first()); } - while( m_fxChannels.size() ) + while (m_fxChannels.size()) { - FxChannel * f = m_fxChannels[m_fxChannels.size() - 1]; + FxChannel *f = m_fxChannels[m_fxChannels.size() - 1]; m_fxChannels.pop_back(); delete f; } } - int FxMixer::createChannel() { const int index = m_fxChannels.size(); // create new channel - m_fxChannels.push_back( new FxChannel( index, this ) ); + m_fxChannels.push_back(new FxChannel(index, this)); // reset channel state - clearChannel( index ); + clearChannel(index); return index; } @@ -233,7 +230,7 @@ void FxMixer::activateSolo() for (int i = 1; i < m_fxChannels.size(); ++i) { m_fxChannels[i]->m_muteBeforeSolo = m_fxChannels[i]->m_muteModel.value(); - m_fxChannels[i]->m_muteModel.setValue( true ); + m_fxChannels[i]->m_muteModel.setValue(true); } } @@ -241,7 +238,7 @@ void FxMixer::deactivateSolo() { for (int i = 1; i < m_fxChannels.size(); ++i) { - m_fxChannels[i]->m_muteModel.setValue( m_fxChannels[i]->m_muteBeforeSolo ); + m_fxChannels[i]->m_muteModel.setValue(m_fxChannels[i]->m_muteBeforeSolo); } } @@ -252,7 +249,7 @@ void FxMixer::toggledSolo() //untoggle if lastsoloed is entered if (resetSolo) { - m_fxChannels[m_lastSoloed]->m_soloModel.setValue( false ); + m_fxChannels[m_lastSoloed]->m_soloModel.setValue(false); } //determine the soloed channel for (int i = 0; i < m_fxChannels.size(); ++i) @@ -267,20 +264,23 @@ void FxMixer::toggledSolo() { deactivateSolo(); activateSolo(); - } else { + } + else + { activateSolo(); } // unmute the soloed chan and every channel it sends to m_fxChannels[soloedChan]->unmuteForSolo(); - } else { + } + else + { deactivateSolo(); } m_lastSoloed = soloedChan; } - -void FxMixer::deleteChannel( int index ) +void FxMixer::deleteChannel(int index) { // channel deletion is performed between mixer rounds Engine::mixer()->requestChangeInModel(); @@ -290,76 +290,78 @@ void FxMixer::deleteChannel( int index ) tracks += Engine::getSong()->tracks(); tracks += Engine::getBBTrackContainer()->tracks(); - for( Track* t : tracks ) + for (Track *t : tracks) { - if( t->type() == Track::InstrumentTrack ) + if (t->type() == Track::InstrumentTrack) { - InstrumentTrack* inst = dynamic_cast( t ); + InstrumentTrack *inst = dynamic_cast( t ); int val = inst->effectChannelModel()->value(0); - if( val == index ) + if (val == index) { // we are deleting this track's fx send // send to master inst->effectChannelModel()->setValue(0); } - else if( val > index ) + else if (val > index) { // subtract 1 to make up for the missing channel - inst->effectChannelModel()->setValue(val-1); + inst->effectChannelModel()->setValue(val - 1); } } - else if( t->type() == Track::SampleTrack ) + else if (t->type() == Track::SampleTrack) { - SampleTrack* strk = dynamic_cast( t ); + SampleTrack *strk = dynamic_cast( t ); int val = strk->effectChannelModel()->value(0); - if( val == index ) + if (val == index) { // we are deleting this track's fx send // send to master strk->effectChannelModel()->setValue(0); } - else if( val > index ) + else if (val > index) { // subtract 1 to make up for the missing channel - strk->effectChannelModel()->setValue(val-1); + strk->effectChannelModel()->setValue(val - 1); } } } - FxChannel * ch = m_fxChannels[index]; + FxChannel *ch = m_fxChannels[index]; // delete all of this channel's sends and receives - while( ! ch->m_sends.isEmpty() ) + while (!ch->m_sends.isEmpty()) { - deleteChannelSend( ch->m_sends.first() ); + deleteChannelSend(ch->m_sends.first()); } - while( ! ch->m_receives.isEmpty() ) + while (!ch->m_receives.isEmpty()) { - deleteChannelSend( ch->m_receives.first() ); + deleteChannelSend(ch->m_receives.first()); } // if m_lastSoloed was our index, reset it - if (m_lastSoloed == index) { m_lastSoloed = -1; } - // if m_lastSoloed is > delete index, it will move left - else if (m_lastSoloed > index) { --m_lastSoloed; } + if (m_lastSoloed == index) + { m_lastSoloed = -1; } + // if m_lastSoloed is > delete index, it will move left + else if (m_lastSoloed > index) + { --m_lastSoloed; } // actually delete the channel m_fxChannels.remove(index); delete ch; - for( int i = index; i < m_fxChannels.size(); ++i ) + for (int i = index; i < m_fxChannels.size(); ++i) { - validateChannelName( i, i + 1 ); + validateChannelName(i, i + 1); // set correct channel index m_fxChannels[i]->m_channelIndex = i; // now check all routes and update names of the send models - for( FxRoute * r : m_fxChannels[i]->m_sends ) + for (FxRoute *r : m_fxChannels[i]->m_sends) { r->updateName(); } - for( FxRoute * r : m_fxChannels[i]->m_receives ) + for (FxRoute *r : m_fxChannels[i]->m_receives) { r->updateName(); } @@ -369,11 +371,10 @@ void FxMixer::deleteChannel( int index ) } - -void FxMixer::moveChannelLeft( int index ) +void FxMixer::moveChannelLeft(int index) { // can't move master or first channel - if( index <= 1 || index >= m_fxChannels.size() ) + if (index <= 1 || index >= m_fxChannels.size()) { return; } @@ -381,41 +382,43 @@ void FxMixer::moveChannelLeft( int index ) int a = index - 1, b = index; // check if m_lastSoloed is one of our swaps - if (m_lastSoloed == a) { m_lastSoloed = b; } - else if (m_lastSoloed == b) { m_lastSoloed = a; } + if (m_lastSoloed == a) + { m_lastSoloed = b; } + else if (m_lastSoloed == b) + { m_lastSoloed = a; } // go through every instrument and adjust for the channel index change QVector songTrackList = Engine::getSong()->tracks(); QVector bbTrackList = Engine::getBBTrackContainer()->tracks(); QVector trackLists[] = {songTrackList, bbTrackList}; - for(int tl=0; tl<2; ++tl) + for (int tl = 0; tl < 2; ++tl) { QVector trackList = trackLists[tl]; - for(int i=0; itype() == Track::InstrumentTrack ) + if (trackList[i]->type() == Track::InstrumentTrack) { - InstrumentTrack * inst = (InstrumentTrack *) trackList[i]; + InstrumentTrack *inst = (InstrumentTrack *) trackList[i]; int val = inst->effectChannelModel()->value(0); - if( val == a ) + if (val == a) { inst->effectChannelModel()->setValue(b); } - else if( val == b ) + else if (val == b) { inst->effectChannelModel()->setValue(a); } } - else if( trackList[i]->type() == Track::SampleTrack ) + else if (trackList[i]->type() == Track::SampleTrack) { - SampleTrack * strk = (SampleTrack *) trackList[i]; + SampleTrack *strk = (SampleTrack *) trackList[i]; int val = strk->effectChannelModel()->value(0); - if( val == a ) + if (val == a) { strk->effectChannelModel()->setValue(b); } - else if( val == b ) + else if (val == b) { strk->effectChannelModel()->setValue(a); } @@ -428,58 +431,56 @@ void FxMixer::moveChannelLeft( int index ) // Update m_channelIndex of both channels m_fxChannels[index]->m_channelIndex = index; - m_fxChannels[index - 1]->m_channelIndex = index -1; + m_fxChannels[index - 1]->m_channelIndex = index - 1; } - -void FxMixer::moveChannelRight( int index ) +void FxMixer::moveChannelRight(int index) { - moveChannelLeft( index + 1 ); + moveChannelLeft(index + 1); } - -FxRoute * FxMixer::createChannelSend( fx_ch_t fromChannel, fx_ch_t toChannel, - float amount ) +FxRoute *FxMixer::createChannelSend(fx_ch_t fromChannel, fx_ch_t toChannel, + float amount) { // qDebug( "requested: %d to %d", fromChannel, toChannel ); // find the existing connection - FxChannel * from = m_fxChannels[fromChannel]; - FxChannel * to = m_fxChannels[toChannel]; + FxChannel *from = m_fxChannels[fromChannel]; + FxChannel *to = m_fxChannels[toChannel]; - for( int i=0; im_sends.size(); ++i ) + for (int i = 0; i < from->m_sends.size(); ++i) { - if( from->m_sends[i]->receiver() == to ) + if (from->m_sends[i]->receiver() == to) { // simply adjust the amount - from->m_sends[i]->amount()->setValue( amount ); + from->m_sends[i]->amount()->setValue(amount); return from->m_sends[i]; } } // connection does not exist. create a new one - return createRoute( from, to, amount ); + return createRoute(from, to, amount); } -FxRoute * FxMixer::createRoute( FxChannel * from, FxChannel * to, float amount ) +FxRoute *FxMixer::createRoute(FxChannel *from, FxChannel *to, float amount) { - if( from == to ) + if (from == to) { return NULL; } Engine::mixer()->requestChangeInModel(); - FxRoute * route = new FxRoute( from, to, amount ); + FxRoute *route = new FxRoute(from, to, amount); // add us to from's sends - from->m_sends.append( route ); + from->m_sends.append(route); // add us to to's receives - to->m_receives.append( route ); + to->m_receives.append(route); // add us to fxmixer's list - Engine::fxMixer()->m_fxRoutes.append( route ); + Engine::fxMixer()->m_fxRoutes.append(route); Engine::mixer()->doneChangeInModel(); return route; @@ -487,67 +488,67 @@ FxRoute * FxMixer::createRoute( FxChannel * from, FxChannel * to, float amount ) // delete the connection made by createChannelSend -void FxMixer::deleteChannelSend( fx_ch_t fromChannel, fx_ch_t toChannel ) +void FxMixer::deleteChannelSend(fx_ch_t fromChannel, fx_ch_t toChannel) { // delete the send - FxChannel * from = m_fxChannels[fromChannel]; - FxChannel * to = m_fxChannels[toChannel]; + FxChannel *from = m_fxChannels[fromChannel]; + FxChannel *to = m_fxChannels[toChannel]; // find and delete the send entry - for( int i = 0; i < from->m_sends.size(); ++i ) + for (int i = 0; i < from->m_sends.size(); ++i) { - if( from->m_sends[i]->receiver() == to ) + if (from->m_sends[i]->receiver() == to) { - deleteChannelSend( from->m_sends[i] ); + deleteChannelSend(from->m_sends[i]); break; } } } -void FxMixer::deleteChannelSend( FxRoute * route ) +void FxMixer::deleteChannelSend(FxRoute *route) { Engine::mixer()->requestChangeInModel(); // remove us from from's sends - route->sender()->m_sends.remove( route->sender()->m_sends.indexOf( route ) ); + route->sender()->m_sends.remove(route->sender()->m_sends.indexOf(route)); // remove us from to's receives - route->receiver()->m_receives.remove( route->receiver()->m_receives.indexOf( route ) ); + route->receiver()->m_receives.remove(route->receiver()->m_receives.indexOf(route)); // remove us from fxmixer's list - Engine::fxMixer()->m_fxRoutes.remove( Engine::fxMixer()->m_fxRoutes.indexOf( route ) ); + Engine::fxMixer()->m_fxRoutes.remove(Engine::fxMixer()->m_fxRoutes.indexOf(route)); delete route; Engine::mixer()->doneChangeInModel(); } -bool FxMixer::isInfiniteLoop( fx_ch_t sendFrom, fx_ch_t sendTo ) +bool FxMixer::isInfiniteLoop(fx_ch_t sendFrom, fx_ch_t sendTo) { - if( sendFrom == sendTo ) return true; - FxChannel * from = m_fxChannels[sendFrom]; - FxChannel * to = m_fxChannels[sendTo]; - bool b = checkInfiniteLoop( from, to ); + if (sendFrom == sendTo) return true; + FxChannel *from = m_fxChannels[sendFrom]; + FxChannel *to = m_fxChannels[sendTo]; + bool b = checkInfiniteLoop(from, to); return b; } -bool FxMixer::checkInfiniteLoop( FxChannel * from, FxChannel * to ) +bool FxMixer::checkInfiniteLoop(FxChannel *from, FxChannel *to) { // can't send master to anything - if( from == m_fxChannels[0] ) + if (from == m_fxChannels[0]) { return true; } // can't send channel to itself - if( from == to ) + if (from == to) { return true; } // follow sendTo's outputs recursively looking for something that sends // to sendFrom - for( int i=0; i < to->m_sends.size(); ++i ) + for (int i = 0; i < to->m_sends.size(); ++i) { - if( checkInfiniteLoop( from, to->m_sends[i]->receiver() ) ) + if (checkInfiniteLoop(from, to->m_sends[i]->receiver())) { return true; } @@ -558,18 +559,18 @@ bool FxMixer::checkInfiniteLoop( FxChannel * from, FxChannel * to ) // how much does fromChannel send its output to the input of toChannel? -FloatModel * FxMixer::channelSendModel( fx_ch_t fromChannel, fx_ch_t toChannel ) +FloatModel *FxMixer::channelSendModel(fx_ch_t fromChannel, fx_ch_t toChannel) { - if( fromChannel == toChannel ) + if (fromChannel == toChannel) { return NULL; } - const FxChannel * from = m_fxChannels[fromChannel]; - const FxChannel * to = m_fxChannels[toChannel]; + const FxChannel *from = m_fxChannels[fromChannel]; + const FxChannel *to = m_fxChannels[toChannel]; - for( FxRoute * route : from->m_sends ) + for (FxRoute *route : from->m_sends) { - if( route->receiver() == to ) + if (route->receiver() == to) { return route->amount(); } @@ -579,30 +580,26 @@ FloatModel * FxMixer::channelSendModel( fx_ch_t fromChannel, fx_ch_t toChannel ) } - -void FxMixer::mixToChannel( const sampleFrame * _buf, fx_ch_t _ch ) +void FxMixer::mixToChannel(const sampleFrame *_buf, fx_ch_t _ch) { - if( m_fxChannels[_ch]->m_muteModel.value() == false ) + if (m_fxChannels[_ch]->m_muteModel.value() == false) { m_fxChannels[_ch]->m_lock.lock(); - MixHelpers::add( m_fxChannels[_ch]->m_buffer, _buf, Engine::mixer()->framesPerPeriod() ); + MixHelpers::add(m_fxChannels[_ch]->m_buffer, _buf, Engine::mixer()->framesPerPeriod()); m_fxChannels[_ch]->m_hasInput = true; m_fxChannels[_ch]->m_lock.unlock(); } } - - void FxMixer::prepareMasterMix() { - BufferManager::clear( m_fxChannels[0]->m_buffer, - Engine::mixer()->framesPerPeriod() ); + BufferManager::clear(m_fxChannels[0]->m_buffer, + Engine::mixer()->framesPerPeriod()); } - -void FxMixer::masterMix( sampleFrame * _buf ) +void FxMixer::masterMix(sampleFrame *_buf) { const int fpp = Engine::mixer()->framesPerPeriod(); @@ -613,25 +610,25 @@ void FxMixer::masterMix( sampleFrame * _buf ) // also instantly add all muted channels as they don't need to care // about their senders, and can just increment the deps of their // recipients right away. - MixerWorkerThread::resetJobQueue( MixerWorkerThread::JobQueue::Dynamic ); - for( FxChannel * ch : m_fxChannels ) + MixerWorkerThread::resetJobQueue(MixerWorkerThread::JobQueue::Dynamic); + for (FxChannel *ch : m_fxChannels) { ch->m_muted = ch->m_muteModel.value(); - if( ch->m_muted ) // instantly "process" muted channels + if (ch->m_muted) // instantly "process" muted channels { ch->processed(); ch->done(); } - else if( ch->m_receives.size() == 0 ) + else if (ch->m_receives.size() == 0) { ch->m_queued = true; - MixerWorkerThread::addJob( ch ); + MixerWorkerThread::addJob(ch); } } while (m_fxChannels[0]->state() != ThreadableJob::ProcessingState::Done) { bool found = false; - for( FxChannel * ch : m_fxChannels ) + for (FxChannel *ch : m_fxChannels) { const auto s = ch->state(); if (s == ThreadableJob::ProcessingState::Queued @@ -641,7 +638,7 @@ void FxMixer::masterMix( sampleFrame * _buf ) break; } } - if( !found ) + if (!found) { break; } @@ -649,11 +646,11 @@ void FxMixer::masterMix( sampleFrame * _buf ) } // handle sample-exact data in master volume fader - ValueBuffer * volBuf = m_fxChannels[0]->m_volumeModel.valueBuffer(); + ValueBuffer *volBuf = m_fxChannels[0]->m_volumeModel.valueBuffer(); - if( volBuf ) + if (volBuf) { - for( int f = 0; f < fpp; f++ ) + for (int f = 0; f < fpp; f++) { m_fxChannels[0]->m_buffer[f][0] *= volBuf->values()[f]; m_fxChannels[0]->m_buffer[f][1] *= volBuf->values()[f]; @@ -661,16 +658,16 @@ void FxMixer::masterMix( sampleFrame * _buf ) } const float v = volBuf - ? 1.0f - : m_fxChannels[0]->m_volumeModel.value(); - MixHelpers::addSanitizedMultiplied( _buf, m_fxChannels[0]->m_buffer, v, fpp ); + ? 1.0f + : m_fxChannels[0]->m_volumeModel.value(); + MixHelpers::addSanitizedMultiplied(_buf, m_fxChannels[0]->m_buffer, v, fpp); // clear all channel buffers and // reset channel process state - for( int i = 0; i < numChannels(); ++i) + for (int i = 0; i < numChannels(); ++i) { - BufferManager::clear( m_fxChannels[i]->m_buffer, - Engine::mixer()->framesPerPeriod() ); + BufferManager::clear(m_fxChannels[i]->m_buffer, + Engine::mixer()->framesPerPeriod()); m_fxChannels[i]->reset(); m_fxChannels[i]->m_queued = false; // also reset hasInput @@ -680,11 +677,9 @@ void FxMixer::masterMix( sampleFrame * _buf ) } - - void FxMixer::clear() { - while( m_fxChannels.size() > 1 ) + while (m_fxChannels.size() > 1) { deleteChannel(1); } @@ -693,64 +688,63 @@ void FxMixer::clear() } - void FxMixer::clearChannel(fx_ch_t index) { - FxChannel * ch = m_fxChannels[index]; + FxChannel *ch = m_fxChannels[index]; ch->m_fxChain.clear(); - ch->m_volumeModel.setValue( 1.0f ); - ch->m_muteModel.setValue( false ); - ch->m_soloModel.setValue( false ); - ch->m_name = ( index == 0 ) ? tr( "Master" ) : tr( "FX %1" ).arg( index ); - ch->m_volumeModel.setDisplayName( ch->m_name + ">" + tr( "Volume" ) ); - ch->m_muteModel.setDisplayName( ch->m_name + ">" + tr( "Mute" ) ); - ch->m_soloModel.setDisplayName( ch->m_name + ">" + tr( "Solo" ) ); + ch->m_volumeModel.setValue(1.0f); + ch->m_muteModel.setValue(false); + ch->m_soloModel.setValue(false); + ch->m_name = (index == 0) ? tr("Master") : tr("FX %1").arg(index); + ch->m_volumeModel.setDisplayName(ch->m_name + ">" + tr("Volume")); + ch->m_muteModel.setDisplayName(ch->m_name + ">" + tr("Mute")); + ch->m_soloModel.setDisplayName(ch->m_name + ">" + tr("Solo")); // send only to master - if( index > 0) + if (index > 0) { // delete existing sends - while( ! ch->m_sends.isEmpty() ) + while (!ch->m_sends.isEmpty()) { - deleteChannelSend( ch->m_sends.first() ); + deleteChannelSend(ch->m_sends.first()); } // add send to master - createChannelSend( index, 0 ); + createChannelSend(index, 0); } // delete receives - while( ! ch->m_receives.isEmpty() ) + while (!ch->m_receives.isEmpty()) { - deleteChannelSend( ch->m_receives.first() ); + deleteChannelSend(ch->m_receives.first()); } } -void FxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) +void FxMixer::saveSettings(QDomDocument &_doc, QDomElement &_this) { // save channels - for( int i = 0; i < m_fxChannels.size(); ++i ) + for (int i = 0; i < m_fxChannels.size(); ++i) { - FxChannel * ch = m_fxChannels[i]; + FxChannel *ch = m_fxChannels[i]; - QDomElement fxch = _doc.createElement( QString( "fxchannel" ) ); - _this.appendChild( fxch ); + QDomElement fxch = _doc.createElement(QString("fxchannel")); + _this.appendChild(fxch); - ch->m_fxChain.saveState( _doc, fxch ); - ch->m_volumeModel.saveSettings( _doc, fxch, "volume" ); - ch->m_muteModel.saveSettings( _doc, fxch, "muted" ); - ch->m_soloModel.saveSettings( _doc, fxch, "soloed" ); - fxch.setAttribute( "num", i ); - fxch.setAttribute( "name", ch->m_name ); + ch->m_fxChain.saveState(_doc, fxch); + ch->m_volumeModel.saveSettings(_doc, fxch, "volume"); + ch->m_muteModel.saveSettings(_doc, fxch, "muted"); + ch->m_soloModel.saveSettings(_doc, fxch, "soloed"); + fxch.setAttribute("num", i); + fxch.setAttribute("name", ch->m_name); // add the channel sends - for( int si = 0; si < ch->m_sends.size(); ++si ) + for (int si = 0; si < ch->m_sends.size(); ++si) { - QDomElement sendsDom = _doc.createElement( QString( "send" ) ); - fxch.appendChild( sendsDom ); + QDomElement sendsDom = _doc.createElement(QString("send")); + fxch.appendChild(sendsDom); - sendsDom.setAttribute( "channel", ch->m_sends[si]->receiverIndex() ); - ch->m_sends[si]->amount()->saveSettings( _doc, sendsDom, "amount" ); + sendsDom.setAttribute("channel", ch->m_sends[si]->receiverIndex()); + ch->m_sends[si]->amount()->saveSettings(_doc, sendsDom, "amount"); } } } @@ -758,55 +752,54 @@ void FxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) // make sure we have at least num channels void FxMixer::allocateChannelsTo(int num) { - while( num > m_fxChannels.size() - 1 ) + while (num > m_fxChannels.size() - 1) { createChannel(); // delete the default send to master - deleteChannelSend( m_fxChannels.size()-1, 0 ); + deleteChannelSend(m_fxChannels.size() - 1, 0); } } -void FxMixer::loadSettings( const QDomElement & _this ) +void FxMixer::loadSettings(const QDomElement &_this) { clear(); QDomNode node = _this.firstChild(); - while( ! node.isNull() ) + while (!node.isNull()) { QDomElement fxch = node.toElement(); // index of the channel we are about to load - int num = fxch.attribute( "num" ).toInt(); + int num = fxch.attribute("num").toInt(); // allocate enough channels - allocateChannelsTo( num ); + allocateChannelsTo(num); - m_fxChannels[num]->m_volumeModel.loadSettings( fxch, "volume" ); - m_fxChannels[num]->m_muteModel.loadSettings( fxch, "muted" ); - m_fxChannels[num]->m_soloModel.loadSettings( fxch, "soloed" ); - m_fxChannels[num]->m_name = fxch.attribute( "name" ); + m_fxChannels[num]->m_volumeModel.loadSettings(fxch, "volume"); + m_fxChannels[num]->m_muteModel.loadSettings(fxch, "muted"); + m_fxChannels[num]->m_soloModel.loadSettings(fxch, "soloed"); + m_fxChannels[num]->m_name = fxch.attribute("name"); - m_fxChannels[num]->m_fxChain.restoreState( fxch.firstChildElement( - m_fxChannels[num]->m_fxChain.nodeName() ) ); + m_fxChannels[num]->m_fxChain.restoreState(fxch.firstChildElement( + m_fxChannels[num]->m_fxChain.nodeName())); // mixer sends QDomNodeList chData = fxch.childNodes(); - for( unsigned int i=0; iamount()->loadSettings( chDataItem, "amount" ); + int sendTo = chDataItem.attribute("channel").toInt(); + allocateChannelsTo(sendTo); + FxRoute *fxr = createChannelSend(num, sendTo, 1.0f); + if (fxr) fxr->amount()->loadSettings(chDataItem, "amount"); } } - node = node.nextSibling(); } @@ -814,10 +807,10 @@ void FxMixer::loadSettings( const QDomElement & _this ) } -void FxMixer::validateChannelName( int index, int oldIndex ) +void FxMixer::validateChannelName(int index, int oldIndex) { - if( m_fxChannels[index]->m_name == tr( "FX %1" ).arg( oldIndex ) ) + if (m_fxChannels[index]->m_name == tr("FX %1").arg(oldIndex)) { - m_fxChannels[index]->m_name = tr( "FX %1" ).arg( index ); + m_fxChannels[index]->m_name = tr("FX %1").arg(index); } }