Beispiel #1
0
double SelectProjectJob::GetCurrentValue()
{
	int i=-1;
	ReaProject *prj, *curprj=EnumProjects(-1, NULL, 0);
	while (prj = EnumProjects(++i, NULL, 0))
		if (prj == curprj)
			return i;
	return 0.0;
}
Beispiel #2
0
void OpenProjectsFromList(COMMAND_T*)
{
	char cPath[256];
	GetProjectPath(cPath, 256);
	char* filename = BrowseForFiles(__LOCALIZE("Select project list","sws_mbox"), cPath, NULL, false, "Reaper Project List (*.RPL)\0*.RPL\0All Files\0*.*\0");
	if (filename)
	{
		FILE* f = fopenUTF8(filename, "r");
		if (f)
		{
			// Save "prompt on new project" variable
			int iNewProjOpts;
			int sztmp;
			int* pNewProjOpts = (int*)get_config_var("newprojdo", &sztmp);
			iNewProjOpts = *pNewProjOpts;
			*pNewProjOpts = 0;
			int i = 0;

			int iProjects = -1;
			while (EnumProjects(++iProjects, NULL, 0)); // Count projects
			char cName[10];
			EnumProjects(-1, cName, 10);

			if (iProjects != 1 || cName[0] != 0 || GetNumTracks() != 0)
			{
				if (MessageBox(g_hwndParent, __LOCALIZE("Close active tabs first?","sws_mbox"), __LOCALIZE("SWS Project List Open","sws_mbox"), MB_YESNO) == IDYES)
					Main_OnCommand(40886, 0);
				else
					i = 1;
			}

			while(fgets(cPath, 256, f))
			{
				char* pC;
				while((pC = strchr(cPath, '\r'))) *pC = 0; // Strip newlines no matter the format
				while((pC = strchr(cPath, '\n'))) *pC = 0;
				if (cPath[0])
				{
					if (i++)
						Main_OnCommand(41929, 0); // New project tab (ignore default template)
					Main_openProject(cPath);
				}
			}
			fclose(f);

			*pNewProjOpts = iNewProjOpts;
		}
		else
			MessageBox(g_hwndParent, __LOCALIZE("Unable to open file.","sws_mbox"), __LOCALIZE("SWS Project List Open","sws_mbox"), MB_OK);

		free(filename);
	}
}
Beispiel #3
0
void SWS_ProjectListView::GetItemList(SWS_ListItemList* pList)
{
	ReaProject* proj;
	int i = 0;
	while((proj = EnumProjects(i++, NULL, 0)))
		pList->Add((SWS_ListItem*)proj);
}
Beispiel #4
0
void ShowStartupActions(COMMAND_T* _ct)
{
	WDL_FastString msg(__LOCALIZE("No project startup action is defined","sws_startup_action"));
	if (int cmdId = SNM_NamedCommandLookup(g_prjActions.Get()->Get()))
		msg.SetFormatted(512, __LOCALIZE_VERFMT("'%s' is defined as project startup action", "sws_startup_action"), kbd_getTextFromCmd(cmdId, NULL));

	char prjFn[SNM_MAX_PATH] = "";
	EnumProjects(-1, prjFn, sizeof(prjFn));
	if (*prjFn)
	{
		msg.Append("\r\n");
		msg.AppendFormatted(SNM_MAX_PATH, __LOCALIZE_VERFMT("for %s", "sws_startup_action"), prjFn);
	}
	msg.Append(".");
	msg.Append("\r\n\r\n");

	if (int cmdId = SNM_NamedCommandLookup(g_globalAction.Get()))
	{
		msg.AppendFormatted(512, __LOCALIZE_VERFMT("'%s' is defined as global startup action", "sws_startup_action"), kbd_getTextFromCmd(cmdId, NULL));
	}
	else
	{
		msg.Append(__LOCALIZE("No global startup action is defined","sws_startup_action"));
	}
	msg.Append(".");

	MessageBox(GetMainHwnd(), msg.Get(), SWS_CMD_SHORTNAME(_ct), MB_OK);
}
Beispiel #5
0
void RunActionMarker(const char* cName)
{
	if (cName && cName[0] == '!' && !EnumProjects(0x40000000, NULL, 0)) // disabled while rendering (0x40000000 trick == rendered project, if any)
	{
		if (g_bIgnoreNext)
		{	// Ignore the entire marker action
			g_bIgnoreNext = false;
			return;
		}
		LineParser lp(false);
		lp.parse(&cName[1]);
		for (int i = 0; i < lp.getnumtokens(); i++)
		{
			int iCommand = lp.gettoken_int(i);
			if (!iCommand)
				iCommand = NamedCommandLookup(lp.gettoken_str(i));

			if (iCommand)
			{
				int iZero = 0;
				if (!kbd_RunCommandThroughHooks(NULL, &iCommand, &iZero, &iZero, &iZero, g_hwndParent))
				{
					KBD_OnMainActionEx(iCommand, 0, 0, 0, g_hwndParent, NULL);
				}
			}
		}
	}
}
Beispiel #6
0
double SelectProjectJob::GetMaxValue()
{
	int i=0;
	ReaProject *prj;
	while (prj = EnumProjects(i++, NULL, 0));
	return i;
}
Beispiel #7
0
bool IsActiveProjectInLoadSave(char* _projfn, int _projfnSz, bool _ensureRPP)
{
	bool ok = (GetCurrentProjectInLoadSave() == EnumProjects(-1, _projfn, _projfnSz));
	if (_ensureRPP)
	{
		if (!_projfn || !_projfnSz)
		{
			char buf[SNM_MAX_PATH] = "";
			EnumProjects(-1, buf, sizeof(buf));
			ok = HasFileExtension(buf, "RPP");
		}
		else
			ok = HasFileExtension(_projfn, "RPP");
	}
	return ok;
}
Beispiel #8
0
void OpenRelatedProject(COMMAND_T* pCmd)
{
	if ((int)pCmd->user == g_relatedProjects.Get()->GetSize())
		// Give the user the chance to add a related project if they selected the first open spot
		if (MessageBox(g_hwndParent, __LOCALIZE("No related project found. Add one now?","sws_mbox"), __LOCALIZE("SWS Open Related Project","sws_mbox"), MB_YESNO) == IDYES)
			AddRelatedProject();

	if ((int)pCmd->user >= g_relatedProjects.Get()->GetSize())
		return;

	WDL_String* pStr = g_relatedProjects.Get()->Get((int)pCmd->user);
	ReaProject* pProj;
	// See if it's already opened
	char cOpenedProj[256];
	int i = 0;
	while ((pProj = EnumProjects(i++, cOpenedProj, 256)))
	{
		if (_stricmp(cOpenedProj, pStr->Get()) == 0)
		{
			SelectProjectInstance(pProj);
			return;
		}
	}

	// Nope, open in new tab
	// Save "prompt on new project" variable
	int iNewProjOpts;
	int sztmp;
	int* pNewProjOpts = (int*)get_config_var("newprojdo", &sztmp);
	iNewProjOpts = *pNewProjOpts;
	*pNewProjOpts = 0;
	pProj = EnumProjects(-1, NULL, 0);
	Main_OnCommand(41929, 0); // New project tab (ignore default template)
	Main_openProject(pStr->Get());
	EnumProjects(-1, cOpenedProj, 256);
	if (_stricmp(pStr->Get(), cOpenedProj))
	{
		Main_OnCommand(40860, 0); // 40860 = Close current project tab
		SelectProjectInstance(pProj);
		g_relatedProjects.Get()->Delete((int)pCmd->user, true);
	}
	*pNewProjOpts = iNewProjOpts;
}
Beispiel #9
0
// ****************************************************************************
// **** Project list  *********************************************************
// ****************************************************************************
void SaveProjectList(COMMAND_T*)
{
	int i = 0;
	bool bValid = false;
	char filename[256] = { 0, };
	while (EnumProjects(i++, filename, 256))
		if (filename[0])
			bValid = true;
	if (!bValid)
	{
		MessageBox(g_hwndParent, __LOCALIZE("No saved projects are open. Please save your projects first.","sws_mbox"), __LOCALIZE("SWS Project List Save","sws_mbox"), MB_OK);
		return;
	}

	char cPath[256];
	GetProjectPath(cPath, 256);
	if (BrowseForSaveFile(__LOCALIZE("Select project list","sws_mbox"), cPath, NULL, "Reaper Project List (*.RPL)\0*.RPL\0All Files\0*.*\0", filename, 256))
	{
		FILE* f = fopenUTF8(filename, "w");
		if (f)
		{
			i = 0;
			while (EnumProjects(i++, filename, 256))
			{
				if (filename[0])
				{
					strncat(filename, "\r\n", 256);
					fwrite(filename, strlen(filename), 1, f);
				}
			}
			fclose(f);
		}
		else
			MessageBox(g_hwndParent, __LOCALIZE("Unable to write to file.","sws_mbox"), __LOCALIZE("SWS Project List Save","sws_mbox"), MB_OK);
	}
}
Beispiel #10
0
void SetProjectStartupAction(COMMAND_T* _ct)
{
	if (PromptClearProjectStartupAction(false) == IDNO)
		return;

	char idstr[SNM_MAX_ACTION_CUSTID_LEN];
	lstrcpyn(idstr, __LOCALIZE("Paste command ID or identifier string here","sws_mbox"), sizeof(idstr));
	if (PromptUserForString(GetMainHwnd(), SWS_CMD_SHORTNAME(_ct), idstr, sizeof(idstr), true))
	{
		WDL_FastString msg;
		if (int cmdId = SNM_NamedCommandLookup(idstr))
		{
			// more checks: http://forum.cockos.com/showpost.php?p=1252206&postcount=1618
			if (int tstNum = CheckSwsMacroScriptNumCustomId(idstr))
			{
				msg.SetFormatted(256, __LOCALIZE_VERFMT("%s failed: unreliable command ID '%s'!","sws_DLG_161"), SWS_CMD_SHORTNAME(_ct), idstr);
				msg.Append("\n");

				// localization note: msgs shared with the CA editor
				if (tstNum==-1)
					msg.Append(__LOCALIZE("For SWS/S&M actions, you must use identifier strings (e.g. _SWS_ABOUT), not command IDs (e.g. 47145).\nTip: to copy such identifiers, right-click the action in the Actions window > Copy selected action cmdID/identifier string.","sws_mbox"));
				else if (tstNum==-2)
					msg.Append(__LOCALIZE("For macros/scripts, you must use identifier strings (e.g. _f506bc780a0ab34b8fdedb67ed5d3649), not command IDs (e.g. 47145).\nTip: to copy such identifiers, right-click the macro/script in the Actions window > Copy selected action cmdID/identifier string.","sws_mbox"));
				MessageBox(GetMainHwnd(), msg.Get(), __LOCALIZE("S&M - Error","sws_DLG_161"), MB_OK);
			}
			else
			{
				g_prjActions.Get()->Set(idstr);
				Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(_ct), UNDO_STATE_MISCCFG, -1);

				msg.SetFormatted(256, __LOCALIZE_VERFMT("'%s' is defined as project startup action","sws_mbox"), kbd_getTextFromCmd(cmdId, NULL));
				char prjFn[SNM_MAX_PATH] = "";
				EnumProjects(-1, prjFn, sizeof(prjFn));
				if (*prjFn) {
					msg.Append("\n");
					msg.AppendFormatted(SNM_MAX_PATH, __LOCALIZE_VERFMT("for %s","sws_mbox"), prjFn);
				}
				msg.Append(".");
				MessageBox(GetMainHwnd(), msg.Get(), SWS_CMD_SHORTNAME(_ct), MB_OK);
			}
		}
		else
		{
			msg.SetFormatted(256, __LOCALIZE_VERFMT("%s failed: command ID or identifier string '%s' not found in the 'Main' section of the action list!","sws_DLG_161"), SWS_CMD_SHORTNAME(_ct), idstr);
			MessageBox(GetMainHwnd(), msg.Get(), __LOCALIZE("S&M - Error","sws_DLG_161"), MB_OK);
		}
	}
}
Beispiel #11
0
void TieFileToProject(const char* _fn, ReaProject* _prj, bool _tie)
{
	if (_fn && *_fn)
	{
		if (ReaProject* prj = _prj ? _prj : EnumProjects(-1, NULL, 0))
		{
			void *p[2] = { (void*)_fn, (void*)prj };
			plugin_register(_tie ? "file_in_project_ex" : "-file_in_project_ex", p);
#ifdef _SNM_DEBUG
			char dbg[256]="";
			_snprintfSafe(dbg, sizeof(dbg), "TieFileToProject() - ReaProject: %p, %s %s\n", prj, _tie ? "Added" : "Removed", _fn);
			OutputDebugString(dbg);
#endif
		}
	}
}
Beispiel #12
0
void UpdateOpenProjectTabActions()
{
	// Add more actions for project tabs if > 10
	static int iActions = 10;
	int iProjs = iActions-1;
	while (EnumProjects(++iProjs, NULL, 0));
	if (iProjs > iActions)
		for (; iActions < iProjs; iActions++)
		{
			char cID[BUFFER_SIZE];
			char cDesc[BUFFER_SIZE];
			_snprintf(cID, BUFFER_SIZE, "SWS_PROJTAB%d", iActions+1);
			_snprintf(cDesc, BUFFER_SIZE, __LOCALIZE_VERFMT("SWS: Switch to project tab %d","sws_actions"), iActions+1);
			SWSRegisterCommandExt(OpenProjectTab, cID, cDesc, iActions, false);
		}
}
Beispiel #13
0
void* GetConfigVar(const char* cVar)
{
	int sztmp;
	void* p = NULL;
	if (int iOffset = projectconfig_var_getoffs(cVar, &sztmp))
	{
		p = projectconfig_var_addr(EnumProjects(-1, NULL, 0), iOffset);
	}
	else if ((p = get_config_var(cVar, &sztmp)))
	{
	}
	else
	{
		p = get_midi_config_var(cVar, &sztmp);
	}
	return p;
}
Beispiel #14
0
void LoadOrSelectProject(const char* _fn, bool _newTab)
{
	if (!_fn)
		return;

	int i=0;
	bool found = false;
	ReaProject* prj = NULL;
	char fn[SNM_MAX_PATH] = "";
	while (!found && (prj = EnumProjects(i++, fn, sizeof(fn))))
		if (!_stricmp(_fn, fn))
			found = true;

	if (found)
		SelectProjectInstance(prj);
	else {
		if (_newTab) Main_OnCommand(40859,0);
		Main_openProject((char*)_fn); // includes an undo point
	}
}
Beispiel #15
0
void SWS_ProjectListView::GetItemText(SWS_ListItem* item, int iCol, char* str, int iStrMax)
{
	ReaProject* proj = (ReaProject*)item;
	int i = 0;
	char cFilename[512];
	while (proj != EnumProjects(i, cFilename, 512))
		i++;
	
	switch (iCol)
	{
	case 0: // #
		_snprintf(str, iStrMax, "%d", i+1);
		break;
	case 1: // Name
		{
			char* pSlash = strrchr(cFilename, PATH_SLASH_CHAR);
			if (pSlash)
			{
				char* pExt = strrchr(cFilename, '.');
				if (pExt) *pExt = 0;
				lstrcpyn(str, pSlash+1, iStrMax);
			}
			else
				lstrcpyn(str, cFilename, iStrMax);
			break;
		}
	case 2: // Path
		{
			char* pSlash = strrchr(cFilename, PATH_SLASH_CHAR);
			if (pSlash) *pSlash = 0;
			lstrcpyn(str, cFilename, iStrMax);
			break;
		}
		break;
	}
}
Beispiel #16
0
void SelectProjectJob::Perform() {
	if (ReaProject* proj = EnumProjects(GetIntValue(), NULL, 0)) // project number is 0-based
		SelectProjectInstance(proj);
}
Beispiel #17
0
void LastProjectTab(COMMAND_T*)
{
	int iNumProjects = 0;
	while (EnumProjects(++iNumProjects, NULL, 0));
	SelectProjectInstance(EnumProjects(iNumProjects-1, NULL, 0));
}
Beispiel #18
0
void OpenProjectTab(COMMAND_T* ctx)
{
	ReaProject* proj = EnumProjects((int)ctx->user, NULL, 0);
	if (proj)
		SelectProjectInstance(proj);
}