Skip to content

Commit

Permalink
Move to begin/end transaction around voice initiation (#7)
Browse files Browse the repository at this point in the history
* Move to begin/end transaction around voice initiation

This changes the responder API somewhat from count voices / make voices
to begin transaction / make voices / end transaction with the guarantee
that we will not begin another transaction until end is called. This allows
responders to share internal state over the voice creation while still
allowing the manager a chance to steal etc... although it does change
the public API of the responder.

* format
  • Loading branch information
baconpaul authored Sep 17, 2024
1 parent 56ee211 commit 952a4b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion include/sst/voicemanager/managers/polymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ template <typename Cfg, typename Responder> struct PolyManager
}

auto voicesToBeLaunched =
responder.voiceCountForInitializationAction(port, channel, key, noteid, velocity);
responder.beginVoiceCreationTransaction(port, channel, key, noteid, velocity);

if (voicesToBeLaunched == 0)
{
responder.endVoiceCreationTransaction(port, channel, key, noteid, velocity);
return true;
}

/*
if(voicesToBeLaunched + something > somethingElse)
Expand Down Expand Up @@ -158,10 +161,16 @@ template <typename Cfg, typename Responder> struct PolyManager
}
voicesLeft--;
if (voicesLeft == 0)
{
responder.endVoiceCreationTransaction(port, channel, key, noteid, velocity);

return true;
}
}
}

responder.endVoiceCreationTransaction(port, channel, key, noteid, velocity);

return false;
}

Expand Down
8 changes: 6 additions & 2 deletions tests/basic_poly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ struct ConcreteResp
void retriggerVoiceWithNewNoteID(void *v, int32_t noteid, float velocity) {}

void setVoiceMIDIPitchBend(void *v, uint16_t) {}
int voiceCountForInitializationAction(uint16_t port, uint16_t channel, uint16_t key,
int32_t noteid, float velocity)
int beginVoiceCreationTransaction(uint16_t port, uint16_t channel, uint16_t key, int32_t noteid,
float velocity)
{
return 1;
}
void endVoiceCreationTransaction(uint16_t port, uint16_t channel, uint16_t key, int32_t noteid,
float velocity)
{
}

// Innards
struct Innards
Expand Down

0 comments on commit 952a4b8

Please sign in to comment.