Skip to content

Commit

Permalink
Initialize child process' audio device manager with the configuration…
Browse files Browse the repository at this point in the history
… state of the main process.
  • Loading branch information
gbevin committed Dec 27, 2016
1 parent 6ad5835 commit 680276a
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 111 deletions.
6 changes: 0 additions & 6 deletions Builds/LinuxMakefile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ OBJECTS := \
$(JUCE_OBJDIR)/ChildAudioComponent_f05d428b.o \
$(JUCE_OBJDIR)/MainAudioComponent_2d58d0e2.o \
$(JUCE_OBJDIR)/AudioMasterProcess_baed3740.o \
$(JUCE_OBJDIR)/AudioProcessMessageTypes_7732add4.o \
$(JUCE_OBJDIR)/AudioProcessMessageUtils_9db78a0c.o \
$(JUCE_OBJDIR)/AudioSlaveProcess_3d06ee2f.o \
$(JUCE_OBJDIR)/MainContentComponent_52535d99.o \
Expand Down Expand Up @@ -119,11 +118,6 @@ $(JUCE_OBJDIR)/AudioMasterProcess_baed3740.o: ../../Source/Process/AudioMasterPr
@echo "Compiling AudioMasterProcess.cpp"
@$(CXX) $(JUCE_CXXFLAGS) -o "$@" -c "$<"

$(JUCE_OBJDIR)/AudioProcessMessageTypes_7732add4.o: ../../Source/Process/AudioProcessMessageTypes.cpp
-@mkdir -p $(JUCE_OBJDIR)
@echo "Compiling AudioProcessMessageTypes.cpp"
@$(CXX) $(JUCE_CXXFLAGS) -o "$@" -c "$<"

$(JUCE_OBJDIR)/AudioProcessMessageUtils_9db78a0c.o: ../../Source/Process/AudioProcessMessageUtils.cpp
-@mkdir -p $(JUCE_OBJDIR)
@echo "Compiling AudioProcessMessageUtils.cpp"
Expand Down
4 changes: 0 additions & 4 deletions Builds/MacOSX/HEELP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
87487DB4B03DF248CDFD8543 = {isa = PBXBuildFile; fileRef = A825A59EFF7D169224376501; };
A39429F976E9FFE22F88F6F0 = {isa = PBXBuildFile; fileRef = 8A921870D83F6AD11489714F; };
97B2E4AD2F74E6A606CAB5B7 = {isa = PBXBuildFile; fileRef = 39A74836EA636F2D72E4AC5B; };
D7BFF7604FAE60C69FAB494D = {isa = PBXBuildFile; fileRef = E7ADA93859CBF49EF130CFE0; };
3FCF1A1AADECCC7D5508B6B4 = {isa = PBXBuildFile; fileRef = 63C5A8E84B3C16995B15B58E; };
0D57467A365DB5F7A9ACFA0A = {isa = PBXBuildFile; fileRef = F5C69F4A41690CA0D8CCE421; };
189C979F354DB8919BE42084 = {isa = PBXBuildFile; fileRef = 8D40196CFDA0B1258FC61E8B; };
Expand Down Expand Up @@ -1108,7 +1107,6 @@
E6617C6110FDC17BB5D3D7EB = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_posix_SharedCode.h"; path = "../../JuceLibraryCode/modules/juce_core/native/juce_posix_SharedCode.h"; sourceTree = "SOURCE_ROOT"; };
E66A403C5D3474905D290FC7 = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_MidiDataConcatenator.h"; path = "../../JuceLibraryCode/modules/juce_audio_devices/native/juce_MidiDataConcatenator.h"; sourceTree = "SOURCE_ROOT"; };
E6F96BCD22524A03E0D1F9DD = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "juce_ImageCache.h"; path = "../../JuceLibraryCode/modules/juce_graphics/images/juce_ImageCache.h"; sourceTree = "SOURCE_ROOT"; };
E7ADA93859CBF49EF130CFE0 = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = AudioProcessMessageTypes.cpp; path = ../../Source/Process/AudioProcessMessageTypes.cpp; sourceTree = "SOURCE_ROOT"; };
E7D5864A9122D14EC6FB3FC2 = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = "juce_audio_utils.mm"; path = "../../JuceLibraryCode/modules/juce_audio_utils/juce_audio_utils.mm"; sourceTree = "SOURCE_ROOT"; };
E7F09E37714C7D70D4D3E8E7 = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = "juce_FlacAudioFormat.cpp"; path = "../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp"; sourceTree = "SOURCE_ROOT"; };
E8014B3AB7995E909021B8BD = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = "juce_gui_basics.mm"; path = "../../JuceLibraryCode/modules/juce_gui_basics/juce_gui_basics.mm"; sourceTree = "SOURCE_ROOT"; };
Expand Down Expand Up @@ -1239,7 +1237,6 @@
C3A1D42038074136DA4EF28C = {isa = PBXGroup; children = (
39A74836EA636F2D72E4AC5B,
81B8D5D283D8B59AA4442F87,
E7ADA93859CBF49EF130CFE0,
20F39E8DD4D9BE685ED5D010,
63C5A8E84B3C16995B15B58E,
C2DE9E5909173ED752BD9D19,
Expand Down Expand Up @@ -2744,7 +2741,6 @@
87487DB4B03DF248CDFD8543,
A39429F976E9FFE22F88F6F0,
97B2E4AD2F74E6A606CAB5B7,
D7BFF7604FAE60C69FAB494D,
3FCF1A1AADECCC7D5508B6B4,
0D57467A365DB5F7A9ACFA0A,
189C979F354DB8919BE42084,
Expand Down
1 change: 0 additions & 1 deletion Builds/VisualStudio2015/HEELP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
<ClCompile Include="..\..\Source\Audio\ChildAudioComponent.cpp"/>
<ClCompile Include="..\..\Source\Audio\MainAudioComponent.cpp"/>
<ClCompile Include="..\..\Source\Process\AudioMasterProcess.cpp"/>
<ClCompile Include="..\..\Source\Process\AudioProcessMessageTypes.cpp"/>
<ClCompile Include="..\..\Source\Process\AudioProcessMessageUtils.cpp"/>
<ClCompile Include="..\..\Source\Process\AudioSlaveProcess.cpp"/>
<ClCompile Include="..\..\Source\UI\MainContentComponent.cpp"/>
Expand Down
3 changes: 0 additions & 3 deletions Builds/VisualStudio2015/HEELP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@
<ClCompile Include="..\..\Source\Process\AudioMasterProcess.cpp">
<Filter>HEELP\Source\Process</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\Process\AudioProcessMessageTypes.cpp">
<Filter>HEELP\Source\Process</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\Process\AudioProcessMessageUtils.cpp">
<Filter>HEELP\Source\Process</Filter>
</ClCompile>
Expand Down
2 changes: 0 additions & 2 deletions HEELP.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
file="Source/Process/AudioMasterProcess.cpp"/>
<FILE id="VAETAp" name="AudioMasterProcess.h" compile="0" resource="0"
file="Source/Process/AudioMasterProcess.h"/>
<FILE id="KlBKOM" name="AudioProcessMessageTypes.cpp" compile="1" resource="0"
file="Source/Process/AudioProcessMessageTypes.cpp"/>
<FILE id="tMnGlN" name="AudioProcessMessageTypes.h" compile="0" resource="0"
file="Source/Process/AudioProcessMessageTypes.h"/>
<FILE id="K9Ff2J" name="AudioProcessMessageUtils.cpp" compile="1" resource="0"
Expand Down
2 changes: 1 addition & 1 deletion Source/AbstractHelpApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace heelp
AbstractHeelpApplication() {}
virtual ~AbstractHeelpApplication() {}

virtual void initialise(const String& commandLine) = 0;
virtual bool initialise(const String& commandLine) = 0;
virtual void shutdown() = 0;
};
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Audio/ChildAudioComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ using namespace heelp;

struct ChildAudioComponent::Pimpl
{
Pimpl(ChildAudioComponent* parent, int childId, int shmId) : parent_(parent), childId_(childId), shmId_(shmId), sharedMemory_(nullptr), sharedAudioBuffer_(nullptr)
Pimpl(ChildAudioComponent* parent, int childId, int shmId, const XmlElement* const audioDeviceXml) : parent_(parent), childId_(childId), shmId_(shmId), sharedMemory_(nullptr), sharedAudioBuffer_(nullptr)
{
parent_->setAudioChannels(0, 2);
parent_->setAudioChannels(0, 2, audioDeviceXml);

sharedMemory_ = (char*)shmat(shmId_, 0, SHM_RND);
if (sharedMemory_ == nullptr)
Expand Down Expand Up @@ -125,8 +125,8 @@ struct ChildAudioComponent::Pimpl
float* sharedAudioBuffer_;
};

ChildAudioComponent::ChildAudioComponent(int childId, int shmId) : pimpl_(new Pimpl(this, childId, shmId)) {}
ChildAudioComponent::~ChildAudioComponent() { pimpl_ = nullptr; }
ChildAudioComponent::ChildAudioComponent(int childId, int shmId, const XmlElement* const xml) : pimpl_(new Pimpl(this, childId, shmId, xml)) {}
ChildAudioComponent::~ChildAudioComponent() { pimpl_ = nullptr; }

void ChildAudioComponent::prepareToPlay(int samplesPerBlockExpected, double sampleRate) { pimpl_->prepareToPlay(samplesPerBlockExpected, sampleRate); }
void ChildAudioComponent::releaseResources() { pimpl_->releaseResources(); }
Expand Down
2 changes: 1 addition & 1 deletion Source/Audio/ChildAudioComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace heelp
class ChildAudioComponent : public AudioAppComponent
{
public:
ChildAudioComponent(int childId, int shmId);
ChildAudioComponent(int childId, int shmId, const XmlElement* const audioDeviceXml);
~ChildAudioComponent();

void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override;
Expand Down
26 changes: 20 additions & 6 deletions Source/HeelpApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ struct HeelpApplication::Pimpl

void initialise(const String& commandLine)
{
ScopedPointer<AudioSlaveProcess> slave(new AudioSlaveProcess());
if (slave->initialiseFromCommandLine(commandLine, audioCommandLineUID))
if (commandLine.contains(HeelpChildApplication::CMD_ARG_CHILDID) &&
commandLine.contains(HeelpChildApplication::CMD_ARG_SHMID))
{
slave.release(); // allow the slave object to stay alive - it'll handle its own deletion.

realApp_ = new HeelpChildApplication();
realApp_->initialise(commandLine);
HeelpChildApplication* realApp = new HeelpChildApplication();
realApp_ = realApp;
if (realApp->initialise(commandLine))
{
ScopedPointer<AudioSlaveProcess> slave(new AudioSlaveProcess(realApp));
if (slave->initialiseFromCommandLine(commandLine, audioCommandLineUID))
{
slave.release(); // allow the slave object to stay alive - it'll handle its own deletion.
}
else
{
shutdown();
}
}
else
{
shutdown();
}
}
else
{
Expand Down
46 changes: 28 additions & 18 deletions Source/HeelpChildApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,55 @@ using namespace heelp;

struct HeelpChildApplication::Pimpl
{
Pimpl() : logger_(nullptr), audio_(nullptr), shmId_(-1)
Pimpl() : logger_(nullptr), childId_(-1), shmId_(-1), audio_(nullptr)
{
}

void initialise(const String& commandLine)
bool initialise(const String& commandLine)
{
bool result = true;

#ifdef JUCE_MAC
Process::setDockIconVisible(false);
#endif

int childId = -1;
StringArray params = JUCEApplication::getInstance()->getCommandLineParameterArray();
for (auto&& param : params)
{
if (param.startsWith("--child="))
if (param.startsWith(CMD_ARG_CHILDID))
{
childId = param.substring(8).getIntValue();
childId_ = param.substring(String(CMD_ARG_CHILDID).length()).getIntValue();
}
if (param.startsWith("--shmid="))
if (param.startsWith(CMD_ARG_SHMID))
{
shmId_ = param.substring(8).getIntValue();
shmId_ = param.substring(String(CMD_ARG_SHMID).length()).getIntValue();
}
}

if (shmId_ < 0)
if (childId_ < 0)
{
LOG("Couldn't determine shared memory ID to use with child process.");
LOG("Couldn't determine the child process ID.");
result = false;
}
else if (childId < 0)
else if (shmId_ < 0)
{
LOG("Couldn't determine the child process ID.");
LOG("Couldn't determine shared memory ID to use with child process.");
result = false;
}
else
{
logger_ = new HeelpLogger(childId);
logger_ = new HeelpLogger(childId_);
Logger::setCurrentLogger(logger_);

LOG("Setting up child " << childId << " with shared memory ID " << shmId_);
audio_ = new ChildAudioComponent(childId, shmId_);
LOG("Initialised child " << childId_ << " with shared memory ID " << shmId_);
}

return result;
}

void startAudio(const XmlElement* const xml)
{
LOG("Setting up audio for child " << childId_ << " with shared memory ID " << shmId_);
audio_ = new ChildAudioComponent(childId_, shmId_, xml);
}

void shutdown()
Expand All @@ -89,13 +98,14 @@ struct HeelpChildApplication::Pimpl

ScopedPointer<FileLogger> logger_;

ScopedPointer<ChildAudioComponent> audio_;

int childId_;
int shmId_;
ScopedPointer<ChildAudioComponent> audio_;
};

HeelpChildApplication::HeelpChildApplication() : pimpl_(new Pimpl()) {}
HeelpChildApplication::~HeelpChildApplication() { pimpl_ = nullptr; }

void HeelpChildApplication::initialise(const String& commandLine) { pimpl_->initialise(commandLine); }
bool HeelpChildApplication::initialise(const String& commandLine) { return pimpl_->initialise(commandLine); }
void HeelpChildApplication::shutdown() { pimpl_->shutdown(); }
void HeelpChildApplication::startAudio(const XmlElement* const xml) { pimpl_->startAudio(xml); }
7 changes: 6 additions & 1 deletion Source/HeelpChildApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ namespace heelp
class HeelpChildApplication : public AbstractHeelpApplication
{
public:
constexpr static const char* const CMD_ARG_CHILDID = "--childid=";
constexpr static const char* const CMD_ARG_SHMID = "--shmid=";

HeelpChildApplication();
virtual ~HeelpChildApplication();

void initialise(const String& commandLine) override;
bool initialise(const String& commandLine) override;
void shutdown() override;

void startAudio(const XmlElement* const xml);

class Pimpl;
private:
ScopedPointer<Pimpl> pimpl_;
Expand Down
18 changes: 9 additions & 9 deletions Source/HeelpMainApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "HeelpMainApplication.h"

#include "HeelpApplication.h"
#include "HeelpChildApplication.h"
#include "HeelpLogger.h"
#include "Utils.h"
#include "Audio/ChildAudioState.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ struct HeelpMainApplication::Pimpl
{
}

void initialise(const String& commandLine)
bool initialise(const String& commandLine)
{
// setup logging system
logger_ = new HeelpLogger(0);
Expand All @@ -71,6 +72,8 @@ struct HeelpMainApplication::Pimpl
audio_ = new MainAudioComponent();

Process::makeForegroundProcess();

return true;
}

void launchChildProcess(int childId)
Expand Down Expand Up @@ -100,19 +103,16 @@ struct HeelpMainApplication::Pimpl
}

StringArray args;
args.add("--child="+String(childId));
args.add("--shmid="+String(shmId));
args.add(HeelpChildApplication::CMD_ARG_CHILDID+String(childId));
args.add(HeelpChildApplication::CMD_ARG_SHMID+String(shmId));
LOG("Launching child " << childId << " with shared memory ID " << shmId);
if (masterProcess->launchSlaveProcess(File::getSpecialLocation(File::currentExecutableFile), audioCommandLineUID, args))
{
LOG("Child process started");

ValueTree message(AudioProcessMessageTypes::AUDIODEVICEMANAGER_STATEXML);
XmlElement* state = audio_->deviceManager.createStateXml();
String stateString;
if (state)
{
stateString = state->createDocument("");
}
String stateString = (state ? stateString = state->createDocument("") : "");
message.setProperty(AudioProcessMessageProperties::STATE, stateString, nullptr);
masterProcess->sendMessageToSlave(valueTreeToMemoryBlock(message));
}
Expand Down Expand Up @@ -177,7 +177,7 @@ struct HeelpMainApplication::Pimpl
HeelpMainApplication::HeelpMainApplication() : pimpl_(new Pimpl(this)) {}
HeelpMainApplication::~HeelpMainApplication() { pimpl_ = nullptr; }

void HeelpMainApplication::initialise(const String& commandLine) { pimpl_->initialise(commandLine); }
bool HeelpMainApplication::initialise(const String& commandLine) { return pimpl_->initialise(commandLine); }
void HeelpMainApplication::launchChildProcess(int childId) { pimpl_->launchChildProcess(childId); }
void HeelpMainApplication::killChildProcess(int childId) { pimpl_->killChildProcess(childId); }
void HeelpMainApplication::shutdown() { pimpl_->shutdown(); }
2 changes: 1 addition & 1 deletion Source/HeelpMainApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace heelp
HeelpMainApplication();
virtual ~HeelpMainApplication();

void initialise(const String& commandLine) override;
bool initialise(const String& commandLine) override;
void shutdown() override;

void launchChildProcess(int childId);
Expand Down
4 changes: 2 additions & 2 deletions Source/Process/AudioMasterProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ AudioMasterProcess::AudioMasterProcess(HeelpMainApplication* app, int identifier

void AudioMasterProcess::handleMessageFromSlave(const MemoryBlock& mb)
{
ValueTree incomingMessage (memoryBlockToValueTree(mb));
LOG("Received: " + valueTreeToString(incomingMessage));
ValueTree msg(memoryBlockToValueTree(mb));
LOG("Received: " + valueTreeToString(msg));
}

void AudioMasterProcess::handleConnectionLost()
Expand Down
31 changes: 0 additions & 31 deletions Source/Process/AudioProcessMessageTypes.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions Source/Process/AudioProcessMessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ namespace heelp
{
namespace AudioProcessMessageTypes
{
extern const char* AUDIODEVICEMANAGER_STATEXML;
constexpr const char* const AUDIODEVICEMANAGER_STATEXML = "AudioDeviceManager::StateXml";
};

namespace AudioProcessMessageProperties
{
extern const char* STATE;
constexpr const char* const STATE = "State";
};
};

Expand Down
Loading

0 comments on commit 680276a

Please sign in to comment.