Skip to content

Commit

Permalink
Refactor AudioMixerX to AudioMixer
Browse files Browse the repository at this point in the history
This could be changed again later, as I'm not sure it's a great choice for the class name, but for now it eases development of GUI++

MIDI.ino - updated to 6 voices; fix crash on noteOff for note we couldn't allocate
  • Loading branch information
h4yn0nnym0u5e committed Jan 5, 2022
1 parent 3f23e52 commit af9d85d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
16 changes: 8 additions & 8 deletions OSCAudioAutogen-dynamic.h
Expand Up @@ -1095,12 +1095,12 @@ class OSCAudioInputTDM2 : public AudioInputTDM2, public OSCAudioBase
}
};

// ============== AudioMixer4 ====================
class OSCAudioMixer4 : public AudioMixer4, public OSCAudioBase
// ============== AudioMixer ====================
class OSCAudioMixer : public AudioMixer, public OSCAudioBase
{
public:
OSCAudioMixer4(const char* _name) : OSCAudioBase(_name, (AudioStream*) this) {}
OSCAudioMixer4(const char* _name, OSCAudioGroup& grp) : OSCAudioBase(_name, grp, (AudioStream*) this) {}
OSCAudioMixer(const char* _name,unsigned char ninputs) : AudioMixer(ninputs), OSCAudioBase(_name, (AudioStream*) this) {}
OSCAudioMixer(const char* _name, OSCAudioGroup& grp,unsigned char ninputs) : AudioMixer(ninputs), OSCAudioBase(_name, grp, (AudioStream*) this) {}

void route(OSCMessage& msg, int addrOff, OSCBundle& reply)
{
Expand All @@ -1113,12 +1113,12 @@ class OSCAudioMixer4 : public AudioMixer4, public OSCAudioBase
}
};

// ============== AudioMixerX ====================
class OSCAudioMixerX : public AudioMixerX, public OSCAudioBase
// ============== AudioMixer4 ====================
class OSCAudioMixer4 : public AudioMixer4, public OSCAudioBase
{
public:
OSCAudioMixerX(const char* _name,unsigned char ninputs) : AudioMixerX(ninputs), OSCAudioBase(_name, (AudioStream*) this) {}
OSCAudioMixerX(const char* _name, OSCAudioGroup& grp,unsigned char ninputs) : AudioMixerX(ninputs), OSCAudioBase(_name, grp, (AudioStream*) this) {}
OSCAudioMixer4(const char* _name) : OSCAudioBase(_name, (AudioStream*) this) {}
OSCAudioMixer4(const char* _name, OSCAudioGroup& grp) : OSCAudioBase(_name, grp, (AudioStream*) this) {}

void route(OSCMessage& msg, int addrOff, OSCBundle& reply)
{
Expand Down
25 changes: 13 additions & 12 deletions OSCAudioBase.cpp
Expand Up @@ -43,8 +43,9 @@ OSC_AUDIO_CLASSES
#undef OSC_CLASS

// special cases
OSCAudioBase* mk1_AudioMixerX(const char* nm, unsigned char ninputs) {return (OSCAudioBase*) new OSCAudioMixerX(nm,ninputs);} \
OSCAudioBase* mk2_AudioMixerX(const char* nm, OSCAudioGroup& grp, unsigned char ninputs) {return (OSCAudioBase*) new OSCAudioMixerX(nm,grp,ninputs);}
const char* AudioMixerName = "AudioMixer";
OSCAudioBase* mk1_AudioMixer(const char* nm, unsigned char ninputs) {return (OSCAudioBase*) new OSCAudioMixer(nm,ninputs);} \
OSCAudioBase* mk2_AudioMixer(const char* nm, OSCAudioGroup& grp, unsigned char ninputs) {return (OSCAudioBase*) new OSCAudioMixer(nm,grp,ninputs);}

#define OSC_CLASS(a,o) {#a,mk1_##o,mk2_##o},
const OSCAudioTypes_t OSCAudioBase::audioTypes[] = {
Expand All @@ -65,7 +66,7 @@ const OSCAudioTypes_t OSCAudioBase::audioTypes[] = {
// Return number of available audio objects
size_t OSCAudioBase::countOfAudioTypes(void) {return COUNT_OF(audioTypes);}
#define CONNECTION_INDEX -1 //!< special "object number" denoting AudioConnection rather than AudioStream object type
#define AUDIOMIXERX_INDEX -2 //!< special variable-width mixer
#define AUDIOMIXER_INDEX -2 //!< special variable-width mixer
// ********* end of magic array generator stuff ********************


Expand Down Expand Up @@ -489,9 +490,9 @@ OSCAudioBase::error DynamicAudioCreateObject(int objIdx, //!< index of [OSC]Au
pNewObj = OSCAudioBase::audioTypes[objIdx].mkRoot(objName+1);
break;

case AUDIOMIXERX_INDEX:
case AUDIOMIXER_INDEX:
if (mixerSize > 0)
pNewObj = mk1_AudioMixerX(objName+1,mixerSize);
pNewObj = mk1_AudioMixer(objName+1,mixerSize);
break;

case CONNECTION_INDEX:
Expand All @@ -507,9 +508,9 @@ OSCAudioBase::error DynamicAudioCreateObject(int objIdx, //!< index of [OSC]Au
pNewObj = OSCAudioBase::audioTypes[objIdx].mkGroup(objName+1,*((OSCAudioGroup*) parent));
break;

case AUDIOMIXERX_INDEX:
case AUDIOMIXER_INDEX:
if (mixerSize > 0)
pNewObj = mk2_AudioMixerX(objName+1,*((OSCAudioGroup*) parent),mixerSize);
pNewObj = mk2_AudioMixer(objName+1,*((OSCAudioGroup*) parent),mixerSize);
break;

case CONNECTION_INDEX:
Expand All @@ -527,8 +528,8 @@ OSCAudioBase::error DynamicAudioCreateObject(int objIdx, //!< index of [OSC]Au
name = OSCAudioBase::audioTypes[objIdx].name;
break;

case AUDIOMIXERX_INDEX:
name = "AudioMixerX";
case AUDIOMIXER_INDEX:
name = AudioMixerName;
break;

case CONNECTION_INDEX:
Expand Down Expand Up @@ -571,13 +572,13 @@ void OSCAudioBase::createObject(OSCMessage& msg, int addressOffset, OSCBundle& r
objIdx = OSCAudioBase::getTypeIndex(typ); // see if we've got a valid object type
if (objIdx < 0) // could be a special case: so far we only have one
{
if (msg.isInt(ml) && 0 == strcmp("AudioMixerX",typ)) // last parameter is an integer? variable width mixer?
if (msg.isInt(ml) && 0 == strcmp(AudioMixerName,typ)) // last parameter is an integer? variable width mixer?
mixerSize = msg.getInt(ml); // get mixer width
objIdx = AUDIOMIXERX_INDEX;
objIdx = AUDIOMIXER_INDEX;
isRoot = ml<3;
}

if (objIdx >= 0 || AUDIOMIXERX_INDEX == objIdx) // valid type
if (objIdx >= 0 || AUDIOMIXER_INDEX == objIdx) // valid type
{
msg.getString(1,objName,50);
if (strlen(objName) > 0)
Expand Down
2 changes: 1 addition & 1 deletion dev/OSCAudioMakeA6VoiceSynth.py
Expand Up @@ -90,7 +90,7 @@ def OSCmakeBundle(ell,ttag=1):

if 1:
# create the root-level objects
msgl += [OSCpackAuto('/teensy1/dynamic/crOb','AudioMixerX','mixer',poly)]
msgl += [OSCpackAuto('/teensy1/dynamic/crOb','AudioMixer','mixer',poly)]

# create group and sub-groups
msgl += [OSCpackAuto('/teensy1/dynamic/crGrp','voice1','/')]
Expand Down
7 changes: 4 additions & 3 deletions examples/OSCAudioMIDIgroupsFS/MIDI.ino
Expand Up @@ -76,8 +76,9 @@ void dbgMIDIget(void)

//-----------------------------------------------------
#define AVAIL 0xFF
byte allocate[4];
byte pending[4];
#define VOICES 6
byte allocate[VOICES];
byte pending[VOICES];
// return index in allocate array of available voice,
// or one that's already playing this note. Also
// mark slot as "taken" by this note.
Expand All @@ -98,7 +99,7 @@ int allocateMIDI(byte note)
// was allocated, and mark as available
int deallocateMIDI(byte note)
{
size_t i;
int i;
for (i=COUNT_OF(allocate)-1;i>=0;i--)
if (note == allocate[i])
{
Expand Down

0 comments on commit af9d85d

Please sign in to comment.