Skip to content
Snippets Groups Projects
Commit 97a40351 authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

Fixed lost communication when reinit

parent 24051ef4
No related branches found
No related tags found
No related merge requests found
......@@ -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"]
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -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]
......
......@@ -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'])
......
......@@ -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());
}
......
......@@ -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();
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment