Пример #1
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);
	}
}
Пример #2
0
static void LoadGrooveFromFile(int flags, void *data)
{
    GrooveTemplateHandler *me = GrooveTemplateHandler::Instance();
    char* cFilename = BrowseForFiles("Select groove template", me->GetGrooveDir().c_str(), NULL, false,
                                     "Reaper Groove Templates (*.rgt)\0*.rgt\0All Files (*.*)\0*.*\0");
    if (cFilename)
    {
        std::string errMessage;
        std::string fName = cFilename;
        if(!me->LoadGroove(fName, errMessage))
            MessageBox(GetMainHwnd(), errMessage.c_str(), __LOCALIZE("FNG - Error","sws_mbox"), 0);
        free(cFilename);
    }
}
Пример #3
0
void AddRelatedProject(COMMAND_T* = NULL)
{
	char cPath[256];
	GetProjectPath(cPath, 256);

	char* filename = BrowseForFiles(__LOCALIZE("Select related projects","sws_mbox"), cPath, NULL, false, "Reaper Project (*.RPP)\0*.RPP");
	char* pBuf = filename;
	if (pBuf)
	{
		while(filename[0])
		{
			g_relatedProjects.Get()->Add(new WDL_String(filename));
			filename += strlen(filename) +1;
		}

		free(pBuf);
		Undo_OnStateChangeEx(__LOCALIZE("Add related projects","sws_mbox"), UNDO_STATE_MISCCFG, -1);
	}
}
Пример #4
0
char *WDL_ChooseFileForOpen(HWND parent,
                                        const char *text, 
                                        const char *initialdir,  
                                        const char *initialfile, 
                                        const char *extlist,
                                        const char *defext,

                                        bool preservecwd,
                                        bool allowmul, 

                                        const char *dlgid, 
                                        void *dlgProc, 
#ifdef _WIN32
                                        HINSTANCE hInstance
#else
                                        struct SWELL_DialogResourceIndex *reshead
#endif
                                        )
{
  char olddir[2048];
  GetCurrentDirectory(sizeof(olddir),olddir);

#ifdef _WIN32

#ifdef WDL_FILEBROWSE_WIN7VISTAMODE
  if (!allowmul) // todo : check impl of multiple select, too?
  {
    Win7FileDialog fd(text);
    if(fd.inited())
    {
      //vista+ file open dialog
      fd.addOptions(FOS_FILEMUSTEXIST);
      fd.setFilterList(extlist);
      if (defext) 
      {
        fd.setDefaultExtension(defext);
        
        int i = 0;
        const char *p = extlist;
        while(*p)
        {
          if(*p) p+=strlen(p)+1;
          if(!*p) break;
          if(stristr(p, defext)) 
          {
            fd.setFileTypeIndex(i+1);
            break;
          }
          i++;
          p+=strlen(p)+1;
        }
      }
      fd.setFolder(initialdir?initialdir:olddir, 0);
      fd.setTemplate(hInstance, dlgid, (LPOFNHOOKPROC)dlgProc);
      if(initialfile) 
      {
        char temp[4096];
        lstrcpyn(temp,initialfile,sizeof(temp));
        //check for folder name
        char *p = temp+strlen(temp);
        while(p>temp && *p!='/' && *p!='\\') p--;
        if(*p=='/'||*p=='\\')
        {
          //folder found
          *p=0;
          fd.setFolder(temp, 0);
          fd.setFilename(p+1);
        }
        else
          fd.setFilename(temp);
      }

      if(fd.show(parent))
      {
        char temp[4096];
        temp[0]=0;
        //ifileopendialog saves the last folder automatically
        fd.getResult(temp, sizeof(temp)-1);



        if (preservecwd) SetCurrentDirectory(olddir);
        return temp[0] ? strdup(temp) : NULL;
      }

      if (preservecwd) SetCurrentDirectory(olddir);
      return NULL;
    }
  }
#endif

  int temp_size = allowmul ? 256*1024-1 : 4096-1;
  char *temp = (char *)calloc(temp_size+1,1);

  OPENFILENAME l={sizeof(l), parent, hInstance, extlist, NULL, 0, 0, temp, temp_size, NULL, 0, initialdir, text,
    OFN_HIDEREADONLY|OFN_EXPLORER|OFN_FILEMUSTEXIST,0,0, (char *)(defext ? defext : ""), 0, (LPOFNHOOKPROC)dlgProc, dlgid};

  if (hInstance&&dlgProc&&dlgid) l.Flags |= OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_ENABLESIZING;
  if (allowmul) l.Flags|=OFN_ALLOWMULTISELECT;
  if (preservecwd) l.Flags|=OFN_NOCHANGEDIR;

  if (initialfile) lstrcpyn(temp,initialfile,temp_size);

  WDL_fixfnforopenfn(temp);

  if (!l.lpstrInitialDir||!l.lpstrInitialDir[0]) l.lpstrInitialDir=olddir;

  int r = GetOpenFileName(&l);
  if (preservecwd) SetCurrentDirectory(olddir);

  if (!r) free(temp);
  return r?temp:NULL;

#else  
  char if_temp[4096];
  if (initialfile) 
  {
    lstrcpyn(if_temp,initialfile,sizeof(if_temp));
    WDL_fixfnforopenfn(if_temp);
    initialfile = if_temp;
  }
  
  // defext support?
  BrowseFile_SetTemplate(dlgid,(DLGPROC)dlgProc,reshead);
  char *ret = BrowseForFiles(text,initialdir,initialfile,allowmul,extlist);
  if (preservecwd) SetCurrentDirectory(olddir);

  return ret;
#endif
}
Пример #5
0
void ImportJson(COMMAND_T* pCommand)
{
   char* selectedFile = BrowseForFiles("Select Auphonic JSON file", 0, 0, false, "Auphonic JSON (*.json)\0*.json\0All Files (*.*)\0*.*\0");
   if((selectedFile != 0) && (strlen(selectedFile) > 0))
   {
      std::string rawData = GetFileContents(std::string(selectedFile));
      std::string errorMessage;
      json11::Json cookedData = json11::Json::parse(rawData, errorMessage);
      if(errorMessage.empty() == true)
      {
         std::map<std::string, std::set<ActivityItem>> trackActivities;
         
         const json11::Json statistics = cookedData["statistics"];
         for(const json11::Json& track : statistics["tracks"].array_items())
         {
            const std::string trackId = track["identifier"].string_value();
            if(trackId.empty() == false)
            {
               std::set<ActivityItem> activities;
               for(const json11::Json& activity : track["activity"].array_items())
               {
                  const double begin = activity.array_items()[0].number_value();
                  const double end = activity.array_items()[1].number_value();
                  activities.insert(ActivityItem(begin, end));
               }
               
               if(activities.empty() == false)
               {
                  trackActivities.insert(std::map<std::string, std::set<ActivityItem>>::value_type(trackId, activities));
               }
               else
               {
                  ErrorMessage("No activities for track");
               }
            }
            else
            {
               ErrorMessage("Found invalid track identifier");
            }
         }

         std::map<std::string, MediaTrack*> reaperTracks;
         for(int i = 0; i < GetNumTracks(); ++i)
         {
            MediaTrack* reaperTrack = GetTrack(0, i);
            AssertTrue(reaperTrack != 0);
            std::string trackName = MediaTrack_GetStringProperty(reaperTrack, "P_NAME");
            reaperTracks[trackName] = reaperTrack;
         }
         
         for(const std::map<std::string, std::set<ActivityItem>>::value_type& trackActivity : trackActivities)
         {
            const std::string& trackId = trackActivity.first;
            std::map<std::string, MediaTrack*>::iterator trackIterator = reaperTracks.find(trackId);
            if(trackIterator != reaperTracks.end())
            {
               MediaTrack* reaperTrack = trackIterator->second;
               if(reaperTrack != 0)
               {
                  MediaItem* reaperItem = AddMediaItemToTrack(reaperTrack);
                  if(reaperItem != 0)
                  {
                     const std::set<ActivityItem>& activities = trackActivity.second;
                     for(const ActivityItem& activity : activities)
                     {
                        SetMediaItemPosition(reaperItem, activity.Begin(), true);
                        SetMediaItemLength(reaperItem, activity.Duration(), true);
                        MediaItem_SetStringProperty(reaperItem, "P_NOTES", trackId);
                        
//                        int color = MediaTrack_GetIntProperty(reaperTrack, "I_CUSTOMCOLOR");
                        int color = MediaTrack_GetProperty<int>(reaperTrack, "I_CUSTOMCOLOR");
                        
                        char buffer[4096] = {0};
                        sprintf(buffer, "%s (%.2fs)", trackId.c_str(), activity.Duration());
                        const char* activityLabel = AllocCopyString(buffer);

                        AddProjectMarker2(0, true, activity.Begin(), activity.End(), activityLabel, 0, color);
                     }
                  }
                  else
                  {
                     ErrorMessage("Failed to add activity");
                  }
               }
               else
               {
                  ErrorMessage("Failed to find track");
               }
            }
         }
      }
      else
      {
         ErrorMessage(errorMessage.c_str());
      }
   }
}
Пример #6
0
char *WDL_ChooseFileForOpen2(HWND parent,
                                        const char *text, 
                                        const char *initialdir,  
                                        const char *initialfile, 
                                        const char *extlist,
                                        const char *defext,

                                        bool preservecwd,
                                        int allowmul, 

                                        const char *dlgid, 
                                        void *dlgProc, 
#ifdef _WIN32
                                        HINSTANCE hInstance
#else
                                        struct SWELL_DialogResourceIndex *reshead
#endif
                                        )
{
  char olddir[2048];
  GetCurrentDirectory(sizeof(olddir),olddir);

#ifdef _WIN32

#ifdef WDL_FILEBROWSE_WIN7VISTAMODE
  if (allowmul!=1)
  {
    Win7FileDialog fd(text);
    if(fd.inited())
    {
      //vista+ file open dialog
      fd.addOptions(FOS_FILEMUSTEXIST|(allowmul?FOS_ALLOWMULTISELECT:0));
      fd.setFilterList(extlist);
      if (defext) 
      {
        fd.setDefaultExtension(defext);
        
        int i = 0;
        const char *p = extlist;
        while(*p)
        {
          if(*p) p+=strlen(p)+1;
          if(!*p) break;
          if(stristr(p, defext)) 
          {
            fd.setFileTypeIndex(i+1);
            break;
          }
          i++;
          p+=strlen(p)+1;
        }
      }
      fd.setFolder(initialdir?initialdir:olddir, 0);
      fd.setTemplate(hInstance, dlgid, (LPOFNHOOKPROC)dlgProc);
      if(initialfile) 
      {
        char temp[4096];
        lstrcpyn_safe(temp,initialfile,sizeof(temp));
        //check for folder name
        if (WDL_remove_filepart(temp))
        {
          //folder found
          fd.setFolder(temp, 0);
          fd.setFilename(temp + strlen(temp) + 1);
        }
        else
          fd.setFilename(temp);
      }

      if(fd.show(parent))
      {
        char *ret=NULL;
        char temp[4096];
        temp[0]=0;

        //ifileopendialog saves the last folder automatically
        if (!allowmul)
        {
          fd.getResult(temp, sizeof(temp)-1);
          ret= temp[0] ? strdup(temp) : NULL;
        }
        else
        {
          char* p=NULL;
          int totallen=0, cnt=fd.getResultCount();
          if (cnt>1)
          {
            // sets an empty path as 1st returned string for multipath support
            // (when selecting files among search results for ex.)
            ret = strdup("");
            totallen=1;
          }

          int i;
          for (i=0; i<cnt; i++)
          {
            int len = fd.getResult(i, temp, sizeof(temp)-1);
            p = len ? (char*)realloc(ret, totallen + len + ((i==cnt-1)?1:0)) : NULL;
            if (p)
            {
              ret=p;
              memcpy(ret+totallen, temp, len);
              totallen+=len;
            }
            else
            {
              free(ret);
              ret=NULL;
              break;
            }
          }
          if (ret) p[totallen]=0;
        }

        if (preservecwd) SetCurrentDirectory(olddir);
        return ret;
      }

      if (preservecwd) SetCurrentDirectory(olddir);
      return NULL;
    }
  }
#endif

  int temp_size = allowmul ? 256*1024-1 : 4096-1;
  char *temp = (char *)calloc(temp_size+1,1);

  OPENFILENAME l={sizeof(l), parent, hInstance, extlist, NULL, 0, 0, temp, temp_size, NULL, 0, initialdir, text,
    OFN_HIDEREADONLY|OFN_EXPLORER|OFN_FILEMUSTEXIST,0,0, (char *)(defext ? defext : ""), 0, (LPOFNHOOKPROC)dlgProc, dlgid};

  if (hInstance&&dlgProc&&dlgid) l.Flags |= OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_ENABLESIZING;
  if (allowmul) l.Flags|=OFN_ALLOWMULTISELECT;
  if (preservecwd) l.Flags|=OFN_NOCHANGEDIR;

  if (initialfile) lstrcpyn_safe(temp,initialfile,temp_size);

  WDL_fixfnforopenfn(temp);

  if (!l.lpstrInitialDir||!l.lpstrInitialDir[0]) l.lpstrInitialDir=olddir;

  int r = GetOpenFileName(&l);
  if (preservecwd) SetCurrentDirectory(olddir);

  if (!r) free(temp);
  return r?temp:NULL;

#else  
  char if_temp[4096];
  if (initialfile) 
  {
    lstrcpyn_safe(if_temp,initialfile,sizeof(if_temp));
    WDL_fixfnforopenfn(if_temp);
    initialfile = if_temp;
  }
  
  // defext support?
  BrowseFile_SetTemplate(dlgid,(DLGPROC)dlgProc,reshead);
  char *ret = BrowseForFiles(text,initialdir,initialfile,allowmul,extlist);
  if (preservecwd) SetCurrentDirectory(olddir);

  return ret;
#endif
}
Пример #7
0
INT_PTR WINAPI doColorDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
#ifndef _WIN32
	static int iSettingColor = -1;
#endif
	if (INT_PTR r = SNM_HookThemeColorsMessage(hwndDlg, uMsg, wParam, lParam))
		return r;
	
	switch (uMsg)
	{
		case WM_INITDIALOG:
			UpdateCustomColors();
			RestoreWindowPos(hwndDlg, COLORDLG_WINDOWPOS_KEY, false);
			return 0;
		case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT pDI = (LPDRAWITEMSTRUCT)lParam;
			HBRUSH hb = NULL;
			switch (pDI->CtlID)
			{
				case IDC_COLOR1:
					hb = CreateSolidBrush(g_crGradStart);
					break;
				case IDC_COLOR2:
					hb = CreateSolidBrush(g_crGradEnd);
					break;
			}
			FillRect(pDI->hDC, &pDI->rcItem, hb);
			DeleteObject(hb);
			return 1;
		}
#ifndef _WIN32
		case WM_TIMER:
		{
			COLORREF cr;
			if (iSettingColor != -1 && GetChosenColor(&cr))
			{
				switch (iSettingColor)
				{	
				case 0:
					g_crGradStart = cr;
					break;
				case 1:
					g_crGradEnd = cr;
					break;
				case 2:
					UpdateCustomColors();
					break;
				}
				PersistColors();
				InvalidateRect(hwndDlg, NULL, 0);
				KillTimer(hwndDlg, 1);
				iSettingColor = -1;
			}
			break;
		}
#endif
		case WM_COMMAND:
		{
			wParam = LOWORD(wParam);
			switch(wParam)
			{
				case IDC_COLOR1:
				case IDC_COLOR2:
				case IDC_SETCUST:
				{
#ifdef _WIN32
					CHOOSECOLOR cc;
					memset(&cc, 0, sizeof(CHOOSECOLOR));
					cc.lStructSize = sizeof(CHOOSECOLOR);
					cc.hwndOwner = hwndDlg;
					cc.lpCustColors = g_custColors;
					cc.Flags = CC_FULLOPEN | CC_RGBINIT;

					if (wParam == IDC_COLOR1)
					{
						cc.rgbResult = g_crGradStart;
						if (ChooseColor(&cc))
						{
							g_crGradStart = cc.rgbResult;
							PersistColors();
							RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
						}
					}
					else if (wParam == IDC_COLOR2)
					{
						cc.rgbResult = g_crGradEnd;
						if (ChooseColor(&cc))
						{
							g_crGradEnd = cc.rgbResult;
							PersistColors();
							RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
						}
					}
					else if (wParam == IDC_SETCUST && ChooseColor(&cc))
						PersistColors();
#else
					switch(wParam)
					{
						case IDC_COLOR1:  iSettingColor = 0; ShowColorChooser(g_crGradStart); break;
						case IDC_COLOR2:  iSettingColor = 1; ShowColorChooser(g_crGradEnd);   break;
						case IDC_SETCUST: iSettingColor = 2; ShowColorChooser(g_custColors[0]); break;
					}
					SetTimer(hwndDlg, 1, 50, NULL);
#endif
					break;
				}
				case IDC_SAVECOL:
				case IDC_LOADCOL:
				case IDC_LOADFROMTHEME:
				{
					char cPath[512] = { 0 };
					const char* cExt = "SWS Color Files (*.SWSColor)\0*.SWSColor\0Color Theme Files (*.ReaperTheme)\0*.ReaperTheme\0All Files\0*.*\0";
					GetPrivateProfileString("REAPER", "lastthemefn", "", cPath, 512, get_ini_file());
					char* pC = strrchr(cPath, PATH_SLASH_CHAR);
					if (pC)
						*pC = 0;

					if (wParam == IDC_SAVECOL)
					{
						char cFilename[512];
						UpdateCustomColors();
						if (BrowseForSaveFile(__LOCALIZE("Save color theme","sws_color"), cPath, NULL, cExt, cFilename, 512))
						{
							char key[32];
							char val[32];
							for (int i = 0; i < 16; i++)
							{
								sprintf(key, "custcolor%d", i+1);
								sprintf(val, "%d", g_custColors[i]);
								WritePrivateProfileString("SWS Color", key, val, cFilename);
							}
							sprintf(val, "%d", g_crGradStart);
							WritePrivateProfileString("SWS Color", "gradientStart", val, cFilename);
							sprintf(val, "%d", g_crGradEnd);
							WritePrivateProfileString("SWS Color", "gradientEnd", val, cFilename);
						}
					}
					else if (wParam == IDC_LOADCOL || wParam == IDC_LOADFROMTHEME)
					{
#ifndef _WIN32
						if (MessageBox(hwndDlg, __LOCALIZE("WARNING: Loading colors from file will overwrite your global personalized color choices.\nIf these are important to you, press press cancel to abort the loading of new colors!","sws_color"), __LOCALIZE("OSX Color Load WARNING","sws_color"), MB_OKCANCEL) == IDCANCEL)
							break;
#endif
						if (wParam == IDC_LOADCOL)
						{
							char* cFile = BrowseForFiles(__LOCALIZE("Choose color theme file","sws_color"), cPath, NULL, false, cExt);
							if (cFile)
							{
								lstrcpyn(cPath, cFile, 512);
								free(cFile);
							}
							else
								cPath[0] = 0;
						}
						else
							GetPrivateProfileString("REAPER", "lastthemefn", "", cPath, 512, get_ini_file());

						if (cPath[0])
						{
							char key[32];
							bool bFound = false;
							for (int i = 0; i < 16; i++)
							{
								sprintf(key, "custcolor%d", i+1);
								int iColor = GetPrivateProfileInt("SWS Color", key, -1, cPath);
								if (iColor != -1)
								{
									g_custColors[i] = iColor;
									bFound = true;
								}

							}
							if (!bFound)
							{
								char cMsg[512];
								_snprintf(cMsg, 512, __LOCALIZE_VERFMT("No SWS custom colors found in %s.","sws_color"), cPath);
								MessageBox(hwndDlg, cMsg, __LOCALIZE("SWS Color Load","sws_color"), MB_OK);
							}

							g_crGradStart = GetPrivateProfileInt("SWS Color", "gradientStart", g_crGradStart, cPath);
							g_crGradEnd   = GetPrivateProfileInt("SWS Color", "gradientEnd", g_crGradEnd, cPath);
							PersistColors();
#ifdef _WIN32
							RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
#else
							InvalidateRect(hwndDlg, NULL, 0);
#endif							
						}
					}
				}
				break;
				case IDOK:
					// Do something ?
					// fall through!
				case IDCANCEL:
#ifndef _WIN32
					if (iSettingColor != -1)
					{
						HideColorChooser();
						KillTimer(hwndDlg, 1);
					}
#endif
					SaveWindowPos(hwndDlg, COLORDLG_WINDOWPOS_KEY);
					EndDialog(hwndDlg,0);
					break;
			}
			return 0;
		}
	}
	return 0;
}
Пример #8
0
WDL_DLGRET CueBussDlgProc(HWND _hwnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam)
{
	if (INT_PTR r = SNM_HookThemeColorsMessage(_hwnd, _uMsg, _wParam, _lParam))
		return r;

	const char cWndPosKey[] = "CueBus Window Pos";
	switch(_uMsg)
	{
		case WM_INITDIALOG:
		{
			WDL_UTF8_HookComboBox(GetDlgItem(_hwnd, IDC_SNM_CUEBUS_TYPE));
			WDL_UTF8_HookComboBox(GetDlgItem(_hwnd, IDC_COMBO));
			for(int i=0; i < SNM_MAX_HW_OUTS; i++)
				WDL_UTF8_HookComboBox(GetDlgItem(_hwnd, IDC_SNM_CUEBUS_HWOUT1+i));

			RestoreWindowPos(_hwnd, cWndPosKey, false);
			char buf[16] = "";
			for(int i=0; i < SNM_MAX_CUE_BUSS_CONFS; i++)
				if (_snprintfStrict(buf,sizeof(buf),"%d",i+1) > 0)
					SendDlgItemMessage(_hwnd,IDC_COMBO,CB_ADDSTRING,0,(LPARAM)buf);
			SendDlgItemMessage(_hwnd,IDC_COMBO,CB_SETCURSEL,0,0);
			FillCueBussDlg(_hwnd);
			return 0;
		}
		break;

		case WM_CLOSE :
			g_cueBussHwnd = NULL; // for proper toggle state report, see openCueBussWnd()
			break;

		case WM_COMMAND :
			switch(LOWORD(_wParam))
			{
				case IDC_COMBO:
					if(HIWORD(_wParam) == CBN_SELCHANGE) // config id update?
					{ 
						int id = (int)SendDlgItemMessage(_hwnd, IDC_COMBO, CB_GETCURSEL, 0, 0);
						if (id != CB_ERR) {
							g_cueBussConfId = id;
							FillCueBussDlg();
						}
					}
					break;
				case IDOK:
					CueBuss(__LOCALIZE("Create cue buss from track selection","sws_undo"), g_cueBussConfId);
					return 0;
				case IDCANCEL:
					g_cueBussHwnd = NULL; // for proper toggle state report, see openCueBussWnd()
					ShowWindow(_hwnd, SW_HIDE);
					return 0;
				case IDC_FILES: {
					char curPath[SNM_MAX_PATH]="";
					GetDlgItemText(_hwnd, IDC_SNM_CUEBUS_TEMPLATE, curPath, sizeof(curPath));
					if (!*curPath || !FileOrDirExists(curPath))
						if (_snprintfStrict(curPath, sizeof(curPath), "%s%cTrackTemplates", GetResourcePath(), PATH_SLASH_CHAR) <= 0)
							*curPath = '\0';
					if (char* fn = BrowseForFiles(__LOCALIZE("S&M - Load track template","sws_DLG_149"), curPath, NULL, false, "REAPER Track Template (*.RTrackTemplate)\0*.RTrackTemplate\0")) {
						SetDlgItemText(_hwnd,IDC_SNM_CUEBUS_TEMPLATE,fn);
						free(fn);
						SaveCueBussSettings();
					}
					break;
				}
				case IDC_CHECK3: {
					bool templateEnable = (IsDlgButtonChecked(_hwnd, IDC_CHECK3) == 1);
					EnableWindow(GetDlgItem(_hwnd, IDC_SNM_CUEBUS_TEMPLATE), templateEnable);
					EnableWindow(GetDlgItem(_hwnd, IDC_FILES), templateEnable);
					EnableWindow(GetDlgItem(_hwnd, IDC_SNM_CUEBUS_NAME), !templateEnable);
					for(int k=0; k < SNM_MAX_HW_OUTS ; k++)
						EnableWindow(GetDlgItem(_hwnd, IDC_SNM_CUEBUS_HWOUT1+k), !templateEnable);
					EnableWindow(GetDlgItem(_hwnd, IDC_CHECK1), !templateEnable);
					EnableWindow(GetDlgItem(_hwnd, IDC_CHECK4), !templateEnable);
//					SetFocus(GetDlgItem(_hwnd, templateEnable ? IDC_SNM_CUEBUS_TEMPLATE : IDC_SNM_CUEBUS_NAME));
					SaveCueBussSettings();
					break;
				}
				case IDC_SNM_CUEBUS_SOLOGRP:
				case IDC_CHECK1:
				case IDC_CHECK2:
				case IDC_CHECK4:
					SaveCueBussSettings();
					break;
				case IDC_SNM_CUEBUS_TYPE:
				case IDC_SNM_CUEBUS_HWOUT1:
				case IDC_SNM_CUEBUS_HWOUT2:
				case IDC_SNM_CUEBUS_HWOUT3:
				case IDC_SNM_CUEBUS_HWOUT4:
				case IDC_SNM_CUEBUS_HWOUT5:
				case IDC_SNM_CUEBUS_HWOUT6:
				case IDC_SNM_CUEBUS_HWOUT7:
				case IDC_SNM_CUEBUS_HWOUT8:
					if(HIWORD(_wParam) == CBN_SELCHANGE)
						SaveCueBussSettings();
					break;
				case IDC_SNM_CUEBUS_TEMPLATE:
				case IDC_SNM_CUEBUS_NAME:
					if (HIWORD(_wParam)==EN_CHANGE)
						SaveCueBussSettings();
					break;
			}
			break;

		case WM_DESTROY:
			SaveWindowPos(_hwnd, cWndPosKey);
			break;
	}
	return 0;
}
Пример #9
0
// Import local files from m3u/pls playlists onto a new track
void PlaylistImport(COMMAND_T* ct)
{
	char cPath[256];
	vector<SPlaylistEntry> filelist;

	GetProjectPath(cPath, 256);
	string listpath = BrowseForFiles(__LOCALIZE("Import playlist","sws_mbox"), cPath, NULL, false, "Playlist files (*.m3u,*.pls)\0*.m3u;*.pls\0All Files (*.*)\0*.*\0");
	string ext = ParseFileExtension(listpath);

	// Decide what kind of playlist we have
	if(ext == "m3u")
	{
		ParseM3U(listpath, filelist);
	}
	else if(ext == "pls")
	{
		ParsePLS(listpath, filelist);
	}

	if(filelist.empty())
	{
		ShowMessageBox(__LOCALIZE("Failed to import playlist. No files found.","sws_mbox"), __LOCALIZE("Import playlist","sws_mbox"), 0);
		return;
	}

	// Validate files
	vector<string> badfiles;
	for(int i = 0, c = (int)filelist.size(); i < c; i++)
	{
		SPlaylistEntry e = filelist[i];
		if(!file_exists(e.path.c_str()))
		{
			badfiles.push_back(e.path);
		}
	}

	// If files can't be found, ask user what to do.
	bool includeMissing = false;
	if(!badfiles.empty())
	{
		stringstream ss;
		ss << __LOCALIZE("Cannot find some files. Create items anyway?\n","sws_mbox");

		unsigned int limit = min((int)badfiles.size(), 9); // avoid enormous messagebox
		for(unsigned int i = 0; i < limit; i++)
		{
			ss << "\n " << badfiles[i];
		}
		if(badfiles.size() > limit)
		{
			ss << "\n +" << badfiles.size() - limit << __LOCALIZE(" more files","sws_mbox");
		}

		switch(ShowMessageBox(ss.str().c_str(), __LOCALIZE("Import playlist","sws_mbox"), 3))
		{
		case 6 : // Yes
			includeMissing = true;
			break;

		case 7 : // No
			break;

		default :
			return;
		}
	}

	Undo_BeginBlock2(NULL);

	// Add new track
	int idx = GetNumTracks();
	int panMode = 5;		// Stereo pan
	double panLaw = 1.0;	// 0dB
	InsertTrackAtIndex(idx, false);
	MediaTrack *pTrack = GetTrack(NULL, idx);
	GetSetMediaTrackInfo(pTrack, "P_NAME", (void*) listpath.c_str());
	GetSetMediaTrackInfo(pTrack, "I_PANMODE", (void*) &panMode);
	GetSetMediaTrackInfo(pTrack, "D_PANLAW", (void*) &panLaw);
	SetOnlyTrackSelected(pTrack);

	// Add new items to track
	double pos = 0.0;
	for(int i = 0, c = (int)filelist.size(); i < c; i++)
	{
		SPlaylistEntry e = filelist[i];

		//TODO: Would be better if missing files were offline rather than just empty items.
		PCM_source *pSrc = PCM_Source_CreateFromFile(e.path.c_str());
		if(pSrc || includeMissing)
		{
			MediaItem *pItem = AddMediaItemToTrack(pTrack);
			if(pItem)
			{
				MediaItem_Take *pTake = AddTakeToMediaItem(pItem);
				if(pTake)
				{
					GetSetMediaItemTakeInfo(pTake, "P_SOURCE", pSrc);
					GetSetMediaItemTakeInfo(pTake, "P_NAME", (void*) e.title.c_str());
					SetMediaItemPosition(pItem, pos, false);
					SetMediaItemLength(pItem, e.length, false);
					pos += e.length;
				}
			}
		}
	}

	Undo_EndBlock2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ITEMS|UNDO_STATE_TRACKCFG);

	TrackList_AdjustWindows(false);
	UpdateTimeline();

	Main_OnCommand(40047, 0); // Build missing peaks
}