From 779a05a5cbbc67157fa311df1bd4f7782beeeef8 Mon Sep 17 00:00:00 2001 From: BERTHAUT Florent <florent.berthaut@univ-lille1.fr> Date: Tue, 14 Jul 2020 18:37:04 +0200 Subject: [PATCH] Updated stop function --- SConstruct | 45 ++++++++++++++++++++++++++++++++++----------- src/gdpd.cpp | 14 +++++++++++--- src/gdpd.hpp | 1 + 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/SConstruct b/SConstruct index ce423e5..6ee59d1 100644 --- a/SConstruct +++ b/SConstruct @@ -11,6 +11,7 @@ opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx'])) opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx'])) opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no')) +opts.Add(BoolVariable('use_mingw', "Use the MingW for cross-compiling", 'no')) opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/')) opts.Add(PathVariable('target_name', 'The library name.', 'libgdpd', PathVariable.PathAccept)) @@ -30,6 +31,7 @@ if env['use_llvm']: env['CC'] = 'clang' env['CXX'] = 'clang++' + if env['p'] != '': env['platform'] = env['p'] @@ -75,19 +77,40 @@ elif env['platform'] in ('x11', 'linux'): elif env['platform'] == "windows": env['target_path'] += 'win64/' cpp_library += '.windows' - # This makes sure to keep the session environment variables on windows, - # that way you can run scons in a vs 2017 prompt and it will find all the required tools env.Append(ENV=os.environ) - env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS']) - env.Append(CCFLAGS=['-W3', '-GR']) - if env['target'] in ('debug', 'd'): - env.Append(CPPDEFINES=['_DEBUG']) - env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI']) - env.Append(LINKFLAGS=['-DEBUG']) + if not env['use_mingw']: + # MSVC + env.Append(LINKFLAGS=['/WX']) + if env['target'] == 'debug': + env.Append(CCFLAGS=['/EHsc', '/D_DEBUG', '/MDd']) + elif env['target'] == 'release': + env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD']) else: - env.Append(CPPDEFINES=['NDEBUG']) - env.Append(CCFLAGS=['-O2', '-EHsc', '-MD']) + # MinGW + env['CXX'] = 'x86_64-w64-mingw32-g++-win32' + env['CC'] = 'x86_64-w64-mingw32-gcc-win32' + env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings', '-fpermissive']) + env.Append(LINKFLAGS=['--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++']) + env.Append(CPPDEFINES=['WIN32', '_WIN32', '_MSC_VER', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS']) + #env.Append(CPPDEFINES=['__WINDOWS_DS__', 'LIBPD_EXTRA']) + env.Append(CPPDEFINES=['__RTAUDIO_DUMMY__', 'LIBPD_EXTRA']) + env.Append(CFLAGS=['-DUSEAPI_DUMMY', '-DPD', '-DHAVE_UNISTD_H', '-D_GNU_SOURCE']) + + + #env.Append(CPPDEFINES=['WINVER=0x502']) + #env.Append(CCFLAGS=['-W3', '-GR']) + env.Append(LINKFLAGS=['-pthread']) + #if env['use_mingw']: + #env['CC'] = 'x86_64-w64-mingw32-gcc' + #env['CXX'] = 'x86_64-w64-mingw32-g++' + #env['AR'] = "x86_64-w64-mingw32-ar" + #env['RANLIB'] = "x86_64-w64-mingw32-ranlib" + #env['LINK'] = "x86_64-w64-mingw32-g++" +# env.Append(CFLAGS=['-std=c11']) + # env.Append(CXXFLAGS=['-fpermissive']) + # env.Append(LIBS=['ws2_32', 'kernel32']) + # env.Append(LINKFLAGS=['-shared', '-Wl,--export-all-symbols','-mwindows','-Wl,-enable-stdcall-fixup']) if env['target'] in ('debug', 'd'): cpp_library += '.debug' @@ -96,7 +119,7 @@ else: cpp_library += '.' + str(bits) -# make sure our binding library is properly includes +# make sure our binding library is properly included env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/', 'src/libpd/cpp','src/libpd/pure-data/src', 'src/libpd/libpd_wrapper', 'src/libpd/libpd_wrapper/util', 'src/rtaudio']) env.Append(LIBPATH=[cpp_bindings_path + 'bin/']) env.Append(LIBS=[cpp_library]) diff --git a/src/gdpd.cpp b/src/gdpd.cpp index 4cc88e3..0d53f63 100644 --- a/src/gdpd.cpp +++ b/src/gdpd.cpp @@ -9,6 +9,7 @@ void Gdpd::_register_methods() { &Gdpd::get_available_output_devices); register_method("init_devices", &Gdpd::init_devices); register_method("init", &Gdpd::init); + register_method("stop", &Gdpd::stop); register_method("openfile", &Gdpd::openfile); register_method("closefile", &Gdpd::closefile); register_method("subscribe", &Gdpd::subscribe); @@ -130,8 +131,6 @@ int Gdpd::start() { Godot::print("There are no available sound devices."); } - - RtAudio::StreamOptions options; options.streamName = "gdpd"; options.flags = RTAUDIO_SCHEDULE_REALTIME; @@ -154,6 +153,14 @@ int Gdpd::start() { return 0; } +void Gdpd::stop() { + m_audio.stopStream(); + m_audio.closeStream(); + m_pd.closePatch(m_patch); + m_pd.computeAudio(false); + print("Stopped"); +} + void Gdpd::processAudio(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData) { @@ -173,7 +180,8 @@ void Gdpd::openfile(godot::String baseStr, godot::String dirStr) { std::wstring dirWs = dirStr.unicode_str(); std::string dirS(dirWs.begin(), dirWs.end()); - libpd_openfile(baseS.c_str(), dirS.c_str()); + //libpd_openfile(baseS.c_str(), dirS.c_str()); + m_patch = m_pd.openPatch(baseS.c_str(), dirS.c_str()); print("Opened patch"); } diff --git a/src/gdpd.hpp b/src/gdpd.hpp index e16f9d4..ae00d9f 100644 --- a/src/gdpd.hpp +++ b/src/gdpd.hpp @@ -46,6 +46,7 @@ public: int init_devices(String inputDevice, String outputDevice); int init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize); int start(); + void stop(); void openfile(String basename, String dirname); void closefile(); bool has_message(); -- GitLab