Code cleanup
This commit is contained in:
parent
8c944a49af
commit
0d7213d41a
6 changed files with 15 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
zmidimap
|
zmidimap
|
||||||
obj
|
obj
|
||||||
|
Zmakefile
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public:
|
||||||
bool start_loop();
|
bool start_loop();
|
||||||
void run_signal(char* buff);
|
void run_signal(char* buff);
|
||||||
|
|
||||||
bool import_chunk(ztd::chunkdat const& ch);
|
bool import_chunk(const ztd::chunkdat& ch);
|
||||||
ztd::chunkdat export_chunk();
|
ztd::chunkdat export_chunk();
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,6 @@ void device_check();
|
||||||
|
|
||||||
void announce_loop();
|
void announce_loop();
|
||||||
|
|
||||||
void filetime_loop(std::string filepath);
|
void filetime_loop(std::string const& filepath);
|
||||||
|
|
||||||
#endif //SYSTEM_HPP
|
#endif //SYSTEM_HPP
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ static std::string dequote(const std::string& in)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _isNum(char a)
|
static bool _isNum(const char& a)
|
||||||
{
|
{
|
||||||
return (a>='0' && a<='9');
|
return (a>='0' && a<='9');
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ bool Device::start_loop()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int32_t,int32_t> importRange(ztd::chunkdat const& ch, std::string const& tag, int32_t low, int32_t high)
|
std::pair<int32_t,int32_t> importRange(const ztd::chunkdat& ch, const std::string& tag, int32_t low, int32_t high)
|
||||||
{
|
{
|
||||||
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
||||||
if(pch != nullptr)
|
if(pch != nullptr)
|
||||||
|
|
@ -89,7 +89,7 @@ std::pair<int32_t,int32_t> importRange(ztd::chunkdat const& ch, std::string cons
|
||||||
return std::make_pair(low, high);
|
return std::make_pair(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<float,float> importRangeFloat(ztd::chunkdat const& ch, std::string const& tag, float low, float high)
|
std::pair<float,float> importRangeFloat(const ztd::chunkdat& ch, const std::string& tag, float low, float high)
|
||||||
{
|
{
|
||||||
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
||||||
if(pch != nullptr)
|
if(pch != nullptr)
|
||||||
|
|
@ -113,7 +113,7 @@ std::pair<float,float> importRangeFloat(ztd::chunkdat const& ch, std::string con
|
||||||
return std::make_pair(low, high);
|
return std::make_pair(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool importBool(ztd::chunkdat const& ch, std::string const& tag, bool defbool)
|
bool importBool(const ztd::chunkdat& ch, const std::string& tag, const bool& defbool)
|
||||||
{
|
{
|
||||||
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
ztd::chunkdat* pch=ch.subChunkPtr(tag);
|
||||||
if(pch != nullptr)
|
if(pch != nullptr)
|
||||||
|
|
@ -127,7 +127,7 @@ bool importBool(ztd::chunkdat const& ch, std::string const& tag, bool defbool)
|
||||||
return defbool;
|
return defbool;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::import_chunk(ztd::chunkdat const& ch)
|
bool Device::import_chunk(const ztd::chunkdat& ch)
|
||||||
{
|
{
|
||||||
ztd::chunkdat& cch = ch["commands"];
|
ztd::chunkdat& cch = ch["commands"];
|
||||||
this->name=dequote(ch["name"].strval());
|
this->name=dequote(ch["name"].strval());
|
||||||
|
|
@ -177,13 +177,11 @@ bool Device::import_chunk(ztd::chunkdat const& ch)
|
||||||
uint8_t id_high=127;
|
uint8_t id_high=127;
|
||||||
uint8_t low=1;
|
uint8_t low=1;
|
||||||
uint8_t high=127;
|
uint8_t high=127;
|
||||||
std::string tt;
|
|
||||||
|
|
||||||
//id
|
//id
|
||||||
intpair=importRange(tch, "id", id_low, id_high);
|
intpair=importRange(tch, "id", id_low, id_high);
|
||||||
id_low=intpair.first;
|
id_low=intpair.first;
|
||||||
id_high=intpair.second;
|
id_high=intpair.second;
|
||||||
// id=stoi(tch["id"].strval());
|
|
||||||
|
|
||||||
//trigger
|
//trigger
|
||||||
intpair = importRange(tch, "trigger", low, high);
|
intpair = importRange(tch, "trigger", low, high);
|
||||||
|
|
@ -317,7 +315,7 @@ void Device::run_signal(char* buff)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// throw std::runtime_error("Unknown MIDI signal:\n" + std::string(buff));
|
// throw std::runtime_error("Unknown MIDI signal:\n" + std::string(buff));
|
||||||
printf("Unsupported signal, ignoring\n");
|
std::cerr << "Unsupported signal, ignoring\n" ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,8 @@ int main(int argc, char* argv[])
|
||||||
catch(ztd::option_error& err)
|
catch(ztd::option_error& err)
|
||||||
{
|
{
|
||||||
printf("%s\n", err.what());
|
printf("%s\n", err.what());
|
||||||
|
if(err.type() == ztd::option_error::unknown_option)
|
||||||
|
help();
|
||||||
stop(1);
|
stop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,8 +275,8 @@ int main(int argc, char* argv[])
|
||||||
//main loop
|
//main loop
|
||||||
log("Starting scan for devices\n");
|
log("Starting scan for devices\n");
|
||||||
if(autoreload)
|
if(autoreload)
|
||||||
std::thread(filetime_loop, filepath).detach();
|
std::thread(filetime_loop, filepath).detach(); // start the killer thread
|
||||||
announce_loop();
|
announce_loop(); // loop until killed
|
||||||
ztd::chunkdat bak_data = file.data();
|
ztd::chunkdat bak_data = file.data();
|
||||||
while(autoreload)
|
while(autoreload)
|
||||||
{
|
{
|
||||||
|
|
@ -297,7 +299,7 @@ int main(int argc, char* argv[])
|
||||||
log("Reloading old config\n");
|
log("Reloading old config\n");
|
||||||
load_commands(bak_data);
|
load_commands(bak_data);
|
||||||
}
|
}
|
||||||
announce_loop();
|
announce_loop(); // loop until killed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ztd::format_error& e)
|
catch (ztd::format_error& e)
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ void announce_loop()
|
||||||
free(buff);
|
free(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void filetime_loop(std::string filepath)
|
void filetime_loop(std::string const& filepath)
|
||||||
{
|
{
|
||||||
struct stat attrib;
|
struct stat attrib;
|
||||||
stat(filepath.c_str(), &attrib);
|
stat(filepath.c_str(), &attrib);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue