Skip to content

Commit

Permalink
Add mapping resource by struct instead or arg
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed May 19, 2024
1 parent f740c61 commit 17399dc
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 170 deletions.
1 change: 0 additions & 1 deletion src/controllers/defs_controllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ inline QString userMappingsPath(UserSettingsPointer pConfig) {
#define HID_MAPPING_EXTENSION ".hid.xml"
#define MIDI_MAPPING_EXTENSION ".midi.xml"
#define BULK_MAPPING_EXTENSION ".bulk.xml"
#define REQUIRED_SCRIPT_FILE "common-controller-scripts.js"
#define XML_SCHEMA_VERSION "1"
57 changes: 12 additions & 45 deletions src/controllers/legacycontrollermapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ class LegacyControllerMapping {
#endif
};

ScriptFileInfo()
: builtin(false) {
}

QString name;
QString identifier;
QFileInfo file;
Type type;
bool builtin;
QString name; // Name of the script file to add.
QString identifier; // The script's function prefix with Javascript OR
// the screen identifier this QML should be run for
// (or empty string).
QFileInfo file; // A FileInfo object pointing to the script file.
Type type; // A ScriptFileInfo::Type the specify script file type.
bool builtin; // If this is true, the script won't be written to the XML.
};

// TODO (xxx): this is a temporary solution to address devices that don't
Expand Down Expand Up @@ -126,24 +124,9 @@ class LegacyControllerMapping {
#endif

/// Adds a script file to the list of controller scripts for this mapping.
/// @param filename Name of the script file to add.
/// @param identifier The script's function prefix with Javascript OR the
/// screen identifier this QML should be run for (or empty string).
/// @param file A FileInfo object pointing to the script file.
/// @param type A ScriptFileInfo::Type the specify script file type.
/// @param builtin If this is true, the script won't be written to the XML.
virtual void addScriptFile(const QString& name,
const QString& identifier,
const QFileInfo& file,
ScriptFileInfo::Type type = ScriptFileInfo::Type::Javascript,
bool builtin = false) {
ScriptFileInfo info;
info.name = name;
info.identifier = identifier;
info.file = file;
info.type = type;
info.builtin = builtin;
m_scripts.append(info);
/// @param info The script info to add.
virtual void addScriptFile(ScriptFileInfo info) {
m_scripts.append(std::move(info));
setDirty(true);
}

Expand Down Expand Up @@ -233,24 +216,8 @@ class LegacyControllerMapping {
/// @param endian the pixel endian format
/// @param reversedColor whether or not the RGB is swapped BGR
/// @param rawData whether or not the screen is allowed to reserve bare data, not transformed
virtual void addScreenInfo(const QString& identifier,
const QSize& size,
uint targetFps,
uint msaa,
std::chrono::milliseconds splashoff,
QImage::Format pixelFormat,
LegacyControllerMapping::ScreenInfo::ColorEndian endian,
bool reversedColor,
bool rawData) {
m_screens.append(ScreenInfo{identifier,
size,
targetFps,
msaa,
splashoff,
pixelFormat,
endian,
reversedColor,
rawData});
virtual void addScreenInfo(ScreenInfo info) {
m_screens.append(std::move(info));
setDirty(true);
}

Expand Down
25 changes: 16 additions & 9 deletions src/controllers/legacycontrollermappingfilehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ QMap<QString, LegacyControllerMapping::ScreenInfo::ColorEndian>
namespace {
const mixxx::Logger kLogger("LegacyControllerMappingFileHandler");

const QString kRequiredScriptFile = QStringLiteral("common-controller-scripts.js");

#ifdef MIXXX_USE_QML

/// Find a module directory (QML) in the mapping or system path.
Expand Down Expand Up @@ -165,15 +167,16 @@ bool parseAndAddScreenDefinition(const QDomElement& screen, LegacyControllerMapp
}

kLogger.debug() << "Adding screen" << identifier;
mapping->addScreenInfo(identifier,
mapping->addScreenInfo(LegacyControllerMapping::ScreenInfo{
identifier,
QSize(width, height),
targetFps,
msaa,
std::chrono::milliseconds(splashOff),
pixelFormat,
endian,
reversedColor,
rawData);
rawData});
return true;
}
#endif
Expand Down Expand Up @@ -374,11 +377,12 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
.firstChildElement("file");

// Default currently required file
mapping->addScriptFile(REQUIRED_SCRIPT_FILE,
mapping->addScriptFile(LegacyControllerMapping::ScriptFileInfo{
kRequiredScriptFile,
"",
findScriptFile(mapping, REQUIRED_SCRIPT_FILE, systemMappingsPath),
findScriptFile(mapping, kRequiredScriptFile, systemMappingsPath),
LegacyControllerMapping::ScriptFileInfo::Type::Javascript,
true);
true});

// Look for additional ones
while (!scriptFile.isNull()) {
Expand All @@ -387,10 +391,12 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
if (file.suffix() == "qml") {
#ifdef MIXXX_USE_QML
QString identifier = scriptFile.attribute("identifier", "");
mapping->addScriptFile(filename,
mapping->addScriptFile(LegacyControllerMapping::ScriptFileInfo{
filename,
identifier,
file,
LegacyControllerMapping::ScriptFileInfo::Type::Qml);
LegacyControllerMapping::ScriptFileInfo::Type::Qml,
false});
#else
kLogger.warning()
<< "Unsupported render scene for file" << file.filePath()
Expand All @@ -399,10 +405,11 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
#endif
} else {
QString functionPrefix = scriptFile.attribute("functionprefix", "");
mapping->addScriptFile(filename,
mapping->addScriptFile(LegacyControllerMapping::ScriptFileInfo{filename,
functionPrefix,
file,
LegacyControllerMapping::ScriptFileInfo::Type::Javascript);
LegacyControllerMapping::ScriptFileInfo::Type::Javascript,
false});
}
scriptFile = scriptFile.nextSiblingElement("file");
}
Expand Down
Loading

0 comments on commit 17399dc

Please sign in to comment.