Skip to content

Commit 580b01a

Browse files
committed
More fixes
1 parent 1a4b6b5 commit 580b01a

10 files changed

Lines changed: 453 additions & 253 deletions

File tree

cmake/yup_standalone.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ function (yup_standalone_app)
102102
list (APPEND additional_libraries perfetto::perfetto)
103103
endif()
104104

105-
_yup_target_list_contains ("${YUP_ARG_MODULES}" yup_audio_plugin_host has_audio_plugin_host)
106-
if (has_audio_plugin_host)
107-
_yup_collect_audio_plugin_host_dependencies ("${YUP_ARG_DEFINITIONS}" audio_plugin_host_libraries)
108-
list (APPEND additional_libraries ${audio_plugin_host_libraries})
105+
if (YUP_PLATFORM_DESKTOP)
106+
_yup_target_list_contains ("${YUP_ARG_MODULES}" yup_audio_plugin_host has_audio_plugin_host)
107+
if (has_audio_plugin_host)
108+
_yup_collect_audio_plugin_host_dependencies ("${YUP_ARG_DEFINITIONS}" audio_plugin_host_libraries)
109+
list (APPEND additional_libraries ${audio_plugin_host_libraries})
110+
endif()
109111
endif()
110112

111113
# ==== Prepare executable

examples/graphics/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,19 @@ endif()
4848

4949
# ==== Prepare target
5050
set (additional_modules "")
51+
set (additional_definitions "")
5152
if (YUP_PLATFORM_DESKTOP AND NOT YUP_PLATFORM_WINDOWS)
5253
set (additional_modules yup::yup_python)
5354
endif()
5455

56+
if (YUP_PLATFORM_DESKTOP)
57+
list (APPEND additional_modules yup::yup_audio_plugin_host)
58+
list (APPEND additional_definitions
59+
YUP_AUDIO_PLUGIN_HOST_ENABLE_CLAP=1
60+
YUP_AUDIO_PLUGIN_HOST_ENABLE_AU=1
61+
YUP_AUDIO_PLUGIN_HOST_ENABLE_VST3=1)
62+
endif()
63+
5564
yup_standalone_app (
5665
TARGET_NAME ${target_name}
5766
TARGET_VERSION ${target_version}
@@ -60,9 +69,7 @@ yup_standalone_app (
6069
TARGET_APP_NAMESPACE "org.yup"
6170
DEFINITIONS
6271
YUP_EXAMPLE_GRAPHICS_RIVE_FILE="${rive_file}"
63-
YUP_AUDIO_PLUGIN_HOST_ENABLE_CLAP=1
64-
YUP_AUDIO_PLUGIN_HOST_ENABLE_AU=1
65-
YUP_AUDIO_PLUGIN_HOST_ENABLE_VST3=1
72+
${additional_definitions}
6673
PRELOAD_FILES
6774
"${CMAKE_CURRENT_LIST_DIR}/${rive_file}@${rive_file}"
6875
MODULES
@@ -76,7 +83,6 @@ yup_standalone_app (
7683
yup::yup_audio_gui
7784
yup::yup_audio_processors
7885
yup::yup_audio_formats
79-
yup::yup_audio_plugin_host
8086
pffft_library
8187
opus_library
8288
flac_library

modules/yup_audio_gui/graph/yup_AudioGraphComponent.cpp

Lines changed: 60 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ namespace yup
2424

2525
namespace
2626
{
27-
constexpr float minZoom = 0.1f;
28-
constexpr float maxZoom = 4.0f;
29-
constexpr float wireHitDistance = 8.0f;
30-
constexpr float dragWireThreshold = 4.0f;
31-
3227
bool endpointsMatch (const AudioGraphEndpoint& a, const AudioGraphEndpoint& b) noexcept
3328
{
3429
return a == b;
@@ -46,6 +41,10 @@ AudioGraphNodeView* findNodeViewForEventSource (Component* source) noexcept
4641
}
4742
} // namespace
4843

44+
//==============================================================================
45+
const Identifier AudioGraphComponent::Style::backgroundColorId ("audioGraphBackground");
46+
const Identifier AudioGraphComponent::Style::gridColorId ("audioGraphGrid");
47+
4948
//==============================================================================
5049
AudioGraphComponent::AudioGraphComponent (std::shared_ptr<AudioGraphProcessor> graphIn)
5150
: graph (std::move (graphIn))
@@ -186,6 +185,44 @@ void AudioGraphComponent::setZoom (float newZoom)
186185
repaint();
187186
}
188187

188+
void AudioGraphComponent::setMinZoom (float newMinZoom)
189+
{
190+
const auto clampedMinZoom = jmax (0.001f, newMinZoom);
191+
if (minZoom == clampedMinZoom)
192+
return;
193+
194+
minZoom = clampedMinZoom;
195+
196+
if (maxZoom < minZoom)
197+
maxZoom = minZoom;
198+
199+
setZoom (zoom);
200+
}
201+
202+
void AudioGraphComponent::setMaxZoom (float newMaxZoom)
203+
{
204+
const auto clampedMaxZoom = jmax (0.001f, newMaxZoom);
205+
if (maxZoom == clampedMaxZoom)
206+
return;
207+
208+
maxZoom = clampedMaxZoom;
209+
210+
if (minZoom > maxZoom)
211+
minZoom = maxZoom;
212+
213+
setZoom (zoom);
214+
}
215+
216+
void AudioGraphComponent::setWireHitDistance (float newWireHitDistance)
217+
{
218+
wireHitDistance = jmax (0.0f, newWireHitDistance);
219+
}
220+
221+
void AudioGraphComponent::setDragWireThreshold (float newDragWireThreshold)
222+
{
223+
dragWireThreshold = jmax (0.0f, newDragWireThreshold);
224+
}
225+
189226
void AudioGraphComponent::setCanvasOffset (Point<float> offset)
190227
{
191228
needsInitialReset = false;
@@ -206,7 +243,7 @@ void AudioGraphComponent::resetView()
206243

207244
needsInitialReset = false;
208245
needsInitialZoomToFit = false;
209-
zoom = 1.0f;
246+
zoom = jlimit (minZoom, maxZoom, 1.0f);
210247

211248
centerViewOnNodes();
212249
}
@@ -307,18 +344,8 @@ void AudioGraphComponent::resized()
307344

308345
void AudioGraphComponent::paint (Graphics& g)
309346
{
310-
g.setFillColor (Color (0xff101522));
311-
g.fillAll();
312-
313-
drawGrid (g);
314-
315-
if (graph != nullptr)
316-
{
317-
for (const auto& connection : graph->getConnections())
318-
drawConnection (g, connection, 1.0f);
319-
}
320-
321-
drawPendingWire (g);
347+
if (auto style = ApplicationTheme::findComponentStyle (*this))
348+
style->paint (g, *ApplicationTheme::getGlobalTheme(), *this);
322349
}
323350

324351
//==============================================================================
@@ -773,6 +800,21 @@ Color AudioGraphComponent::getEndpointColor (const AudioGraphEndpoint& endpoint)
773800
return AudioGraphNodeView::getPortKindColor (AudioGraphNodeView::PortKind::audio);
774801
}
775802

803+
bool AudioGraphComponent::isPendingWireVisible() const noexcept
804+
{
805+
return activeEndpoint.has_value() && (interaction == Interaction::armedPort || interaction == Interaction::draggingWire);
806+
}
807+
808+
std::optional<AudioGraphEndpoint> AudioGraphComponent::getPendingWireEndpoint() const
809+
{
810+
return activeEndpoint;
811+
}
812+
813+
Point<float> AudioGraphComponent::getPendingWireEndPosition() const noexcept
814+
{
815+
return interaction == Interaction::draggingWire ? pendingWireEnd : lastMouseScreen;
816+
}
817+
776818
bool AudioGraphComponent::tryConnect (const AudioGraphEndpoint& first, const AudioGraphEndpoint& second)
777819
{
778820
if (graph == nullptr || ! isCompatiblePair (first, second))
@@ -842,87 +884,6 @@ AudioGraphConnection AudioGraphComponent::makeConnection (const AudioGraphEndpoi
842884
: AudioGraphConnection { second, first };
843885
}
844886

845-
//==============================================================================
846-
void AudioGraphComponent::drawGrid (Graphics& g)
847-
{
848-
const auto spacing = 24.0f * zoom;
849-
if (spacing < 6.0f)
850-
return;
851-
852-
const auto startX = std::fmod (canvasOffset.getX(), spacing);
853-
const auto startY = std::fmod (canvasOffset.getY(), spacing);
854-
855-
g.setFillColor (Colors::white.withAlpha (0.045f));
856-
857-
for (auto x = startX; x < getWidth(); x += spacing)
858-
{
859-
for (auto y = startY; y < getHeight(); y += spacing)
860-
g.fillEllipse (x - 1.0f, y - 1.0f, 2.0f, 2.0f);
861-
}
862-
}
863-
864-
void AudioGraphComponent::drawConnection (Graphics& g, const AudioGraphConnection& connection, float opacity)
865-
{
866-
const auto start = getEndpointScreenPosition (connection.source);
867-
const auto end = getEndpointScreenPosition (connection.destination);
868-
869-
if (! getLocalBounds().reduced (-200.0f).contains (start) && ! getLocalBounds().reduced (-200.0f).contains (end))
870-
return;
871-
872-
const auto controlOffset = jmax (60.0f * zoom, std::abs (end.getX() - start.getX()) * 0.5f);
873-
const auto cp1 = Point<float> { start.getX() + controlOffset, start.getY() };
874-
const auto cp2 = Point<float> { end.getX() - controlOffset, end.getY() };
875-
876-
drawBezierHalf (g, start, cp1, cp2, end, getEndpointColor (connection.source).withMultipliedAlpha (opacity), true);
877-
drawBezierHalf (g, start, cp1, cp2, end, getEndpointColor (connection.destination).withMultipliedAlpha (opacity), false);
878-
}
879-
880-
void AudioGraphComponent::drawBezierHalf (Graphics& g, Point<float> p0, Point<float> p1, Point<float> p2, Point<float> p3, Color color, bool firstHalf)
881-
{
882-
const auto p01 = (p0 + p1) * 0.5f;
883-
const auto p12 = (p1 + p2) * 0.5f;
884-
const auto p23 = (p2 + p3) * 0.5f;
885-
const auto p012 = (p01 + p12) * 0.5f;
886-
const auto p123 = (p12 + p23) * 0.5f;
887-
const auto midpoint = (p012 + p123) * 0.5f;
888-
889-
Path path;
890-
if (firstHalf)
891-
path.moveTo (p0).cubicTo (p01, p012.getX(), p012.getY(), midpoint.getX(), midpoint.getY());
892-
else
893-
path.moveTo (midpoint).cubicTo (p123, p23.getX(), p23.getY(), p3.getX(), p3.getY());
894-
895-
g.setStrokeColor (color);
896-
g.setStrokeWidth (jmax (1.5f, 3.0f * zoom));
897-
g.setStrokeCap (StrokeCap::Round);
898-
g.strokePath (path);
899-
}
900-
901-
void AudioGraphComponent::drawPendingWire (Graphics& g)
902-
{
903-
if (! activeEndpoint.has_value() || (interaction != Interaction::armedPort && interaction != Interaction::draggingWire))
904-
return;
905-
906-
const auto start = getEndpointScreenPosition (*activeEndpoint);
907-
const auto end = interaction == Interaction::draggingWire ? pendingWireEnd : lastMouseScreen;
908-
const auto controlOffset = jmax (60.0f * zoom, std::abs (end.getX() - start.getX()) * 0.5f);
909-
const auto cp1 = Point<float> { start.getX() + (activeEndpoint->isSource() ? controlOffset : -controlOffset), start.getY() };
910-
const auto cp2 = Point<float> { end.getX() - (activeEndpoint->isSource() ? controlOffset : -controlOffset), end.getY() };
911-
912-
Path path;
913-
path.moveTo (start).cubicTo (cp1, cp2.getX(), cp2.getY(), end.getX(), end.getY());
914-
915-
g.setStrokeColor (getEndpointColor (*activeEndpoint).withAlpha (0.55f));
916-
g.setStrokeWidth (jmax (1.5f, 2.5f * zoom));
917-
g.setStrokeCap (StrokeCap::Round);
918-
g.strokePath (path);
919-
920-
g.setFillColor (getEndpointColor (*activeEndpoint).withAlpha (0.20f));
921-
const auto center = getEndpointScreenPosition (*activeEndpoint);
922-
const auto radius = 14.0f * zoom;
923-
g.fillEllipse (center.getX() - radius, center.getY() - radius, radius * 2.0f, radius * 2.0f);
924-
}
925-
926887
Point<float> AudioGraphComponent::cubicPoint (Point<float> p0, Point<float> p1, Point<float> p2, Point<float> p3, float t) const noexcept
927888
{
928889
const auto u = 1.0f - t;

0 commit comments

Comments
 (0)