Welcome to %s forums

BrainModular Users Forum

Login Register

need help with string !

Create your own modules in C++
Post Reply
User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 10 Jul 2013, 23:31

Hi !
I'm trying to make a user module that will put a new appearing character at the end of a existing string
this is for my project of born again Minitel (sooo french).

I already made a script that works fine, and was quite straight forward to make :

Code: Select all

//////////////////////////
// retourneur de string
/////////////////////////

// parameters declaration
Var input, dummy, reset   : TParameter;
Var output    : TParameter;
var sl1       : UNICODESTRING;
var sl2       : UNICODESTRING;
var size      : integer;

// destroy
procedure Destroy;
begin  
 sl1.free;
 sl2.free;
end;
// initialisation : create parameters
procedure init;
begin  
 SetModuleColor($800080+302999);
 input := createParam('in',ptTextField);
 SetIsOutPut(input,false);
 reset:=  CreateParam('reset',PtButton);  
 SetIsOutput(reset,false);
 output  := createParam('out',ptTextField);
 SetIsInPut(output,false);
 size  := createParam('size',ptDataField);
 SetIsInPut(size,false);
end;



// Global variables

//////////////////////////////
// CallBack proc
//////////////////////////////
Procedure CallBack(n:integer);
begin
if (n = reset) then begin
 IF (reset >= 1) THEN
  sl2 := getStringValue(input);
end;
if (n = input) then begin
 sl1 := getStringValue(input);
 sl2 := sl2 + sl1
 end;
 SetStringValue(output,sl2);
 SetValue(size,Length(sl2));
end;
Now I'm stuck with the user module : the sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) str); is the problem as every thing compile fine without it

Code: Select all

void StringFlip::onCallBack(UsineMessage *Message) 
{
	if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "enable" input
	{
	    m_textNew = sdkGetEvtPChar(m_textInput); //
		std::string str;
		str.push_back((char)m_textNew);
		sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) str); // this is not working, no conversion between std::string and AinsiCharPtr
	}

	if ((Message->wParam == 2) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "reset" input
	{
		sdkSetEvtPChar(m_textOutput, "");
	}
}
I did some research on the old 5.8 archive and find this :
http://www.sensomusic.com/wiki/doku.php?id=sdk:code:snippets:event_parameters:

but I don't understand "what" is pPrototype->PTextTest->len; I need to declare it but how ?

well I'm stuck !

thanx for your help.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 11 Jul 2013, 08:31

I too have a similar problem, but I was trying to use a std::string variable as a parameter caption. I tried different approaches, and ended up with casting similar to examples in the SDK:

(AinsiCharPtr) (s.c_str())

This compiled without warnings, and the string also looked OK when traced, but the parameter caption was empty.
Bjørn S

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 11 Jul 2013, 11:29

oli_lab wrote:I'm trying to make a user module that will put a new appearing character at the end of a existing string
bsork wrote:I too have a similar problem, but I was trying to use a std::string variable as a parameter caption. I tried different approaches, and ended up with casting similar to examples in the SDK:

(AinsiCharPtr) (s.c_str())

This compiled without warnings, and the string also looked OK when traced, but the parameter caption was empty.
using std::string and casting it like that is the way to go.

but be sure to declare this std::string variable at module level (in the include file, as a member of the module), you can modify it's content at any time, but declaring it as a member variable of the module ensure the variable is alive when usine try to copy it's content.

if you declare it in the onGetParamInfos() or onCallback() function, it's just a locale variable without enough lifetime and is already destroyed when usine try to copy it's content.

to resume :
declare the string variable as a module member.
construct or modify the string content when you want before using it
Martin FLEURENT - Usine Developer - SDK maintainer

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 11 Jul 2013, 12:13

I thought it might have something to do with scope, but it got to late last night to try that approach. However, it seems a bit strange as long as I build the string locally and immediately assign the value to the Caption member. One would think that the value is stored in Caption together with all the other data, and that the (temporary) string variable no longer is of interest.

Well, anyway, I'll try with a global variable tonight.
Bjørn S

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 11 Jul 2013, 12:34

bsork wrote:However, it seems a bit strange as long as I build the string locally and immediately assign the value to the Caption member. One would think that the value is stored in Caption together with all the other data, and that the (temporary) string variable no longer is of interest.
but the variable stored in Caption is a pointer, who is just the address to the string content
so the string have to be alive until this pointer is used by usine to access the string content and copy it

welcome in C/C++ world ;)
Martin FLEURENT - Usine Developer - SDK maintainer

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 11 Jul 2013, 14:32

martignasse wrote:welcome in C/C++ world ;)
...and thank you! :)

Of course, a pointer - I didn't think of that. That's why you go to all the trouble with vector arrays and all in the matrix modules.
Bjørn S

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 11 Jul 2013, 17:42

oh well, I'm going nowhere.

is "declare the string variable as a module member." means here :
protected:
// protected members goes here ?

...

Code: Select all

                m_textNew = sdkGetEvtPChar(m_textInput); //
		str.push_back((char) m_textNew);
		sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) (str.c_str()));
		//sdkSetEvtPChar(m_textOutput, m_textNew);
there's something wrong with the cast as if I set 77 on the input I get 'P' on the output.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 11 Jul 2013, 20:54

Code: Select all

         m_textNew = sdkGetEvtPChar(m_textInput); //
        str.push_back((char) m_textNew);
        sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) (str.c_str()));
        //sdkSetEvtPChar(m_textOutput, m_textNew);
m_textNew is a char pointer, and you add it to str as a char, that's the problem

replace

Code: Select all

 str.push_back((char) m_textNew);
by

Code: Select all

str.append(m_textNew);
and it should work
Martin FLEURENT - Usine Developer - SDK maintainer

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 12 Jul 2013, 01:53

yes it is working now ! Many thanks !

weird, this wasn't working :

Code: Select all

if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "enable" input
    {
but this is working fine

Code: Select all

	if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE)) 
	        {
		  if (sdkGetEvtData(m_enable) == 1)
		{
so now I have the proper user module to write text from a MINITEL to Usine, next to do is the module to send comma text to the MINITEL

And in between I have to better understand C++ syntax, hope "le site du zero" will suffice.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Blaakk
Member
Posts: 96
Location: Tyne and Wear, UK
Contact:

Unread post by Blaakk » 05 Apr 2015, 02:58

I know this is from relatively back-in-the-day but I just ran into the same compiler fail. Y'all probably will kick yourselves.

AinsiCharPtr
^
AnsiCharPtr

6.2 is superb.

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 13 Apr 2015, 09:43

Blaakk wrote:I know this is from relatively back-in-the-day but I just ran into the same compiler fail. Y'all probably will kick yourselves.

AinsiCharPtr
^
AnsiCharPtr

6.2 is superb.
hi Blaakk,

Yep, i made some refactoring with this version.
It's mentioned in the 'Release notes' which should be consulted carefully for each version release.
We try to avoid refactoring as it can prevent existing code to compile, but in some case, we have to.

The gold rule is to always read the 'Release notes' for new distrib version.

I'm really happy that you like the 6.2 :D
Martin FLEURENT - Usine Developer - SDK maintainer

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests