Previous topicNext topic

MDK: get MWT_FILECHOOSER data

Questions, comments, feedback, etc.
Post Reply
coolhand2120
Posts: 9
Joined: Fri May 24, 2019 9:03 am

MDK: get MWT_FILECHOOSER data

Post by coolhand2120 »

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.
Sadler
Posts: 1139
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: MDK: get MWT_FILECHOOSER data

Post by Sadler »

'char*' instead of 'char'?
coolhand2120
Posts: 9
Joined: Fri May 24, 2019 9:03 am

Re: MDK: get MWT_FILECHOOSER data

Post by coolhand2120 »

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!!
Sadler
Posts: 1139
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: MDK: get MWT_FILECHOOSER data

Post by Sadler »

If your sure that the data your referencing is string data then just cast the value.

char* id = (char*) userData->paramValues[1];
coolhand2120
Posts: 9
Joined: Fri May 24, 2019 9:03 am

Re: MDK: get MWT_FILECHOOSER data

Post by coolhand2120 »

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!!
TKS
Posts: 139
Joined: Mon May 17, 2021 10:40 am

Re: MDK: get MWT_FILECHOOSER data

Post by TKS »

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:

Code: Select all

std::string myPath (userData->paramValues[0]);
Sadler
Posts: 1139
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: MDK: get MWT_FILECHOOSER data

Post by Sadler »

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.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: MDK: get MWT_FILECHOOSER data

Post by Magic »

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:

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)
    }
}
coolhand2120
Posts: 9
Joined: Fri May 24, 2019 9:03 am

Re: MDK: get MWT_FILECHOOSER data

Post by coolhand2120 »

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!
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: MDK: get MWT_FILECHOOSER data

Post by Magic »

Yup that’s correct!
Post Reply