diff --git a/README.md b/README.md index a40a3ead781b0ad9c929eb2551ac36cfddd66913..971e8a9789f2113c07d028d07a92288bdbe0d0bb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ Use the Godot3 branch for previous versions. # 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, @@ -22,51 +24,8 @@ In a script, @onready var _gdpd = GdPd.new() ``` -2. Initialize the audio inputs and outputs -```python -#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) -``` +2. For a full working example, open the Godot project in the demo folder. diff --git a/src/gdpd.cpp b/src/gdpd.cpp index 5baa83cb9d28098433beb99ccdf3dfee09f034d4..6c69a1ecc43ab3aafa682e94f1c7de24bf937564 100644 --- a/src/gdpd.cpp +++ b/src/gdpd.cpp @@ -355,6 +355,8 @@ void GdPd::send(String address, Array arguments) { lo_message_add_string(msg, String(arguments[i]).utf8().get_data()); break; + default : + break; } } @@ -378,10 +380,13 @@ void GdPd::send(String address, Array arguments) { case Variant::FLOAT : libpd_add_float(arguments[i]); break; - case Variant::STRING : + case Variant::STRING : { std::string symbS(String(arguments[i]).utf8().get_data()); libpd_add_symbol(symbS.c_str()); break; + } + default : + break; } } libpd_finish_list("from_godot"); @@ -481,35 +486,30 @@ bool GdPd::open_patch() { if(OS::get_singleton()->get_name() == "Android") { print("On Android, so start copying files to user folder"); - String packageName = ProjectSettings::get_singleton() - ->globalize_path("user://").trim_suffix("/").rsplit("/")[2]; - - print(packageName.utf8().get_data()); + String packageName = + (ProjectSettings::get_singleton()->globalize_path("user://")) + .split("/")[3]; userPath = String("/sdcard/Android/data/") + packageName + String("/files/"); + + print(std::string("Copying to ")+userPath.utf8().get_data()); } else { 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 patchDir = pd_patch.trim_suffix(patch).trim_prefix("res://"); //Recursively copy this folder from res to user directory recurseCopy("res://"+patchDir, userPath+patchDir); - //Also copy gdpd patches from patches folder - std::vector<String> gdpdFiles{"gdpd.pd", "gdpd_send.pd", - "gdpd_receive.pd"}; - for(auto& f : gdpdFiles) { - Ref<DirAccess> diracc = DirAccess::open("res://"); - diracc->copy(addon_patches_folder+"/"+f, - userPath+patchDir+"/"+f); - } + //Also copy patches from addon patches folder + recurseCopy(addon_patches_folder, userPath+patchDir); //Define new paths m_pdPatchStr = std::string(patch.utf8().get_data()); @@ -537,13 +537,16 @@ void GdPd::recurseCopy(String fromPath, String toPath) { //Create the toPath folder 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 PackedStringArray files = DirAccess::get_files_at(fromPath); for(int i=0; i<files.size(); ++i) { String fileName = files[i]; Ref<DirAccess> diracc = DirAccess::open("res://"); 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 diff --git a/src/gdpd.h b/src/gdpd.h index 74d278a992c1f700c77d6ce60a3e459808103504..4d89ea5cbceac36182147836beb1ddc0e152fdf3 100644 --- a/src/gdpd.h +++ b/src/gdpd.h @@ -156,10 +156,10 @@ public: void send(String destination, Array arguments); - virtual void print(const std::string& message); + virtual void print(const std::string& message) override; //libpd hooks - void receiveList(const std::string& dest, const pd::List& list); + void receiveList(const std::string& dest, const pd::List& list) override; //rtaudio static int audioCallback(void *outputBuffer, void *inputBuffer, @@ -183,8 +183,8 @@ public: GdPdStream(); Ref<AudioStreamPlayback> _instantiate_playback() const override; - virtual String _get_stream_name() const {return "GdPd";} - virtual double _get_length() const { return 0; } + virtual String _get_stream_name() const override {return "GdPd";} + virtual double _get_length() const override { return 0; } void setGdPd(GdPd* gdpd){m_gdpd=gdpd;} GdPd* getGdPd(){return m_gdpd;}