Search guides and the APICtrl K
  1. API reference
  2. Files and codecs

file_dialog.h

Asking the user for a file.

#include <sonore/file_dialog.h>
  • 2types
  • 2other declarations
On this page

Design notes

A sampler that cannot load a sample is not a sampler. A convolver needs an impulse response, a preset system needs somewhere to save to, and a plugin with a "Load…" button that does nothing is worse than one without the button. This is the piece of a file chooser a plugin actually uses.

The page cannot do it. <input type="file"> is disabled by default in an embedded WebView2, behaves differently again under WebKitGTK, and gives a browser sandbox's idea of a file rather than a path a DSP can open. So the dialog is native, on every platform, and returns a real path.

MAIN THREAD, and MODAL. The call does not return until the user is done, which blocks the host's UI the way every blocking file dialog does, and the same way every DAW expects. Never from the audio thread and never from a timer that the host is also waiting on.

WHAT IS VERIFIED: the Windows path is exercised on this machine. The Cocoa and GTK paths are written against their documented APIs and have never been run, for the same reason the AU wrapper has not: there is no macOS or Linux desktop in this loop. The parts that decide anything (filters, extensions, defaults) are shared across all three and are tested; what is unverified is the platform call at the end of each.

Types 2

One line of a file filter: what to call it and what it matches.

Ask the user for a file: one to open, where to save, or a folder. The reference's file chooser, as three static calls.

Each returns the chosen path, or an empty string if they cancelled or there is no way to ask. Those two are deliberately the same answer: a plugin has to handle "no file" either way, and a caller that treated "cannot ask" as an error would show an error box on a machine that simply has no GTK.

MAIN THREAD and MODAL (see the file comment). parentWindow is the native window to sit over -- an HWND on Windows -- and may be null; the GTK and macOS paths ignore it.

Functions 2

↑↓ to move↵ to openEvery public name in the headers, and every guide