Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Supporting JUCE-level track info #144

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/GainPlugin/GainPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ void GainPlugin::setStateInformation(const void *data, int sizeInBytes)
vts.replaceState(juce::ValueTree::fromXml(*xmlState));
}

void GainPlugin::updateTrackProperties(const TrackProperties &properties)
{
trackProperties = properties;
if (updateEditor)
updateEditor();
}

void GainPlugin::paramIndicationSetMapping(const juce::RangedAudioParameter &param,
bool has_mapping, const juce::Colour *colour,
const juce::String &label,
Expand Down
7 changes: 7 additions & 0 deletions examples/GainPlugin/GainPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class GainPlugin : public juce::AudioProcessor,
void getStateInformation(juce::MemoryBlock &data) override;
void setStateInformation(const void *data, int sizeInBytes) override;

void updateTrackProperties(const TrackProperties &properties) override;

bool supportsParamIndication() const noexcept override { return true; }
void paramIndicationSetMapping(const juce::RangedAudioParameter &param, bool has_mapping,
const juce::Colour *colour, const juce::String &label,
Expand All @@ -51,6 +53,9 @@ class GainPlugin : public juce::AudioProcessor,
juce::String getPluginTypeString() const;
auto *getGainParameter() { return gainDBParameter; }
auto &getValueTreeState() { return vts; }
const auto& getTrackProperties() const { return trackProperties; }

std::function<void()> updateEditor = nullptr;

private:
ModulatableFloatParameter *gainDBParameter = nullptr;
Expand All @@ -59,5 +64,7 @@ class GainPlugin : public juce::AudioProcessor,

juce::dsp::Gain<float> gain;

TrackProperties trackProperties{};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GainPlugin)
};
9 changes: 8 additions & 1 deletion examples/GainPlugin/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ PluginEditor::PluginEditor(GainPlugin &plug) : juce::AudioProcessorEditor(plug),
constrainer.setSizeLimits (200, 200, 500, 500);
constrainer.setFixedAspectRatio (1.0);
setConstrainer (&constrainer);

plugin.updateEditor = [this] {
gainSlider->setColour (juce::Slider::rotarySliderFillColourId, plugin.getTrackProperties().colour);
repaint();
};
plugin.updateEditor();
}

PluginEditor::~PluginEditor()
{
auto *gainParameter = plugin.getGainParameter();
plugin.getValueTreeState().removeParameterListener(gainParameter->paramID, this);
plugin.paramIndicationHelper.removeListener(this);
plugin.updateEditor = nullptr;
}

void PluginEditor::resized()
Expand All @@ -83,7 +90,7 @@ void PluginEditor::paint(juce::Graphics &g)
g.setColour(juce::Colours::black);
g.setFont(25.0f);
const auto titleBounds = getLocalBounds().removeFromTop(30);
const auto titleText = "Gain Plugin " + plugin.getPluginTypeString();
const auto titleText = "Gain Plugin " + plugin.getPluginTypeString() + " (" + plugin.getTrackProperties().name + ")";
g.drawFittedText(titleText, titleBounds, juce::Justification::centred, 1);

if (auto *paramIndicatorInfo =
Expand Down
22 changes: 22 additions & 0 deletions src/wrapper/clap-juce-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,28 @@ class ClapJuceWrapper : public clap::helpers::Plugin<
return false;
}

bool implementsTrackInfo() const noexcept override { return true; }

void trackInfoChanged() noexcept override
{
clap_track_info clapTrackInfo {};
if (_host.trackInfoGet(&clapTrackInfo))
{
juce::AudioProcessor::TrackProperties juceTrackInfo{};

if (clapTrackInfo.flags & CLAP_TRACK_INFO_HAS_TRACK_NAME)
{
juceTrackInfo.name = juce::CharPointer_UTF8(clapTrackInfo.name);
}
if (clapTrackInfo.flags & CLAP_TRACK_INFO_HAS_TRACK_COLOR)
{
juceTrackInfo.colour = clapColourToJUCEColour(clapTrackInfo.color);
}

processor->updateTrackProperties(juceTrackInfo);
}
}

bool implementsParamIndication() const noexcept override
{
if (processorAsClapExtensions)
Expand Down
Loading