Welcome to %s forums

BrainModular Users Forum

Login Register

What is the hh Pascal equivalent of chr()?

I need help on a Patch
Post Reply
ahonoe
Member
Posts: 161
Location: Toronto
Contact:

Unread post by ahonoe » 24 Jul 2016, 22:55

I'm trying to build a string from an array of ascii values using scripting. When I try to use the standard Pascal chr() function to convert the integers in my array, hh throws an "Unknown declaration "chr"" error. (BTW I do know that in hh a string is an arrays of chars.)

Thanks for your help!
Regards,

Scott

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

Unread post by oli_lab » 25 Jul 2016, 14:56

Hi,
I'm fact you treat the char as single

Var currentChar: single

...

currentChar := GetdataArrayvalue(input, Idx );

...

SetdataArrayvalue (output, Idx, currentChar) ;
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

ahonoe
Member
Posts: 161
Location: Toronto
Contact:

Unread post by ahonoe » 25 Jul 2016, 18:39

Thanks oli. What I am trying to do is build a complete string within the script before outputting it. Something like s:=s+chr(char_arr).

Thanks again.
Regards,

Scott

shawnb
Member
Posts: 190
Location: San Francisco
Contact:

Unread post by shawnb » 25 Jul 2016, 21:36

Concatenation works - the '+' operator.

In case you missed it, there's a very handy page on strings in the scripting language tutorial:
http://www.sensomusic.org/wiki3/doku.ph ... tutorial05

Look at the examples towards the bottom.
Address the process rather than the outcome. Then, the outcome becomes more likely. - Fripp

ahonoe
Member
Posts: 161
Location: Toronto
Contact:

Unread post by ahonoe » 26 Jul 2016, 06:11

Thanks shawn. Yes I am familiar with this section of the tutorial. Appending chars to strings is clear to me. Maybe I'm missing something though.

To recap : I have an array of singles where each value represents an acsii character. I'm trying to convert this to a string. So I read each value in the array, round()ing it as I go. Now I want to convert each integer value to a char so I can append it to a string. In Pascal proper I'd use the chr() function but in hh that's not available. I guess my question really is how do I convert a single to a char.
Regards,

Scott

shawnb
Member
Posts: 190
Location: San Francisco
Contact:

Unread post by shawnb » 26 Jul 2016, 06:49

I don't do a lot of string manipulation, so I can only tell you what I'd try...

There are three approaches I'd experiment with...

(1) Your example with a recast along the way... s := s+inttostr(char_arr);

(2) Loop StrSet's, e.g., StrSet(char_arr, x, s); Don't forget to do a SetLength somewhere in there

(3) Declare char_arr as a string to begin with

Dealing with small integers you may need to recast using trunc() or int() somewhere along the line...

Shawn
Address the process rather than the outcome. Then, the outcome becomes more likely. - Fripp

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

Unread post by oli_lab » 26 Jul 2016, 18:21

Maybe simply
S := S + ArrChar ?
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

ahonoe
Member
Posts: 161
Location: Toronto
Contact:

Unread post by ahonoe » 26 Jul 2016, 18:51

shawnb:

1) appends the ascii value to my string rather than the acsii character
2) StrSet() looks interesting however hh throws an "Unknown declaration "StrSet"" error. Maybe this procedure hasn't been implement in hh?
3) char_arr is, by functional requirement, an array of singles though the values at the relevant index are always converted to integers (as they are ascii vals)

oli:

Same problem as #3 above. The array values are singles and can't be added to a string.

Thanks again for your suggestions. I do appreciate them.
Regards,

Scott

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

Unread post by oli_lab » 26 Jul 2016, 19:06

I remember having trouble with char and string with script in the past, I think I find it easier with the sdk.
I'll check in my archive for script I made using char and string...
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

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 26 Jul 2016, 20:17

hi,
you're right the CHR is missing in the script engine. It will be corrected in the next major release.

the work arround is to create the CHR function yourself like bellow. Fully customizable

senso+++

Code: Select all

function MyCHR(i:integer):Char;
const S ='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
begin
  result := S[i-40];
end;
//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
  writeln(MyChr(41)+MyChr(42));
end;

ahonoe
Member
Posts: 161
Location: Toronto
Contact:

Unread post by ahonoe » 27 Jul 2016, 15:32

Thanks oli and Olviier. I've worked around the issue by writing the chrs to, then reading them back from, a ptString output.
Regards,

Scott

Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests