-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(gain-plugin) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
juce_add_plugin(jive-gain-example | ||
PRODUCT_NAME | ||
"JIVE Gain Example" | ||
VERSION | ||
${PROJECT_VERSION} | ||
FORMATS | ||
Standalone | ||
VST3 | ||
AU | ||
PLUGIN_MANUFACTURER_CODE | ||
Jive | ||
PLUGIN_CODE | ||
Gain | ||
) | ||
|
||
target_sources(jive-gain-example | ||
PUBLIC source/CreatePluginFilter.cpp | ||
source/Processor.h | ||
source/View.h | ||
) | ||
|
||
target_compile_definitions(jive-gain-example | ||
PRIVATE JIVE_IS_PLUGIN_PROJECT=1 | ||
JIVE_GUI_ITEMS_HAVE_STYLE_SHEETS=1 | ||
JUCE_VST3_CAN_REPLACE_VST2=0 | ||
) | ||
|
||
target_link_libraries(jive-gain-example | ||
PRIVATE jive::compiler_and_linker_options | ||
jive::jive_layouts | ||
jive::jive_style_sheets | ||
juce::juce_audio_devices | ||
juce::juce_audio_utils | ||
juce::juce_recommended_config_flags | ||
juce::juce_recommended_lto_flags | ||
juce::juce_recommended_warning_flags | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "Processor.h" | ||
|
||
[[nodiscard]] juce::AudioProcessor* createPluginFilter() | ||
{ | ||
return new jive_example::GainPlugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include "View.h" | ||
|
||
#include <jive_layouts/jive_layouts.h> | ||
#include <juce_audio_processors/juce_audio_processors.h> | ||
|
||
namespace jive_example | ||
{ | ||
class GainPlugin : public juce::AudioProcessor | ||
{ | ||
public: | ||
const juce::String getName() const final | ||
{ | ||
return "JIVE Gain Example"; | ||
} | ||
|
||
void prepareToPlay(double, int) final | ||
{ | ||
if (auto* editor = dynamic_cast<jive::GuiItem*>(getActiveEditor())) | ||
jive::findItemWithID(*editor, "gain-knob")->attachToParameter(apvts.getParameter("gain"), &undoManager); | ||
} | ||
|
||
void releaseResources() final | ||
{ | ||
sliderAttachment = nullptr; | ||
} | ||
|
||
void processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer&) final | ||
{ | ||
buffer.applyGain(juce::Decibels::decibelsToGain<float>(gain)); | ||
} | ||
|
||
double getTailLengthSeconds() const final | ||
{ | ||
return 0.0; | ||
} | ||
|
||
bool acceptsMidi() const final | ||
{ | ||
return false; | ||
} | ||
|
||
bool producesMidi() const final | ||
{ | ||
return false; | ||
} | ||
|
||
juce::AudioProcessorEditor* createEditor() final | ||
{ | ||
auto view = getGainPluginView(); | ||
|
||
if (auto editor = viewInterpreter.interpret(view, this)) | ||
{ | ||
if (dynamic_cast<juce::AudioProcessorEditor*>(editor.get())) | ||
{ | ||
viewInterpreter.listenTo(*editor); | ||
jive::findItemWithID(*editor, "gain-knob")->attachToParameter(apvts.getParameter("gain"), &undoManager); | ||
jive::findItemWithID(*editor, "gain-label")->attachToParameter(apvts.getParameter("gain"), &undoManager); | ||
return dynamic_cast<juce::AudioProcessorEditor*>(editor.release()); | ||
} | ||
} | ||
|
||
return new juce::GenericAudioProcessorEditor{ *this }; | ||
} | ||
|
||
bool hasEditor() const final | ||
{ | ||
return true; | ||
} | ||
|
||
int getNumPrograms() final | ||
{ | ||
return 1; | ||
} | ||
|
||
int getCurrentProgram() final | ||
{ | ||
return 0; | ||
} | ||
|
||
void setCurrentProgram(int) final | ||
{ | ||
} | ||
|
||
const juce::String getProgramName(int) final | ||
{ | ||
return ""; | ||
} | ||
|
||
void changeProgramName(int, const juce::String&) final | ||
{ | ||
} | ||
|
||
void getStateInformation(juce::MemoryBlock&) final | ||
{ | ||
} | ||
|
||
void setStateInformation(const void*, int) final | ||
{ | ||
} | ||
|
||
private: | ||
jive::Interpreter viewInterpreter; | ||
|
||
juce::UndoManager undoManager; | ||
juce::AudioProcessorValueTreeState apvts{ | ||
*this, | ||
&undoManager, | ||
"APVTS", | ||
[]() -> juce::AudioProcessorValueTreeState::ParameterLayout { | ||
return { | ||
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID{ "gain", 1 }, | ||
"Gain", | ||
juce::NormalisableRange<float>{ -12.0f, 12.0f }, | ||
0.0f, | ||
juce::AudioParameterFloatAttributes{} | ||
.withStringFromValueFunction([](float value, int) { | ||
const auto maxLength = value < 0 ? 5 : 4; | ||
return juce::String::toDecimalStringWithSignificantFigures(value, 3) | ||
.paddedRight('0', maxLength) | ||
.substring(0, maxLength); | ||
}) | ||
.withValueFromStringFunction([](const juce::String& text) { | ||
return text.getFloatValue(); | ||
}) | ||
.withCategory(juce::AudioProcessorParameter::Category::outputGain) | ||
.withAutomatable(true)), | ||
}; | ||
}(), | ||
}; | ||
juce::AudioParameterFloat& gain{ | ||
dynamic_cast<juce::AudioParameterFloat&>(*apvts.getParameter("gain")), | ||
}; | ||
std::unique_ptr<juce::SliderParameterAttachment> sliderAttachment; | ||
}; | ||
} // namespace jive_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <jive_core/jive_core.h> | ||
|
||
namespace jive_example | ||
{ | ||
[[nodiscard]] inline auto GainKnob() | ||
{ | ||
return juce::ValueTree{ | ||
"Knob", | ||
{ | ||
{ "id", "gain-knob" }, | ||
{ "width", 80 }, | ||
{ "height", 80 }, | ||
}, | ||
}; | ||
} | ||
|
||
[[nodiscard]] inline auto GainLabel() | ||
{ | ||
return juce::ValueTree{ | ||
"Text", | ||
{ | ||
{ "id", "gain-label" }, | ||
{ | ||
"style", | ||
new jive::Object{ | ||
{ "foreground", "#4BB1D9" }, | ||
{ "font-size", 20 }, | ||
{ "letter-spacing", 1.5 }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
juce::ValueTree{ | ||
"Text", | ||
{ | ||
{ "text", "dB" }, | ||
{ | ||
"style", | ||
new jive::Object{ | ||
{ "font-weight", "bold" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
[[nodiscard]] inline auto getGainPluginView() | ||
{ | ||
return juce::ValueTree{ | ||
"Editor", | ||
{ | ||
{ "width", 400 }, | ||
{ "height", 250 }, | ||
{ "align-items", "centre" }, | ||
{ "justify-content", "centre" }, | ||
{ | ||
"style", | ||
new jive::Object{ | ||
{ "background", "#323D42" }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
GainKnob(), | ||
GainLabel(), | ||
} | ||
}; | ||
} | ||
} // namespace jive_example |