Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed May 30, 2024
1 parent a928f3f commit de94ebd
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 37 deletions.
4 changes: 4 additions & 0 deletions cmake/yup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ function (yup_add_module module_path)
"${module_frameworks}"
"${module_dependencies}"
"${module_arc_enabled}")

file (GLOB_RECURSE all_module_files_clap "${module_path}/clap/*")
add_library (${module_name}_clap-module INTERFACE ${all_module_files_clap})
source_group (TREE ${module_path}/clap/ FILES ${all_module_files_clap})
endif()

endfunction()
Expand Down
10 changes: 5 additions & 5 deletions examples/graphics/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ class CustomWindow
setTitle ("main");

for (int i = 0; i < totalRows * totalColumns; ++i)
addAndMakeVisible (sliders.add (std::make_unique<CustomSlider> (i, font)));
addAndMakeVisible (sliders.add (std::make_unique<yup::Slider> (yup::String (i), font)));

button = std::make_unique<TextButton> ("xyz", font);
addAndMakeVisible (*button);
//button = std::make_unique<yup::TextButton> ("xyz", font);
//addAndMakeVisible (*button);

//deviceManager.addAudioCallback (this);
//deviceManager.initialiseWithDefaultDevices (1, 0);
Expand Down Expand Up @@ -464,11 +464,11 @@ class CustomWindow
yup::WaitableEvent renderReady;
int readPos = 0;

yup::OwnedArray<CustomSlider> sliders;
yup::OwnedArray<yup::Slider> sliders;
int totalRows = 4;
int totalColumns = 4;

std::unique_ptr<TextButton> button;
std::unique_ptr<yup::TextButton> button;

yup::Font font;
yup::StyledText styleText;
Expand Down
33 changes: 32 additions & 1 deletion examples/plugin/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ struct Voice
float parameterOffsets[P_COUNT];
};

struct MyEditor : public yup::Component
{
MyEditor (yup::AudioProcessor& processor)
: audioProcessor (processor)
{
x = std::make_unique<yup::Slider> ("Slider", yup::Font());
x->setValue (audioProcessor.getParameter (0).getValue());

x->onValueChanged = [this](float value)
{
audioProcessor.getParameter (0).setValue (value);
};

addAndMakeVisible (*x);
}

void resized() override
{
x->setBounds (getLocalBounds().largestFittingSquare());
}

void paint (yup::Graphics& g) override
{
g.setFillColor (0xff404040);
g.fillAll();
}

yup::AudioProcessor& audioProcessor;
std::unique_ptr<yup::Slider> x;
};

struct MyPlugin : public yup::AudioProcessor
{
float sampleRate;
Expand Down Expand Up @@ -275,7 +306,7 @@ struct MyPlugin : public yup::AudioProcessor

yup::Component* createEditor() override
{
return new yup::Component();
return new MyEditor (*this);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include "../yup_audio_plugin_client.h"

//==============================================================================

#if YUP_AUDIO_PLUGIN_ENABLE_CLAP

#include <string_view>
Expand All @@ -35,6 +33,8 @@ extern "C" yup::AudioProcessor* createPluginProcessor();
namespace yup
{

//==============================================================================

std::optional<MidiMessage> clapEventToMidiNoteMessage (const clap_event_header_t* event)
{
switch (event->type)
Expand All @@ -45,8 +45,6 @@ std::optional<MidiMessage> clapEventToMidiNoteMessage (const clap_event_header_t
const int channel = noteEvent->channel < 0 ? 1 : noteEvent->channel + 1;

return MidiMessage::noteOn (channel, noteEvent->key, static_cast<uint8> (noteEvent->velocity * 127.0f));

break;
}

case CLAP_EVENT_NOTE_OFF:
Expand All @@ -72,6 +70,8 @@ std::optional<MidiMessage> clapEventToMidiNoteMessage (const clap_event_header_t
return std::nullopt;
}

//==============================================================================

void clapEventToParameterChange (const clap_event_header_t* event, AudioProcessor& audioProcessor)
{
if (event->type != CLAP_EVENT_PARAM_VALUE)
Expand All @@ -87,6 +87,8 @@ void clapEventToParameterChange (const clap_event_header_t* event, AudioProcesso
audioProcessor.getParameter (parameterIndex).setValue (parameterValue);
}

//==============================================================================

/*
void pluginSyncMainToAudio (AudioProcessor& audioProcessor, const clap_output_events_t* out)
{
Expand Down Expand Up @@ -169,6 +171,8 @@ static const char* const preferredApi = CLAP_WINDOW_API_WIN32;
static const char* const preferredApi = CLAP_WINDOW_API_X11;
#endif

//==============================================================================

class AudioPluginWrapperCLAP
{
public:
Expand Down Expand Up @@ -210,16 +214,20 @@ class AudioPluginWrapperCLAP

std::unique_ptr<yup::Component> audioProcessorEditor;

static int instancesCount;
static std::atomic_int instancesCount;
};

int AudioPluginWrapperCLAP::instancesCount = 0;
//==============================================================================

std::atomic_int AudioPluginWrapperCLAP::instancesCount = 0;

AudioPluginWrapperCLAP* getWrapper (const clap_plugin_t* plugin)
{
return reinterpret_cast<yup::AudioPluginWrapperCLAP*> (plugin->plugin_data);
}

//==============================================================================

AudioPluginWrapperCLAP::AudioPluginWrapperCLAP (const clap_host_t* host)
: host (host)
{
Expand Down Expand Up @@ -354,10 +362,14 @@ AudioPluginWrapperCLAP::AudioPluginWrapperCLAP (const clap_host_t* host)
};
}

//==============================================================================

AudioPluginWrapperCLAP::~AudioPluginWrapperCLAP()
{
}

//==============================================================================

bool AudioPluginWrapperCLAP::initialise()
{
jassert (audioProcessor == nullptr);
Expand Down Expand Up @@ -558,7 +570,7 @@ bool AudioPluginWrapperCLAP::initialise()
return false;

//wrapper->audioProcessorEditor->setVisible (true);
wrapper->audioProcessorEditor->setSize ({ 600, 400 });
//wrapper->audioProcessorEditor->setSize ({ 600, 400 });

return true;
};
Expand Down Expand Up @@ -608,7 +620,7 @@ bool AudioPluginWrapperCLAP::initialise()
return true;
};

extensionGUI.adjust_size = [] (const clap_plugin_t* plugin, uint32_t *width, uint32_t *height) -> bool
extensionGUI.adjust_size = [] (const clap_plugin_t* plugin, uint32_t* width, uint32_t* height) -> bool
{
auto wrapper = getWrapper (plugin);

Expand Down Expand Up @@ -680,16 +692,20 @@ bool AudioPluginWrapperCLAP::initialise()
return true;
}

//==============================================================================

void AudioPluginWrapperCLAP::destroy()
{
plugin.plugin_data = nullptr;

delete this;
}

//==============================================================================

bool AudioPluginWrapperCLAP::activate (float sampleRate, int samplesPerBlock)
{
if (instancesCount++ == 0)
if (instancesCount.fetch_add(1) == 0)
{
hostTimerSupport = reinterpret_cast<const clap_host_timer_support_t*> (
host->get_extension (host, CLAP_EXT_TIMER_SUPPORT));
Expand All @@ -702,11 +718,13 @@ bool AudioPluginWrapperCLAP::activate (float sampleRate, int samplesPerBlock)
return true;
}

//==============================================================================

void AudioPluginWrapperCLAP::deactivate()
{
audioProcessor->releaseResources();

if (--instancesCount == 0)
if (instancesCount.fetch_sub(1) == 1)
{
if (hostTimerSupport && hostTimerSupport->register_timer)
{
Expand All @@ -716,32 +734,42 @@ void AudioPluginWrapperCLAP::deactivate()
}
}

//==============================================================================

bool AudioPluginWrapperCLAP::startProcessing()
{
return true;
}

//==============================================================================

void AudioPluginWrapperCLAP::stopProcessing()
{
}

//==============================================================================

void AudioPluginWrapperCLAP::reset()
{
audioProcessor->flush();
}

//==============================================================================

const void* AudioPluginWrapperCLAP::getExtension (std::string_view id)
{
if (id == CLAP_EXT_NOTE_PORTS) return std::addressof (extensionNotePorts);
if (id == CLAP_EXT_AUDIO_PORTS) return std::addressof (extensionAudioPorts);
if (id == CLAP_EXT_PARAMS) return std::addressof (extensionParams);
if (id == CLAP_EXT_STATE) return std::addressof (extensionState);
if (id == CLAP_EXT_TIMER_SUPPORT) return std::addressof (extensionTimerSupport);
// if (id == CLAP_EXT_GUI) return std::addressof (extensionGUI);
if (id == CLAP_EXT_GUI) return std::addressof (extensionGUI);

return nullptr;
}

//==============================================================================

const clap_plugin_t* AudioPluginWrapperCLAP::getPlugin() const
{
return std::addressof (plugin);
Expand Down
6 changes: 4 additions & 2 deletions modules/yup_gui/component/yup_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,14 @@ bool Component::isRenderingUnclipped() const

void Component::repaint()
{
getNativeComponent()->repaint (getBounds());
if (auto nativeComponent = getNativeComponent())
nativeComponent->repaint (getBounds());
}

void Component::repaint (const Rectangle<float>& rect)
{
getNativeComponent()->repaint (rect.translated (getBounds().getTopLeft()));
if (auto nativeComponent = getNativeComponent())
nativeComponent->repaint (rect.translated (getBounds().getTopLeft()));
}

//==============================================================================
Expand Down
14 changes: 4 additions & 10 deletions modules/yup_gui/native/yup_Windowing_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,12 @@ GLFWComponentNative::GLFWComponentNative (Component& component, const Flags& fla

auto monitor = component.isFullScreen() ? glfwGetPrimaryMonitor() : nullptr;

window = glfwCreateWindow (jmax (1, screenBounds.getWidth()),
jmax (1, screenBounds.getHeight()),
component.getTitle().toRawUTF8(),
monitor,
nullptr);

window = glfwCreateWindow (1, 1, component.getTitle().toRawUTF8(), monitor, nullptr);
if (window == nullptr)
return;

if (parent != nullptr)
{
setNativeParent (nullptr, parent, window);
}

glfwSetWindowPos (window, screenBounds.getX(), screenBounds.getY());

#if JUCE_MAC
NSWindow* nswindow = glfwGetCocoaWindow (window);
Expand Down Expand Up @@ -504,6 +495,9 @@ GLFWComponentNative::GLFWComponentNative (Component& component, const Flags& fla
#else
startThread (Priority::high);
#endif

handleMoved (screenBounds.getX(), screenBounds.getY());
handleResized (jmax (1, screenBounds.getWidth()), jmax (1, screenBounds.getHeight()));
}

GLFWComponentNative::~GLFWComponentNative()
Expand Down
28 changes: 21 additions & 7 deletions modules/yup_gui/widgets/yup_Slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ namespace yup

//==============================================================================

Slider::Slider (int index, const Font& font)
: index (index)
Slider::Slider (StringRef componentID, const Font& font)
: Component (componentID)
, font (font)
{
setTitle (String (index));
setValue (0.0f);
}

Expand All @@ -38,7 +37,7 @@ void Slider::setValue (float newValue)
{
value = jlimit (0.0f, 1.0f, newValue);

valueChanged();
sendValueChanged();

updateRenderItems (false);
}
Expand Down Expand Up @@ -191,9 +190,24 @@ void Slider::updateRenderItems (bool forceAll)
foregroundLine.clear();
foregroundLine.addLine (Line<float> (pos, center).keepOnlyStart (0.25f));

text.clear();
text.appendText (font, proportionOfHeight(0.1f), proportionOfHeight(0.1f), String (value, 3).toRawUTF8());
text.layout (getLocalBounds().reduced (5).removeFromBottom (proportionOfWidth (0.1f)), StyledText::center);
/*
if (font.getFont() != nullptr)
{
text.clear();
text.appendText (font, proportionOfHeight(0.1f), proportionOfHeight(0.1f), String (value, 3).toRawUTF8());
text.layout (getLocalBounds().reduced (5).removeFromBottom (proportionOfWidth (0.1f)), StyledText::center);
}
*/
}

//==============================================================================

void Slider::sendValueChanged()
{
valueChanged();

if (onValueChanged)
onValueChanged (getValue());
}

} // namespace yup
Loading

0 comments on commit de94ebd

Please sign in to comment.