Skip to content

Commit

Permalink
Allow multiple instances of Light Host
Browse files Browse the repository at this point in the history
- Requires argument `-multi-instance=profileName` where profileName
should be changed for each instance
  • Loading branch information
rolandoislas committed Sep 23, 2016
1 parent 7c5332e commit cb69f21
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions Source/HostStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class PluginHostApp : public JUCEApplication
{

public:
PluginHostApp() {}

Expand All @@ -17,6 +18,8 @@ class PluginHostApp : public JUCEApplication
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Preferences";

checkArguments(&options);

appProperties = new ApplicationProperties();
appProperties->setStorageParameters (options);

Expand All @@ -26,16 +29,6 @@ class PluginHostApp : public JUCEApplication
#if JUCE_MAC
Process::setDockIconVisible(false);
#endif

File fileToOpen;

for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
{
fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);

if (fileToOpen.existsAsFile())
break;
}
}

void shutdown() override
Expand All @@ -52,15 +45,42 @@ class PluginHostApp : public JUCEApplication

const String getApplicationName() override { return "Light Host"; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return false; }
bool moreThanOneInstanceAllowed() override {
StringArray multiInstance = getParameter("-multi-instance");
return multiInstance.size() == 2;
}

ApplicationCommandManager commandManager;
ScopedPointer<ApplicationProperties> appProperties;
LookAndFeel_V3 lookAndFeel;

private:
ScopedPointer<IconMenu> mainWindow;
};
ScopedPointer<IconMenu> mainWindow;

StringArray getParameter(String lookFor) {
StringArray parameters = getCommandLineParameterArray();
StringArray found;
for (int i = 0; i < parameters.size(); ++i)
{
String param = parameters[i];
if (param.contains(lookFor))
{
found.add(lookFor);
int delimiter = param.indexOf(0, "=") + 1;
String val = param.substring(delimiter);
found.add(val);
return found;
}
}
return found;
}

void checkArguments(PropertiesFile::Options *options) {
StringArray multiInstance = getParameter("-multi-instance");
if (multiInstance.size() == 2)
options->filenameSuffix = multiInstance[1] + "." + options->filenameSuffix;
}
};

static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
Expand Down

0 comments on commit cb69f21

Please sign in to comment.