It was less painful than I though. Works perfectly. Anyone who’s interested in using this, download the text file. It contains a conversion chart that you need if you want to convert strings that have been imported as files with a fileButton or the “LAST_FILE_DROPPED” channel. Latin letters are flagged with an ASCII code of 204 that is surrounded by 2 other ones that determine the actual letter. Unfortunately there’s no system to how they are composed. Interestingly these quite complex encoded letters have a different encoding than strings with Latin letters that have been assigned in the orchestra or parsed through a texteditor widget e.t.c. Those have a simpler encoding for which you don’t need the chart. You can see in the ConvertLatins opcode that those are flagged with an ASCII code of 195 and just a second one that determines the Character which is simply just their actual ASCII code minus 64. So if you only want to display Latin letters you don’t need the text file with the conversion chart and you can delete the first part in the converting opcode and the instrument (“load Array”) that loads the text file data into some arrays.
I’m glad I’m not restricted to only English letters:
LatinConversionChart.txt (609 Bytes)
LatinCharConversion.csd (4.1 KB)
opcode ExtFromPath ,S,S
SPath xin
kStart strrindexk SPath,"."
kLength strlenk SPath
SName strsubk SPath,kStart,kLength
xout SName
endop
opcode NameXFromPath ,S,S
SPath xin
kStart strrindexk SPath,"/"
kEnd strindexk SPath,"."
;kLength strlenk SPath
SName strsubk SPath,kStart+1,kEnd
xout SName
endop
opcode DirFromPath ,S,S
SPath xin
kStart strrindexk SPath,"/"
SName strsubk SPath,0,kStart+1
xout SName
endop
gkLatinBase[] init 53
gkLatinType[] init 53
gkLatinAscii[] init 53
opcode ConvertLatins ,S,S
Sinput xin
SDir DirFromPath Sinput
SExt ExtFromPath Sinput
SName NameXFromPath Sinput
kascii = 0
kNameLen strlenk SName
kcnt = 0
while kcnt <= kNameLen do
kascii strchark strsubk(SName,kcnt,kcnt+1)
if(kascii == 204)then
Sleft strsubk SName,0,kcnt-1
Sright strsubk SName,kcnt+2,strlenk:k(SName)
kBase strchark strsubk(SName,kcnt-1,kcnt)
kType strchark strsubk(SName,kcnt+1,kcnt+2)
kcntChart = 0
while kcntChart < 53 do
if(kBase == gkLatinBase[kcntChart] && kType == gkLatinType[kcntChart])then
SName sprintfk "%s%c%s",Sleft,gkLatinAscii[kcntChart],Sright
endif
kcntChart += 1
od
endif
if(kascii == 195)then
Sleft strsubk SName,0,kcnt
Sright strsubk SName,kcnt+2,strlenk:k(SName)
kType strchark strsubk(SName,kcnt+1,kcnt+2)
SName sprintfk "%s%c%s",Sleft,kType+64,Sright
endif
kcnt += 1
od
SLatin sprintfk "%s%s%s",SDir,SName,SExt
xout SLatin
endop
instr loadArray
SCharChart init "GUI_Rescources/LatinConversionChart.txt"
kline init 0
Sline[] init 101
SLine init ""
strset 234,"1"
kcnt init 0
while (kcnt <= 100 && kline != -1) do
SLine,kline readf SCharChart
if(kcnt>0 && kcnt <=53)then
String1 sprintfk "%s",strsubk:S(SLine,0,strindexk:k(SLine,","))
String2 sprintfk "%s",strsubk:S(SLine,strindexk:k(SLine,",")+1,strindexk:k(SLine,":"))
String3 sprintfk "%s",strsubk:S(SLine,strindexk:k(SLine,":")+1,strindexk:k(SLine,"\n"))
String1 strget 234
gkLatinBase[kcnt-1] strtolk String1
String2 strget 234
gkLatinType[kcnt-1] strtolk String2
String3 strget 234
gkLatinAscii[kcnt-1] strtolk String3
endif
kcnt +=1
od
endin
instr 1
SDrop cabbageGet "LAST_FILE_DROPPED"
if(changed(SDrop)==1)then
SLatin ConvertLatins SDrop
cabbageSet 1,"filename","text",SLatin
SIdentString sprintfk "file(\"%s\")",SLatin
cabbageSet 1, "waveform", SIdentString
endif
SRename cabbageGet "rename"
if(changed(SRename)==1)then
SLatin ConvertLatins SRename
cabbageSet 1,"filename","text",SLatin
endif
endin