Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
VAPython
Commits
9d35155d
Commit
9d35155d
authored
Aug 23, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Fixing problems with string to unicode conversions by replacing false characters with underscores
parent
f349ce7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/vasingleton.cpp
View file @
9d35155d
...
...
@@ -19,15 +19,15 @@ static struct PyMethodDef va_methods[] =
{
"call_module"
,
(
PyCFunction
)
va_call_module
,
METH_FASTCALL
,
va_no_doc
},
{
"add_search_path"
,
(
PyCFunction
)
va_add_search_path
,
METH_FASTCALL
,
va_no_doc
},
{
"load_directivity"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"free_directivity"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"get_directivity_info"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"get_directivity_infos"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"load_hrir"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"free_hrir"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"get_hrir_info"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"get_hrir_infos"
,
(
PyCFunction
)
va_
not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"load_directivity"
,
(
PyCFunction
)
va_
load_directivity
,
METH_FASTCALL
,
va_no_doc
},
{
"free_directivity"
,
(
PyCFunction
)
va_
free_directivity
,
METH_FASTCALL
,
va_no_doc
},
{
"get_directivity_info"
,
(
PyCFunction
)
va_
get_directivity_info
,
METH_FASTCALL
,
va_no_doc
},
{
"get_directivity_infos"
,
(
PyCFunction
)
va_
get_directivity_infos
,
METH_FASTCALL
,
va_no_doc
},
{
"load_hrir"
,
(
PyCFunction
)
va_
load_hrir
,
METH_FASTCALL
,
va_no_doc
},
{
"free_hrir"
,
(
PyCFunction
)
va_
free_hrir
,
METH_FASTCALL
,
va_no_doc
},
{
"get_hrir_info"
,
(
PyCFunction
)
va_
get_hrir_info
,
METH_FASTCALL
,
va_no_doc
},
{
"get_hrir_infos"
,
(
PyCFunction
)
va_
get_hrir_infos
,
METH_FASTCALL
,
va_no_doc
},
{
"create_audio_file_signal_source"
,
(
PyCFunction
)
va_not_implemented
,
METH_FASTCALL
,
va_no_doc
},
{
"create_text_to_speech_signal_source"
,
(
PyCFunction
)
va_not_implemented
,
METH_FASTCALL
,
va_no_doc
},
...
...
src/vasingletonmethods.hpp
View file @
9d35155d
...
...
@@ -58,7 +58,7 @@ PyObject* ConvertVAStructToPythonDict(const CVAStruct& oInStruct)
}
else
if
(
oValue
.
IsString
())
{
pNewValue
=
PyUnicode_FromString
(
std
::
string
(
oValue
).
c_str
());
pNewValue
=
PyUnicode_FromString
(
SaveStringToUnicodeConversion
(
std
::
string
(
oValue
)
)
.
c_str
());
}
else
if
(
oValue
.
IsStruct
())
{
...
...
@@ -150,6 +150,17 @@ CVAStruct ConvertPythonDictToVAStruct(PyObject* pInDict)
};
std
::
string
SaveStringToUnicodeConversion
(
const
std
::
string
&
sInputString
)
{
std
::
string
sOutputString
=
sInputString
;
const
Py_ssize_t
iLength
=
sInputString
.
length
();
char
*
pcBuffer
(
&
sOutputString
[
0
]
);
for
(
Py_ssize_t
i
=
0
;
i
<
iLength
;
i
++
)
if
(
pcBuffer
[
i
]
<
0
)
pcBuffer
[
i
]
=
'_'
;
return
&
sOutputString
[
0
];
};
// ------------------------------- Python module extension methods
static
PyObject
*
va_connect
(
PyObject
*
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
...
...
@@ -339,15 +350,15 @@ static PyObject* va_get_directivity_info(PyObject*, PyObject** ppArgs, Py_ssize_
long
iID
=
-
1
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
iID
))
return
NULL
;
CVADirectivityInfo
oInfo
=
g_pVANetClient
->
GetCoreInstance
()
->
GetDirectivityInfo
(
iID
);
PyObject
*
pInfo
=
Py_BuildValue
(
"{s:i,s:s,s:s,s:i,s:s}"
,
"id"
,
oInfo
.
iID
,
"name"
,
oInfo
.
sName
.
c_str
(),
"filepath"
,
oInfo
.
sFilename
.
c_str
(),
PyObject
*
pInfo
=
Py_BuildValue
(
"{s:i,s:s,s:s,s:i,s:s}"
,
"id"
,
oInfo
.
iID
,
"name"
,
SaveStringToUnicodeConversion
(
oInfo
.
sName
)
.
c_str
(),
"filepath"
,
SaveStringToUnicodeConversion
(
oInfo
.
sFilename
)
.
c_str
(),
"references"
,
oInfo
.
iReferences
,
"description"
,
oInfo
.
sDesc
.
c_str
());
"description"
,
SaveStringToUnicodeConversion
(
oInfo
.
sDesc
)
.
c_str
());
return
pInfo
;
...
...
@@ -368,14 +379,96 @@ static PyObject* va_get_directivity_infos(PyObject*, PyObject*)
CVADirectivityInfo
&
oInfo
(
voInfos
[
i
]);
PyObject
*
pInfo
=
Py_BuildValue
(
"{s:i,s:s,s:s,s:i,s:s}"
,
"id"
,
oInfo
.
iID
,
"name"
,
oInfo
.
sName
.
c_str
(),
"filepath"
,
oInfo
.
sFilename
.
c_str
(),
"name"
,
SaveStringToUnicodeConversion
(
oInfo
.
sName
)
.
c_str
(),
"filepath"
,
SaveStringToUnicodeConversion
(
oInfo
.
sFilename
)
.
c_str
(),
"references"
,
oInfo
.
iReferences
,
"description"
,
oInfo
.
sDesc
.
c_str
());
"description"
,
SaveStringToUnicodeConversion
(
oInfo
.
sDesc
)
.
c_str
());
PyList_SetItem
(
pInfoList
,
i
,
pInfo
);
// steals reference
}
return
pInfoList
;
VAPY_CATCH_RETURN
;
};
\ No newline at end of file
};
static
PyObject
*
va_load_hrir
(
PyObject
*
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
VAPY_REQUIRE_CONN_TRY
;
static
const
char
*
const
_keywords
[]
=
{
"path"
,
"name"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"s|s:load_hrir"
,
_keywords
,
0
};
char
*
pcPath
=
nullptr
;
char
*
pcName
=
nullptr
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
pcPath
,
&
pcName
))
return
NULL
;
std
::
string
sName
=
pcName
?
std
::
string
(
pcName
)
:
""
;
return
PyBool_FromLong
(
g_pVANetClient
->
GetCoreInstance
()
->
LoadHRIRDataset
(
std
::
string
(
pcPath
),
sName
));
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_free_hrir
(
PyObject
*
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
VAPY_REQUIRE_CONN_TRY
;
static
const
char
*
const
_keywords
[]
=
{
"id"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"i:free_hrir"
,
_keywords
,
0
};
long
iID
=
-
1
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
iID
))
return
NULL
;
return
PyBool_FromLong
(
g_pVANetClient
->
GetCoreInstance
()
->
FreeHRIRDataset
(
iID
));
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_get_hrir_info
(
PyObject
*
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
VAPY_REQUIRE_CONN_TRY
;
static
const
char
*
const
_keywords
[]
=
{
"id"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"i:get_hrir_info"
,
_keywords
,
0
};
long
iID
=
-
1
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
iID
))
return
NULL
;
CVAHRIRInfo
oInfo
=
g_pVANetClient
->
GetCoreInstance
()
->
GetHRIRInfo
(
iID
);
PyObject
*
pInfo
=
Py_BuildValue
(
"{s:i,s:s,s:s,s:i,s:s}"
,
"id"
,
oInfo
.
iID
,
"name"
,
SaveStringToUnicodeConversion
(
oInfo
.
sName
).
c_str
(),
"filepath"
,
SaveStringToUnicodeConversion
(
oInfo
.
sFilename
).
c_str
(),
"references"
,
oInfo
.
iReferences
,
"description"
,
SaveStringToUnicodeConversion
(
oInfo
.
sDesc
).
c_str
());
return
pInfo
;
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_get_hrir_infos
(
PyObject
*
,
PyObject
*
)
{
VAPY_REQUIRE_CONN_TRY
;
std
::
vector
<
CVAHRIRInfo
>
voInfos
;
g_pVANetClient
->
GetCoreInstance
()
->
GetHRIRInfos
(
voInfos
);
PyObject
*
pInfoList
=
PyList_New
(
voInfos
.
size
());
for
(
size_t
i
=
0
;
i
<
voInfos
.
size
();
i
++
)
{
CVAHRIRInfo
&
oInfo
(
voInfos
[
i
]);
PyObject
*
pInfo
=
Py_BuildValue
(
"{s:i,s:s,s:s,s:i,s:s}"
,
"id"
,
oInfo
.
iID
,
"name"
,
SaveStringToUnicodeConversion
(
oInfo
.
sName
).
c_str
(),
"filepath"
,
SaveStringToUnicodeConversion
(
oInfo
.
sFilename
).
c_str
(),
"references"
,
oInfo
.
iReferences
,
"description"
,
SaveStringToUnicodeConversion
(
oInfo
.
sDesc
).
c_str
());
PyList_SetItem
(
pInfoList
,
i
,
pInfo
);
// steals reference
}
return
pInfoList
;
VAPY_CATCH_RETURN
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment