Adding sound-design randomization feature for Performance / FX / Preset / OP

pull/508/head
Vincent GAUCHE 1 year ago
parent 2be4e4af13
commit 3eccb2a9e1
  1. 213
      src/uimenu.cpp
  2. 13
      src/uimenu.h

@ -29,6 +29,9 @@
#include <cmath>
#include <circle/sysconfig.h>
#include <assert.h>
#include <chrono>
#include <dexed.h>
using namespace std;
@ -74,6 +77,7 @@ const CUIMenu::TMenuItem CUIMenu::s_TGMenu[] =
{"Modulation", MenuHandler, s_ModulationMenu},
{"Channel", EditTGParameter, 0, CMiniDexed::TGParameterMIDIChannel},
{"Edit Voice", MenuHandler, s_EditVoiceMenu},
{"Random", CUIMenu::GenerateRandomPreset, nullptr, 0},
{0}
};
@ -130,6 +134,7 @@ const CUIMenu::TMenuItem CUIMenu::s_ReverbMenu[] =
{"Low pass", EditGlobalParameter, 0, CMiniDexed::ParameterReverbLowPass},
{"Diffusion", EditGlobalParameter, 0, CMiniDexed::ParameterReverbDiffusion},
{"Level", EditGlobalParameter, 0, CMiniDexed::ParameterReverbLevel},
{"Random", CUIMenu::GenerateRandomFX, nullptr, 0},
{0}
};
@ -191,6 +196,7 @@ const CUIMenu::TMenuItem CUIMenu::s_OperatorMenu[] =
{"A Mod Sens.", EditOPParameter, 0, DEXED_OP_AMP_MOD_SENS},
{"K Vel. Sens.", EditOPParameter, 0, DEXED_OP_KEY_VEL_SENS},
{"Enable", EditOPParameter, 0, DEXED_OP_ENABLE},
{"Random", CUIMenu::GenerateRandomOperator, nullptr, 0},
{0}
};
@ -317,6 +323,7 @@ const char CUIMenu::s_NoteName[100][4] =
"A8", "A#8", "B8", "C8", "C#8", "D8", "D#8", "E8", "F8", "F#8", "G8", "G#8",
"A9", "A#9", "B9", "C9"
};
static const unsigned NoteC3 = 27;
const CUIMenu::TMenuItem CUIMenu::s_PerformanceMenu[] =
@ -324,10 +331,10 @@ const CUIMenu::TMenuItem CUIMenu::s_PerformanceMenu[] =
{"Load", PerformanceMenu, 0, 0},
{"Save", MenuHandler, s_SaveMenu},
{"Delete", PerformanceMenu, 0, 1},
{"Random", CUIMenu::GenerateRandomPerformance, nullptr, 0},
{0}
};
CUIMenu::CUIMenu(CUserInterface *pUI, CMiniDexed *pMiniDexed)
: m_pUI(pUI),
m_pMiniDexed(pMiniDexed),
@ -419,12 +426,9 @@ void CUIMenu::MenuHandler (CUIMenu *pUIMenu, TMenuEvent Event)
assert(pUIMenu->m_nCurrentMenuDepth < MaxMenuDepth);
pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pParentMenu;
pUIMenu->m_MenuStackMenu[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pCurrentMenu;
pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth]
= pUIMenu->m_nCurrentMenuItem;
pUIMenu->m_nMenuStackSelection[pUIMenu->m_nCurrentMenuDepth]
= pUIMenu->m_nCurrentSelection;
pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth]
= pUIMenu->m_nCurrentParameter;
pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_nCurrentMenuItem;
pUIMenu->m_nMenuStackSelection[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_nCurrentSelection;
pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_nCurrentParameter;
pUIMenu->m_nCurrentMenuDepth++;
pUIMenu->m_pParentMenu = pUIMenu->m_pCurrentMenu;
@ -506,7 +510,8 @@ void CUIMenu::EditGlobalParameter (CUIMenu *pUIMenu, TMenuEvent Event)
const char *pMenuName =
pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth - 1]
[pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth-1]].Name;
[pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth - 1]]
.Name;
string Value = GetGlobalValueString(Param, pUIMenu->m_pMiniDexed->GetParameter(Param));
@ -551,8 +556,7 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
string TG("TG");
TG += to_string(nTG + 1);
string Value = to_string (nValue+1) + "="
+ pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetBankName (nValue);
string Value = to_string(nValue + 1) + "=" + pUIMenu->m_pMiniDexed->GetSysExFileLoader()->GetBankName(nValue);
pUIMenu->m_pUI->DisplayWrite(TG.c_str(),
pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name,
@ -605,18 +609,19 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event)
}
string voiceName = pUIMenu->m_pMiniDexed->GetVoiceName(nTG); // Skip empty voices
if (voiceName == "EMPTY "
|| voiceName == " "
|| voiceName == "----------"
|| voiceName == "~~~~~~~~~~" )
if (voiceName == "EMPTY " || voiceName == " " || voiceName == "----------" || voiceName == "~~~~~~~~~~")
{
if (Event == MenuEventStepUp)
{
if (Event == MenuEventStepUp) {
CUIMenu::EditProgramNumber(pUIMenu, MenuEventStepUp);
}
if (Event == MenuEventStepDown) {
if (Event == MenuEventStepDown)
{
CUIMenu::EditProgramNumber(pUIMenu, MenuEventStepDown);
}
} else {
}
else
{
string TG("TG");
TG += to_string(nTG + 1);
@ -732,7 +737,6 @@ void CUIMenu::EditTGParameter2 (CUIMenu *pUIMenu, TMenuEvent Event) // second me
pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name,
Value.c_str(),
nValue > rParam.Minimum, nValue < rParam.Maximum);
}
void CUIMenu::EditVoiceParameter(CUIMenu *pUIMenu, TMenuEvent Event)
@ -901,7 +905,8 @@ void CUIMenu::SavePerformance (CUIMenu *pUIMenu, TMenuEvent Event)
const char *pMenuName =
pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth - 1]
[pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth-1]].Name;
[pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth - 1]]
.Name;
pUIMenu->m_pUI->DisplayWrite(pMenuName,
pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name,
@ -1016,9 +1021,12 @@ string CUIMenu::ToMIDIChannel (int nValue)
{
switch (nValue)
{
case CMIDIDevice::OmniMode: return "Omni";
case CMIDIDevice::Disabled: return "Off";
default: return to_string (nValue+1);
case CMIDIDevice::OmniMode:
return "Omni";
case CMIDIDevice::Disabled:
return "Off";
default:
return to_string(nValue + 1);
}
}
@ -1102,9 +1110,12 @@ string CUIMenu::ToPortaMode (int nValue)
{
switch (nValue)
{
case 0: return "Fingered";
case 1: return "Full time";
default: return to_string (nValue);
case 0:
return "Fingered";
case 1:
return "Full time";
default:
return to_string(nValue);
}
};
@ -1112,9 +1123,12 @@ string CUIMenu::ToPortaGlissando (int nValue)
{
switch (nValue)
{
case 0: return "Off";
case 1: return "On";
default: return to_string (nValue);
case 0:
return "Off";
case 1:
return "On";
default:
return to_string(nValue);
}
};
@ -1122,9 +1136,12 @@ string CUIMenu::ToPolyMono (int nValue)
{
switch (nValue)
{
case 0: return "Poly";
case 1: return "Mono";
default: return to_string (nValue);
case 0:
return "Poly";
case 1:
return "Mono";
default:
return to_string(nValue);
}
}
@ -1137,8 +1154,7 @@ void CUIMenu::TGShortcutHandler (TMenuEvent Event)
assert(m_nMenuStackItem[1] == nTG);
assert(m_nMenuStackParameter[1] == nTG);
assert ( Event == MenuEventPressAndStepDown
|| Event == MenuEventPressAndStepUp);
assert(Event == MenuEventPressAndStepDown || Event == MenuEventPressAndStepUp);
if (Event == MenuEventPressAndStepDown)
{
nTG--;
@ -1167,8 +1183,7 @@ void CUIMenu::OPShortcutHandler (TMenuEvent Event)
assert(m_nMenuStackItem[m_nCurrentMenuDepth - 1] == nOP);
assert(m_nMenuStackParameter[m_nCurrentMenuDepth - 1] == nOP);
assert ( Event == MenuEventPressAndStepDown
|| Event == MenuEventPressAndStepUp);
assert(Event == MenuEventPressAndStepDown || Event == MenuEventPressAndStepUp);
if (Event == MenuEventPressAndStepDown)
{
nOP--;
@ -1318,7 +1333,6 @@ void CUIMenu::PerformanceMenu (CUIMenu *pUIMenu, TMenuEvent Event)
{
Value = pUIMenu->m_pMiniDexed->GetPerformanceName(nValue);
std::string nPSelected = "";
if (nValue == pUIMenu->m_pMiniDexed->GetActualPerformanceID())
{
@ -1387,7 +1401,6 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
unsigned nPosition = pUIMenu->m_InputTextPosition;
unsigned nChar = pUIMenu->m_InputText[nPosition];
switch (Event)
{
case MenuEventUpdate:
@ -1415,10 +1428,10 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
case MenuEventStepDown:
if (nChar > 32)
{
do {
do
{
--nChar;
}
while (NoValidChars.find(nChar) != std::string::npos);
} while (NoValidChars.find(nChar) != std::string::npos);
}
pUIMenu->m_InputTextChar = nChar;
break;
@ -1426,16 +1439,14 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
case MenuEventStepUp:
if (nChar < 126)
{
do {
do
{
++nChar;
}
while (NoValidChars.find(nChar) != std::string::npos);
} while (NoValidChars.find(nChar) != std::string::npos);
}
pUIMenu->m_InputTextChar = nChar;
break;
case MenuEventSelect:
if (pUIMenu->m_nCurrentParameter == 1)
{
@ -1473,7 +1484,6 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
return;
}
// \E[2;%dH Cursor move to row %1 and column %2 (starting at 1)
// \E[?25h Normal cursor visible
// \E[?25l Cursor invisible
@ -1482,7 +1492,6 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
escCursor += to_string(nPosition + 2);
escCursor += "H";
std::string Value = pUIMenu->m_InputText;
Value[nPosition] = nChar;
pUIMenu->m_InputText = Value;
@ -1494,8 +1503,6 @@ void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event)
Value = Value + " " + escCursor;
pUIMenu->m_pUI->DisplayWrite(MenuTitleR.c_str(), MenuTitleL.c_str(), Value.c_str(), false, false);
}
void CUIMenu::EditTGParameterModulation(CUIMenu *pUIMenu, TMenuEvent Event)
@ -1551,7 +1558,115 @@ void CUIMenu::EditTGParameterModulation (CUIMenu *pUIMenu, TMenuEvent Event)
pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name,
Value.c_str(),
nValue > rParam.Minimum, nValue < rParam.Maximum);
}
// RANDOMIZATION
int CUIMenu::GetRandomValue(int min, int max)
{
static std::mt19937 gen(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
std::uniform_int_distribution<int> dice(min, max);
return dice(gen);
}
void CUIMenu::GenerateRandomOperator(CUIMenu *pUIMenu, TMenuEvent Event)
{
if (Event != TMenuEvent::MenuEventSelect)
{
return;
}
size_t nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth - 3];
size_t nOP = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth - 1];
CUIMenu::GenerateRandomOperatorTG(pUIMenu, nTG, nOP);
}
void CUIMenu::GenerateRandomOperatorTG(CUIMenu *pUIMenu, size_t nTG, size_t nOP)
{
assert(nTG < CConfig::ToneGenerators);
assert(nOP <= OPERATORS::OP6);
for (int nParam = DexedVoiceOPParameters::DEXED_OP_EG_R1; nParam <= DexedVoiceOPParameters::DEXED_OP_OSC_DETUNE; ++nParam)
{
TParameter param = CUIMenu::s_OPParameter[nParam];
uint8_t value = (uint8_t)CUIMenu::GetRandomValue(param.Minimum, param.Maximum);
pUIMenu->m_pMiniDexed->SetVoiceParameter(nParam, value, nOP, nTG);
}
}
void CUIMenu::GenerateRandomVoice(CUIMenu *pUIMenu, size_t nTG)
{
assert(nTG < CConfig::ToneGenerators);
for (size_t nOP = OPERATORS::OP1; nOP <= OPERATORS::OP6; ++nOP)
{
CUIMenu::GenerateRandomOperatorTG(pUIMenu, nTG, nOP);
}
for (int nParam = DexedVoiceParameters::DEXED_PITCH_EG_R1; nParam < DexedVoiceParameters::DEXED_NAME; ++nParam)
{
TParameter param = CUIMenu::s_VoiceParameter[nParam];
uint8_t value = (uint8_t)CUIMenu::GetRandomValue(param.Minimum, param.Maximum);
pUIMenu->m_pMiniDexed->SetVoiceParameter(nParam, value, CMiniDexed::NoOP, nTG);
}
}
void CUIMenu::GenerateRandomPreset(CUIMenu *pUIMenu, TMenuEvent Event)
{
if (Event != TMenuEvent::MenuEventSelect)
{
return;
}
size_t nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth - 1];
CUIMenu::GenerateRandomPresetTG(pUIMenu, nTG);
}
void CUIMenu::GenerateRandomPresetTG(CUIMenu *pUIMenu, size_t nTG)
{
assert(nTG < CConfig::ToneGenerators);
CUIMenu::GenerateRandomVoice(pUIMenu, nTG);
for (int nParam = CMiniDexed::TTGParameter::TGParameterVolume; nParam < CMiniDexed::TTGParameter::TGParameterUnknown; ++nParam)
{
TParameter param = CUIMenu::s_TGParameter[nParam];
uint8_t value = (uint8_t)CUIMenu::GetRandomValue(param.Minimum, param.Maximum);
pUIMenu->m_pMiniDexed->SetTGParameter(static_cast<CMiniDexed::TTGParameter>(nParam), value, nTG);
}
pUIMenu->m_pMiniDexed->SetTGParameter(CMiniDexed::TTGParameter::TGParameterMIDIChannel, CMIDIDevice::OmniMode, nTG);
}
void CUIMenu::GenerateRandomFX(CUIMenu *pUIMenu, TMenuEvent Event)
{
if (Event != TMenuEvent::MenuEventSelect)
{
return;
}
for (int nParam = CMiniDexed::TParameter::ParameterCompressorEnable; nParam < CMiniDexed::TParameter::ParameterUnknown; ++nParam)
{
TParameter param = CUIMenu::s_GlobalParameter[nParam];
uint8_t value = (uint8_t)CUIMenu::GetRandomValue(param.Minimum, param.Maximum);
pUIMenu->m_pMiniDexed->SetParameter(static_cast<CMiniDexed::TParameter>(nParam), value);
}
}
void CUIMenu::GenerateRandomPerformance(CUIMenu *pUIMenu, TMenuEvent Event)
{
if (Event != TMenuEvent::MenuEventSelect)
{
return;
}
for (size_t nTG = 0; nTG < CConfig::ToneGenerators; ++nTG)
{
CUIMenu::GenerateRandomPresetTG(pUIMenu, nTG);
}
CUIMenu::GenerateRandomFX(pUIMenu, Event);
}

@ -25,6 +25,9 @@
#include <string>
#include <circle/timer.h>
#include <cassert>
#include <iostream>
#include <random>
class CMiniDexed;
class CUserInterface;
@ -117,6 +120,15 @@ private:
static void InputTxt(CUIMenu *pUIMenu, TMenuEvent Event);
static void TimerHandlerNoBack(TKernelTimerHandle hTimer, void *pParam, void *pContext);
static int GetRandomValue(int min, int max);
static void GenerateRandomOperator(CUIMenu *pUIMenu, TMenuEvent Event);
static void GenerateRandomOperatorTG(CUIMenu *pUIMenu, size_t nTG, size_t nOp);
static void GenerateRandomVoice(CUIMenu *pUIMenu, size_t nTG);
static void GenerateRandomPreset(CUIMenu *pUIMenu, TMenuEvent Event);
static void GenerateRandomPresetTG(CUIMenu *pUIMenu, size_t nTG);
static void GenerateRandomFX(CUIMenu *pUIMenu, TMenuEvent Event);
static void GenerateRandomPerformance(CUIMenu *pUIMenu, TMenuEvent Event);
private:
CUserInterface *m_pUI;
CMiniDexed *m_pMiniDexed;
@ -163,7 +175,6 @@ private:
bool m_bConfirmDeletePerformance = false;
unsigned m_nSelectedPerformanceID = 0;
bool m_bSplashShow = false;
};
#endif

Loading…
Cancel
Save