StandAlone-appens filer
This commit is contained in:
1 parent
ee80ef7d89
commit
ca7f1ec825
2 files changed
+363
No files matched your search
@@ -0,0 +1,300 @@
|
||||
#include "StandaloneMain.h"
|
||||
|
||||
StandaloneAudioEngine::StandaloneAudioEngine()
|
||||
{
|
||||
deviceManager.initialise(2, 2, nullptr, true);
|
||||
|
||||
for (auto* type : deviceManager.getAvailableDeviceTypes())
|
||||
{
|
||||
if (type != nullptr && type->getTypeName().containsIgnoreCase("ASIO"))
|
||||
{
|
||||
deviceManager.setCurrentAudioDeviceType(type->getTypeName(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
deviceManager.addAudioCallback(this);
|
||||
}
|
||||
|
||||
StandaloneAudioEngine::~StandaloneAudioEngine()
|
||||
{
|
||||
deviceManager.removeAudioCallback(this);
|
||||
deviceManager.closeAudioDevice();
|
||||
}
|
||||
|
||||
void StandaloneAudioEngine::setBassInputChannel(int channel) noexcept
|
||||
{
|
||||
bassInputChannel.store(juce::jmax(0, channel), std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
int StandaloneAudioEngine::getBassInputChannel() const noexcept
|
||||
{
|
||||
return bassInputChannel.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void StandaloneAudioEngine::audioDeviceAboutToStart(juce::AudioIODevice* device)
|
||||
{
|
||||
if (device == nullptr)
|
||||
return;
|
||||
|
||||
const auto sampleRate = device->getCurrentSampleRate();
|
||||
const auto blockSize = device->getCurrentBufferSizeSamples();
|
||||
|
||||
processingBuffer.setSize(2, blockSize, false, true, true);
|
||||
processor.setRateAndBufferSizeDetails(sampleRate, blockSize);
|
||||
processor.prepareToPlay(sampleRate, blockSize);
|
||||
}
|
||||
|
||||
void StandaloneAudioEngine::audioDeviceStopped()
|
||||
{
|
||||
processor.releaseResources();
|
||||
}
|
||||
|
||||
void StandaloneAudioEngine::audioDeviceIOCallbackWithContext(
|
||||
const float* const* inputChannelData,
|
||||
int numInputChannels,
|
||||
float* const* outputChannelData,
|
||||
int numOutputChannels,
|
||||
int numSamples,
|
||||
const juce::AudioIODeviceCallbackContext&)
|
||||
{
|
||||
processingBuffer.setSize(2, numSamples, false, false, true);
|
||||
processingBuffer.clear();
|
||||
|
||||
const int selectedInput = bassInputChannel.load(std::memory_order_relaxed);
|
||||
|
||||
if (selectedInput < numInputChannels && inputChannelData[selectedInput] != nullptr)
|
||||
processingBuffer.copyFrom(0, 0, inputChannelData[selectedInput], numSamples);
|
||||
|
||||
midiBuffer.clear();
|
||||
processor.processBlock(processingBuffer, midiBuffer);
|
||||
|
||||
for (int channel = 0; channel < numOutputChannels; ++channel)
|
||||
{
|
||||
if (outputChannelData[channel] == nullptr)
|
||||
continue;
|
||||
|
||||
if (channel < processingBuffer.getNumChannels())
|
||||
juce::FloatVectorOperations::copy(outputChannelData[channel],
|
||||
processingBuffer.getReadPointer(channel),
|
||||
numSamples);
|
||||
else
|
||||
juce::FloatVectorOperations::clear(outputChannelData[channel], numSamples);
|
||||
}
|
||||
}
|
||||
|
||||
StandaloneMainComponent::StandaloneMainComponent()
|
||||
{
|
||||
juce::PropertiesFile::Options options;
|
||||
options.applicationName = "Crille Bass Strip";
|
||||
options.filenameSuffix = ".settings";
|
||||
options.folderName = "Crille Audio";
|
||||
options.storageFormat = juce::PropertiesFile::storeAsXML;
|
||||
settings = std::make_unique<juce::PropertiesFile>(options);
|
||||
|
||||
// Restore every APVTS/plugin parameter before the editor is created,
|
||||
// so all knobs open at their last saved values.
|
||||
loadPluginState();
|
||||
|
||||
inputLabel.setText("BASS INPUT", juce::dontSendNotification);
|
||||
inputLabel.setColour(juce::Label::textColourId, juce::Colour(0xffd9dde3));
|
||||
inputLabel.setFont(juce::Font(12.0f, juce::Font::bold));
|
||||
inputLabel.setJustificationType(juce::Justification::centredRight);
|
||||
addAndMakeVisible(inputLabel);
|
||||
|
||||
inputSelector.setColour(juce::ComboBox::backgroundColourId, juce::Colour(0xff1b1f24));
|
||||
inputSelector.setColour(juce::ComboBox::textColourId, juce::Colour(0xfff0f1f2));
|
||||
inputSelector.setColour(juce::ComboBox::outlineColourId, juce::Colour(0xffe5a536));
|
||||
addAndMakeVisible(inputSelector);
|
||||
|
||||
audioSettingsButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff30343a));
|
||||
audioSettingsButton.setColour(juce::TextButton::textColourOffId, juce::Colour(0xfff0f1f2));
|
||||
addAndMakeVisible(audioSettingsButton);
|
||||
|
||||
refreshInputChoices();
|
||||
|
||||
const int savedInput = settings->getIntValue("bassInput", 0);
|
||||
inputSelector.setSelectedId(juce::jlimit(1, juce::jmax(1, inputSelector.getNumItems()), savedInput + 1),
|
||||
juce::dontSendNotification);
|
||||
audioEngine.setBassInputChannel(juce::jmax(0, inputSelector.getSelectedId() - 1));
|
||||
|
||||
inputSelector.onChange = [this]
|
||||
{
|
||||
audioEngine.setBassInputChannel(inputSelector.getSelectedId() - 1);
|
||||
saveSettings();
|
||||
};
|
||||
|
||||
audioSettingsButton.onClick = [this] { showAudioSettings(); };
|
||||
|
||||
editor = std::make_unique<CrilleBassStripAudioProcessorEditor>(audioEngine.getProcessor());
|
||||
addAndMakeVisible(*editor);
|
||||
|
||||
setSize(1080, 480);
|
||||
}
|
||||
|
||||
StandaloneMainComponent::~StandaloneMainComponent()
|
||||
{
|
||||
// Save both application settings and every knob value when the app closes.
|
||||
savePluginState();
|
||||
saveSettings();
|
||||
editor.reset();
|
||||
}
|
||||
|
||||
juce::File StandaloneMainComponent::getPluginStateFile() const
|
||||
{
|
||||
// Windows: %APPDATA%\Crille Audio\CrilleBassStrip.state
|
||||
auto folder = juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory)
|
||||
.getChildFile("Crille Audio");
|
||||
folder.createDirectory();
|
||||
return folder.getChildFile("CrilleBassStrip.state");
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::loadPluginState()
|
||||
{
|
||||
const auto stateFile = getPluginStateFile();
|
||||
if (!stateFile.existsAsFile())
|
||||
return;
|
||||
|
||||
juce::MemoryBlock state;
|
||||
if (stateFile.loadFileAsData(state) && state.getSize() > 0)
|
||||
audioEngine.getProcessor().setStateInformation(state.getData(), static_cast<int>(state.getSize()));
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::savePluginState()
|
||||
{
|
||||
juce::MemoryBlock state;
|
||||
audioEngine.getProcessor().getStateInformation(state);
|
||||
|
||||
if (state.getSize() == 0)
|
||||
return;
|
||||
|
||||
const auto stateFile = getPluginStateFile();
|
||||
stateFile.replaceWithData(state.getData(), state.getSize());
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::refreshInputChoices()
|
||||
{
|
||||
const int previousSelection = juce::jmax(1, inputSelector.getSelectedId());
|
||||
inputSelector.clear(juce::dontSendNotification);
|
||||
|
||||
if (auto* device = audioEngine.getDeviceManager().getCurrentAudioDevice())
|
||||
{
|
||||
const auto names = device->getInputChannelNames();
|
||||
for (int i = 0; i < names.size(); ++i)
|
||||
inputSelector.addItem(names[i].isNotEmpty() ? names[i] : "Input " + juce::String(i + 1), i + 1);
|
||||
}
|
||||
|
||||
if (inputSelector.getNumItems() == 0)
|
||||
{
|
||||
inputSelector.addItem("Input 1", 1);
|
||||
inputSelector.addItem("Input 2", 2);
|
||||
}
|
||||
|
||||
inputSelector.setSelectedId(juce::jlimit(1, inputSelector.getNumItems(), previousSelection),
|
||||
juce::dontSendNotification);
|
||||
audioEngine.setBassInputChannel(inputSelector.getSelectedId() - 1);
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::showAudioSettings()
|
||||
{
|
||||
juce::DialogWindow::LaunchOptions options;
|
||||
options.dialogTitle = "Audio Setup";
|
||||
options.dialogBackgroundColour = juce::Colour(0xff1b1f24);
|
||||
options.escapeKeyTriggersCloseButton = true;
|
||||
options.useNativeTitleBar = true;
|
||||
options.resizable = false;
|
||||
|
||||
auto selector = std::make_unique<juce::AudioDeviceSelectorComponent>(
|
||||
audioEngine.getDeviceManager(),
|
||||
2, 2,
|
||||
2, 2,
|
||||
false, false, false, false);
|
||||
|
||||
selector->setSize(500, 420);
|
||||
options.content.setOwned(selector.release());
|
||||
|
||||
auto* dialog = options.launchAsync();
|
||||
if (dialog != nullptr)
|
||||
dialog->enterModalState(true, juce::ModalCallbackFunction::create([safe = juce::Component::SafePointer<StandaloneMainComponent>(this)](int)
|
||||
{
|
||||
if (safe != nullptr)
|
||||
{
|
||||
safe->refreshInputChoices();
|
||||
safe->saveSettings();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::saveSettings()
|
||||
{
|
||||
if (settings != nullptr)
|
||||
{
|
||||
settings->setValue("bassInput", juce::jmax(0, inputSelector.getSelectedId() - 1));
|
||||
settings->saveIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
void StandaloneMainComponent::resized()
|
||||
{
|
||||
auto area = getLocalBounds();
|
||||
auto topBar = area.removeFromTop(50);
|
||||
|
||||
inputLabel.setBounds(topBar.removeFromLeft(115).reduced(10, 8));
|
||||
inputSelector.setBounds(topBar.removeFromLeft(220).reduced(5, 8));
|
||||
topBar.removeFromLeft(10);
|
||||
audioSettingsButton.setBounds(topBar.removeFromLeft(130).reduced(5, 8));
|
||||
|
||||
if (editor != nullptr)
|
||||
editor->setBounds(area);
|
||||
}
|
||||
|
||||
class CrilleBassStripApplication final : public juce::JUCEApplication
|
||||
{
|
||||
public:
|
||||
const juce::String getApplicationName() override { return "Crille Bass Strip"; }
|
||||
const juce::String getApplicationVersion() override { return "1.0.0"; }
|
||||
bool moreThanOneInstanceAllowed() override { return false; }
|
||||
|
||||
void initialise(const juce::String&) override
|
||||
{
|
||||
mainWindow = std::make_unique<MainWindow>(getApplicationName());
|
||||
}
|
||||
|
||||
void shutdown() override
|
||||
{
|
||||
mainWindow.reset();
|
||||
}
|
||||
|
||||
void systemRequestedQuit() override
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
||||
void anotherInstanceStarted(const juce::String&) override {}
|
||||
|
||||
private:
|
||||
class MainWindow final : public juce::DocumentWindow
|
||||
{
|
||||
public:
|
||||
explicit MainWindow(const juce::String& name)
|
||||
: DocumentWindow(name,
|
||||
juce::Colour(0xff111317),
|
||||
juce::DocumentWindow::closeButton)
|
||||
{
|
||||
setUsingNativeTitleBar(true);
|
||||
setResizable(false, false);
|
||||
setContentOwned(new StandaloneMainComponent(), true);
|
||||
centreWithSize(getWidth(), getHeight());
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void closeButtonPressed() override
|
||||
{
|
||||
juce::JUCEApplication::getInstance()->systemRequestedQuit();
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<MainWindow> mainWindow;
|
||||
};
|
||||
|
||||
START_JUCE_APPLICATION(CrilleBassStripApplication)
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include <JuceHeader.h>
|
||||
#include "PluginProcessor.h"
|
||||
#include "PluginEditor.h"
|
||||
|
||||
class StandaloneAudioEngine final : public juce::AudioIODeviceCallback
|
||||
{
|
||||
public:
|
||||
StandaloneAudioEngine();
|
||||
~StandaloneAudioEngine() override;
|
||||
|
||||
juce::AudioDeviceManager& getDeviceManager() noexcept { return deviceManager; }
|
||||
CrilleBassStripAudioProcessor& getProcessor() noexcept { return processor; }
|
||||
|
||||
void setBassInputChannel(int channel) noexcept;
|
||||
int getBassInputChannel() const noexcept;
|
||||
|
||||
void audioDeviceAboutToStart(juce::AudioIODevice* device) override;
|
||||
void audioDeviceStopped() override;
|
||||
void audioDeviceIOCallbackWithContext(const float* const* inputChannelData,
|
||||
int numInputChannels,
|
||||
float* const* outputChannelData,
|
||||
int numOutputChannels,
|
||||
int numSamples,
|
||||
const juce::AudioIODeviceCallbackContext&) override;
|
||||
|
||||
private:
|
||||
juce::AudioDeviceManager deviceManager;
|
||||
CrilleBassStripAudioProcessor processor;
|
||||
juce::AudioBuffer<float> processingBuffer;
|
||||
juce::MidiBuffer midiBuffer;
|
||||
std::atomic<int> bassInputChannel { 0 };
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneAudioEngine)
|
||||
};
|
||||
|
||||
class StandaloneMainComponent final : public juce::Component
|
||||
{
|
||||
public:
|
||||
StandaloneMainComponent();
|
||||
~StandaloneMainComponent() override;
|
||||
|
||||
void resized() override;
|
||||
|
||||
private:
|
||||
void showAudioSettings();
|
||||
void refreshInputChoices();
|
||||
void saveSettings();
|
||||
void loadPluginState();
|
||||
void savePluginState();
|
||||
juce::File getPluginStateFile() const;
|
||||
|
||||
StandaloneAudioEngine audioEngine;
|
||||
std::unique_ptr<CrilleBassStripAudioProcessorEditor> editor;
|
||||
|
||||
juce::Label inputLabel;
|
||||
juce::ComboBox inputSelector;
|
||||
juce::TextButton audioSettingsButton { "AUDIO SETUP" };
|
||||
|
||||
std::unique_ptr<juce::PropertiesFile> settings;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneMainComponent)
|
||||
};
|
||||
Reference in new issue
Block a user