Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide osdialog-like async calls as Cardinal plugin API #51

Closed
falkTX opened this issue Nov 21, 2021 · 2 comments
Closed

Provide osdialog-like async calls as Cardinal plugin API #51

falkTX opened this issue Nov 21, 2021 · 2 comments

Comments

@falkTX
Copy link
Contributor

falkTX commented Nov 21, 2021

Plugins can use osdialog to deal with file open/save dialogs.
Since we cannot use osdialog we need to replace those, but that means a new/replacement API is also needed.
We should try to get 1-2 plugins that load files to work with this new API.

Later on we will need to make a list of plugins that use osdialog, perhaps this can even be automated.

@falkTX
Copy link
Contributor Author

falkTX commented Dec 11, 2021

Attempting this now.

The custom Cardinal APIs being:

#ifdef USING_CARDINAL_NOT_RACK
void async_dialog_message(const char* message);
void async_dialog_message(const char* message, std::function<void()> action);
void async_dialog_filebrowser(bool saving, const char* filename, std::function<void(char* path)> action);
#endif

cf Player plugin patching test:

diff --git a/src/PLAYER.cpp b/src/PLAYER.cpp
index 6e0a920..05c4e15 100644
--- a/src/PLAYER.cpp
+++ b/src/PLAYER.cpp
@@ -411,8 +411,18 @@ struct PLAYERItem : MenuItem {
        PLAYER *rm ;
        void onAction(const event::Action &e) override {
                
+#ifdef USING_CARDINAL_NOT_RACK
+               async_dialog_filebrowser(false, nullptr, [this](char* path) {
+                       pathSelected(path);
+               });
+#else
                //std::string dir = module->lastPath.empty() ? NULL : rack::string::directory(module->lastPath); /////////////////////////////////////////
                char *path = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL);        //////////dir.c_str(),
+               pathSelected(path);
+#endif
+       }
+
+       void pathSelected(char* path) {
                if (path) {
                        rm->play = false;
                        rm->reload = true;

@falkTX
Copy link
Contributor Author

falkTX commented Dec 11, 2021

Going to finalize on these 4, which should cover all the needs of osdialog:

// opens a file browser, startDir and title can be null
// action is always triggered on close (path can be null), must be freed if not null
void async_dialog_filebrowser(bool saving, const char* startDir, const char* title,
                              std::function<void(char* path)> action);

// opens a message dialog with only an "ok" button
void async_dialog_message(const char* message);

// opens a message dialog with "ok" and "cancel" buttons
// action is triggered if user presses "ok"
void async_dialog_message(const char* message, std::function<void()> action);

// opens a text input dialog, message and text can be null
// action is always triggered on close (newText can be null), must be freed if not null
void async_dialog_text_input(const char* message, const char* text, std::function<void(char* newText)> action);

We ignore the color picker option, not sure if modules even use it.
If you disagree, if you have ~1h to speak up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant