commit aad6b90117b7db341b4a8fb9b0e4a20c42d1b9cf
parent 5076a43da48372806b6e34d5fda71b0188b5b2ed
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Thu, 21 Jul 2016 12:37:54 -0400
Middleware: Add File Search OSC Ports
Diffstat:
1 file changed, 60 insertions(+), 0 deletions(-)
diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp
@@ -838,6 +838,24 @@ class MwDataObj:public rtosc::RtData
MiddleWareImpl *mwi;
};
+static std::vector<std::string> getFiles(const char *folder, int mask)
+{
+ DIR *dir = opendir(folder);
+
+ if(dir == NULL) {
+ return {};
+ }
+
+ struct dirent *fn;
+ std::vector<string> files;
+
+ while((fn = readdir(dir)))
+ if(fn->d_type == mask)
+ files.push_back(fn->d_name);
+
+ closedir(dir);
+ return files;
+}
@@ -1157,6 +1175,48 @@ static rtosc::Ports middwareSnoopPorts = {
const char *file = rtosc_argument(msg,1).s;
impl.savePart(part_id, file);
rEnd},
+ {"file_home_dir:", 0, 0,
+ rBegin;
+ d.reply(d.loc, "s", getenv("HOME"));
+ rEnd},
+ {"file_list_files:s", 0, 0,
+ rBegin;
+ const char *folder = rtosc_argument(msg, 0).s;
+
+ auto files = getFiles(folder, DT_REG);
+
+ const int N = files.size();
+ rtosc_arg_t *args = new rtosc_arg_t[N];
+ char *types = new char[N+1];
+ types[N] = 0;
+ for(int i=0; i<N; ++i) {
+ args[i].s = files[i].c_str();
+ types[i] = 's';
+ }
+
+ d.replyArray(d.loc, types, args);
+ delete [] types;
+ delete [] args;
+ rEnd},
+ {"file_list_dirs:s", 0, 0,
+ rBegin;
+ const char *folder = rtosc_argument(msg, 0).s;
+
+ auto files = getFiles(folder, DT_DIR);
+
+ const int N = files.size();
+ rtosc_arg_t *args = new rtosc_arg_t[N];
+ char *types = new char[N+1];
+ types[N] = 0;
+ for(int i=0; i<N; ++i) {
+ args[i].s = files[i].c_str();
+ types[i] = 's';
+ }
+
+ d.replyArray(d.loc, types, args);
+ delete [] types;
+ delete [] args;
+ rEnd},
{"reload_auto_save:i", 0, 0,
rBegin
const int save_id = rtosc_argument(msg,0).i;