This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

191
guitar/registry.cpp Normal file
View File

@@ -0,0 +1,191 @@
#include <guitar/registry.hpp>
#include <guitar/GlobalDefs.hpp>
Registry::Registry(void)
: mRegistryKeyName(STRING_REGISTRYKEYNAME),
mHistoryKeyName(STRING_HISTORYKEYNAME),
mHistoryKeyShortName(STRING_HISTORYKEYSHORTNAME),
mSettingsKeyName(STRING_SETTINGSKEYNAME),
mRegKeyHistory(RegKey::CurrentUser),
mSettingsAction(STRING_SETTINGSACTION),
mSettingsMicrosecondsPerQuarterNote(STRING_SETTINGSMICROSECONDSPERQUARTERNOTE),
mSettingsInstrument(STRING_SETTINGSINSTRUMENT),
mSettingsNoteLetters(STRING_SETTINGSNOTELETTERS),
mSettingsMIDIOutput(STRING_SETTINGSMIDIOUTPUT)
{
guarantee();
getCacheNames();
}
Registry::Registry(const Registry &someRegistry)
: mRegistryKeyName(STRING_REGISTRYKEYNAME),
mHistoryKeyName(STRING_HISTORYKEYNAME),
mHistoryKeyShortName(STRING_HISTORYKEYSHORTNAME),
mSettingsMIDIOutput(STRING_SETTINGSMIDIOUTPUT),
mRegKeyHistory(RegKey::CurrentUser)
{
*this=someRegistry;
}
Registry::~Registry()
{
}
Registry &Registry::operator=(const Registry &/*registry*/)
{
return *this;
}
void Registry::getCacheNames(void)
{
int itemIndex(0);
String entryName;
DWORD status;
mCachedNames.remove();
while(mRegKeyHistory.enumValue(itemIndex++,entryName,status))mCachedNames.insert(&entryName);
}
void Registry::guarantee(void)
{
if(!mRegKeyHistory.openKey(mHistoryKeyName))
{
mRegKeyHistory.createKey(mHistoryKeyName,"");
mRegKeyHistory.openKey(mHistoryKeyName);
}
if(!mRegKeySettings.openKey(mSettingsKeyName))
{
mRegKeySettings.createKey(mSettingsKeyName,"");
mRegKeySettings.openKey(mSettingsKeyName);
setShowAction(GlobalDefs::ShowAction);
setShowNotes(GlobalDefs::ShowNotes);
setMicrosecondsPerQuarterNote(GlobalDefs::MicrosecondsPerQuarterNote);
setMIDIOutputDevice("MIDIMAPPER");
}
Instrument instrument=getInstrument();
if(!instrument.isOkay())setInstrument(Instruments()[0]);
}
bool Registry::isOkay(void)const
{
return mRegKeyHistory.isOkay();
}
bool Registry::getHistory(Block<String> &nameList)
{
nameList=mCachedNames;
return nameList.size()?TRUE:FALSE;
}
bool Registry::setHistory(Block<String> &nameList)
{
removeHistory();
for(int itemIndex=0;itemIndex<nameList.size();itemIndex++)mRegKeyHistory.setValue(nameList[itemIndex],0);
return nameList.size()?true:false;
}
bool Registry::removeHistory(void)
{
int itemIndex(0);
Block<String> values;
String entryName;
DWORD status;
while(mRegKeyHistory.enumValue(itemIndex++,entryName,status))values.insert(&entryName);
for(int index=0;index<values.size();index++)mRegKeyHistory.deleteValue(values[index]);
return true;
}
bool Registry::insertHistory(const String &strName)
{
for(int itemIndex=0;itemIndex<mCachedNames.size();itemIndex++)if(mCachedNames[itemIndex]==strName)return FALSE;
mCachedNames.insert(&strName);
if(mCachedNames.size()>MaxCachedNames)
{
Block<String> mruCachedNames;
for(int itemIndex=0;itemIndex<MaxCachedNames;itemIndex++)mruCachedNames.insert(&String());
for(itemIndex=0;itemIndex<MaxCachedNames;itemIndex++)mruCachedNames[mruCachedNames.size()-itemIndex-1]=mCachedNames[mCachedNames.size()-itemIndex-1];
mCachedNames=mruCachedNames;
setHistory(mCachedNames);
}
else mRegKeyHistory.setValue(strName,0);
return TRUE;
}
bool Registry::removeHistory(const String &strName)
{
bool found=false;
for(int itemIndex=0;itemIndex<mCachedNames.size();itemIndex++)
{
if(mCachedNames[itemIndex]==strName)
{
found=true;
mCachedNames.remove(itemIndex);
itemIndex=-1;
}
}
if(!found)return false;
setHistory(mCachedNames);
return true;
}
bool Registry::getShowAction(void)const
{
DWORD action;
mRegKeySettings.queryValue(mSettingsAction,action);
return (bool)action;
}
void Registry::setShowAction(bool showAction)
{
mRegKeySettings.setValue(mSettingsAction,(DWORD)showAction);
}
bool Registry::getShowNotes(void)
{
DWORD showNoteLetters;
mRegKeySettings.queryValue(mSettingsNoteLetters,showNoteLetters);
return (bool)showNoteLetters;
}
void Registry::setShowNotes(bool showNoteLetters)
{
mRegKeySettings.setValue(mSettingsNoteLetters,(DWORD)showNoteLetters);
}
String Registry::getMIDIOutputDevice(void)const
{
String midiOutputDevice;
mRegKeySettings.queryValue(mSettingsMIDIOutput,midiOutputDevice);
return midiOutputDevice;
}
void Registry::setMIDIOutputDevice(const String &midiOutputDevice)
{
mRegKeySettings.setValue(mSettingsMIDIOutput,midiOutputDevice);
}
int Registry::getMicrosecondsPerQuarterNote(void)const
{
DWORD microsecondsPerQuarterNote;
mRegKeySettings.queryValue(mSettingsMicrosecondsPerQuarterNote,microsecondsPerQuarterNote);
return microsecondsPerQuarterNote;
}
void Registry::setMicrosecondsPerQuarterNote(int microsecondsPerQuarterNote)
{
mRegKeySettings.setValue(mSettingsMicrosecondsPerQuarterNote,microsecondsPerQuarterNote);
}
Instrument Registry::getInstrument(void)const
{
String strInstrument;
mRegKeySettings.queryValue(mSettingsInstrument,strInstrument);
return Instrument::fromString(strInstrument);
}
void Registry::setInstrument(Instrument instrument)
{
mRegKeySettings.setValue(mSettingsInstrument,instrument.toString());
}