Skip to content

Commit 8c121a0

Browse files
bltzrclaude
authored andcommitted
engine: move local-tree port options out of the core application settings
Per review on #2116: core ApplicationSettings should not grow device-specific options; plug-ins parse their own CLI flags like score-plugin-js / score-plugin-jit do. - Revert the ApplicationSettings additions. - Parse --local-osc-port / --local-ws-port (and the SCORE_LOCAL_OSC_PORT / SCORE_LOCAL_WS_PORT fallbacks) in Engine::ApplicationPlugin, storing the results in LocalProtocolFactory::defaultOscPort / defaultWsPort. - LocalProtocolFactory::static_defaultSettings() and the per-document local device defaults read those, so the Local device settings dialog shows them as editable defaults; ports remain changeable per-device through its existing OSC / WebSocket spinboxes. Defaults stay 6666 / 9999. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1d864f5 commit 8c121a0

6 files changed

Lines changed: 47 additions & 48 deletions

File tree

src/lib/core/application/ApplicationSettings.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,6 @@ void ApplicationSettings::parse(QStringList cargs, int& argc, char** argv)
8686
"file", "");
8787
parser.addOption(uiOptDebug);
8888

89-
QCommandLineOption localOscPortOpt(
90-
"local-osc-port",
91-
QCoreApplication::translate(
92-
"main",
93-
"Port for score's local OSC control tree (default 6666). Lets several "
94-
"instances run at once. Also settable via $SCORE_LOCAL_OSC_PORT."),
95-
"port");
96-
parser.addOption(localOscPortOpt);
97-
98-
QCommandLineOption localWsPortOpt(
99-
"local-ws-port",
100-
QCoreApplication::translate(
101-
"main",
102-
"Port for score's local WebSocket control tree (default 9999). Also "
103-
"settable via $SCORE_LOCAL_WS_PORT."),
104-
"port");
105-
parser.addOption(localWsPortOpt);
106-
10789
#if defined(__APPLE__)
10890
// Bogus macOS gatekeeper BS:
10991
// https://stackoverflow.com/questions/55562155/qt-application-for-mac-not-being-launched
@@ -184,17 +166,6 @@ void ApplicationSettings::parse(QStringList cargs, int& argc, char** argv)
184166
if(parser.isSet(waitLoadOpt))
185167
waitAfterLoad = parser.value(waitLoadOpt).toInt();
186168

187-
// Local device tree ports: CLI flag wins, else $SCORE_LOCAL_*_PORT, else default.
188-
if(parser.isSet(localOscPortOpt))
189-
localTreeOscPort = parser.value(localOscPortOpt).toInt();
190-
else if(qEnvironmentVariableIsSet("SCORE_LOCAL_OSC_PORT"))
191-
localTreeOscPort = qEnvironmentVariableIntValue("SCORE_LOCAL_OSC_PORT");
192-
193-
if(parser.isSet(localWsPortOpt))
194-
localTreeWebsocketPort = parser.value(localWsPortOpt).toInt();
195-
else if(qEnvironmentVariableIsSet("SCORE_LOCAL_WS_PORT"))
196-
localTreeWebsocketPort = qEnvironmentVariableIntValue("SCORE_LOCAL_WS_PORT");
197-
198169
if(!args.empty() && QFile::exists(args[0]))
199170
{
200171
loadList.push_back(args[0]);

src/lib/core/application/ApplicationSettings.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ struct SCORE_LIB_BASE_EXPORT ApplicationSettings
5151
//! UI event processing rate in ms (used for plug-in gui updates, etc)
5252
int uiEventRate = 64;
5353

54-
//! OSC port for score's local device tree. Lets multiple instances coexist.
55-
int localTreeOscPort = 6666;
56-
57-
//! WebSocket port for score's local device tree.
58-
int localTreeWebsocketPort = 9999;
59-
6054
//! Parse the arguments.
6155
void parse(QStringList args, int& argc, char** argv);
6256
};

src/plugins/score-plugin-engine/Engine/ApplicationPlugin.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Scenario/Settings/ScenarioSettingsModel.hpp>
1313

1414
#include <Execution/DocumentPlugin.hpp>
15+
#include <LocalTree/Device/LocalProtocolFactory.hpp>
1516
#include <LocalTree/LocalTreeDocumentPlugin.hpp>
1617

1718
#include <score/actions/ActionManager.hpp>
@@ -29,6 +30,7 @@
2930

3031
#include <ossia-qt/invoke.hpp>
3132

33+
#include <QCommandLineParser>
3234
#include <QLabel>
3335
#include <QMainWindow>
3436
#include <QTabWidget>
@@ -50,6 +52,37 @@ ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationContext& ctx)
5052
.applicationPlugin<Process::ApplicationPlugin>();
5153
m_playActions.setupContextMenu(ctrl.layerContextMenuRegistrar());
5254
}
55+
56+
{
57+
// Command-line options for the local device tree default ports.
58+
// CLI flag wins, then $SCORE_LOCAL_{OSC,WS}_PORT, then 6666 / 9999.
59+
QCommandLineParser parser;
60+
61+
QCommandLineOption osc_port_opt(
62+
"local-osc-port",
63+
QCoreApplication::translate("engine", "Local device tree OSC port"), "port");
64+
parser.addOption(osc_port_opt);
65+
QCommandLineOption ws_port_opt(
66+
"local-ws-port",
67+
QCoreApplication::translate("engine", "Local device tree WebSocket port"),
68+
"port");
69+
parser.addOption(ws_port_opt);
70+
71+
parser.parse(ctx.applicationSettings.arguments);
72+
73+
using Protocols::LocalProtocolFactory;
74+
if(parser.isSet(osc_port_opt))
75+
LocalProtocolFactory::defaultOscPort = parser.value(osc_port_opt).toInt();
76+
else if(qEnvironmentVariableIsSet("SCORE_LOCAL_OSC_PORT"))
77+
LocalProtocolFactory::defaultOscPort
78+
= qEnvironmentVariableIntValue("SCORE_LOCAL_OSC_PORT");
79+
80+
if(parser.isSet(ws_port_opt))
81+
LocalProtocolFactory::defaultWsPort = parser.value(ws_port_opt).toInt();
82+
else if(qEnvironmentVariableIsSet("SCORE_LOCAL_WS_PORT"))
83+
LocalProtocolFactory::defaultWsPort
84+
= qEnvironmentVariableIntValue("SCORE_LOCAL_WS_PORT");
85+
}
5386
}
5487

5588
ApplicationPlugin::~ApplicationPlugin()

src/plugins/score-plugin-engine/LocalTree/Device/LocalProtocolFactory.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#include <LocalTree/Device/LocalSpecificSettings.hpp>
1111
#include <LocalTree/LocalTreeDocumentPlugin.hpp>
1212

13-
#include <score/application/ApplicationContext.hpp>
14-
15-
#include <core/application/ApplicationSettings.hpp>
16-
1713
#include <QDebug>
1814
#include <QObject>
1915
#include <QUrl>
@@ -27,6 +23,9 @@ struct VisitorVariant;
2723

2824
namespace Protocols
2925
{
26+
int LocalProtocolFactory::defaultOscPort = 6666;
27+
int LocalProtocolFactory::defaultWsPort = 9999;
28+
3029
QString LocalProtocolFactory::prettyName() const noexcept
3130
{
3231
return QObject::tr("Local");
@@ -58,17 +57,17 @@ Device::DeviceInterface* LocalProtocolFactory::makeDevice(
5857

5958
const Device::DeviceSettings& LocalProtocolFactory::static_defaultSettings()
6059
{
61-
static const Device::DeviceSettings settings = [&]() {
60+
static Device::DeviceSettings settings = [&]() {
6261
Device::DeviceSettings s;
6362
s.protocol = static_concreteKey(); // Todo check for un-set protocol.
6463
s.name = "score";
65-
LocalSpecificSettings specif;
66-
specif.oscPort = score::AppContext().applicationSettings.localTreeOscPort;
67-
specif.wsPort = score::AppContext().applicationSettings.localTreeWebsocketPort;
68-
s.deviceSpecificSettings = QVariant::fromValue(specif);
6964
return s;
7065
}();
7166

67+
LocalSpecificSettings specif;
68+
specif.oscPort = defaultOscPort;
69+
specif.wsPort = defaultWsPort;
70+
settings.deviceSpecificSettings = QVariant::fromValue(specif);
7271
return settings;
7372
}
7473

src/plugins/score-plugin-engine/LocalTree/Device/LocalProtocolFactory.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class LocalProtocolFactory final : public DefaultProtocolFactory
2424
public:
2525
static const Device::DeviceSettings& static_defaultSettings();
2626

27+
//! Default ports for new local devices; set at startup from CLI / environment.
28+
static int defaultOscPort;
29+
static int defaultWsPort;
30+
2731
private:
2832
// Implement with OSSIA::Device
2933
QString prettyName() const noexcept override;

src/plugins/score-plugin-engine/LocalTree/LocalTreeDocumentPlugin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <LocalTree/IntervalComponent.hpp>
1313

1414
#include <score/application/GUIApplicationContext.hpp>
15-
16-
#include <core/application/ApplicationSettings.hpp>
1715
#include <score/tools/Bind.hpp>
1816
#include <score/tools/IdentifierGeneration.hpp>
1917

@@ -31,8 +29,8 @@ Device::DeviceSettings defaultSettings(const score::DocumentContext& ctx)
3129
s.protocol = Protocols::LocalProtocolFactory::static_concreteKey();
3230
s.name = QString("score (%1)").arg(ctx.document.metadata().documentName());
3331
Protocols::LocalSpecificSettings specif;
34-
specif.oscPort = ctx.app.applicationSettings.localTreeOscPort;
35-
specif.wsPort = ctx.app.applicationSettings.localTreeWebsocketPort;
32+
specif.oscPort = Protocols::LocalProtocolFactory::defaultOscPort;
33+
specif.wsPort = Protocols::LocalProtocolFactory::defaultWsPort;
3634
s.deviceSpecificSettings = QVariant::fromValue(specif);
3735
return s;
3836
}

0 commit comments

Comments
 (0)