Old 12-21-2014, 10:21 PM   #1
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,067
Default GetUserInputs Noob Question

Hi,
Still trying to figure out some stuff. I have a extension that I'm working on, and I'm have trouble with the "GetUserInputs"

I can't seem to get the defaults to display, or when I do, I can't get the typed inputs to work.
Here's the split function code I'm using:
Code:
std::vector<string> &split(const string &s, char delim, vector<string> &elems){
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		elems.push_back(item);
	}
	return elems;
}

std::vector<string> split(const string &s, char delim){
	vector<string> elems;
	split(s, delim, elems);
	return elems;
}
Here's my snippet of code.

Code:
		const char*
			names = "Pause at project start (sec):,"
			"Pause between tracks (sec):,"
			"Pregap on first track (frames):,"
			"Pregap on other tracks (frames):,"
			"Postgap on all tracks (frames):,"
			"Postgap on last track (frames):";
		char* defvalues = "2,2,30,9,1,60";
		int maxreturnlength = 22;
		std::vector<char> resultvec(maxreturnlength);
        vector<string> Input = split(defvalues, (','));

		defvalues = resultvec.data();

		Query = GetUserInputs("CD setup", 6, names,  resultvec.data(), maxreturnlength);
		if (Query == true)// # user clicked OK
		{
			double StartPauseSec = stod(Input[0]);
			double TrackPauseSec = stod(Input[1]);
			double FirstTrackStartSilenceSec = stod(Input[2]) * framesize;
			double TrackStartSilence = stod(Input[3]);
			double TrackStartSilenceSec = TrackStartSilence * framesize;
			double TrackEndSilence = stod(Input[4]);
			double TrackEndSilenceSec = TrackEndSilence * framesize;
			double LastEndSilenceSec = stod(Input[5]) * framesize;

			ShowConsoleMsg(Input[1].c_str());
Any help would greatly be appreciated.
Thanks, Wyatt
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 12-22-2014, 01:15 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Your split default values strings are never seen by GetUserInputs function. You should split the string in the resultvec instead, after the GetUserInputs returns with true.

Also you have a mistake in your defvalues variable. A char* should not be initialized from a constant string. (A string constant needs to go to a const char*.) It may appear to work but it is not correct. (I think you mentioned it did not work anyway, though...?) In this case dealing with this a bit tricky since the Reaper API wants a char* pointing to existing contents that it then wants to modify. (The GetUserInputs API is horribly designed! The guy at Cockos responsible for that should be spanked!) You need to do something like :

Code:
std::vector<char> resultvec(maxinputsize);
strcpy(resultvec.data(),"2,2,30,9,1,60");
So, you could drop the use of the defvalues variable from the code.

This is a slightly unusual thing too...

Code:
std::vector<string> &split(const string &s, char delim, vector<string> &elems)
While I believe this will work in this case, generally you should avoid returning references from functions so that you won't do the tragic "return a reference to a local variable" mistake. In this case I'd recommend changing the function to :

Code:
void split(const string &s, char delim, vector<string> &elems)
And remove the return elems; line. You are not using the return value in the code anyway!

Are you sure using C(++) for this is worth the effort and the dangers involved? I don't see anything in this code that would warrant writing an extension plugin, ReaScript would be a much better and safer fit.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.

Last edited by Xenakios; 12-22-2014 at 01:31 AM.
Xenakios is offline   Reply With Quote
Old 12-23-2014, 10:22 AM   #3
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,067
Default

Xenakios, again many thanks for your help. That worked.

Meanwhile, I found another split function, and it seams to work too.
Would this work any better?
Sorry for such noob questions.

Code:
vector<string> split(string str, char delimiter) {
	vector<string> internal;
	stringstream ss(str); // Turn the string into a stream.
	string tok;

	while (getline(ss, tok, delimiter)) {
		internal.push_back(tok);
	}

	return internal;
	
	
}
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 12-23-2014, 10:30 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by WyattRice View Post
Xenakios, again many thanks for your help. That worked.

Meanwhile, I found another split function, and it seams to work too.
Would this work any better?
Sorry for such noob questions.

Code:
vector<string> split(string str, char delimiter) {
	vector<string> internal;
	stringstream ss(str); // Turn the string into a stream.
	string tok;

	while (getline(ss, tok, delimiter)) {
		internal.push_back(tok);
	}

	return internal;
	
	
}
This functions seems to be just a shorter way of doing the same thing that was in your original code, so if it works, I guess it's OK.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.