aboutsummaryrefslogtreecommitdiff
path: root/visualization/renderer/qmpsettingsro.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-30 01:12:38 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-30 01:12:38 +0800
commitbd165c0254b9095bb9e5ea54def56b6404033ebe (patch)
treee6e965ff343c0cd4feea0180dd63522e05085567 /visualization/renderer/qmpsettingsro.cpp
parent8766f3b12e13d40b65eca23a850f687b0043d022 (diff)
downloadQMidiPlayer-bd165c0254b9095bb9e5ea54def56b6404033ebe.tar.xz
Add visualization renderer.
Add API for getting raw pitch bend values. Fix non-compliant RPN handling. The visualization renderer is still at the "proof-of-concept" stage. It's not very usable (yet).
Diffstat (limited to 'visualization/renderer/qmpsettingsro.cpp')
-rw-r--r--visualization/renderer/qmpsettingsro.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/visualization/renderer/qmpsettingsro.cpp b/visualization/renderer/qmpsettingsro.cpp
new file mode 100644
index 0000000..cc6e0bf
--- /dev/null
+++ b/visualization/renderer/qmpsettingsro.cpp
@@ -0,0 +1,167 @@
+#include <QScopedPointer>
+#include <QSettings>
+
+#include "qmpsettingsro.hpp"
+
+qmpSettingsRO::qmpSettingsRO()
+{
+}
+
+void qmpSettingsRO::registerOptionInt(std::string tab,std::string desc,std::string key,int min,int max,int defaultval)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,qmpOptionR::ParameterType::parameter_int,defaultval,min,max);
+}
+int qmpSettingsRO::getOptionInt(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_int)
+ return settings.value(QString(key.c_str()),options[key].defaultval).toInt();
+ return options[key].defaultval.toInt();
+}
+void qmpSettingsRO::setOptionInt(std::string key,int val)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_int)
+ settings.insert(QString(key.c_str()),val);
+}
+
+void qmpSettingsRO::registerOptionUint(std::string tab,std::string desc,std::string key,unsigned min,unsigned max,unsigned defaultval)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,qmpOptionR::ParameterType::parameter_uint,defaultval,min,max);
+}
+unsigned qmpSettingsRO::getOptionUint(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_uint)
+ return settings.value(QString(key.c_str()),options[key].defaultval).toUInt();
+ return options[key].defaultval.toUInt();
+}
+void qmpSettingsRO::setOptionUint(std::string key,unsigned val)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_uint)
+ settings.insert(QString(key.c_str()),val);
+}
+
+void qmpSettingsRO::registerOptionBool(std::string tab,std::string desc,std::string key,bool defaultval)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,qmpOptionR::ParameterType::parameter_bool,defaultval);
+}
+bool qmpSettingsRO::getOptionBool(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_bool)
+ return settings.value(QString(key.c_str()),options[key].defaultval).toBool();
+ return options[key].defaultval.toBool();
+}
+void qmpSettingsRO::setOptionBool(std::string key,bool val)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_bool)
+ settings.insert(QString(key.c_str()),val);
+}
+
+void qmpSettingsRO::registerOptionDouble(std::string tab,std::string desc,std::string key,double min,double max,double defaultval)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,qmpOptionR::ParameterType::parameter_double,defaultval,min,max);
+}
+double qmpSettingsRO::getOptionDouble(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_double)
+ return settings.value(QString(key.c_str()),options[key].defaultval).toDouble();
+ return options[key].defaultval.toDouble();
+}
+void qmpSettingsRO::setOptionDouble(std::string key,double val)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_double)
+ settings.insert(QString(key.c_str()),val);
+}
+
+void qmpSettingsRO::registerOptionString(std::string tab,std::string desc,std::string key,std::string defaultval,bool is_url)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,
+ is_url?qmpOptionR::ParameterType::parameter_url:qmpOptionR::ParameterType::parameter_str,
+ QString(defaultval.c_str()));
+}
+std::string qmpSettingsRO::getOptionString(std::string key)
+{
+ if(options.find(key)!=options.end()&&
+ (options[key].type==qmpOptionR::ParameterType::parameter_str||options[key].type==qmpOptionR::ParameterType::parameter_url))
+ return settings.value(QString(key.c_str()),options[key].defaultval).toString().toStdString();
+ return options[key].defaultval.toString().toStdString();
+}
+void qmpSettingsRO::setOptionString(std::string key,std::string val)
+{
+ if(options.find(key)!=options.end()&&
+ (options[key].type==qmpOptionR::ParameterType::parameter_str||options[key].type==qmpOptionR::ParameterType::parameter_url))
+ settings.insert(QString(key.c_str()),QString(val.c_str()));
+}
+
+void qmpSettingsRO::registerOptionEnumInt(std::string tab,std::string desc,std::string key,std::vector<std::string> enumlist,int defaultval)
+{
+ Q_UNUSED(tab)
+ optionlist.push_back(key);
+ options[key]=qmpOptionR(desc,qmpOptionR::ParameterType::parameter_enum,defaultval);
+ options[key].enumlist=enumlist;
+}
+int qmpSettingsRO::getOptionEnumInt(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_enum)
+ {
+ std::string curitm=settings.value(QString(key.c_str()),options[key].defaultval).toString().toStdString();
+ auto curidx=std::find(options[key].enumlist.begin(),options[key].enumlist.end(),curitm);
+ if(curidx!=options[key].enumlist.end())
+ return static_cast<int>(curidx-options[key].enumlist.begin());
+ else
+ {
+ return options[key].defaultval.toInt();
+ }
+ }
+ return options[key].defaultval.toInt();
+}
+std::string qmpSettingsRO::getOptionEnumIntOptName(std::string key)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_enum)
+ {
+ std::string curitm=settings.value(QString(key.c_str()),options[key].defaultval).toString().toStdString();
+ auto curidx=std::find(options[key].enumlist.begin(),options[key].enumlist.end(),curitm);
+ if(curidx!=options[key].enumlist.end())
+ return curitm;
+ else
+ {
+ return options[key].enumlist[static_cast<size_t>(options[key].defaultval.toInt())];
+ }
+ }
+ return options[key].enumlist[static_cast<size_t>(options[key].defaultval.toInt())];
+}
+void qmpSettingsRO::setOptionEnumInt(std::string key,int val)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_enum)
+ {
+ if(static_cast<size_t>(val)<options[key].enumlist.size())
+ settings.insert(QString(key.c_str()),QString(options[key].enumlist[static_cast<size_t>(val)].c_str()));
+ }
+}
+void qmpSettingsRO::setOptionEnumIntOptName(std::string key,std::string valname)
+{
+ if(options.find(key)!=options.end()&&options[key].type==qmpOptionR::ParameterType::parameter_enum)
+ {
+ auto curidx=std::find(options[key].enumlist.begin(),options[key].enumlist.end(),valname);
+ if(curidx!=options[key].enumlist.end())
+ settings.insert(QString(key.c_str()),QString(valname.c_str()));
+ }
+}
+
+void qmpSettingsRO::load(const char *path)
+{
+ QScopedPointer<QSettings> qsettings(new QSettings(path,QSettings::Format::IniFormat));
+ settings.clear();
+ for(QString&k:qsettings->allKeys())
+ {
+ settings.insert(k,qsettings->value(k));
+ }
+}