示例#1
0
文件: gd_browser.cpp 项目: rzr/giada
void gdBrowser::__cb_save_project() {

	if (strcmp(name->value(), "") == 0) {    /// FIXME glue business
		gdAlert("Please choose a project name.");
		return;
	}

	/* check if name->value() contains ".gprj" */

	char ext[6] = ".gprj";
	if (strstr(name->value(), ".gprj") != NULL)
		ext[0] = '\0';

	char fullpath[PATH_MAX];
#if defined(_WIN32)
	sprintf(fullpath, "%s\\%s%s", where->value(), name->value(), ext);
#else
	sprintf(fullpath, "%s/%s%s", where->value(), name->value(), ext);
#endif

	if (gIsProject(fullpath) && !gdConfirmWin("Warning", "Project exists: overwrite?"))
		return;

	if (glue_saveProject(fullpath, name->value()))
		do_callback();
	else
		gdAlert("Unable to save the project!");
}
示例#2
0
文件: gd_browser.cpp 项目: rzr/giada
void gdBrowser::__cb_load_patch() {

	if (browser->text(browser->value()) == NULL)
		return;

	/* patchFile is the file to open.
	 * For patches:  browser->get_selected_item()
	 * for projects: browser->get_selected_item() without extention +
	 *               patch name appended */

	std::string patchFile = browser->get_selected_item();;
	bool        isProject;

	if (gIsProject(browser->get_selected_item())) {
		std::string patchName = gGetProjectName(browser->get_selected_item());
#if defined(__linux__) || defined(__APPLE__)
		patchFile = patchFile+"/"+patchName+".gptc";
#elif defined(_WIN32)
		patchFile = patchFile+"\\"+patchName+".gptc";
#endif
		isProject = true;
	}
	else
		isProject = false;

	int res = glue_loadPatch(patchFile.c_str(),	browser->path_obj->value(),	status, isProject);

	if (res == PATCH_UNREADABLE) {
		status->hide();
		if (isProject)
			gdAlert("This project is unreadable.");
		else
			gdAlert("This patch is unreadable.");
	}
	else if (res == PATCH_INVALID) {
		status->hide();
		if (isProject)
			gdAlert("This project is not valid.");
		else
			gdAlert("This patch is not valid.");
	}
	else
		do_callback();
}
示例#3
0
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());
}
示例#4
0
文件: utils.cpp 项目: asd55/giada
bool gIsDir(const char *path)
{
	bool ret;

#if defined(__linux__)

	struct stat s1;
	stat(path, &s1);
	ret = S_ISDIR(s1.st_mode);

#elif defined(__APPLE__)

	if (strcmp(path, "")==0)
		ret = false;
	else {
		struct stat s1;
		stat(path, &s1);
		ret = S_ISDIR(s1.st_mode);

		/* check if ret is a bundle, a special OS X folder which must be
		 * shown as a regular file (VST).
		 * FIXME - consider native functions CFBundle... */

		if (ret) {
			std::string tmp = path;
			tmp += "/Contents/Info.plist";
			if (gFileExists(tmp.c_str()))
				ret = false;
		}
	}

#elif defined(__WIN32)

  unsigned dwAttrib = GetFileAttributes(path);
  ret = (dwAttrib != INVALID_FILE_ATTRIBUTES &&
        (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
#endif

	return ret & !gIsProject(path);
}
示例#5
0
int glue_saveProject(const char *folderPath, const char *projName) {

	if (gIsProject(folderPath)) {
		puts("[glue] the project folder already exists");
		// don't exit
	}
	else if (!gMkdir(folderPath)) {
		puts("[glue] unable to make project directory!");
		return 0;
	}

	/* copy all samples inside the folder. Takes and logical ones are saved
	 * with glue_saveSample() */

	for (int i=0; i<MAX_NUM_CHAN; i++) {

		if (G_Mixer.chan[i] == NULL)
			continue;

		/* update the new samplePath: everything now comes from the project folder */

		char samplePath[PATH_MAX];
		sprintf(samplePath, "%s/%s.wav", folderPath, G_Mixer.chan[i]->name.c_str());

		/* remove any existing file */

		if (gFileExists(samplePath))
			remove(samplePath);
		if (glue_saveSample(i, samplePath))
			G_Mixer.chan[i]->pathfile = samplePath;
	}

	std::string projNameClean = stripExt(projName);
	char gptcPath[PATH_MAX];
	sprintf(gptcPath, "%s/%s.gptc", folderPath, projNameClean.c_str());
	glue_savePatch(gptcPath, projName);

	return 1;
}
示例#6
0
文件: gd_browser.cpp 项目: rzr/giada
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();
}