diff --git a/GdpdExample/Main.tscn b/GdpdExample/Main.tscn index fd759a5edab940885595187a4b7f457500da9ec3..9c9c91d01212770da591b055664da4a17323640b 100644 --- a/GdpdExample/Main.tscn +++ b/GdpdExample/Main.tscn @@ -3,35 +3,83 @@ [sub_resource type="GDScript" id=1] script/source = "extends Control -var gdpd = load(\"res://addons/gdpd/bin/gdpd.gdns\") -#var patch +var _gdpd -func _ready(): - - #the patch path should be the absolute one - _load_patch(ProjectSettings.globalize_path(\"res://patch1.pd\")) - _load_patch(ProjectSettings.globalize_path(\"res://patch2.pd\")) +var _patch = 0 +func _ready(): + _gdpd = load(\"res://addons/gdpd/bin/gdpd.gdns\").new() + pass + +func _process(delta): + while _gdpd.has_message() : + print(\"got msg\") + var msg = _gdpd.get_next() + print(msg) func _load_patch(pd_patch) : #separate file name from directory var patch_name = pd_patch.split(\"/\")[-1] var patch_dir = pd_patch.trim_suffix(patch_name) + + #load patch + _gdpd.openfile(patch_name, patch_dir) + +func _on_Start_pressed() : + var inps = _gdpd.get_available_input_devices() + var outs = _gdpd.get_available_output_devices() + _gdpd.init_devices(inps[0], outs[0]) - #initialize pd - var patch = gdpd.new() + #the patch path should be the absolute one + _load_patch(ProjectSettings.globalize_path(\"res://patch1.pd\")) + _load_patch(ProjectSettings.globalize_path(\"res://patch2.pd\")) + + _gdpd.start_message(1) + _gdpd.add_symbol(\"from godot\") + _gdpd.finish_list(\"blup\") - #retrieve - var inps = patch.get_available_input_devices() - var outs = patch.get_available_output_devices() - patch.init_devices(inps[0], outs[0]) + _gdpd.subscribe(\"toBfWeb\") +func _on_Stop_pressed(): - #load patch - patch.openfile(patch_name, patch_dir) + _gdpd.closefile(\"patch1.pd\") + _gdpd.closefile(\"patch2.pd\") + _gdpd.stop() + + " [node name="Control" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 script = SubResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Stop" type="Button" parent="."] +margin_left = 73.0 +margin_top = 198.0 +margin_right = 176.0 +margin_bottom = 244.0 +text = "Stop" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Start" type="Button" parent="."] +margin_left = 83.0 +margin_top = 93.0 +margin_right = 187.0 +margin_bottom = 144.0 +text = "Start" + +[node name="Load" type="Button" parent="."] +margin_left = 103.0 +margin_top = 159.0 +margin_right = 145.0 +margin_bottom = 179.0 +text = "Load" +[connection signal="pressed" from="Stop" to="." method="_on_Stop_pressed"] +[connection signal="pressed" from="Start" to="." method="_on_Start_pressed"] +[connection signal="pressed" from="Load" to="." method="_on_Load_pressed"] diff --git a/GdpdExample/patch1.pd b/GdpdExample/patch1.pd index 1b76f22db6ca7e7058e0a5c3f1f4d3fdabdba2ac..3c3f092e53e168b62056dfd4cffeee438ef2843c 100644 Binary files a/GdpdExample/patch1.pd and b/GdpdExample/patch1.pd differ diff --git a/GdpdExample/patch2.pd b/GdpdExample/patch2.pd index a21bd1f0f0bbc0e0ca10b06711b81c5f93e550f0..099314ff1570d8d522778c1d39ceece6d758e04f 100644 Binary files a/GdpdExample/patch2.pd and b/GdpdExample/patch2.pd differ diff --git a/GdpdExample/project.godot b/GdpdExample/project.godot index ccec52e3f776f1b9920d0b5c74b7ec7bd2ba7ff3..efa53133e88dc4f346b0297d5503b25119e90be8 100644 --- a/GdpdExample/project.godot +++ b/GdpdExample/project.godot @@ -17,6 +17,7 @@ _global_script_class_icons={ config/name="GdpdExample" run/main_scene="res://Main.tscn" +run/low_processor_mode=true config/icon="res://icon.png" [rendering] diff --git a/SConstruct b/SConstruct index 62b159afec1666beafda5da739cfbc68ada10ccd..bc8f2ee236509126f2699c0610d4e41ccf40b5c0 100644 --- a/SConstruct +++ b/SConstruct @@ -61,6 +61,8 @@ if env['platform'] == "osx": env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64']) elif env['platform'] in ('x11', 'linux'): + env['CC'] = 'gcc-7' + env['CXX'] = 'g++-7' env['target_path'] += 'x11/' cpp_library += '.linux' env.Append(CPPDEFINES=['__UNIX_JACK__', 'LIBPD_EXTRA']) @@ -90,7 +92,7 @@ elif env['platform'] == "windows": # 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(CXXFLAGS=['-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(CFLAGS=['-DWINVER=0x502','-DWIN32','-D_WIN32','-Wno-int-to-pointer-cast', @@ -104,13 +106,11 @@ elif env['platform'] == "windows": env.Append(LINKFLAGS=['-Wl,--export-all-symbols', '-static-libgcc','/usr/x86_64-w64-mingw32/lib/libm.a']) - #env.Append(LINKFLAGS=['-lkernel32','-luser32', '-lgdi32', - # '-lwinspool', '-lshell32', '-lole32', - # '-loleaut32', '-luuid', '-lcomdlg32', - # '-ladvapi32','-lws2_32', '-lwsock32']) - env.Append(LINKFLAGS=['/usr/x86_64-w64-mingw32/lib/libws2_32.a', - '/usr/x86_64-w64-mingw32/lib/libwsock32.a']) - + env.Append(LIBS=['-lkernel32','-luser32', '-lgdi32', + '-lwinspool', '-lshell32', '-lole32', + '-loleaut32', '-luuid', '-lcomdlg32', + '-ladvapi32','-lws2_32', '-lwsock32']) + env['SHLIBSUFFIX'] = '.dll' #env.Append(CPPDEFINES=['WINVER=0x502']) #env.Append(CCFLAGS=['-W3', '-GR']) diff --git a/src/gdpd.cpp b/src/gdpd.cpp index 551b1a6ee4133bdffe5b368d86e4effa5b0c5a5f..e1c3d57995a9af2edb5a68e1d0f6b3f46e03e90c 100644 --- a/src/gdpd.cpp +++ b/src/gdpd.cpp @@ -32,6 +32,9 @@ int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer, } Gdpd::Gdpd(): m_vol(1) { + //create message array + m_messages = new Array(); + m_init=false; } void Gdpd::_init() { @@ -110,19 +113,12 @@ int Gdpd::start() { if(!m_pd.init(m_nbInputs, m_nbOutputs, m_sampleRate, true)) { - Godot::print("GDPD : Error starting libpd"); + print("GDPD : Error starting libpd"); return 1; } //libpd_set_verbose(1); - //create message array - m_messages = new Array(); - - //create message hook - m_pd.subscribe("to_gdpd"); - m_pd.setReceiver(this); - //start dsp m_pd.computeAudio(true); @@ -142,11 +138,16 @@ int Gdpd::start() { m_sampleRate, &m_bufferFrames, &audioCallback, this, &options); m_audio.startStream(); + print("Stream started"); } catch(RtAudioError& e) { Godot::print(e.getMessage().c_str()); } + //create message hook + m_pd.subscribe("to_gdpd"); + m_pd.setReceiver(this); + m_init=true; print("Initialized"); @@ -156,7 +157,6 @@ int Gdpd::start() { void Gdpd::stop() { m_audio.stopStream(); m_audio.closeStream(); - m_pd.clear(); m_pd.computeAudio(false); print("Stopped"); } @@ -180,17 +180,42 @@ void Gdpd::openfile(godot::String baseStr, godot::String dirStr) { std::wstring dirWs = dirStr.unicode_str(); std::string dirS(dirWs.begin(), dirWs.end()); + if(m_patchsMap.find(baseS)!=m_patchsMap.end()) { + print("Patch "+baseS+" already opened"); + return; + } + //libpd_openfile(baseS.c_str(), dirS.c_str()); //m_patch = m_pd.openPatch(baseS.c_str(), dirS.c_str()); - m_pd.openPatch(baseS.c_str(), dirS.c_str()); + pd::Patch p1 = m_pd.openPatch(baseS.c_str(), dirS.c_str()); + if(!p1.isValid()) { + print("Could not open patch "+baseS); + } + else { + print("Opened patch "+baseS); + m_patchsMap[baseS] = p1; + } + + //m_pd.subscribe("to_gdpd"); - print("Opened patch"); + /* + if(!m_pd.init(m_nbInputs, m_nbOutputs, m_sampleRate, true)) { + Godot::print("GDPD : Error starting libpd"); + } + m_pd.setReceiver(this); + m_pd.computeAudio(true); + */ } void Gdpd::closefile(godot::String baseStr) { std::wstring baseWs = baseStr.unicode_str(); std::string baseS(baseWs.begin(), baseWs.end()); - m_pd.closePatch(baseS.c_str()); + if(m_patchsMap.find(baseS)!=m_patchsMap.end()) { + m_pd.closePatch(m_patchsMap[baseS]); + m_patchsMap.erase(baseS); + print("Closed patch "+baseS); + } + //m_pd.closePatch(baseS.c_str()); } void Gdpd::subscribe(String symbStr) { @@ -240,7 +265,6 @@ int Gdpd::finish_list(String destStr) { return res; } - void Gdpd::print(const std::string& message) { Godot::print((std::string("GDPD : ")+message).c_str()); } diff --git a/src/gdpd.hpp b/src/gdpd.hpp index 2bedbb99c3ea5c445e9fa1a73237277bb787afd6..3bf3ea1c3725b8ce6c0c8b0726d3639fdd0d21d2 100644 --- a/src/gdpd.hpp +++ b/src/gdpd.hpp @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <map> #include <Godot.hpp> #include <AudioStreamPlayer.hpp> @@ -31,6 +32,9 @@ private: int m_sampleRate; int m_inputDevice; int m_outputDevice; + std::map<std::string, pd::Patch> m_patchsMap; + + bool m_init; public: static void _register_methods(); diff --git a/src/rtaudio/RtAudio.os b/src/rtaudio/RtAudio.os index 067f8bb431a651b59d9ae5deccc671021129c206..3dcef4dac9ca78a6d91bee5d39bcb91a19fc6473 100644 Binary files a/src/rtaudio/RtAudio.os and b/src/rtaudio/RtAudio.os differ