Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jarikomppa/soloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jarikomppa committed Nov 15, 2021
2 parents 3016557 + 3a3fc74 commit 365018a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Osman Turan https://osmanturan.com
Samson Close https://github.com/qwertysam
Bruce A Henderson https://github.com/woollybah
Philip Bennefall https://github.com/blastbay/
Sebastian Hartte https://github.com/shartte/
Jean-Luc Mackail https://github.com/fuzzyquills
HumanGamer https://github.com/HumanGamer/
Ales Mlakar https://github.com/jazzbre
Expand Down
7 changes: 7 additions & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if (UNIX AND NOT WIN32 AND NOT APPLE)
mark_as_advanced (LIB_POSTFIX)
endif ()
endif ()
if (MSVC)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
endif()
if (NOT DEFINED LIB_POSTFIX)
set (LIB_POSTFIX "")
endif ()
Expand All @@ -29,4 +32,8 @@ IF (SOLOUD_BUILD_DEMOS)
include (demos.cmake)
endif ()

IF (SOLOUD_GENERATE_GLUE)
include (gen_glue.cmake)
endif ()

include (InstallExport)
6 changes: 6 additions & 0 deletions contrib/Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ print_option_status (SOLOUD_DYNAMIC "Build dynamic library")
option (SOLOUD_STATIC "Set to ON to build static SoLoud" ON)
print_option_status (SOLOUD_STATIC "Build static library")

option (SOLOUD_C_API "Set to ON to include the C API" OFF)
print_option_status (SOLOUD_C_API "Build C API")

# TODO:
option (SOLOUD_BUILD_DEMOS "Set to ON for building demos" OFF)
print_option_status (SOLOUD_BUILD_DEMOS "Build demos")
Expand Down Expand Up @@ -34,3 +37,6 @@ print_option_status (SOLOUD_BACKEND_WINMM "WINMM backend")

option (SOLOUD_BACKEND_WASAPI "Set to ON for building WASAPI backend" OFF)
print_option_status (SOLOUD_BACKEND_WASAPI "WASAPI backend")

option (SOLOUD_GENERATE_GLUE "Set to ON for generating the Glue APIs" OFF)
print_option_status (SOLOUD_GENERATE_GLUE "Generate Glue")
47 changes: 47 additions & 0 deletions contrib/gen_glue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# We need python to run the glue-code generators
find_package (Python3 COMPONENTS Interpreter REQUIRED)

# Create the executable that generates soloud_codegen.py
add_executable (codegen ../src/tools/codegen/main.cpp)

# Add a command to run the executable to generate the python file
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
COMMAND codegen ARGS go
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Now we can run the actual Python code-generators, BUT we need to add a dependency on
# soloud_codegen.py, or otherwise codegen.exe will not be run beforehand

###############################################################################
# C# API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_cs.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_cs.py"
)
add_custom_target (generate_glue_cs ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs" DESTINATION glue)

###############################################################################
# Python API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_ruby.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_ruby.py"
)
add_custom_target (generate_glue_ruby ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb" DESTINATION glue)

###############################################################################
# Ruby API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_python.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_python.py"
)
add_custom_target(generate_glue_python ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py" DESTINATION glue)
13 changes: 12 additions & 1 deletion contrib/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set (TARGET_HEADERS
${HEADER_PATH}/soloud_bassboostfilter.h
${HEADER_PATH}/soloud_biquadresonantfilter.h
${HEADER_PATH}/soloud_bus.h
${HEADER_PATH}/soloud_c.h
${HEADER_PATH}/soloud_dcremovalfilter.h
${HEADER_PATH}/soloud_echofilter.h
${HEADER_PATH}/soloud_error.h
Expand Down Expand Up @@ -275,6 +274,18 @@ set (TARGET_SOURCES
${FILTERS_SOURCES}
)

if (SOLOUD_C_API)
set (TARGET_SOURCES
${TARGET_SOURCES}
${SOURCE_PATH}/c_api/soloud.def
${SOURCE_PATH}/c_api/soloud_c.cpp
)
set (TARGET_HEADERS
${TARGET_HEADERS}
${HEADER_PATH}/soloud_c.h
)
endif()

if (SOLOUD_DYNAMIC)
add_library(${TARGET_NAME} ${TARGET_SOURCES})
endif ()
Expand Down
22 changes: 18 additions & 4 deletions scripts/gen_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ def fix_default_param(defparam, classname):
""" 'fixes' default parameters from C to what python expectes """
if (classname + '::') == defparam[0:len(classname)+2:]:
return defparam[len(classname)+2::]
#if defparam[len(defparam)-1] == "f":
# return defparam[0:len(defparam)-1]
return defparam

# The C API doesn't use BOOL, so the generated source will use int too,
# using a boolean as the default param for an int won't work.
if defparam == "true":
return "1"
elif defparam == "false":
return "0"

# C# uses . as namespace/class separator
return defparam.replace("::", ".")

def external_pointer_fix(param):
if param == "SoloudObject":
Expand All @@ -125,7 +132,7 @@ def external_pointer_fix(param):
if (x + "_") == y[1][0:len(x)+1:]:
if first:
fo.write('\n')
fo.write('public class %s : SoloudObject\n{\n'%(x))
fo.write('public class %s : SoloudObject, IDisposable\n{\n'%(x))
for z in soloud_codegen.soloud_enum:
if z[0:len(x)+1] == x.upper()+'_':
s = str(soloud_codegen.soloud_enum[z])
Expand All @@ -138,6 +145,13 @@ def external_pointer_fix(param):
fo.write('\t~%s()\n\t{\n'%(x))
fo.write('\t\t%s_destroy(objhandle);\n'%(x))
fo.write('\t}\n')
fo.write('\tpublic void Dispose()\n\t{\n')
fo.write('\t\tif (objhandle != IntPtr.Zero) {\n')
fo.write('\t\t\t%s_destroy(objhandle);\n'%(x))
fo.write('\t\t\tobjhandle = IntPtr.Zero;\n')
fo.write('\t\t\tGC.SuppressFinalize(this);\n')
fo.write('\t\t}\n')
fo.write('\t}\n')

first = False
funcname = y[1][len(x)+1::]
Expand Down

0 comments on commit 365018a

Please sign in to comment.