Skip to content

Commit

Permalink
Add client notification messages (surge-synthesizer#1171)
Browse files Browse the repository at this point in the history
Per surge-synthesizer#1159 we now at least have a serialization thread message
which the engine can send to the UI with an open/close/update
type semantic. We send the messages from SF2 load but we don't do
anything with them other than a SCLOG_ONCE for now. Just some
progress to get in the codebase before I close my laptop.
  • Loading branch information
baconpaul authored Aug 21, 2024
1 parent 0babc62 commit 073eaf5
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src-ui/app/SCXTEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ struct SCXTEditor : sst::jucegui::components::WindowPanel, juce::DragAndDropCont
allProcessors = v;
}

void onActivityNotification(const scxt::messaging::client::activityNotificationPayload_t &);

std::array<std::array<scxt::engine::Macro, scxt::macrosPerPart>, scxt::numParts> macroCache;
void onMacroFullState(const scxt::messaging::client::macroFullState_t &);
void onMacroValue(const scxt::messaging::client::macroValue_t &);
Expand Down
8 changes: 8 additions & 0 deletions src-ui/app/editor-impl/SCXTEditorResponseHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,12 @@ void SCXTEditor::onPartConfiguration(
if (editScreen && editScreen->partSidebar)
editScreen->partSidebar->partConfigurationChanged(pt);
}

void SCXTEditor::onActivityNotification(
const scxt::messaging::client::activityNotificationPayload_t &payload)
{
auto [idx, msg] = payload;
// SCLOG((idx == 1 ? "Open" : (idx == 0 ? "Close" : "Update")) << " [" << msg << "]");
SCLOG_ONCE("Update activity messages currently ignored");
}
} // namespace scxt::ui::app
5 changes: 5 additions & 0 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ void Engine::loadSf2MultiSampleIntoSelectedPart(const fs::path &p)
{
assert(messageController->threadingChecker.isSerialThread());

auto cng = messaging::MessageController::ClientActivityNotificationGuard(
"Loading SF2", *(getMessageController()));

try
{
auto riff = std::make_unique<RIFF::File>(p.u8string());
Expand Down Expand Up @@ -697,6 +700,8 @@ void Engine::loadSf2MultiSampleIntoSelectedPart(const fs::path &p)
if (sfsamp == nullptr)
continue;

messageController->updateClientActivityNotification("Loading sample " +
std::to_string(j));
auto sid = sampleManager->loadSampleFromSF2(p, sf.get(), pc, i, j);
if (!sid.has_value())
continue;
Expand Down
6 changes: 4 additions & 2 deletions src/messaging/client/client_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace scxt::messaging::client
* s2c_send_selection_state
* - Name the object a camelcase version of the enum without s2c,
* so for instance SendSelectionState
* - Make the SCXT Editor callback names onObjectName
* - name the payloads as objectNamePayload_t so sendSelectionStatePayload_t
* - Make the SCXT Editor callback names onSelectionState
* - name the payloads as objectNamePayload_t so selectionStatePayload_t
* if the payload type is a custom type.
*
* C2S:
Expand Down Expand Up @@ -158,6 +158,8 @@ enum SerializationToClientMessageIds
s2c_report_error,
s2c_send_initial_metadata,
s2c_send_debug_info,
s2c_send_activity_notification,

s2c_engine_status,
s2c_update_group_or_zone_adsr_view,
s2c_respond_zone_mapping,
Expand Down
5 changes: 5 additions & 0 deletions src/messaging/client/enginestatus_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ inline void stopSoundsMessage(const stopSounds_t &payload, messaging::MessageCon
});
}
CLIENT_TO_SERIAL(StopSounds, c2s_silence_engine, stopSounds_t, stopSoundsMessage(payload, cont));

// First in here is: -1, show if open, 0, close, 1, show and open
using activityNotificationPayload_t = std::pair<int, std::string>;
SERIAL_TO_CLIENT(SendActivityNotification, s2c_send_activity_notification,
activityNotificationPayload_t, onActivityNotification);
} // namespace scxt::messaging::client

#endif // SHORTCIRCUIT_ENGINESTATUS_MESSAGES_H
19 changes: 19 additions & 0 deletions src/messaging/messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,23 @@ void MessageController::serializationThreadPostAudioQueueDrain()
macroSetValueCompressorUsed = false;
}
}

void MessageController::updateClientActivityNotification(const std::string &msg, int idx)
{
serializationSendToClient(client::s2c_send_activity_notification,
client::activityNotificationPayload_t{idx, msg},
*(engine.getMessageController()));
}

MessageController::ClientActivityNotificationGuard::ClientActivityNotificationGuard(
const std::string &ms, MessageController &m)
: man(m)
{
man.updateClientActivityNotification(ms, 1);
}

MessageController::ClientActivityNotificationGuard::~ClientActivityNotificationGuard()
{
man.updateClientActivityNotification("", 0);
}
} // namespace scxt::messaging
11 changes: 11 additions & 0 deletions src/messaging/messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ struct MessageController : MoveableOnly<MessageController>
streamNotificationConditionVariable.notify_all();
}

/*
* Helping the client know things like a waiting message and so on
*/
void updateClientActivityNotification(const std::string &msg, int idx = -1);
struct ClientActivityNotificationGuard
{
MessageController &man;
ClientActivityNotificationGuard(const std::string &ms, MessageController &m);
~ClientActivityNotificationGuard();
};

private:
uint64_t inboundClientMessageCount{0};
void runSerialization();
Expand Down
2 changes: 1 addition & 1 deletion src/selection/selection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ void SelectionManager::selectAction(
auto zt = z.contiguousFrom;
if (zt < zf)
{
SCLOG("Swapping ZF and ZT");
std::swap(zf, zt);
}
if (zf.part != zt.part)
Expand Down Expand Up @@ -809,4 +808,5 @@ void SelectionManager::clearAllSelections()
g = {};
selectedPart = 0;
}

} // namespace scxt::selection

0 comments on commit 073eaf5

Please sign in to comment.