Skip to content

Commit

Permalink
A rudimentary hookup of group level polyphony
Browse files Browse the repository at this point in the history
Not part yet, only group, but it works
  • Loading branch information
baconpaul committed Oct 24, 2024
1 parent 1b19165 commit 6fdd807
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 17 deletions.
61 changes: 54 additions & 7 deletions src-ui/app/edit-screen/components/GroupSettingsCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#include "GroupSettingsCard.h"
#include "messaging/messaging.h"
#include "app/SCXTEditor.h"

namespace scxt::ui::app::edit_screen
Expand All @@ -36,11 +37,6 @@ GroupSettingsCard::GroupSettingsCard(SCXTEditor *e)
: HasEditor(e), info(e->editorDataCache.groupOutputInfo)
{
using fac = connectors::SingleValueFactory<attachment_t, floatMsg_t>;
editor->editorDataCache.addNotificationCallback(&info,
[w = juce::Component::SafePointer(this)]() {
if (w)
w->rebuildFromInfo();
});

auto mkg = [this](auto gl) {
auto res = std::make_unique<jcmp::GlyphPainter>(gl);
Expand Down Expand Up @@ -68,7 +64,10 @@ GroupSettingsCard::GroupSettingsCard(SCXTEditor *e)
polyGlygh = mkg(jcmp::GlyphPainter::GlyphType::POLYPHONY);
polyMenu = std::make_unique<jcmp::TextPushButton>();
polyMenu->setLabel("PART");
polyMenu->setOnCallback([w = juce::Component::SafePointer(this)]() { SCLOG("POLY MENU"); });
polyMenu->setOnCallback([w = juce::Component::SafePointer(this)]() {
if (w)
w->showPolyMenu();
});
addAndMakeVisible(*polyMenu);

prioGlyph = mkg(jcmp::GlyphPainter::GlyphType::NOTE_PRIORITY);
Expand All @@ -84,6 +83,12 @@ GroupSettingsCard::GroupSettingsCard(SCXTEditor *e)

tuneGlyph = mkg(jcmp::GlyphPainter::GlyphType::TUNING);
tuneDrag = mkd('grtn', "Tune");

editor->editorDataCache.addNotificationCallback(&info,
[w = juce::Component::SafePointer(this)]() {
if (w)
w->rebuildFromInfo();
});
}

void GroupSettingsCard::paint(juce::Graphics &g)
Expand Down Expand Up @@ -132,6 +137,48 @@ void GroupSettingsCard::resized()
ospair(tuneGlyph, tuneDrag);
}

void GroupSettingsCard::rebuildFromInfo() { SCLOG("Rebuild from Info"); }
void GroupSettingsCard::rebuildFromInfo()
{
if (info.hasIndependentPolyLimit)
{
polyMenu->setLabel(std::to_string(info.polyLimit));
}
else
{
polyMenu->setLabel("PART");
}
}

void GroupSettingsCard::showPolyMenu()
{
auto p = juce::PopupMenu();
p.addSectionHeader("Group Voice Polyphony");
p.addSeparator();
p.addItem(
"Part", true, !info.hasIndependentPolyLimit, [w = juce::Component::SafePointer(this)]() {
if (!w)
return;
w->info.hasIndependentPolyLimit = false;

w->rebuildFromInfo();
w->sendToSerialization(messaging::client::UpdateGroupOutputInfoPolyphony{w->info});
});
p.addSeparator();
for (auto pol : {1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64})
{
p.addItem(std::to_string(pol), true, info.hasIndependentPolyLimit && info.polyLimit == pol,
[pol, w = juce::Component::SafePointer(this)]() {
if (!w)
return;
w->info.hasIndependentPolyLimit = true;
w->info.polyLimit = pol;

w->rebuildFromInfo();
w->sendToSerialization(
messaging::client::UpdateGroupOutputInfoPolyphony{w->info});
});
}
p.showMenuAsync(editor->defaultPopupMenuOptions());
}

} // namespace scxt::ui::app::edit_screen
2 changes: 2 additions & 0 deletions src-ui/app/edit-screen/components/GroupSettingsCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct GroupSettingsCard : juce::Component, HasEditor
std::unique_ptr<attachment_t> volAttachment, panAttachment;

engine::Group::GroupOutputInfo &info;

void showPolyMenu();
};
} // namespace scxt::ui::app::edit_screen
#endif // GROUPSETTINGSCARD_H
9 changes: 8 additions & 1 deletion src/engine/engine_voice_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ int32_t Engine::VoiceManagerResponder::beginVoiceCreationTransaction(
auto &z = engine.zoneByPath(path);

voiceCreationWorkingBuffer[voicesCreated] = {path, -1};
buffer[idx].polyphonyGroup = 0;
if (z->parentGroup->outputInfo.hasIndependentPolyLimit)
{
buffer[idx].polyphonyGroup = (uint64_t)z->parentGroup;
}
else
{
buffer[idx].polyphonyGroup = 0;
}
SCLOG_IF(voiceResponder, "-- Created at " << voicesCreated << " - " << path.part << "/"
<< path.group << "/" << path.zone
<< " zone handles variant");
Expand Down
15 changes: 14 additions & 1 deletion src/engine/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ const engine::Engine *Group::getEngine() const
return nullptr;
}

void Group::setupOnUnstream(const engine::Engine &e)
void Group::setupOnUnstream(engine::Engine &e)
{
onRoutingChanged();
rePrepareAndBindGroupMatrix();
Expand Down Expand Up @@ -466,6 +466,7 @@ void Group::setupOnUnstream(const engine::Engine &e)
}

triggerConditions.setupOnUnstream(parentPart->groupTriggerInstrumentState);
resetPolyAndPlaymode(e);
}
void Group::onSampleRateChanged()
{
Expand Down Expand Up @@ -605,5 +606,17 @@ bool Group::isActive() const

void Group::onRoutingChanged() { SCLOG_ONCE("Implement Group LFO modulator use optimization"); }

void Group::resetPolyAndPlaymode(engine::Engine &e)
{
if (!outputInfo.hasIndependentPolyLimit)
{
// TODO we really want a 'clear'
}
else
{
e.voiceManager.setPolyphonyGroupVoiceLimit((uint64_t)this, outputInfo.polyLimit);
}
}

template struct HasGroupZoneProcessors<Group>;
} // namespace scxt::engine
7 changes: 3 additions & 4 deletions src/engine/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ struct Group : MoveableOnly<Group>,
BusAddress routeTo{DEFAULT_BUS};

bool hasIndependentPolyLimit{false};
bool polyLimitIsVoices{true};
int32_t polyLimit{0};

bool isMonoLegato{false};
} outputInfo;

GroupTriggerConditions triggerConditions;
Expand All @@ -105,7 +102,7 @@ struct Group : MoveableOnly<Group>,
template <bool OS> void processWithOS(Engine &onto);
bool lastOversample{true};

void setupOnUnstream(const engine::Engine &e);
void setupOnUnstream(engine::Engine &e);

// ToDo editable name
std::string getName() const { return name; }
Expand Down Expand Up @@ -181,6 +178,8 @@ struct Group : MoveableOnly<Group>,

void onSampleRateChanged() override;

void resetPolyAndPlaymode(engine::Engine &);

sst::filters::HalfRate::HalfRateFilter osDownFilter;

/*
Expand Down
5 changes: 1 addition & 4 deletions src/json/engine_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ SC_STREAMDEF(scxt::engine::Group::GroupOutputInfo, SC_FROM({
{"oversample", t.oversample}, {"velocitySensitivity", t.velocitySensitivity},
{"muted", t.muted}, {"procRouting", t.procRouting},
{"routeTo", (int)t.routeTo}, {"hip", t.hasIndependentPolyLimit},
{"piv", t.polyLimitIsVoices}, {"pl", t.polyLimit},
{"iml", t.isMonoLegato}};
{"pl", t.polyLimit}};
}),
SC_TO({
findIf(v, "amplitude", result.amplitude);
Expand All @@ -290,9 +289,7 @@ SC_STREAMDEF(scxt::engine::Group::GroupOutputInfo, SC_FROM({
int rt{engine::BusAddress::DEFAULT_BUS};
findIf(v, "routeTo", rt);
findIf(v, "hip", result.hasIndependentPolyLimit);
findIf(v, "piv", result.polyLimitIsVoices);
findIf(v, "pl", result.polyLimit);
findIf(v, "iml", result.isMonoLegato);
result.routeTo = (engine::BusAddress)(rt);
}));

Expand Down
1 change: 1 addition & 0 deletions src/messaging/client/client_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ enum ClientToSerializationMessagesIds
c2s_update_group_output_float_value,
c2s_update_group_output_int16_t_value,
c2s_update_group_output_bool_value,
c2s_update_group_output_info_polyphony,

c2s_update_group_trigger_conditions,

Expand Down
18 changes: 18 additions & 0 deletions src/messaging/client/group_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,23 @@ CLIENT_TO_SERIAL(UpdateGroupTriggerConditions, c2s_update_group_trigger_conditio
scxt::engine::GroupTriggerConditions,
doUpdateGroupTriggerConditions(payload, engine, cont));

inline void doUpdateGroupOutputInfoPolyphony(const scxt::engine::Group::GroupOutputInfo payload,
const engine::Engine &engine,
messaging::MessageController &cont)
{
auto ga = engine.getSelectionManager()->currentLeadGroup(engine);
if (ga.has_value())
{
cont.scheduleAudioThreadCallback([p = payload, g = *ga](auto &eng) {
auto &grp = eng.getPatch()->getPart(g.part)->getGroup(g.group);
grp->outputInfo = p;
grp->resetPolyAndPlaymode(eng);
});
}
}
CLIENT_TO_SERIAL(UpdateGroupOutputInfoPolyphony, c2s_update_group_output_info_polyphony,
scxt::engine::Group::GroupOutputInfo,
doUpdateGroupOutputInfoPolyphony(payload, engine, cont));

} // namespace scxt::messaging::client
#endif // SHORTCIRCUIT_GROUP_MESSAGES_H

0 comments on commit 6fdd807

Please sign in to comment.