Skip to content

Commit

Permalink
Initial commit for configuration TGs and polyphony across RPI1-5.
Browse files Browse the repository at this point in the history
  • Loading branch information
diyelectromusic committed Jul 20, 2024
1 parent 3b033db commit d945b9c
Show file tree
Hide file tree
Showing 13 changed files with 617 additions and 297 deletions.
56 changes: 56 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ void CConfig::Load (void)
{
m_Properties.Load ();

// Number of Tone Generators and Polyphony
m_nToneGenerators = m_Properties.GetNumber ("ToneGenerators", DefToneGenerators);
m_nPolyphony = m_Properties.GetNumber ("Polyphony", DefaultNotes);
// At present there are only two options for tone generators: min or max
// and for the Pi 1,2,3 these are the same anyway.
if ((m_nToneGenerators != MinToneGenerators) && (m_nToneGenerators != AllToneGenerators))
{
m_nToneGenerators = DefToneGenerators;
}
if (m_nPolyphony >= MaxNotes)
{
m_nPolyphony = DefaultNotes;
}

m_bUSBGadget = m_Properties.GetNumber ("USBGadget", 0) != 0;
m_nUSBGadgetPin = m_Properties.GetNumber ("USBGadgetPin", 0); // Default OFF
SetUSBGadgetMode(m_bUSBGadget); // Might get overriden later by USBGadgetPin state
Expand Down Expand Up @@ -177,6 +191,48 @@ void CConfig::Load (void)
m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0);
}

unsigned CConfig::GetToneGenerators (void) const
{
return m_nToneGenerators;
}

unsigned CConfig::GetPolyphony (void) const
{
return m_nPolyphony;
}

unsigned CConfig::GetTGsCore1 (void) const
{
#ifndef ARM_ALLOW_MULTI_CORE
return 0;
#else
if (m_nToneGenerators > MinToneGenerators)
{
return TGsCore1 + TGsCore1Opt;
}
else
{
return TGsCore1;
}
#endif
}

unsigned CConfig::GetTGsCore23 (void) const
{
#ifndef ARM_ALLOW_MULTI_CORE
return 0;
#else
if (m_nToneGenerators > MinToneGenerators)
{
return TGsCore23 + TGsCore23Opt;
}
else
{
return TGsCore23;
}
#endif
}

bool CConfig::GetUSBGadget (void) const
{
return m_bUSBGadget;
Expand Down
48 changes: 44 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,49 @@
class CConfig // Configuration for MiniDexed
{
public:
// Set maximum, minimum and default numbers of tone generators, depending on Pi version.
// Actual number in can be changed via config settings for some Pis.
#ifndef ARM_ALLOW_MULTI_CORE
static const unsigned ToneGenerators = 1;
// Pi V1 or Zero (single core)
static const unsigned MinToneGenerators = 1;
static const unsigned AllToneGenerators = 1;
static const unsigned DefToneGenerators = AllToneGenerators;
#else
#if (RASPPI==4 || RASPPI==5)
// Pi 4 and 5 quad core
// These are max values, default is to support 8 in total with optional 16 TGs
static const unsigned TGsCore1 = 2; // process 2 TGs on core 1
static const unsigned TGsCore23 = 3; // process 3 TGs on core 2 and 3 each
static const unsigned ToneGenerators = TGsCore1 + 2*TGsCore23;
static const unsigned TGsCore1Opt = 2; // process optional additional 2 TGs on core 1
static const unsigned TGsCore23Opt = 3; // process optional additional 3 TGs on core 2 and 3 each
static const unsigned MinToneGenerators = TGsCore1 + 2*TGsCore23;
static const unsigned AllToneGenerators = TGsCore1 + TGsCore1Opt + 2*TGsCore23 + 2*TGsCore23Opt;
static const unsigned DefToneGenerators = MinToneGenerators;
#else
// Pi 2 or 3 quad core
static const unsigned TGsCore1 = 2; // process 2 TGs on core 1
static const unsigned TGsCore23 = 3; // process 3 TGs on core 2 and 3 each
static const unsigned TGsCore1Opt = 0;
static const unsigned TGsCore23Opt = 0;
static const unsigned MinToneGenerators = TGsCore1 + 2*TGsCore23;
static const unsigned AllToneGenerators = MinToneGenerators;
static const unsigned DefToneGenerators = AllToneGenerators;
#endif

#endif

// Set maximum polyphony, depending on PI version. This can be changed via config settings
#if RASPPI == 1
static const unsigned MaxNotes = 8; // polyphony
static const unsigned MaxNotes = 8;
static const unsigned DefaultNotes = 8;
#elif RASPPI == 4
static const unsigned MaxNotes = 24;
static const unsigned DefaultNotes = 16;
#elif RASPPI == 5
static const unsigned MaxNotes = 32;
static const unsigned DefaultNotes = 16;
#else
static const unsigned MaxNotes = 16;
static const unsigned DefaultNotes = 16;
#endif

static const unsigned MaxChunkSize = 4096;
Expand All @@ -67,6 +98,12 @@ class CConfig // Configuration for MiniDexed

void Load (void);

// TGs and Polyphony
unsigned GetToneGenerators (void) const;
unsigned GetPolyphony (void) const;
unsigned GetTGsCore1 (void) const;
unsigned GetTGsCore23 (void) const;

// USB Mode
bool GetUSBGadget (void) const;
unsigned GetUSBGadgetPin (void) const;
Expand Down Expand Up @@ -195,6 +232,9 @@ class CConfig // Configuration for MiniDexed
private:
CPropertiesFatFsFile m_Properties;

unsigned m_nToneGenerators;
unsigned m_nPolyphony;

bool m_bUSBGadget;
unsigned m_nUSBGadgetPin;
bool m_bUSBGadgetMode;
Expand Down
10 changes: 5 additions & 5 deletions src/mididevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CMIDIDevice::CMIDIDevice (CMiniDexed *pSynthesizer, CConfig *pConfig, CUserInter
m_pConfig (pConfig),
m_pUI (pUI)
{
for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++)
for (unsigned nTG = 0; nTG < CConfig::AllToneGenerators; nTG++)
{
m_ChannelMap[nTG] = Disabled;
}
Expand All @@ -78,13 +78,13 @@ CMIDIDevice::~CMIDIDevice (void)

void CMIDIDevice::SetChannel (u8 ucChannel, unsigned nTG)
{
assert (nTG < CConfig::ToneGenerators);
assert (nTG < CConfig::AllToneGenerators);
m_ChannelMap[nTG] = ucChannel;
}

u8 CMIDIDevice::GetChannel (unsigned nTG) const
{
assert (nTG < CConfig::ToneGenerators);
assert (nTG < CConfig::AllToneGenerators);
return m_ChannelMap[nTG];
}

Expand Down Expand Up @@ -238,8 +238,8 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign
break;
}

// Process MIDI for each Tone Generator
for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++)
// Process MIDI for each active Tone Generator
for (unsigned nTG = 0; nTG < m_pConfig->GetToneGenerators(); nTG++)
{
if (ucStatus == MIDI_SYSTEM_EXCLUSIVE_BEGIN)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mididevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CMIDIDevice
CConfig *m_pConfig;
CUserInterface *m_pUI;

u8 m_ChannelMap[CConfig::ToneGenerators];
u8 m_ChannelMap[CConfig::AllToneGenerators];

std::string m_DeviceName;

Expand Down
Loading

0 comments on commit d945b9c

Please sign in to comment.