Fixed lost communication when reinit
This commit is contained in:
parent
24051ef4bb
commit
97a4035115
8 changed files with 146 additions and 40 deletions
|
|
@ -3,35 +3,83 @@
|
||||||
[sub_resource type="GDScript" id=1]
|
[sub_resource type="GDScript" id=1]
|
||||||
script/source = "extends Control
|
script/source = "extends Control
|
||||||
|
|
||||||
var gdpd = load(\"res://addons/gdpd/bin/gdpd.gdns\")
|
var _gdpd
|
||||||
#var patch
|
|
||||||
|
var _patch = 0
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
_gdpd = load(\"res://addons/gdpd/bin/gdpd.gdns\").new()
|
||||||
|
pass
|
||||||
|
|
||||||
#the patch path should be the absolute one
|
func _process(delta):
|
||||||
_load_patch(ProjectSettings.globalize_path(\"res://patch1.pd\"))
|
while _gdpd.has_message() :
|
||||||
_load_patch(ProjectSettings.globalize_path(\"res://patch2.pd\"))
|
print(\"got msg\")
|
||||||
|
var msg = _gdpd.get_next()
|
||||||
|
print(msg)
|
||||||
|
|
||||||
func _load_patch(pd_patch) :
|
func _load_patch(pd_patch) :
|
||||||
#separate file name from directory
|
#separate file name from directory
|
||||||
var patch_name = pd_patch.split(\"/\")[-1]
|
var patch_name = pd_patch.split(\"/\")[-1]
|
||||||
var patch_dir = pd_patch.trim_suffix(patch_name)
|
var patch_dir = pd_patch.trim_suffix(patch_name)
|
||||||
|
|
||||||
#initialize pd
|
|
||||||
var patch = gdpd.new()
|
|
||||||
|
|
||||||
#retrieve
|
|
||||||
var inps = patch.get_available_input_devices()
|
|
||||||
var outs = patch.get_available_output_devices()
|
|
||||||
patch.init_devices(inps[0], outs[0])
|
|
||||||
|
|
||||||
|
|
||||||
#load patch
|
#load patch
|
||||||
patch.openfile(patch_name, patch_dir)
|
_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])
|
||||||
|
|
||||||
|
#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\")
|
||||||
|
|
||||||
|
_gdpd.subscribe(\"toBfWeb\")
|
||||||
|
|
||||||
|
func _on_Stop_pressed():
|
||||||
|
|
||||||
|
_gdpd.closefile(\"patch1.pd\")
|
||||||
|
_gdpd.closefile(\"patch2.pd\")
|
||||||
|
_gdpd.stop()
|
||||||
|
|
||||||
|
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="Control" type="Control"]
|
[node name="Control" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
script = SubResource( 1 )
|
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"]
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,29 @@
|
||||||
#N canvas 2 88 450 300 12;
|
#N canvas 2 268 738 330 12;
|
||||||
#X obj 344 82 s pd;
|
#X obj 344 82 s pd;
|
||||||
#X obj 344 31 loadbang;
|
#X obj 344 31 loadbang;
|
||||||
#X msg 344 55 dsp 1;
|
#X msg 344 55 dsp 1;
|
||||||
#X obj 152 134 dac~;
|
#X obj 152 134 dac~;
|
||||||
#X obj 152 86 osc~ 440;
|
#X obj 152 86 osc~ 440;
|
||||||
#X obj 152 110 *~ 0.1;
|
#X obj 152 110 *~ 0.1;
|
||||||
|
#X obj 240 91 loadbang;
|
||||||
|
#X obj 241 141 metro 1000;
|
||||||
|
#X msg 240 168 patch1 0;
|
||||||
|
#X obj 564 191 print patch1;
|
||||||
|
#X obj 491 27 r blup;
|
||||||
|
#X obj 506 91 print patch1;
|
||||||
|
#X obj 239 255 s toBfWeb;
|
||||||
|
#X obj 559 148 r toBfWeb;
|
||||||
|
#X obj 240 193 list append;
|
||||||
|
#X obj 491 51 t b b;
|
||||||
#X connect 1 0 2 0;
|
#X connect 1 0 2 0;
|
||||||
#X connect 2 0 0 0;
|
#X connect 2 0 0 0;
|
||||||
#X connect 4 0 5 0;
|
#X connect 4 0 5 0;
|
||||||
#X connect 5 0 3 0;
|
#X connect 5 0 3 0;
|
||||||
#X connect 5 0 3 1;
|
#X connect 5 0 3 1;
|
||||||
|
#X connect 6 0 7 0;
|
||||||
|
#X connect 7 0 8 0;
|
||||||
|
#X connect 8 0 14 0;
|
||||||
|
#X connect 10 0 15 0;
|
||||||
|
#X connect 13 0 9 0;
|
||||||
|
#X connect 14 0 12 0;
|
||||||
|
#X connect 15 1 11 0;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,24 @@
|
||||||
#N canvas 2 88 450 300 12;
|
#N canvas 2 328 450 300 12;
|
||||||
#X obj 344 82 s pd;
|
#X obj 344 82 s pd;
|
||||||
#X obj 344 31 loadbang;
|
#X obj 344 31 loadbang;
|
||||||
#X msg 344 55 dsp 1;
|
#X msg 344 55 dsp 1;
|
||||||
#X obj 152 134 dac~;
|
#X obj 152 134 dac~;
|
||||||
#X obj 152 110 *~ 0.1;
|
#X obj 152 110 *~ 0.1;
|
||||||
#X obj 152 86 osc~ 600;
|
#X obj 152 86 osc~ 600;
|
||||||
|
#X obj 240 111 loadbang;
|
||||||
|
#X obj 241 141 metro 1000;
|
||||||
|
#X msg 240 168 patch2 0;
|
||||||
|
#X obj 230 239 s toBfWeb;
|
||||||
|
#X obj 247 207 list append;
|
||||||
|
#X obj 24 166 r toBfWeb;
|
||||||
|
#X obj 24 190 print patch2;
|
||||||
#X connect 1 0 2 0;
|
#X connect 1 0 2 0;
|
||||||
#X connect 2 0 0 0;
|
#X connect 2 0 0 0;
|
||||||
#X connect 4 0 3 0;
|
#X connect 4 0 3 0;
|
||||||
#X connect 4 0 3 1;
|
#X connect 4 0 3 1;
|
||||||
#X connect 5 0 4 0;
|
#X connect 5 0 4 0;
|
||||||
|
#X connect 6 0 7 0;
|
||||||
|
#X connect 7 0 8 0;
|
||||||
|
#X connect 8 0 10 0;
|
||||||
|
#X connect 10 0 9 0;
|
||||||
|
#X connect 11 0 12 0;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ _global_script_class_icons={
|
||||||
|
|
||||||
config/name="GdpdExample"
|
config/name="GdpdExample"
|
||||||
run/main_scene="res://Main.tscn"
|
run/main_scene="res://Main.tscn"
|
||||||
|
run/low_processor_mode=true
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
|
||||||
16
SConstruct
16
SConstruct
|
|
@ -61,6 +61,8 @@ if env['platform'] == "osx":
|
||||||
env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
|
env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
|
||||||
|
|
||||||
elif env['platform'] in ('x11', 'linux'):
|
elif env['platform'] in ('x11', 'linux'):
|
||||||
|
env['CC'] = 'gcc-7'
|
||||||
|
env['CXX'] = 'g++-7'
|
||||||
env['target_path'] += 'x11/'
|
env['target_path'] += 'x11/'
|
||||||
cpp_library += '.linux'
|
cpp_library += '.linux'
|
||||||
env.Append(CPPDEFINES=['__UNIX_JACK__', 'LIBPD_EXTRA'])
|
env.Append(CPPDEFINES=['__UNIX_JACK__', 'LIBPD_EXTRA'])
|
||||||
|
|
@ -90,7 +92,7 @@ elif env['platform'] == "windows":
|
||||||
# MinGW
|
# MinGW
|
||||||
env['CXX'] = 'x86_64-w64-mingw32-g++-win32'
|
env['CXX'] = 'x86_64-w64-mingw32-g++-win32'
|
||||||
env['CC'] = 'x86_64-w64-mingw32-gcc-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(LINKFLAGS=['--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++'])
|
||||||
#env.Append(CPPDEFINES=['WIN32', '_WIN32', '_MSC_VER', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS'])
|
#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',
|
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',
|
env.Append(LINKFLAGS=['-Wl,--export-all-symbols',
|
||||||
'-static-libgcc','/usr/x86_64-w64-mingw32/lib/libm.a'])
|
'-static-libgcc','/usr/x86_64-w64-mingw32/lib/libm.a'])
|
||||||
|
|
||||||
#env.Append(LINKFLAGS=['-lkernel32','-luser32', '-lgdi32',
|
env.Append(LIBS=['-lkernel32','-luser32', '-lgdi32',
|
||||||
# '-lwinspool', '-lshell32', '-lole32',
|
'-lwinspool', '-lshell32', '-lole32',
|
||||||
# '-loleaut32', '-luuid', '-lcomdlg32',
|
'-loleaut32', '-luuid', '-lcomdlg32',
|
||||||
# '-ladvapi32','-lws2_32', '-lwsock32'])
|
'-ladvapi32','-lws2_32', '-lwsock32'])
|
||||||
env.Append(LINKFLAGS=['/usr/x86_64-w64-mingw32/lib/libws2_32.a',
|
env['SHLIBSUFFIX'] = '.dll'
|
||||||
'/usr/x86_64-w64-mingw32/lib/libwsock32.a'])
|
|
||||||
|
|
||||||
|
|
||||||
#env.Append(CPPDEFINES=['WINVER=0x502'])
|
#env.Append(CPPDEFINES=['WINVER=0x502'])
|
||||||
#env.Append(CCFLAGS=['-W3', '-GR'])
|
#env.Append(CCFLAGS=['-W3', '-GR'])
|
||||||
|
|
|
||||||
50
src/gdpd.cpp
50
src/gdpd.cpp
|
|
@ -32,6 +32,9 @@ int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdpd::Gdpd(): m_vol(1) {
|
Gdpd::Gdpd(): m_vol(1) {
|
||||||
|
//create message array
|
||||||
|
m_messages = new Array();
|
||||||
|
m_init=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gdpd::_init() {
|
void Gdpd::_init() {
|
||||||
|
|
@ -110,19 +113,12 @@ int Gdpd::start() {
|
||||||
|
|
||||||
|
|
||||||
if(!m_pd.init(m_nbInputs, m_nbOutputs, m_sampleRate, true)) {
|
if(!m_pd.init(m_nbInputs, m_nbOutputs, m_sampleRate, true)) {
|
||||||
Godot::print("GDPD : Error starting libpd");
|
print("GDPD : Error starting libpd");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//libpd_set_verbose(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
|
//start dsp
|
||||||
m_pd.computeAudio(true);
|
m_pd.computeAudio(true);
|
||||||
|
|
||||||
|
|
@ -142,11 +138,16 @@ int Gdpd::start() {
|
||||||
m_sampleRate, &m_bufferFrames, &audioCallback,
|
m_sampleRate, &m_bufferFrames, &audioCallback,
|
||||||
this, &options);
|
this, &options);
|
||||||
m_audio.startStream();
|
m_audio.startStream();
|
||||||
|
print("Stream started");
|
||||||
}
|
}
|
||||||
catch(RtAudioError& e) {
|
catch(RtAudioError& e) {
|
||||||
Godot::print(e.getMessage().c_str());
|
Godot::print(e.getMessage().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//create message hook
|
||||||
|
m_pd.subscribe("to_gdpd");
|
||||||
|
m_pd.setReceiver(this);
|
||||||
|
m_init=true;
|
||||||
|
|
||||||
print("Initialized");
|
print("Initialized");
|
||||||
|
|
||||||
|
|
@ -156,7 +157,6 @@ int Gdpd::start() {
|
||||||
void Gdpd::stop() {
|
void Gdpd::stop() {
|
||||||
m_audio.stopStream();
|
m_audio.stopStream();
|
||||||
m_audio.closeStream();
|
m_audio.closeStream();
|
||||||
m_pd.clear();
|
|
||||||
m_pd.computeAudio(false);
|
m_pd.computeAudio(false);
|
||||||
print("Stopped");
|
print("Stopped");
|
||||||
}
|
}
|
||||||
|
|
@ -180,17 +180,42 @@ void Gdpd::openfile(godot::String baseStr, godot::String dirStr) {
|
||||||
std::wstring dirWs = dirStr.unicode_str();
|
std::wstring dirWs = dirStr.unicode_str();
|
||||||
std::string dirS(dirWs.begin(), dirWs.end());
|
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());
|
//libpd_openfile(baseS.c_str(), dirS.c_str());
|
||||||
//m_patch = m_pd.openPatch(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;
|
||||||
|
}
|
||||||
|
|
||||||
print("Opened patch");
|
//m_pd.subscribe("to_gdpd");
|
||||||
|
|
||||||
|
/*
|
||||||
|
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) {
|
void Gdpd::closefile(godot::String baseStr) {
|
||||||
std::wstring baseWs = baseStr.unicode_str();
|
std::wstring baseWs = baseStr.unicode_str();
|
||||||
std::string baseS(baseWs.begin(), baseWs.end());
|
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) {
|
void Gdpd::subscribe(String symbStr) {
|
||||||
|
|
@ -240,7 +265,6 @@ int Gdpd::finish_list(String destStr) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Gdpd::print(const std::string& message) {
|
void Gdpd::print(const std::string& message) {
|
||||||
Godot::print((std::string("GDPD : ")+message).c_str());
|
Godot::print((std::string("GDPD : ")+message).c_str());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <AudioStreamPlayer.hpp>
|
#include <AudioStreamPlayer.hpp>
|
||||||
|
|
@ -31,6 +32,9 @@ private:
|
||||||
int m_sampleRate;
|
int m_sampleRate;
|
||||||
int m_inputDevice;
|
int m_inputDevice;
|
||||||
int m_outputDevice;
|
int m_outputDevice;
|
||||||
|
std::map<std::string, pd::Patch> m_patchsMap;
|
||||||
|
|
||||||
|
bool m_init;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void _register_methods();
|
static void _register_methods();
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue