From 6492411759187baa8ac0fafdd5dea7d0f8f9fd52 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Tue, 19 Sep 2017 15:53:34 +0100 Subject: [PATCH 1/2] Set infoLabel text colour making info text visible --- plugin/Source/SFZeroEditor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/Source/SFZeroEditor.cpp b/plugin/Source/SFZeroEditor.cpp index 8bb9949..00b0dfd 100644 --- a/plugin/Source/SFZeroEditor.cpp +++ b/plugin/Source/SFZeroEditor.cpp @@ -40,6 +40,7 @@ sfzero::SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor *ownerFilter) viewport.setViewedComponent(&infoLabel, false); infoLabel.setFont(labelFont); infoLabel.setJustificationType(Justification::topLeft); + infoLabel.setColour(Label::textColourId, Colours::grey); infoLabel.addClickListener(this); addAndMakeVisible(&midiKeyboard); From 277fd58ef643ab230a9a6047cde800eff2668628 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 20 Sep 2017 16:45:40 +0100 Subject: [PATCH 2/2] Add separate sfzero_plugin namespace --- plugin/Source/ClickableLabel.cpp | 25 +- plugin/Source/ClickableLabel.h | 43 +- plugin/Source/SFZeroAudioProcessor.cpp | 327 +++++++-------- plugin/Source/SFZeroAudioProcessor.h | 144 +++---- plugin/Source/SFZeroEditor.cpp | 541 +++++++++++++------------ plugin/Source/SFZeroEditor.h | 99 +++-- 6 files changed, 594 insertions(+), 585 deletions(-) diff --git a/plugin/Source/ClickableLabel.cpp b/plugin/Source/ClickableLabel.cpp index 7d092c4..ff16f73 100644 --- a/plugin/Source/ClickableLabel.cpp +++ b/plugin/Source/ClickableLabel.cpp @@ -1,15 +1,18 @@ #include "ClickableLabel.h" -sfzero::ClickableLabel::ClickableLabel(const String &componentName, const String &labelText) : Label(componentName, labelText) {} -void sfzero::ClickableLabel::addClickListener(ClickListener *listener) { clickListeners.add(listener); } -void sfzero::ClickableLabel::removeClickListener(ClickListener *listener) { clickListeners.remove(listener); } -void sfzero::ClickableLabel::mouseUp(const MouseEvent &e) +namespace sfzero_plugin { - bool goodClick = e.mouseWasClicked() && contains(e.getPosition()) && !e.mods.isPopupMenu(); - - if (goodClick) - { - BailOutChecker checker(this); - clickListeners.callChecked(checker, &ClickListener::labelClicked, this); - } + ClickableLabel::ClickableLabel(const String &componentName, const String &labelText) : Label(componentName, labelText) {} + void ClickableLabel::addClickListener(ClickListener *listener) { clickListeners.add(listener); } + void ClickableLabel::removeClickListener(ClickListener *listener) { clickListeners.remove(listener); } + void ClickableLabel::mouseUp(const MouseEvent &e) + { + bool goodClick = e.mouseWasClicked() && contains(e.getPosition()) && !e.mods.isPopupMenu(); + + if (goodClick) + { + BailOutChecker checker(this); + clickListeners.callChecked(checker, &ClickListener::labelClicked, this); + } + } } diff --git a/plugin/Source/ClickableLabel.h b/plugin/Source/ClickableLabel.h index 39c18eb..c430fef 100644 --- a/plugin/Source/ClickableLabel.h +++ b/plugin/Source/ClickableLabel.h @@ -3,29 +3,28 @@ #include "JuceHeader.h" -namespace sfzero +namespace sfzero_plugin { - -class ClickableLabel : public Label -{ -public: - ClickableLabel(const String &componentName = String::empty, const String &labelText = String::empty); - - class JUCE_API ClickListener - { - public: - virtual ~ClickListener() {} - virtual void labelClicked(Label *clickedLabel) = 0; - }; - - void addClickListener(ClickListener *listener); - void removeClickListener(ClickListener *listener); - -protected: - ListenerList clickListeners; - - void mouseUp(const MouseEvent &e) override; -}; + class ClickableLabel : public Label + { + public: + ClickableLabel(const String &componentName = String::empty, const String &labelText = String::empty); + + class JUCE_API ClickListener + { + public: + virtual ~ClickListener() {} + virtual void labelClicked(Label *clickedLabel) = 0; + }; + + void addClickListener(ClickListener *listener); + void removeClickListener(ClickListener *listener); + + protected: + ListenerList clickListeners; + + void mouseUp(const MouseEvent &e) override; + }; } diff --git a/plugin/Source/SFZeroAudioProcessor.cpp b/plugin/Source/SFZeroAudioProcessor.cpp index 4c7418b..07851f7 100644 --- a/plugin/Source/SFZeroAudioProcessor.cpp +++ b/plugin/Source/SFZeroAudioProcessor.cpp @@ -1,177 +1,182 @@ #include "SFZeroAudioProcessor.h" #include "SFZeroEditor.h" -sfzero::SFZeroAudioProcessor::SFZeroAudioProcessor() : loadProgress(0.0), loadThread(this) -{ - formatManager.registerBasicFormats(); - - for (int i = 0; i < 128; ++i) - { - synth.addVoice(new sfzero::Voice()); - } -} - -sfzero::SFZeroAudioProcessor::~SFZeroAudioProcessor() {} -const String sfzero::SFZeroAudioProcessor::getName() const { return JucePlugin_Name; } -int sfzero::SFZeroAudioProcessor::getNumParameters() { return 0; } -float sfzero::SFZeroAudioProcessor::getParameter(int /*index*/) { return 0.0f; } -void sfzero::SFZeroAudioProcessor::setParameter(int /*index*/, float /*newValue*/) {} -const String sfzero::SFZeroAudioProcessor::getParameterName(int /*index*/) { return String::empty; } -const String sfzero::SFZeroAudioProcessor::getParameterText(int /*index*/) { return String::empty; } - -void sfzero::SFZeroAudioProcessor::setSfzFile(File *newSfzFile) -{ - sfzFile = *newSfzFile; - loadSound(); -} - -void sfzero::SFZeroAudioProcessor::setSfzFileThreaded(File *newSfzFile) -{ - loadThread.stopThread(2000); - sfzFile = *newSfzFile; - loadThread.startThread(); -} - -bool sfzero::SFZeroAudioProcessor::acceptsMidi() const +namespace sfzero_plugin { + + SFZeroAudioProcessor::SFZeroAudioProcessor() : loadProgress(0.0), loadThread(this) + { + formatManager.registerBasicFormats(); + + for (int i = 0; i < 128; ++i) + { + synth.addVoice(new sfzero::Voice()); + } + } + + SFZeroAudioProcessor::~SFZeroAudioProcessor() {} + const String SFZeroAudioProcessor::getName() const { return JucePlugin_Name; } + int SFZeroAudioProcessor::getNumParameters() { return 0; } + float SFZeroAudioProcessor::getParameter(int /*index*/) { return 0.0f; } + void SFZeroAudioProcessor::setParameter(int /*index*/, float /*newValue*/) {} + const String SFZeroAudioProcessor::getParameterName(int /*index*/) { return String::empty; } + const String SFZeroAudioProcessor::getParameterText(int /*index*/) { return String::empty; } + + void SFZeroAudioProcessor::setSfzFile(File *newSfzFile) + { + sfzFile = *newSfzFile; + loadSound(); + } + + void SFZeroAudioProcessor::setSfzFileThreaded(File *newSfzFile) + { + loadThread.stopThread(2000); + sfzFile = *newSfzFile; + loadThread.startThread(); + } + + bool SFZeroAudioProcessor::acceptsMidi() const + { #if JucePlugin_WantsMidiInput - return true; - + return true; + #else - return false; + return false; #endif -} - -bool sfzero::SFZeroAudioProcessor::producesMidi() const -{ + } + + bool SFZeroAudioProcessor::producesMidi() const + { #if JucePlugin_ProducesMidiOutput - return true; - + return true; + #else - return false; + return false; #endif -} - -int sfzero::SFZeroAudioProcessor::getNumPrograms() { return 1; } -int sfzero::SFZeroAudioProcessor::getCurrentProgram() { return 0; } -void sfzero::SFZeroAudioProcessor::setCurrentProgram(int /*index*/) {} -const String sfzero::SFZeroAudioProcessor::getProgramName(int /*index*/) { return String::empty; } -void sfzero::SFZeroAudioProcessor::changeProgramName(int /*index*/, const String & /*newName*/) {} -void sfzero::SFZeroAudioProcessor::prepareToPlay(double _sampleRate_, int /*samplesPerBlock*/) -{ - synth.setCurrentPlaybackSampleRate(_sampleRate_); - keyboardState.reset(); -} - -void sfzero::SFZeroAudioProcessor::releaseResources() -{ - // When playback stops, you can use this as an opportunity to free up any - // spare memory, etc. - keyboardState.reset(); -} - -void sfzero::SFZeroAudioProcessor::processBlock(AudioSampleBuffer &buffer, MidiBuffer &midiMessages) -{ - int numSamples = buffer.getNumSamples(); - - keyboardState.processNextMidiBuffer(midiMessages, 0, numSamples, true); - buffer.clear(); - synth.renderNextBlock(buffer, midiMessages, 0, numSamples); -} - -bool sfzero::SFZeroAudioProcessor::hasEditor() const -{ - return true; // (change this to false if you choose to not supply an editor) -} - -AudioProcessorEditor *sfzero::SFZeroAudioProcessor::createEditor() { return new SFZeroEditor(this); } - -void sfzero::SFZeroAudioProcessor::getStateInformation(MemoryBlock &destData) -{ - auto obj = new DynamicObject(); - obj->setProperty("sfzFilePath", sfzFile.getFullPathName()); - auto sound = getSound(); - if (sound) - { - int subsound = sound->selectedSubsound(); - if (subsound != 0) - obj->setProperty("subsound", subsound); - } - - MemoryOutputStream out(destData, false); - JSON::writeToStream(out, var(obj)); -} - -void sfzero::SFZeroAudioProcessor::setStateInformation(const void *data, int sizeInBytes) -{ - MemoryInputStream in(data, sizeInBytes, false); - var state = JSON::parse(in); - var pathVar = state["sfzFilePath"]; - if (pathVar.isString()) - { - auto sfzFilePath = pathVar.toString(); - if (!sfzFilePath.isEmpty()) + } + + int SFZeroAudioProcessor::getNumPrograms() { return 1; } + int SFZeroAudioProcessor::getCurrentProgram() { return 0; } + void SFZeroAudioProcessor::setCurrentProgram(int /*index*/) {} + const String SFZeroAudioProcessor::getProgramName(int /*index*/) { return String::empty; } + void SFZeroAudioProcessor::changeProgramName(int /*index*/, const String & /*newName*/) {} + void SFZeroAudioProcessor::prepareToPlay(double _sampleRate_, int /*samplesPerBlock*/) { - File file(sfzFilePath); - setSfzFile(&file); - auto sound = getSound(); - if (sound) - { - var subsoundVar = state["subsound"]; - if (subsoundVar.isInt()) - sound->useSubsound(int(subsoundVar)); - } + synth.setCurrentPlaybackSampleRate(_sampleRate_); + keyboardState.reset(); } - } -} - -sfzero::Sound *sfzero::SFZeroAudioProcessor::getSound() -{ - SynthesiserSound *sound = synth.getSound(0); - - return dynamic_cast(sound); -} - -int sfzero::SFZeroAudioProcessor::numVoicesUsed() { return synth.numVoicesUsed(); } - -String sfzero::SFZeroAudioProcessor::voiceInfoString() { return synth.voiceInfoString(); } - -void sfzero::SFZeroAudioProcessor::loadSound(Thread *thread) -{ - loadProgress = 0.0; - synth.clearSounds(); - - if (!sfzFile.existsAsFile()) - { - return; - } - - sfzero::Sound *sound; - auto extension = sfzFile.getFileExtension(); - if ((extension == ".sf2") || (extension == ".SF2")) - { - sound = new sfzero::SF2Sound(sfzFile); - } - else - { - sound = new sfzero::Sound(sfzFile); - } - sound->loadRegions(); - sound->loadSamples(&formatManager, &loadProgress, thread); - if (thread && thread->threadShouldExit()) - { - delete sound; - return; - } - - synth.addSound(sound); -} - -sfzero::SFZeroAudioProcessor::LoadThread::LoadThread(SFZeroAudioProcessor *processorIn) + + void SFZeroAudioProcessor::releaseResources() + { + // When playback stops, you can use this as an opportunity to free up any + // spare memory, etc. + keyboardState.reset(); + } + + void SFZeroAudioProcessor::processBlock(AudioSampleBuffer &buffer, MidiBuffer &midiMessages) + { + int numSamples = buffer.getNumSamples(); + + keyboardState.processNextMidiBuffer(midiMessages, 0, numSamples, true); + buffer.clear(); + synth.renderNextBlock(buffer, midiMessages, 0, numSamples); + } + + bool SFZeroAudioProcessor::hasEditor() const + { + return true; // (change this to false if you choose to not supply an editor) + } + + AudioProcessorEditor *SFZeroAudioProcessor::createEditor() { return new SFZeroEditor(this); } + + void SFZeroAudioProcessor::getStateInformation(MemoryBlock &destData) + { + auto obj = new DynamicObject(); + obj->setProperty("sfzFilePath", sfzFile.getFullPathName()); + auto sound = getSound(); + if (sound) + { + int subsound = sound->selectedSubsound(); + if (subsound != 0) + obj->setProperty("subsound", subsound); + } + + MemoryOutputStream out(destData, false); + JSON::writeToStream(out, var(obj)); + } + + void SFZeroAudioProcessor::setStateInformation(const void *data, int sizeInBytes) + { + MemoryInputStream in(data, sizeInBytes, false); + var state = JSON::parse(in); + var pathVar = state["sfzFilePath"]; + if (pathVar.isString()) + { + auto sfzFilePath = pathVar.toString(); + if (!sfzFilePath.isEmpty()) + { + File file(sfzFilePath); + setSfzFile(&file); + auto sound = getSound(); + if (sound) + { + var subsoundVar = state["subsound"]; + if (subsoundVar.isInt()) + sound->useSubsound(int(subsoundVar)); + } + } + } + } + + sfzero::Sound *SFZeroAudioProcessor::getSound() + { + SynthesiserSound *sound = synth.getSound(0); + + return dynamic_cast(sound); + } + + int SFZeroAudioProcessor::numVoicesUsed() { return synth.numVoicesUsed(); } + + String SFZeroAudioProcessor::voiceInfoString() { return synth.voiceInfoString(); } + + void SFZeroAudioProcessor::loadSound(Thread *thread) + { + loadProgress = 0.0; + synth.clearSounds(); + + if (!sfzFile.existsAsFile()) + { + return; + } + + sfzero::Sound *sound; + auto extension = sfzFile.getFileExtension(); + if ((extension == ".sf2") || (extension == ".SF2")) + { + sound = new sfzero::SF2Sound(sfzFile); + } + else + { + sound = new sfzero::Sound(sfzFile); + } + sound->loadRegions(); + sound->loadSamples(&formatManager, &loadProgress, thread); + if (thread && thread->threadShouldExit()) + { + delete sound; + return; + } + + synth.addSound(sound); + } + + SFZeroAudioProcessor::LoadThread::LoadThread(SFZeroAudioProcessor *processorIn) : Thread("SFZLoad"), processor(processorIn) -{ + { + } + + void SFZeroAudioProcessor::LoadThread::run() { processor->loadSound(this); } } -void sfzero::SFZeroAudioProcessor::LoadThread::run() { processor->loadSound(this); } +AudioProcessor *JUCE_CALLTYPE createPluginFilter() { return new sfzero_plugin::SFZeroAudioProcessor(); } -AudioProcessor *JUCE_CALLTYPE createPluginFilter() { return new sfzero::SFZeroAudioProcessor(); } diff --git a/plugin/Source/SFZeroAudioProcessor.h b/plugin/Source/SFZeroAudioProcessor.h index 7ec1f8a..ada5bcb 100644 --- a/plugin/Source/SFZeroAudioProcessor.h +++ b/plugin/Source/SFZeroAudioProcessor.h @@ -3,81 +3,81 @@ #include "JuceHeader.h" -namespace sfzero -{ class Sound; -class SFZeroAudioProcessor : public AudioProcessor +namespace sfzero_plugin { -public: - SFZeroAudioProcessor(); - ~SFZeroAudioProcessor(); - - bool silenceInProducesSilenceOut(void) const override { return false; } - double getTailLengthSeconds(void) const override { return 0; } - void prepareToPlay(double sampleRate, int samplesPerBlock) override; - void releaseResources() override; - void processBlock(AudioSampleBuffer &buffer, MidiBuffer &midiMessages) override; - - AudioProcessorEditor *createEditor() override; - bool hasEditor() const override; - - const String getName() const override; - - int getNumParameters() override; - - float getParameter(int index) override; - void setParameter(int index, float newValue) override; - - const String getParameterName(int index) override; - const String getParameterText(int index) override; - - void setSfzFile(File *newSfzFile); - void setSfzFileThreaded(File *newSfzFile); - - File getSfzFile() { return (sfzFile); } - bool acceptsMidi() const override; - bool producesMidi() const override; - - int getNumPrograms() override; - int getCurrentProgram() override; - void setCurrentProgram(int index) override; - const String getProgramName(int index) override; - void changeProgramName(int index, const String &newName) override; - - void getStateInformation(MemoryBlock &destData) override; - void setStateInformation(const void *data, int sizeInBytes) override; - - MidiKeyboardState keyboardState; - double loadProgress; - - Sound *getSound(); - int numVoicesUsed(); - String voiceInfoString(); - -protected: - - class LoadThread : public Thread - { - public: - LoadThread(SFZeroAudioProcessor *processor); - void run() override; - - protected: - SFZeroAudioProcessor *processor; - }; - friend class LoadThread; - - File sfzFile; - Synth synth; - AudioFormatManager formatManager; - LoadThread loadThread; - - void loadSound(Thread *thread = nullptr); - -private: - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SFZeroAudioProcessor); -}; + class SFZeroAudioProcessor : public AudioProcessor + { + public: + SFZeroAudioProcessor(); + ~SFZeroAudioProcessor(); + + bool silenceInProducesSilenceOut(void) const override { return false; } + double getTailLengthSeconds(void) const override { return 0; } + void prepareToPlay(double sampleRate, int samplesPerBlock) override; + void releaseResources() override; + void processBlock(AudioSampleBuffer &buffer, MidiBuffer &midiMessages) override; + + AudioProcessorEditor *createEditor() override; + bool hasEditor() const override; + + const String getName() const override; + + int getNumParameters() override; + + float getParameter(int index) override; + void setParameter(int index, float newValue) override; + + const String getParameterName(int index) override; + const String getParameterText(int index) override; + + void setSfzFile(File *newSfzFile); + void setSfzFileThreaded(File *newSfzFile); + + File getSfzFile() { return (sfzFile); } + bool acceptsMidi() const override; + bool producesMidi() const override; + + int getNumPrograms() override; + int getCurrentProgram() override; + void setCurrentProgram(int index) override; + const String getProgramName(int index) override; + void changeProgramName(int index, const String &newName) override; + + void getStateInformation(MemoryBlock &destData) override; + void setStateInformation(const void *data, int sizeInBytes) override; + + MidiKeyboardState keyboardState; + double loadProgress; + + sfzero::Sound *getSound(); + int numVoicesUsed(); + String voiceInfoString(); + + protected: + + class LoadThread : public Thread + { + public: + LoadThread(SFZeroAudioProcessor *processor); + void run() override; + + protected: + SFZeroAudioProcessor *processor; + }; + friend class LoadThread; + + File sfzFile; + sfzero::Synth synth; + AudioFormatManager formatManager; + LoadThread loadThread; + + void loadSound(Thread *thread = nullptr); + + private: + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SFZeroAudioProcessor); + }; } diff --git a/plugin/Source/SFZeroEditor.cpp b/plugin/Source/SFZeroEditor.cpp index 00b0dfd..11f3522 100644 --- a/plugin/Source/SFZeroEditor.cpp +++ b/plugin/Source/SFZeroEditor.cpp @@ -1,296 +1,299 @@ #include "SFZeroEditor.h" #include "SFZeroAudioProcessor.h" -enum +namespace sfzero_plugin { - hMargin = 12, - vMargin = 12, - labelHeight = 25, - progressBarHeight = 30, - keyboardHeight = 54, -}; - -sfzero::SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor *ownerFilter) + enum + { + hMargin = 12, + vMargin = 12, + labelHeight = 25, + progressBarHeight = 30, + keyboardHeight = 54, + }; + + SFZeroEditor::SFZeroEditor(SFZeroAudioProcessor *ownerFilter) : AudioProcessorEditor(ownerFilter), fileLabel(String::empty, "File... (click here to choose)"), pathLabel(String::empty), - showingInfo(showingSoundInfo), midiKeyboard(ownerFilter->keyboardState, MidiKeyboardComponent::horizontalKeyboard), - progressBar(nullptr) -{ - setSize(500, 300); - + showingInfo(showingSoundInfo), midiKeyboard(ownerFilter->keyboardState, MidiKeyboardComponent::horizontalKeyboard), + progressBar(nullptr) + { + setSize(500, 300); + #ifdef JUCE_MAC - Font fileFont("Helvetica", 22.0, Font::bold); - Font labelFont("Helvetica", 15.0, Font::plain); + Font fileFont("Helvetica", 22.0, Font::bold); + Font labelFont("Helvetica", 15.0, Font::plain); #else - Font fileFont("Ariel", 22.0, Font::bold); - Font labelFont("Ariel", 15.0, Font::plain); + Font fileFont("Ariel", 22.0, Font::bold); + Font labelFont("Ariel", 15.0, Font::plain); #endif - - addAndMakeVisible(&fileLabel); - fileLabel.setFont(fileFont); - fileLabel.setColour(Label::textColourId, Colours::grey); - fileLabel.addClickListener(this); - - addAndMakeVisible(&pathLabel); - pathLabel.setFont(labelFont); - pathLabel.setColour(Label::textColourId, Colours::grey); - pathLabel.addClickListener(this); - - addAndMakeVisible(&viewport); - viewport.setScrollBarsShown(true, true); - viewport.setViewedComponent(&infoLabel, false); - infoLabel.setFont(labelFont); - infoLabel.setJustificationType(Justification::topLeft); - infoLabel.setColour(Label::textColourId, Colours::grey); - infoLabel.addClickListener(this); - - addAndMakeVisible(&midiKeyboard); - midiKeyboard.setOctaveForMiddleC(4); - - startTimer(200); - - File sfzFile = ownerFilter->getSfzFile(); - if (sfzFile != File::nonexistent) - { - updateFile(&sfzFile); - showSoundInfo(); - auto sound = ownerFilter->getSound(); - if (sound && (sound->numSubsounds() > 1)) + + addAndMakeVisible(&fileLabel); + fileLabel.setFont(fileFont); + fileLabel.setColour(Label::textColourId, Colours::grey); + fileLabel.addClickListener(this); + + addAndMakeVisible(&pathLabel); + pathLabel.setFont(labelFont); + pathLabel.setColour(Label::textColourId, Colours::grey); + pathLabel.addClickListener(this); + + addAndMakeVisible(&viewport); + viewport.setScrollBarsShown(true, true); + viewport.setViewedComponent(&infoLabel, false); + infoLabel.setFont(labelFont); + infoLabel.setJustificationType(Justification::topLeft); + infoLabel.setColour(Label::textColourId, Colours::grey); + infoLabel.addClickListener(this); + + addAndMakeVisible(&midiKeyboard); + midiKeyboard.setOctaveForMiddleC(4); + + startTimer(200); + + File sfzFile = ownerFilter->getSfzFile(); + if (sfzFile != File::nonexistent) + { + updateFile(&sfzFile); + showSoundInfo(); + auto sound = ownerFilter->getSound(); + if (sound && (sound->numSubsounds() > 1)) + { + showSubsound(); + } + } + else + { + showVersion(); + } + } + + SFZeroEditor::~SFZeroEditor() { delete progressBar; } + + void SFZeroEditor::paint(Graphics &g) { g.fillAll(Colours::white); } + + void SFZeroEditor::resized() { - showSubsound(); + int marginedWidth = getWidth() - 2 * hMargin; + + fileLabel.setBounds(hMargin, vMargin, marginedWidth, labelHeight); + pathLabel.setBounds(hMargin, vMargin + labelHeight, marginedWidth, labelHeight); + int infoTop = vMargin + 2 * labelHeight; + int keyboardTop = getHeight() - keyboardHeight - vMargin; + int infoLabelHeight = keyboardTop - infoTop - 4; + viewport.setBounds(hMargin, infoTop, marginedWidth, infoLabelHeight); + infoLabel.setBounds(0, 0, marginedWidth, infoLabelHeight * 10); + midiKeyboard.setBounds(hMargin, keyboardTop, marginedWidth, keyboardHeight); } - } - else - { - showVersion(); - } -} - -sfzero::SFZeroEditor::~SFZeroEditor() { delete progressBar; } - -void sfzero::SFZeroEditor::paint(Graphics &g) { g.fillAll(Colours::white); } - -void sfzero::SFZeroEditor::resized() -{ - int marginedWidth = getWidth() - 2 * hMargin; - - fileLabel.setBounds(hMargin, vMargin, marginedWidth, labelHeight); - pathLabel.setBounds(hMargin, vMargin + labelHeight, marginedWidth, labelHeight); - int infoTop = vMargin + 2 * labelHeight; - int keyboardTop = getHeight() - keyboardHeight - vMargin; - int infoLabelHeight = keyboardTop - infoTop - 4; - viewport.setBounds(hMargin, infoTop, marginedWidth, infoLabelHeight); - infoLabel.setBounds(0, 0, marginedWidth, infoLabelHeight * 10); - midiKeyboard.setBounds(hMargin, keyboardTop, marginedWidth, keyboardHeight); -} - -void sfzero::SFZeroEditor::labelClicked(Label *clickedLabel) -{ - if (clickedLabel == &fileLabel) - { - chooseFile(); - } - else if (clickedLabel == &pathLabel) - { - if (showing == showingSubsound) + + void SFZeroEditor::labelClicked(Label *clickedLabel) { - auto processor = getProcessor(); - auto sound = processor->getSound(); - if (sound) - { - PopupMenu menu; - int selectedSubsound = sound->selectedSubsound(); - int numSubsounds = sound->numSubsounds(); - for (int i = 0; i < numSubsounds; ++i) + if (clickedLabel == &fileLabel) { - menu.addItem(i + 1, sound->subsoundName(i), true, (i == selectedSubsound)); + chooseFile(); } - int result = menu.show(); - if (result != 0) + else if (clickedLabel == &pathLabel) { - sound->useSubsound(result - 1); - showSubsound(); + if (showing == showingSubsound) + { + auto processor = getProcessor(); + auto sound = processor->getSound(); + if (sound) + { + PopupMenu menu; + int selectedSubsound = sound->selectedSubsound(); + int numSubsounds = sound->numSubsounds(); + for (int i = 0; i < numSubsounds; ++i) + { + menu.addItem(i + 1, sound->subsoundName(i), true, (i == selectedSubsound)); + } + int result = menu.show(); + if (result != 0) + { + sound->useSubsound(result - 1); + showSubsound(); + } + } + } + else if (showing == showingVersion) + { + showPath(); + } + else + { + showVersion(); + } + } + else if (clickedLabel == &infoLabel) + { + if (showingInfo == showingSoundInfo) + { + showVoiceInfo(); + } + else + { + showSoundInfo(); + } } - } } - else if (showing == showingVersion) + + void SFZeroEditor::timerCallback() { - showPath(); + if (showing == showingProgress) + { + auto processor = getProcessor(); + if (processor->loadProgress >= 1.0) + { + auto sound = processor->getSound(); + if (sound && (sound->numSubsounds() > 1)) + { + showSubsound(); + } + else + { + showPath(); + } + showSoundInfo(); + } + } + + if (showingInfo == showingVoiceInfo) + { + showVoiceInfo(); + } } - else + + void SFZeroEditor::chooseFile() { - showVersion(); + FileChooser chooser("Select an SFZ file...", File::nonexistent, "*.sfz;*.SFZ;*.sf2;*.SF2"); + + if (chooser.browseForFileToOpen()) + { + File sfzFile(chooser.getResult()); + setFile(&sfzFile); + } } - } - else if (clickedLabel == &infoLabel) - { - if (showingInfo == showingSoundInfo) + + void SFZeroEditor::setFile(File *newFile) { - showVoiceInfo(); + auto processor = getProcessor(); + + processor->setSfzFileThreaded(newFile); + + updateFile(newFile); + showProgress(); } - else + + void SFZeroEditor::updateFile(File *file) { - showSoundInfo(); + fileLabel.setText(file->getFileName(), dontSendNotification); + fileLabel.setColour(Label::textColourId, Colours::black); + showPath(); } - } -} - -void sfzero::SFZeroEditor::timerCallback() -{ - if (showing == showingProgress) - { - auto processor = getProcessor(); - if (processor->loadProgress >= 1.0) + + void SFZeroEditor::showSoundInfo() { - auto sound = processor->getSound(); - if (sound && (sound->numSubsounds() > 1)) - { - showSubsound(); - } - else - { - showPath(); - } - showSoundInfo(); + auto processor = getProcessor(); + auto sound = processor->getSound(); + + if (sound) + { + String info; + auto& errors = sound->getErrors(); + if (errors.size() > 0) + { + info << errors.size() << " errors: \n"; + info << errors.joinIntoString("\n"); + info << "\n"; + } + else + { + info << "no errors.\n\n"; + } + auto& warnings = sound->getWarnings(); + if (warnings.size() > 0) + { + info << warnings.size() << " warnings: \n"; + info << warnings.joinIntoString("\n"); + } + else + { + info << "no warnings.\n"; + } + infoLabel.setText(info, dontSendNotification); + } + showingInfo = showingSoundInfo; + } + + void SFZeroEditor::showVoiceInfo() + { + auto processor = getProcessor(); + + infoLabel.setText(processor->voiceInfoString(), dontSendNotification); + showingInfo = showingVoiceInfo; + } + + void SFZeroEditor::showVersion() + { + auto date = Time::getCompilationDate(); + auto str = String::formatted("SFZero beta %d.%d.%d", date.getYear(), date.getMonth(), date.getDayOfMonth()); + pathLabel.setText(str, dontSendNotification); + pathLabel.setColour(Label::textColourId, Colours::grey); + hideProgress(); + showing = showingVersion; + } + + void SFZeroEditor::showPath() + { + auto processor = getProcessor(); + File file = processor->getSfzFile(); + + pathLabel.setText(file.getParentDirectory().getFullPathName(), dontSendNotification); + pathLabel.setColour(Label::textColourId, Colours::grey); + hideProgress(); + showing = showingPath; + } + + void SFZeroEditor::showSubsound() + { + auto processor = getProcessor(); + auto sound = processor->getSound(); + + if (sound == nullptr) + { + return; + } + + pathLabel.setText(sound->subsoundName(sound->selectedSubsound()), dontSendNotification); + pathLabel.setColour(Label::textColourId, Colours::black); + hideProgress(); + showing = showingSubsound; + } + + void SFZeroEditor::showProgress() + { + auto processor = getProcessor(); + + pathLabel.setVisible(false); + infoLabel.setVisible(false); + progressBar = new ProgressBar(processor->loadProgress); + addAndMakeVisible(progressBar); + int marginedWidth = getWidth() - 2 * hMargin; + progressBar->setBounds(hMargin, vMargin + labelHeight, marginedWidth, progressBarHeight); + showing = showingProgress; + } + + void SFZeroEditor::hideProgress() + { + if (progressBar == nullptr) + { + return; + } + + removeChildComponent(progressBar); + delete progressBar; + progressBar = nullptr; + + pathLabel.setVisible(true); + infoLabel.setVisible(true); } - } - - if (showingInfo == showingVoiceInfo) - { - showVoiceInfo(); - } -} - -void sfzero::SFZeroEditor::chooseFile() -{ - FileChooser chooser("Select an SFZ file...", File::nonexistent, "*.sfz;*.SFZ;*.sf2;*.SF2"); - - if (chooser.browseForFileToOpen()) - { - File sfzFile(chooser.getResult()); - setFile(&sfzFile); - } -} - -void sfzero::SFZeroEditor::setFile(File *newFile) -{ - auto processor = getProcessor(); - - processor->setSfzFileThreaded(newFile); - - updateFile(newFile); - showProgress(); -} - -void sfzero::SFZeroEditor::updateFile(File *file) -{ - fileLabel.setText(file->getFileName(), dontSendNotification); - fileLabel.setColour(Label::textColourId, Colours::black); - showPath(); -} - -void sfzero::SFZeroEditor::showSoundInfo() -{ - auto processor = getProcessor(); - auto sound = processor->getSound(); - - if (sound) - { - String info; - auto& errors = sound->getErrors(); - if (errors.size() > 0) - { - info << errors.size() << " errors: \n"; - info << errors.joinIntoString("\n"); - info << "\n"; - } - else - { - info << "no errors.\n\n"; - } - auto& warnings = sound->getWarnings(); - if (warnings.size() > 0) - { - info << warnings.size() << " warnings: \n"; - info << warnings.joinIntoString("\n"); - } - else - { - info << "no warnings.\n"; - } - infoLabel.setText(info, dontSendNotification); - } - showingInfo = showingSoundInfo; -} - -void sfzero::SFZeroEditor::showVoiceInfo() -{ - auto processor = getProcessor(); - - infoLabel.setText(processor->voiceInfoString(), dontSendNotification); - showingInfo = showingVoiceInfo; -} - -void sfzero::SFZeroEditor::showVersion() -{ - auto date = Time::getCompilationDate(); - auto str = String::formatted("SFZero beta %d.%d.%d", date.getYear(), date.getMonth(), date.getDayOfMonth()); - pathLabel.setText(str, dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::grey); - hideProgress(); - showing = showingVersion; -} - -void sfzero::SFZeroEditor::showPath() -{ - auto processor = getProcessor(); - File file = processor->getSfzFile(); - - pathLabel.setText(file.getParentDirectory().getFullPathName(), dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::grey); - hideProgress(); - showing = showingPath; -} - -void sfzero::SFZeroEditor::showSubsound() -{ - auto processor = getProcessor(); - auto sound = processor->getSound(); - - if (sound == nullptr) - { - return; - } - - pathLabel.setText(sound->subsoundName(sound->selectedSubsound()), dontSendNotification); - pathLabel.setColour(Label::textColourId, Colours::black); - hideProgress(); - showing = showingSubsound; -} - -void sfzero::SFZeroEditor::showProgress() -{ - auto processor = getProcessor(); - - pathLabel.setVisible(false); - infoLabel.setVisible(false); - progressBar = new ProgressBar(processor->loadProgress); - addAndMakeVisible(progressBar); - int marginedWidth = getWidth() - 2 * hMargin; - progressBar->setBounds(hMargin, vMargin + labelHeight, marginedWidth, progressBarHeight); - showing = showingProgress; -} - -void sfzero::SFZeroEditor::hideProgress() -{ - if (progressBar == nullptr) - { - return; - } - - removeChildComponent(progressBar); - delete progressBar; - progressBar = nullptr; - - pathLabel.setVisible(true); - infoLabel.setVisible(true); } diff --git a/plugin/Source/SFZeroEditor.h b/plugin/Source/SFZeroEditor.h index c06f885..1a5d7e4 100644 --- a/plugin/Source/SFZeroEditor.h +++ b/plugin/Source/SFZeroEditor.h @@ -5,57 +5,56 @@ #include "ClickableLabel.h" #include "SFZeroAudioProcessor.h" -namespace sfzero +namespace sfzero_plugin { - -class SFZeroEditor : public AudioProcessorEditor, public Timer, public ClickableLabel::ClickListener -{ -public: - SFZeroEditor(SFZeroAudioProcessor *ownerFilter); - ~SFZeroEditor(); - - void paint(Graphics &g) override; - void resized() override; - void labelClicked(Label *clickedLabel) override; - void timerCallback() override; - -protected: - // pathLabel options. - enum - { - showingVersion, - showingPath, - showingProgress, - showingSubsound, - }; - - // infoLabel options. - enum - { - showingSoundInfo, - showingVoiceInfo, - }; - - ClickableLabel fileLabel; - ClickableLabel pathLabel; - ClickableLabel infoLabel; - Viewport viewport; - int showing, showingInfo; - MidiKeyboardComponent midiKeyboard; - ProgressBar *progressBar; - - SFZeroAudioProcessor *getProcessor() const { return static_cast(getAudioProcessor()); } - void chooseFile(); - void setFile(File *newFile); - void updateFile(File *file); - void showSoundInfo(); - void showVoiceInfo(); - void showVersion(); - void showPath(); - void showProgress(); - void hideProgress(); - void showSubsound(); -}; + class SFZeroEditor : public AudioProcessorEditor, public Timer, public ClickableLabel::ClickListener + { + public: + SFZeroEditor(SFZeroAudioProcessor *ownerFilter); + ~SFZeroEditor(); + + void paint(Graphics &g) override; + void resized() override; + void labelClicked(Label *clickedLabel) override; + void timerCallback() override; + + protected: + // pathLabel options. + enum + { + showingVersion, + showingPath, + showingProgress, + showingSubsound, + }; + + // infoLabel options. + enum + { + showingSoundInfo, + showingVoiceInfo, + }; + + ClickableLabel fileLabel; + ClickableLabel pathLabel; + ClickableLabel infoLabel; + Viewport viewport; + int showing, showingInfo; + MidiKeyboardComponent midiKeyboard; + ProgressBar *progressBar; + + SFZeroAudioProcessor *getProcessor() const { return static_cast(getAudioProcessor()); } + void chooseFile(); + void setFile(File *newFile); + void updateFile(File *file); + void showSoundInfo(); + void showVoiceInfo(); + void showVersion(); + void showPath(); + void showProgress(); + void hideProgress(); + void showSubsound(); + }; }