I'm trying to make a C++ module using the development kit. Not 100% sure if I'm doing this correctly, but I'm trying to point to a file using the MWT_FILECHOOSER widget.
#define STStringParams 1
...
static const MagicModuleParam params[STStringParams];
...
const MagicModuleParam ColorRGBExampleModule::params[STStringParams] = {
MagicModuleParam("File Path", "", NULL, NULL, MVT_STRING, MWT_FILECHOOSER, true, "Path to file"),
};
...
Then I'm trying to use the string value at runtime. Not sure how to do that. I just get strange values.
const char value = userData->paramValues[0];
What type should I use? Sorry I'm probably totally doing it wrong.
MDK: get MWT_FILECHOOSER data
Re: MDK: get MWT_FILECHOOSER data
'char*' instead of 'char'?
-
- Posts: 9
- Joined: Fri May 24, 2019 9:03 am
Re: MDK: get MWT_FILECHOOSER data
So I changed
char id = userData->paramValues[1];
to
char* id = userData->paramValues[1];
and I get this error
error C2440: 'initializing': cannot convert from 'const float' to 'char *'
I'm new to C++ development so I only have a basic understanding of what I'm doing here.
Thanks for the help!!
char id = userData->paramValues[1];
to
char* id = userData->paramValues[1];
and I get this error
error C2440: 'initializing': cannot convert from 'const float' to 'char *'
I'm new to C++ development so I only have a basic understanding of what I'm doing here.
Thanks for the help!!
Re: MDK: get MWT_FILECHOOSER data
If your sure that the data your referencing is string data then just cast the value.
char* id = (char*) userData->paramValues[1];
char* id = (char*) userData->paramValues[1];
-
- Posts: 9
- Joined: Fri May 24, 2019 9:03 am
Re: MDK: get MWT_FILECHOOSER data
I really wish that worked, I have experience in C# and TS and did try casting it too. It says "invalid type conversion" and says the userData->paramValues[0] is of type float. Very strange.
I'm trying to use just textboxes now but have the same problem:
const MagicModuleParam MyModule::params[StringPrams] = {
MagicModuleParam("Text 1", "Test 1", NULL, NULL, MVT_STRING, MWT_TEXTBOX, true, "", NULL),
MagicModuleParam("Text 2", "Test 2", NULL, NULL, MVT_STRING, MWT_TEXTBOX, true, "", NULL),
};
Sorry for the changing code, trying lots of new things all at once, but this base problem still persists. Thanks again for the input!!
I'm trying to use just textboxes now but have the same problem:
const MagicModuleParam MyModule::params[StringPrams] = {
MagicModuleParam("Text 1", "Test 1", NULL, NULL, MVT_STRING, MWT_TEXTBOX, true, "", NULL),
MagicModuleParam("Text 2", "Test 2", NULL, NULL, MVT_STRING, MWT_TEXTBOX, true, "", NULL),
};
Sorry for the changing code, trying lots of new things all at once, but this base problem still persists. Thanks again for the input!!
Re: MDK: get MWT_FILECHOOSER data
Disclaimer: I've never looked into the development kit.
But, in general in C++ you don't use 'char' or 'char*'.
Use std::string. And whatever comes in in a different, probably standard C format, convert it to std::string.
So, in your case this is the way to go:
But, in general in C++ you don't use 'char' or 'char*'.
Use std::string. And whatever comes in in a different, probably standard C format, convert it to std::string.
So, in your case this is the way to go:
Code: Select all
std::string myPath (userData->paramValues[0]);
Re: MDK: get MWT_FILECHOOSER data
I've never ventured into MDK but in the header it says:
// Instantaneous values of the mapped params your module uses
const float *paramValues;
Which suggest that these are float values, not strings. Only float (module) parameters can be instantaneous.
// Instantaneous values of the mapped params your module uses
const float *paramValues;
Which suggest that these are float values, not strings. Only float (module) parameters can be instantaneous.
Re: MDK: get MWT_FILECHOOSER data
Great question, perhaps it is not documented well enough so I apologize for that.
As Sadler correctly noted, you don't want to use the instantaneous (dynamic) values, because they are floats.
To handle strings, which are not instantaneous, you use the "fixedParamValueChanged" callback function, which as the name implies, is for fixed values.
If you look at this function, you can see that the value it provides you is a const char *. This is how you get a filename.
Some sample code that uses a std::string (to easily handle the const char *) might look like this:
As Sadler correctly noted, you don't want to use the instantaneous (dynamic) values, because they are floats.
To handle strings, which are not instantaneous, you use the "fixedParamValueChanged" callback function, which as the name implies, is for fixed values.
If you look at this function, you can see that the value it provides you is a const char *. This is how you get a filename.
Some sample code that uses a std::string (to easily handle the const char *) might look like this:
Code: Select all
bool MyModule::fixedParamValueChanged(const int whichValue, const char *newValue)
{
if (whichValue == 0) { // if the parameter that changed is the first one (which usually is the file chooser)
std::string filename = std::string(newValue);
// now do something with your filename (i.e., try to open the file and return true if it succeeds, false if it doesn't)
}
}
-
- Posts: 9
- Joined: Fri May 24, 2019 9:03 am
Re: MDK: get MWT_FILECHOOSER data
So much help! Thank you all!
These comments explained it perfectly. Let me repeat it so I understand.
I should only use
userData->paramValues[0]
To fetch instantaneous values. Meaning floats changed via the various ways the field changes at runtime like via MIDI/OSC.
To fetch fields that contain string values or other "fixed value" fields that don't respond to MIDI/OSC use the event change method fixedParamValueChanged as you described here.
Thanks for all the help!
These comments explained it perfectly. Let me repeat it so I understand.
I should only use
userData->paramValues[0]
To fetch instantaneous values. Meaning floats changed via the various ways the field changes at runtime like via MIDI/OSC.
To fetch fields that contain string values or other "fixed value" fields that don't respond to MIDI/OSC use the event change method fixedParamValueChanged as you described here.
Thanks for all the help!
Re: MDK: get MWT_FILECHOOSER data
Yup that’s correct!