Skip to content

Commit

Permalink
Delete a Variant (#1419)
Browse files Browse the repository at this point in the history
RMB / Delete on a variant now actually delets it and cleans
up the internal state.

Closes #1236
  • Loading branch information
baconpaul authored Oct 13, 2024
1 parent d1a4949 commit 024680a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,13 @@ void VariantDisplay::showVariantTabMenu(int variantIdx)
{
p.addSectionHeader("Variant " + std::to_string(variantIdx + 1));
p.addSeparator();
;

p.addItem("Copy", editor->makeComingSoon("Copy Variant"));
p.addItem("Delete", editor->makeComingSoon("Delete Variant"));
p.addItem("Delete", [variantIdx, w = juce::Component::SafePointer(this)]() {
if (!w)
return;
w->sendToSerialization(cmsg::DeleteVariant(variantIdx));
});
}
p.showMenuAsync(editor->defaultPopupMenuOptions());
}
Expand Down
15 changes: 15 additions & 0 deletions src/engine/zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,20 @@ int16_t Zone::missingSampleCount() const
return ct;
}

void Zone::deleteVariant(int idx)
{
assert(idx >= 0 && idx < maxVariantsPerZone);
for (int nv = idx + 1; nv < maxVariantsPerZone; ++nv)
{
variantData.variants[nv - 1] = variantData.variants[nv];
samplePointers[nv - 1] = samplePointers[nv];
}
if (idx < maxVariantsPerZone - 1)
{
variantData.variants[maxVariantsPerZone - 1] = {};
samplePointers[maxVariantsPerZone - 1] = {};
}
}

template struct HasGroupZoneProcessors<Zone>;
} // namespace scxt::engine
2 changes: 2 additions & 0 deletions src/engine/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ struct Zone : MoveableOnly<Zone>, HasGroupZoneProcessors<Zone>, SampleRateSuppor
[](const auto &s) { return s.active == false; }));
}

void deleteVariant(int idx);

struct ZoneOutputInfo
{
float amplitude{1.f}, pan{0.f};
Expand Down
2 changes: 2 additions & 0 deletions src/messaging/client/client_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ enum ClientToSerializationMessagesIds
c2s_normalize_variant_amplitude,
c2s_clear_variant_amplitude_normalization,

c2s_delete_variant,

c2s_update_zone_output_float_value,
c2s_update_zone_output_int16_t_value,

Expand Down
24 changes: 24 additions & 0 deletions src/messaging/client/zone_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,30 @@ inline void doAddBlankZone(const addBlankZonePayload_t &payload, engine::Engine
CLIENT_TO_SERIAL(AddBlankZone, c2s_add_blank_zone, addBlankZonePayload_t,
doAddBlankZone(payload, engine, cont));

using deleteVariantPayload_t = int;
inline void doDeleteVariant(const deleteVariantPayload_t &payload, engine::Engine &engine,
MessageController &cont)
{
const auto &samples = payload;
auto sz = engine.getSelectionManager()->currentLeadZone(engine);
if (sz.has_value())
{
auto [ps, gs, zs] = *sz;
cont.scheduleAudioThreadCallback(
[p = ps, g = gs, z = zs, var = payload](auto &eng) {
const auto &zone = eng.getPatch()->getPart(p)->getGroup(g)->getZone(z);
zone->deleteVariant(var);
eng.getSampleManager()->purgeUnreferencedSamples();
},
[p = ps, g = gs, z = zs](auto &e) {
SCLOG_ONCE("Delete variant could be optimized to not sending so much back");
e.sendFullRefreshToClient();
});
}
}
CLIENT_TO_SERIAL(DeleteVariant, c2s_delete_variant, deleteVariantPayload_t,
doDeleteVariant(payload, engine, cont))

} // namespace scxt::messaging::client

#endif // SHORTCIRCUIT_ZONE_MESSAGES_H

0 comments on commit 024680a

Please sign in to comment.