void gBrowser::init(const char *init_path) { gLog("[gBrowser] init path = '%s'\n", init_path); if (init_path == NULL || !gIsDir(init_path)) { #if defined(__linux__) || defined(__APPLE__) path_obj->value("/home"); #elif defined(_WIN32) /* SHGetFolderPath is deprecated. We should use SHGetKnownFolderPath * but that would break compatibility with XP. On Vista, GetFolderPath * is a wrapper of GetKnownFolderPath, so no problem. */ char winRoot[1024]; SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, 0, winRoot); // si parte dal Desktop path_obj->value(winRoot); #endif gLog("[gBrowser] init_path null or invalid, using default\n"); } else path_obj->value(init_path); refresh(); sort(); }
int SampleChannel::load(const char *file) { if (strcmp(file, "") == 0 || gIsDir(file)) { gLog("[SampleChannel] file not specified\n"); return SAMPLE_LEFT_EMPTY; } if (strlen(file) > FILENAME_MAX) return SAMPLE_PATH_TOO_LONG; Wave *w = new Wave(); if (!w->open(file)) { gLog("[SampleChannel] %s: read error\n", file); delete w; return SAMPLE_READ_ERROR; } if (w->channels() > 2) { gLog("[SampleChannel] %s: unsupported multichannel wave\n", file); delete w; return SAMPLE_MULTICHANNEL; } if (!w->readData()) { delete w; return SAMPLE_READ_ERROR; } if (w->channels() == 1) /** FIXME: error checking */ wfx_monoToStereo(w); if (w->rate() != G_Conf.samplerate) { gLog("[SampleChannel] input rate (%d) != system rate (%d), conversion needed\n", w->rate(), G_Conf.samplerate); w->resample(G_Conf.rsmpQuality, G_Conf.samplerate); } pushWave(w); /* sample name must be unique. Start from k = 1, zero is too nerdy */ std::string oldName = wave->name; int k = 1; while (!mh_uniqueSamplename(this, wave->name.c_str())) { wave->updateName((oldName + "-" + gItoa(k)).c_str()); k++; } gLog("[SampleChannel] %s loaded in channel %d\n", file, index); return SAMPLE_LOADED_OK; }
void gBrowser::refresh() { DIR *dp; struct dirent *ep; dp = opendir(path_obj->value()); if (dp != NULL) { while ((ep = readdir(dp))) { /* skip: * - "." e ".." * - hidden files */ if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0) { if (ep->d_name[0] != '.') { /* is it a folder? add square brackets. Is it a file? Append * a '/' (on Windows seems useless, though) */ std::string file = path_obj->value(); file.insert(file.size(), gGetSlash()); file += ep->d_name; if (gIsDir(file.c_str())) { char name[PATH_MAX]; sprintf(name, "@b[%s]", ep->d_name); add(name); } else if (gIsProject(file.c_str())) { char name[PATH_MAX]; sprintf(name, "@i@b%s", ep->d_name); add(name); } else add(ep->d_name); } } } closedir(dp); } else gLog("[gBrowser] Couldn't open the directory '%s'\n", path_obj->value()); }
void gdBrowser::__cb_down() { const char *path = browser->get_selected_item(); if (!path) // when click on an empty area return; if (!gIsDir(path)) { /* set the name of the patch/sample/project as the selected item */ if (type == BROWSER_SAVE_PATCH || type == BROWSER_SAVE_SAMPLE || type == BROWSER_SAVE_PROJECT) { if (gIsProject(path)) { std::string tmp = browser->text(browser->value()); tmp.erase(0, 4); name->value(tmp.c_str()); } else name->value(browser->text(browser->value())); } return; } browser->clear(); browser->down_dir(path); browser->sort(); }