kopia lustrzana https://github.com/jameshball/osci-render
Support opening from a file
rodzic
15f6a0ffbb
commit
ad7324b403
|
@ -33,6 +33,9 @@ CommonPluginEditor::CommonPluginEditor(CommonAudioProcessor& p, juce::String app
|
|||
juce::StandalonePluginHolder* standalone = juce::StandalonePluginHolder::getInstance();
|
||||
if (standalone != nullptr) {
|
||||
standalone->getMuteInputValue().setValue(false);
|
||||
standalone->commandLineCallback = [this](const juce::String& commandLine) {
|
||||
handleCommandLine(commandLine);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +72,31 @@ CommonPluginEditor::CommonPluginEditor(CommonAudioProcessor& p, juce::String app
|
|||
#endif
|
||||
}
|
||||
|
||||
void CommonPluginEditor::handleCommandLine(const juce::String& commandLine) {
|
||||
if (commandLine.trim().isNotEmpty()) {
|
||||
// Split the command line into tokens, using space as delimiter
|
||||
// and handling quoted arguments as one token.
|
||||
juce::StringArray tokens = juce::StringArray::fromTokens(commandLine, " ", "\"");
|
||||
|
||||
if (tokens.size() > 0) {
|
||||
// Use the first token as the file path and trim any extra whitespace.
|
||||
juce::String filePath = tokens[0].trim();
|
||||
filePath = filePath.unquoted();
|
||||
juce::File file = juce::File::createFileWithoutCheckingPath(filePath);
|
||||
|
||||
if (file.existsAsFile()) {
|
||||
if (file.getFileExtension().toLowerCase() == "." + projectFileType.toLowerCase()) {
|
||||
openProject(file);
|
||||
} else {
|
||||
juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::WarningIcon, "Invalid Command Line", "Invalid file type: " + file.getFullPathName());
|
||||
}
|
||||
} else {
|
||||
juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::WarningIcon, "Invalid Command Line", "File not found: " + filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonPluginEditor::resized() {
|
||||
audioProcessor.setProperty("appWidth", getWidth());
|
||||
audioProcessor.setProperty("appHeight", getHeight());
|
||||
|
|
|
@ -14,6 +14,7 @@ public:
|
|||
CommonPluginEditor(CommonAudioProcessor&, juce::String appName, juce::String projectFileType, int width, int height);
|
||||
~CommonPluginEditor() override;
|
||||
|
||||
void handleCommandLine(const juce::String& commandLine);
|
||||
void initialiseMenuBar(juce::MenuBarModel& menuBarModel);
|
||||
void openProject(const juce::File& file);
|
||||
void openProject();
|
||||
|
|
|
@ -91,11 +91,14 @@ public:
|
|||
if (mainWindow != nullptr)
|
||||
{
|
||||
mainWindow->toFront(true);
|
||||
mainWindow->handleCommandLine(commandLine);
|
||||
|
||||
if (mainWindow->pluginHolder != nullptr && mainWindow->pluginHolder->commandLineCallback != nullptr) {
|
||||
mainWindow->pluginHolder->commandLineCallback(commandLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual StandaloneFilterWindow* createWindow()
|
||||
virtual StandaloneFilterWindow* createWindow(const String& commandLine)
|
||||
{
|
||||
if (Desktop::getInstance().getDisplays().displays.isEmpty())
|
||||
{
|
||||
|
@ -106,10 +109,10 @@ public:
|
|||
|
||||
return new StandaloneFilterWindow (getApplicationName(),
|
||||
LookAndFeel::getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId),
|
||||
createPluginHolder());
|
||||
createPluginHolder(commandLine));
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<StandalonePluginHolder> createPluginHolder()
|
||||
virtual std::unique_ptr<StandalonePluginHolder> createPluginHolder(const String& commandLine)
|
||||
{
|
||||
constexpr auto autoOpenMidiDevices =
|
||||
#if (JUCE_ANDROID || JUCE_IOS) && ! JUCE_DONT_AUTO_OPEN_MIDI_DEVICES_ON_MOBILE
|
||||
|
@ -127,6 +130,7 @@ public:
|
|||
#endif
|
||||
|
||||
return std::make_unique<StandalonePluginHolder> (appProperties.getUserSettings(),
|
||||
commandLine,
|
||||
false,
|
||||
String{},
|
||||
nullptr,
|
||||
|
@ -137,7 +141,7 @@ public:
|
|||
//==============================================================================
|
||||
void initialise (const String& commandLine) override
|
||||
{
|
||||
mainWindow = rawToUniquePtr (createWindow());
|
||||
mainWindow = rawToUniquePtr(createWindow(commandLine));
|
||||
|
||||
if (mainWindow != nullptr)
|
||||
{
|
||||
|
@ -149,8 +153,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
pluginHolder = createPluginHolder();
|
||||
mainWindow->handleCommandLine(commandLine);
|
||||
pluginHolder = createPluginHolder(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace juce
|
|||
|
||||
The object will create your processor using the same createPluginFilter()
|
||||
function that the other plugin wrappers use, and will run it through the
|
||||
computer's audio/MIDI devices using AudioDeviceManager and AudioProcessorPlayer.
|
||||
computer's audio/MIDI devices using AudioDeviceManager and AudioProcessorPlayer.
|
||||
|
||||
@tags{Audio}
|
||||
*/
|
||||
|
@ -76,6 +76,7 @@ public:
|
|||
In all instances, the settingsToUse will take precedence over the "preferred" options if not null.
|
||||
*/
|
||||
StandalonePluginHolder (PropertySet* settingsToUse,
|
||||
const String& commandLine,
|
||||
bool takeOwnershipOfSettings = true,
|
||||
const String& preferredDefaultDeviceName = String(),
|
||||
const AudioDeviceManager::AudioDeviceSetup* preferredSetupOptions = nullptr,
|
||||
|
@ -88,6 +89,7 @@ public:
|
|||
)
|
||||
|
||||
: settings (settingsToUse, takeOwnershipOfSettings),
|
||||
commandLine (commandLine),
|
||||
channelConfiguration (channels),
|
||||
autoOpenMidiDevices (shouldAutoOpenMidiDevices)
|
||||
{
|
||||
|
@ -426,6 +428,9 @@ public:
|
|||
AudioDeviceManager deviceManager;
|
||||
AudioProcessorPlayer player;
|
||||
Array<PluginInOuts> channelConfiguration;
|
||||
|
||||
const String commandLine;
|
||||
std::function<void(const juce::String&)> commandLineCallback;
|
||||
|
||||
// avoid feedback loop by default
|
||||
bool processorHasPotentialFeedbackLoop = true;
|
||||
|
@ -824,6 +829,7 @@ public:
|
|||
: StandaloneFilterWindow (title,
|
||||
backgroundColour,
|
||||
std::make_unique<StandalonePluginHolder> (settingsToUse,
|
||||
"",
|
||||
takeOwnershipOfSettings,
|
||||
preferredDefaultDeviceName,
|
||||
preferredSetupOptions,
|
||||
|
@ -902,25 +908,6 @@ public:
|
|||
|
||||
std::unique_ptr<StandalonePluginHolder> pluginHolder;
|
||||
|
||||
void handleCommandLine(const String& commandLine)
|
||||
{
|
||||
if (commandLine.isNotEmpty())
|
||||
{
|
||||
handleOpenFile(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
void handleOpenFile(const String& fileName)
|
||||
{
|
||||
if (auto* processor = getAudioProcessor())
|
||||
{
|
||||
// if (processor->openProjectCallback)
|
||||
// {
|
||||
// processor->openProjectCallback(File(fileName));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void updateContent()
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue