Skip to content

Commit

Permalink
Towards basic missing sample resolution (#1375)
Browse files Browse the repository at this point in the history
Missing samlpes get placed in the sample hierarchy as types
we can reason about and replace. This allows us to detect which
zones have missing samples and beam that to the UI so we can color
things at display time as well as just showing the missing list
error dialog.

Along the way clean up some pragmatic use of tuples and replace
them with some actual structures that stream.

This still doesn't let us *fix* anything. But it lets us identify
the problem spots at least in the UI. More to come soon obviously
  • Loading branch information
baconpaul authored Sep 24, 2024
1 parent f3fda0c commit b9280cf
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 64 deletions.
28 changes: 17 additions & 11 deletions src-ui/app/edit-screen/components/GroupZoneTreeControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "sst/jucegui/components/GlyphButton.h"
#include "sst/jucegui/components/Label.h"
#include "engine/feature_enums.h"

namespace scxt::ui::app::edit_screen
{
Expand All @@ -53,7 +54,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
auto &pgz = sidebar->partGroupSidebar->pgzStructure;
thisGroup.clear();
for (const auto &el : pgz)
if (el.first.part == sidebar->editor->selectedPart && el.first.group >= 0)
if (el.address.part == sidebar->editor->selectedPart && el.address.group >= 0)
thisGroup.push_back(el);
}
int getNumRows() override { return thisGroup.size() + 1; /* for the plus */ }
Expand All @@ -74,7 +75,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
auto &tgl = thisGroup;
if (rowNumber < 0 || rowNumber >= tgl.size())
return {};
auto &sad = tgl[rowNumber].first;
auto &sad = tgl[rowNumber].address;
return sad;
}

Expand Down Expand Up @@ -112,7 +113,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::

const auto &sg = tgl[rowNumber];

bool isLeadZone = isZone() && gsb->isLeadZone(sg.first);
bool isLeadZone = isZone() && gsb->isLeadZone(sg.address);

auto editor = gsb->partGroupSidebar->editor;

Expand Down Expand Up @@ -159,7 +160,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
}
}

if (sg.first.zone < 0)
if (sg.address.zone < 0)
{
g.setColour(fillColor);
g.fillRect(getLocalBounds());
Expand All @@ -170,10 +171,10 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
auto bx = getLocalBounds().withWidth(grouplabelPad);
auto nb = getLocalBounds().withTrimmedLeft(grouplabelPad);
g.setColour(lowTextColor);
g.drawText(std::to_string(sg.first.group + 1), bx,
g.drawText(std::to_string(sg.address.group + 1), bx,
juce::Justification::centredLeft);
g.setColour(textColor);
g.drawText(sg.second, nb, juce::Justification::centredLeft);
g.drawText(sg.name, nb, juce::Justification::centredLeft);

if (dragOverState == DRAG_OVER)
{
Expand Down Expand Up @@ -201,7 +202,12 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
g.drawLine(zonePad, getHeight(), getWidth(), getHeight());

g.setColour(textColor);
g.drawText(sg.second, getLocalBounds().translated(zonePad + 2, 0),
if (sg.features & engine::ZoneFeatures::MISSING_SAMPLE)
{
g.setColour(editor->themeColor(theme::ColorMap::warning_1a));
}

g.drawText(sg.name, getLocalBounds().translated(zonePad + 2, 0),
juce::Justification::centredLeft);

if (isLeadZone)
Expand Down Expand Up @@ -266,7 +272,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::

const auto &sg = tgl[rowNumber];

p.addSectionHeader(sg.second);
p.addSectionHeader(sg.name);
p.addSeparator();
p.addItem("Rename", [w = juce::Component::SafePointer(this)]() {
if (!w)
Expand Down Expand Up @@ -368,12 +374,12 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
const auto &tgl = lbm->thisGroup;

const auto &sg = tgl[rowNumber];
assert(sg.first.zone < 0);
assert(sg.address.zone < 0);
auto st = gsb->partGroupSidebar->style();
auto groupFont = gsb->editor->themeApplier.interRegularFor(11);
renameEditor->setFont(groupFont);
renameEditor->applyFontToAllText(groupFont);
renameEditor->setText(sg.second);
renameEditor->setText(sg.name);
renameEditor->setSelectAllWhenFocused(true);
renameEditor->setIndents(2, 1);
renameEditor->setVisible(true);
Expand All @@ -389,7 +395,7 @@ template <typename SidebarParent, bool fz> struct GroupZoneListBoxModel : juce::
auto zoneFont = gsb->editor->themeApplier.interLightFor(11);
renameEditor->setFont(zoneFont);
renameEditor->applyFontToAllText(zoneFont);
renameEditor->setText(sg.second);
renameEditor->setText(sg.name);
renameEditor->setSelectAllWhenFocused(true);
renameEditor->setIndents(2, 1);
renameEditor->setVisible(true);
Expand Down
2 changes: 1 addition & 1 deletion src-ui/app/edit-screen/components/PartGroupSidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct GroupZoneSidebarBase : juce::Component, HasEditor, juce::DragAndDropConta
int selR = -1;
for (const auto &[i, r] : sst::cpputils::enumerate(listBoxModel->thisGroup))
{
if (r.first == a)
if (r.address == a)
{
rows.addRange({(int)i, (int)(i + 1)});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ void MappingDisplay::setLeadSelection(const selection::SelectionManager::ZoneAdd
bool foundZone{false};
for (const auto &s : summary)
{
if (s.first == za)
if (s.address == za)
{
foundZone = true;
if (mappingZones)
mappingZones->setLeadZoneBounds(s.second);
mappingZones->setLeadZoneBounds(s);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ZoneLayoutDisplay.h"
#include "ZoneLayoutKeyboard.h"
#include "MappingDisplay.h"
#include "engine/feature_enums.h"

namespace scxt::ui::app::edit_screen
{
Expand All @@ -47,16 +48,16 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)

for (auto &z : display->summary)
{
auto r = rectangleForZone(z.second);
auto r = rectangleForZone(z);
if (r.contains(e.position))
{
gotOne = display->editor->isSelected(z.first);
gotOne = display->editor->isSelected(z.address);
if (!gotOne)
{
gotOne = true;
display->editor->doSelectionAction(z.first, true, false, true);
display->editor->doSelectionAction(z.address, true, false, true);
}
za = z.first;
za = z.address;
}
}
if (gotOne)
Expand Down Expand Up @@ -121,10 +122,10 @@ void ZoneLayoutDisplay::mouseDown(const juce::MouseEvent &e)
std::vector<selection::SelectionManager::ZoneAddress> potentialZones;
for (auto &z : display->summary)
{
auto r = rectangleForZone(z.second);
if (r.contains(e.position) && display->editor->isAnyZoneFromGroupSelected(z.first.group))
auto r = rectangleForZone(z);
if (r.contains(e.position) && display->editor->isAnyZoneFromGroupSelected(z.address.group))
{
potentialZones.push_back(z.first);
potentialZones.push_back(z.address);
}
}
selection::SelectionManager::ZoneAddress nextZone;
Expand Down Expand Up @@ -461,9 +462,9 @@ void ZoneLayoutDisplay::mouseUp(const juce::MouseEvent &e)
const auto &sel = *(display->editor->currentLeadZoneSelection);
for (const auto &z : display->summary)
{
if (!(z.first == sel))
if (!(z.address == sel))
continue;
if (rz.intersects(rectangleForZone(z.second)))
if (rz.intersects(rectangleForZone(z)))
selectedLead = true;
}
}
Expand All @@ -472,14 +473,14 @@ void ZoneLayoutDisplay::mouseUp(const juce::MouseEvent &e)
bool first = true;
for (const auto &z : display->summary)
{
if (rz.intersects(rectangleForZone(z.second)))
if (rz.intersects(rectangleForZone(z)))
{
display->editor->doSelectionAction(z.first, true, false, first && firstAsLead);
display->editor->doSelectionAction(z.address, true, false, first && firstAsLead);
first = false;
}
else if (!additiveSelect)
{
display->editor->doSelectionAction(z.first, false, false, false);
display->editor->doSelectionAction(z.address, false, false, false);
}
}
}
Expand Down Expand Up @@ -521,7 +522,8 @@ void ZoneLayoutDisplay::mouseUp(const juce::MouseEvent &e)
juce::Rectangle<float>
ZoneLayoutDisplay::rectangleForZone(const engine::Part::zoneMappingItem_t &sum)
{
const auto &[kb, vel, name] = sum;
const auto &kb = sum.kr;
const auto &vel = sum.vr;
return rectangleForRange(kb.keyStart, kb.keyEnd, vel.velStart, vel.velEnd + 1);
}

Expand Down Expand Up @@ -641,36 +643,49 @@ void ZoneLayoutDisplay::paint(juce::Graphics &g)
{
for (const auto &z : display->summary)
{
if (!display->editor->isAnyZoneFromGroupSelected(z.first.group))
if (!display->editor->isAnyZoneFromGroupSelected(z.address.group))
continue;

if (display->editor->isSelected(z.first) != drawSelected)
if (display->editor->isSelected(z.address) != drawSelected)
continue;

if (z.first == display->editor->currentLeadZoneSelection)
if (z.address == display->editor->currentLeadZoneSelection)
continue;

auto r = rectangleForZone(z.second);
auto r = rectangleForZone(z);

auto borderColor = editor->themeColor(theme::ColorMap::accent_2a);
auto fillColor = editor->themeColor(theme::ColorMap::accent_2b).withAlpha(0.32f);
auto textColor = editor->themeColor(theme::ColorMap::accent_2a);

if (z.features & engine::ZoneFeatures::MISSING_SAMPLE)
{
borderColor = editor->themeColor(theme::ColorMap::warning_1b);
fillColor = editor->themeColor(theme::ColorMap::warning_1b).withAlpha(0.32f);
textColor = editor->themeColor(theme::ColorMap::warning_1a);
}
if (drawSelected)
{
borderColor = editor->themeColor(theme::ColorMap::accent_1b);
fillColor = borderColor.withAlpha(0.32f);
textColor = editor->themeColor(theme::ColorMap::accent_1a);

if (z.features & engine::ZoneFeatures::MISSING_SAMPLE)
{
borderColor = editor->themeColor(theme::ColorMap::warning_1a);
fillColor = editor->themeColor(theme::ColorMap::warning_1a).withAlpha(0.32f);
textColor = editor->themeColor(theme::ColorMap::warning_1a);
}
}

g.setColour(fillColor);
g.fillRect(r);
g.setColour(borderColor);
g.drawRect(r, 1.f);

labelZoneRectangle(g, r, std::get<2>(z.second), textColor);
labelZoneRectangle(g, r, z.name, textColor);

auto ct = display->voiceCountFor(z.first);
auto ct = display->voiceCountFor(z.address);
drawVoiceMarkers(r, ct);
}
}
Expand All @@ -681,12 +696,20 @@ void ZoneLayoutDisplay::paint(juce::Graphics &g)

for (const auto &z : display->summary)
{
if (!(z.first == sel))
if (!(z.address == sel))
continue;

const auto &[kb, vel, name] = z.second;
const auto &kb = z.kr;
const auto &vel = z.vr;
const auto &name = z.name;

auto selZoneColor = editor->themeColor(theme::ColorMap::accent_1a);
auto borderColor = selZoneColor;
if (z.features & engine::ZoneFeatures::MISSING_SAMPLE)
{
selZoneColor = editor->themeColor(theme::ColorMap::warning_1a);
borderColor = editor->themeColor(theme::ColorMap::accent_1a);
}
auto c1{selZoneColor.withAlpha(0.f)};
auto c2{selZoneColor.withAlpha(0.5f)};

Expand Down Expand Up @@ -899,14 +922,13 @@ void ZoneLayoutDisplay::paint(juce::Graphics &g)
}
}
}
auto r = rectangleForZone(z.second);
g.setColour(selZoneColor);
auto r = rectangleForZone(z);
g.setColour(borderColor);
g.drawRect(r, 3.f);

labelZoneRectangle(g, r, std::get<2>(z.second),
editor->themeColor(theme::ColorMap::accent_1a));
labelZoneRectangle(g, r, z.name, editor->themeColor(theme::ColorMap::accent_1a));

auto ct = display->voiceCountFor(z.first);
auto ct = display->voiceCountFor(z.address);
drawVoiceMarkers(r, ct);
}
}
Expand All @@ -929,7 +951,7 @@ void ZoneLayoutDisplay::paint(juce::Graphics &g)

for (const auto &z : display->summary)
{
auto rz = rectangleForZone(z.second);
auto rz = rectangleForZone(z);
if (rz.intersects(r))
{
g.setColour(editor->themeColor(theme::ColorMap::generic_content_high));
Expand Down
4 changes: 2 additions & 2 deletions src-ui/app/editor-impl/SCXTEditorResponseHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ void SCXTEditor::onGroupZoneMappingSummary(const scxt::engine::Part::zoneMapping
if constexpr (scxt::log::uiStructure)
{
SCLOG("Updated zone mapping summary");
for (const auto &[addr, item] : d)
for (const auto &z : d)
{
SCLOG(" " << addr << " " << std::get<2>(item));
SCLOG(" " << z.address << " " << z.name);
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <filesystem>
#include <mutex>
#include "messaging/client/client_serial.h"
#include "feature_enums.h"

namespace scxt::engine
{
Expand Down Expand Up @@ -452,7 +453,13 @@ Engine::pgzStructure_t Engine::getPartGroupZoneStructure() const
int32_t zoneidx{0};
for (const auto &zone : *group)
{
res.push_back({{partidx, groupidx, zoneidx}, zone->getName()});
int32_t zoneFeatures{0};
if (zone->missingSampleCount() > 0)
{
zoneFeatures |= ZoneFeatures::MISSING_SAMPLE;
}

res.push_back({{partidx, groupidx, zoneidx}, zone->getName(), zoneFeatures});
zoneidx++;
}

Expand All @@ -466,7 +473,7 @@ Engine::pgzStructure_t Engine::getPartGroupZoneStructure() const
SCLOG("Returning partgroup structure size " << res.size());

for (const auto &pg : res)
SCLOG(" " << pg.first << " @ " << pg.second);
SCLOG(" " << pg.address << " @ " << pg.name);
}

return res;
Expand Down
9 changes: 7 additions & 2 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,13 @@ struct Engine : MoveableOnly<Engine>, SampleRateSupport
const std::optional<dsp::processor::ProcessorStorage>
getProcessorStorage(const processorAddress_t &addr) const;

typedef std::vector<std::pair<selection::SelectionManager::ZoneAddress, std::string>>
pgzStructure_t;
struct PGZStructureBundle
{
selection::SelectionManager::ZoneAddress address;
std::string name;
int32_t features{0};
};
typedef std::vector<PGZStructureBundle> pgzStructure_t;
/**
* Get the Part/Group/Zone structure as a set o fzone addreses. A part with
* no groups will be (p,-1,-1); a group with no zones will be (p,g,-1).
Expand Down
16 changes: 16 additions & 0 deletions src/engine/feature_enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by Paul Walker on 9/24/24.
//

#ifndef FEATURE_ENUMS_H
#define FEATURE_ENUMS_H

namespace scxt::engine
{
enum ZoneFeatures
{
MISSING_SAMPLE = 1 << 0,
};
}

#endif // FEATURE_ENUMS_H
Loading

0 comments on commit b9280cf

Please sign in to comment.