Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gdpd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IVMI
Gdpd
Commits
a17b0e4a
Commit
a17b0e4a
authored
2 months ago
by
Florent Berthaut
Browse files
Options
Downloads
Patches
Plain Diff
Fixed export to android
parent
40211f9b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+4
-45
4 additions, 45 deletions
README.md
src/gdpd.cpp
+18
-15
18 additions, 15 deletions
src/gdpd.cpp
src/gdpd.h
+4
-4
4 additions, 4 deletions
src/gdpd.h
with
26 additions
and
64 deletions
README.md
+
4
−
45
View file @
a17b0e4a
...
@@ -11,7 +11,9 @@ Use the Godot3 branch for previous versions.
...
@@ -11,7 +11,9 @@ Use the Godot3 branch for previous versions.
# Using gdpd
# Using gdpd
Install the gdpd folder in the addons folder of your Godot project.
*
Install the gdpd folder in the addons folder of your Godot project.
*
Add pd patches and other needed files as exported in the export
settings (
\*
.pd,
\*
.wav) so that they are copied in the apk
In a script,
In a script,
...
@@ -22,51 +24,8 @@ In a script,
...
@@ -22,51 +24,8 @@ In a script,
@onready
var
_gdpd
=
GdPd
.
new
()
@onready
var
_gdpd
=
GdPd
.
new
()
```
```
2.
Initialize the audio inputs and outputs
```
python
2.
#retrieve the list of available input and outputs
var
inps
=
_gdpd
.
get_available_input_devices
()
var
outs
=
_gdpd
.
get_available_output_devices
()
#initialise the first ones
_gdpd
.
init_devices
(
inps
[
0
],
outs
[
0
])
```
4.
Load a patch
```
python
var
patch
=
ProjectSettings
.
globalize_path
(
"
res://patch.pd
"
)
var
patch_name
=
patch
.
split
(
"
/
"
)[
-
1
]
var
patch_dir
=
patch
.
trim_suffix
(
patch_name
)
gdpd
.
openfile
(
patch_name
,
patch_dir
)
```
5.
Send a message to the patch
```
python
#send message to [receive from_godot] with one symbol
_gdpd
.
start_message
(
1
)
_gdpd
.
add_symbol
(
"
hello
"
)
_gdpd
.
finish_list
(
"
from_godot
"
)
```
6.
Subscribe and receive messages from the patch
```
python
func
_ready
:
#listen to messages sent with [send to_godot]
_gdpd
.
subscribe
(
"
to_godot
"
)
func
_process
:
while
_gdpd
.
has_message
()
:
#msg is an array with the list of symbols/floats sent to to_godot
var
msg
=
_gdpd
.
get_next
()
print
(
"
got message from pd
"
,
msg
)
```
For a full working example, open the Godot project in the demo folder.
For a full working example, open the Godot project in the demo folder.
...
...
This diff is collapsed.
Click to expand it.
src/gdpd.cpp
+
18
−
15
View file @
a17b0e4a
...
@@ -355,6 +355,8 @@ void GdPd::send(String address, Array arguments) {
...
@@ -355,6 +355,8 @@ void GdPd::send(String address, Array arguments) {
lo_message_add_string
(
msg
,
lo_message_add_string
(
msg
,
String
(
arguments
[
i
]).
utf8
().
get_data
());
String
(
arguments
[
i
]).
utf8
().
get_data
());
break
;
break
;
default
:
break
;
}
}
}
}
...
@@ -378,10 +380,13 @@ void GdPd::send(String address, Array arguments) {
...
@@ -378,10 +380,13 @@ void GdPd::send(String address, Array arguments) {
case
Variant
::
FLOAT
:
case
Variant
::
FLOAT
:
libpd_add_float
(
arguments
[
i
]);
libpd_add_float
(
arguments
[
i
]);
break
;
break
;
case
Variant
::
STRING
:
case
Variant
::
STRING
:
{
std
::
string
symbS
(
String
(
arguments
[
i
]).
utf8
().
get_data
());
std
::
string
symbS
(
String
(
arguments
[
i
]).
utf8
().
get_data
());
libpd_add_symbol
(
symbS
.
c_str
());
libpd_add_symbol
(
symbS
.
c_str
());
break
;
break
;
}
default
:
break
;
}
}
}
}
libpd_finish_list
(
"from_godot"
);
libpd_finish_list
(
"from_godot"
);
...
@@ -481,35 +486,30 @@ bool GdPd::open_patch() {
...
@@ -481,35 +486,30 @@ bool GdPd::open_patch() {
if
(
OS
::
get_singleton
()
->
get_name
()
==
"Android"
)
{
if
(
OS
::
get_singleton
()
->
get_name
()
==
"Android"
)
{
print
(
"On Android, so start copying files to user folder"
);
print
(
"On Android, so start copying files to user folder"
);
String
packageName
=
ProjectSettings
::
get_singleton
()
String
packageName
=
->
globalize_path
(
"user://"
).
trim_suffix
(
"/"
).
rsplit
(
"/"
)[
2
];
(
ProjectSettings
::
get_singleton
()
->
globalize_path
(
"user://"
))
.
split
(
"/"
)[
3
];
print
(
packageName
.
utf8
().
get_data
());
userPath
=
String
(
"/sdcard/Android/data/"
)
userPath
=
String
(
"/sdcard/Android/data/"
)
+
packageName
+
packageName
+
String
(
"/files/"
);
+
String
(
"/files/"
);
print
(
std
::
string
(
"Copying to "
)
+
userPath
.
utf8
().
get_data
());
}
}
else
{
else
{
userPath
=
OS
::
get_singleton
()
->
get_user_data_dir
()
+
"/"
;
userPath
=
OS
::
get_singleton
()
->
get_user_data_dir
()
+
"/"
;
}
}
//Get the folder containing the main pd patch
//Get the folder containing the main pd patch
String
patch
=
pd_patch
.
get_slice
(
"/"
,
pd_patch
.
get_slice_count
(
"/"
)
-
1
);
String
patch
=
pd_patch
.
get_slice
(
"/"
,
pd_patch
.
get_slice_count
(
"/"
)
-
1
);
String
patchDir
=
pd_patch
.
trim_suffix
(
patch
).
trim_prefix
(
"res://"
);
String
patchDir
=
pd_patch
.
trim_suffix
(
patch
).
trim_prefix
(
"res://"
);
//Recursively copy this folder from res to user directory
//Recursively copy this folder from res to user directory
recurseCopy
(
"res://"
+
patchDir
,
userPath
+
patchDir
);
recurseCopy
(
"res://"
+
patchDir
,
userPath
+
patchDir
);
//Also copy gdpd patches from patches folder
//Also copy patches from addon patches folder
std
::
vector
<
String
>
gdpdFiles
{
"gdpd.pd"
,
"gdpd_send.pd"
,
recurseCopy
(
addon_patches_folder
,
userPath
+
patchDir
);
"gdpd_receive.pd"
};
for
(
auto
&
f
:
gdpdFiles
)
{
Ref
<
DirAccess
>
diracc
=
DirAccess
::
open
(
"res://"
);
diracc
->
copy
(
addon_patches_folder
+
"/"
+
f
,
userPath
+
patchDir
+
"/"
+
f
);
}
//Define new paths
//Define new paths
m_pdPatchStr
=
std
::
string
(
patch
.
utf8
().
get_data
());
m_pdPatchStr
=
std
::
string
(
patch
.
utf8
().
get_data
());
...
@@ -537,13 +537,16 @@ void GdPd::recurseCopy(String fromPath, String toPath) {
...
@@ -537,13 +537,16 @@ void GdPd::recurseCopy(String fromPath, String toPath) {
//Create the toPath folder
//Create the toPath folder
DirAccess
::
make_dir_absolute
(
toPath
);
DirAccess
::
make_dir_absolute
(
toPath
);
//print("Copying folder "+ std::string(fromPath.utf8().get_data())
// +" to "+std::string(toPath.utf8().get_data()));
//For each file inside the origin directory
//For each file inside the origin directory
PackedStringArray
files
=
DirAccess
::
get_files_at
(
fromPath
);
PackedStringArray
files
=
DirAccess
::
get_files_at
(
fromPath
);
for
(
int
i
=
0
;
i
<
files
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
files
.
size
();
++
i
)
{
String
fileName
=
files
[
i
];
String
fileName
=
files
[
i
];
Ref
<
DirAccess
>
diracc
=
DirAccess
::
open
(
"res://"
);
Ref
<
DirAccess
>
diracc
=
DirAccess
::
open
(
"res://"
);
diracc
->
copy
(
fromPath
+
"/"
+
fileName
,
toPath
+
"/"
+
fileName
);
diracc
->
copy
(
fromPath
+
"/"
+
fileName
,
toPath
+
"/"
+
fileName
);
print
(
"Copying "
+
std
::
string
(
fileName
.
utf8
().
get_data
()));
//
print("Copying "+ std::string(fileName.utf8().get_data()));
}
}
//For each dir, call recursCopy
//For each dir, call recursCopy
...
...
This diff is collapsed.
Click to expand it.
src/gdpd.h
+
4
−
4
View file @
a17b0e4a
...
@@ -156,10 +156,10 @@ public:
...
@@ -156,10 +156,10 @@ public:
void
send
(
String
destination
,
Array
arguments
);
void
send
(
String
destination
,
Array
arguments
);
virtual
void
print
(
const
std
::
string
&
message
);
virtual
void
print
(
const
std
::
string
&
message
)
override
;
//libpd hooks
//libpd hooks
void
receiveList
(
const
std
::
string
&
dest
,
const
pd
::
List
&
list
);
void
receiveList
(
const
std
::
string
&
dest
,
const
pd
::
List
&
list
)
override
;
//rtaudio
//rtaudio
static
int
audioCallback
(
void
*
outputBuffer
,
void
*
inputBuffer
,
static
int
audioCallback
(
void
*
outputBuffer
,
void
*
inputBuffer
,
...
@@ -183,8 +183,8 @@ public:
...
@@ -183,8 +183,8 @@ public:
GdPdStream
();
GdPdStream
();
Ref
<
AudioStreamPlayback
>
_instantiate_playback
()
const
override
;
Ref
<
AudioStreamPlayback
>
_instantiate_playback
()
const
override
;
virtual
String
_get_stream_name
()
const
{
return
"GdPd"
;}
virtual
String
_get_stream_name
()
const
override
{
return
"GdPd"
;}
virtual
double
_get_length
()
const
{
return
0
;
}
virtual
double
_get_length
()
const
override
{
return
0
;
}
void
setGdPd
(
GdPd
*
gdpd
){
m_gdpd
=
gdpd
;}
void
setGdPd
(
GdPd
*
gdpd
){
m_gdpd
=
gdpd
;}
GdPd
*
getGdPd
(){
return
m_gdpd
;}
GdPd
*
getGdPd
(){
return
m_gdpd
;}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment