Utilities module

Various utilities.

Files

file resources.h
Helpers for loading and using resources such as icons.

Classes

struct SupportedFile
Metadata for a supported file.
struct CairoCaches
Caches for cairo.
struct MPMCQueue
Multiple Producer Multiple Consumer lock-free queue.
struct Stack
Stack implementation.
struct GenericProgressInfo
Generic progress info.
struct UiColors
Commonly used UI colors.
struct UiCursor
Specification for a cursor.
struct UiCaches
Caches.
struct ZrythmObject
Base object for debugging.

Enums

enum ZFileType { FILE_TYPE_MIDI, FILE_TYPE_MP3, FILE_TYPE_FLAC, FILE_TYPE_OGG, FILE_TYPE_WAV, FILE_TYPE_DIR, FILE_TYPE_PARENT_DIR, FILE_TYPE_OTHER, NUM_FILE_TYPES }
File type.
enum BitDepth { BIT_DEPTH_16, BIT_DEPTH_24, BIT_DEPTH_32 }
Bit depth.
enum AudioValueFormat { AUDIO_VALUE_AMPLITUDE, AUDIO_VALUE_DBFS, AUDIO_VALUE_FADER }
enum UiCursorState { UI_CURSOR_STATE_DEFAULT, UI_CURSOR_STATE_RESIZE_L, UI_CURSOR_STATE_REPEAT_L, UI_CURSOR_STATE_RESIZE_R, UI_CURSOR_STATE_REPEAT_R, UI_CURSOR_STATE_RESIZE_UP }
Various cursor states to be shared.
enum UiOverlayAction { UI_OVERLAY_ACTION_NONE, UI_OVERLAY_ACTION_CREATING_RESIZING_R, UI_OVERLAY_ACTION_CREATING_MOVING, UI_OVERLAY_ACTION_RESIZING_L, UI_OVERLAY_ACTION_RESIZING_L_LOOP, UI_OVERLAY_ACTION_RESIZING_L_FADE, UI_OVERLAY_ACTION_RESIZING_R, UI_OVERLAY_ACTION_RESIZING_R_LOOP, UI_OVERLAY_ACTION_RESIZING_R_FADE, UI_OVERLAY_ACTION_RESIZING_UP, UI_OVERLAY_ACTION_RESIZING_UP_FADE_IN, UI_OVERLAY_ACTION_RESIZING_UP_FADE_OUT, UI_OVERLAY_ACTION_STRETCHING_L, UI_OVERLAY_ACTION_STRETCHING_R, UI_OVERLAY_ACTION_AUDITIONING, UI_OVERLAY_ACTION_AUTOFILLING, UI_OVERLAY_ACTION_ERASING, UI_OVERLAY_ACTION_STARTING_ERASING, UI_OVERLAY_ACTION_STARTING_MOVING, UI_OVERLAY_ACTION_STARTING_MOVING_COPY, UI_OVERLAY_ACTION_STARTING_MOVING_LINK, UI_OVERLAY_ACTION_MOVING, UI_OVERLAY_ACTION_MOVING_COPY, UI_OVERLAY_ACTION_MOVING_LINK, UI_OVERLAY_ACTION_STARTING_CHANGING_CURVE, UI_OVERLAY_ACTION_CHANGING_CURVE, UI_OVERLAY_ACTION_STARTING_SELECTION, UI_OVERLAY_ACTION_SELECTING, UI_OVERLAY_ACTION_STARTING_DELETE_SELECTION, UI_OVERLAY_ACTION_DELETE_SELECTING, UI_OVERLAY_ACTION_STARTING_RAMP, UI_OVERLAY_ACTION_RAMPING, UI_OVERLAY_ACTION_CUTTING, UI_OVERLAY_ACTION_RENAMING, NUM_UI_OVERLAY_ACTIONS }
Various overlay actions to be shared.
enum UiDragMode { UI_DRAG_MODE_CURSOR, UI_DRAG_MODE_RELATIVE, UI_DRAG_MODE_RELATIVE_WITH_MULTIPLIER }
Dragging modes for widgets that have click&drag.

Typedefs

using ZFileType = enum ZFileType
File type.
using SupportedFile = struct SupportedFile
Metadata for a supported file.
using BitDepth = enum BitDepth
Bit depth.
using CairoCaches = struct CairoCaches
Caches for cairo.
using MPMCQueue = struct MPMCQueue
Multiple Producer Multiple Consumer lock-free queue.
using Stack = struct Stack
Stack implementation.
using midi_byte_t = uint8_t
MIDI byte.
using nframes_t = uint32_t
Frame count.
using sample_rate_t = uint32_t
Sample rate.
using midi_time_t = uint32_t
MIDI time in global frames.
using channels_t = unsigned int
Number of channels.
using sample_t = float
The sample type.
using bpm_t = float
The BPM type.
using GenericFloatGetter = float(*)(void*object)
Getter prototype for float values.
using GenericFloatSetter = void(*)(void*object, float val)
Setter prototype for float values.
using GenericStringGetter = const char*(*)(void*object)
Getter prototype for strings.
using GenericStringCopyGetter = void(*)(void*object, char*buf)
Getter prototype for strings to be saved in the given buffer.
using GenericStringSetter = void(*)(void*object, const char*val)
Setter prototype for float values.
using GenericCallback = void(*)(void*object)
Generic callback.
using GenericCmpFunc = int(*)(const void*a, const void*b)
Generic comparator.
using GenericPredicateFunc = bool(*)(const void*object, const void*user_data)
Predicate function prototype.
using GenericProgressInfo = struct GenericProgressInfo
Generic progress info.
using UiColors = struct UiColors
Commonly used UI colors.
using UiCursor = struct UiCursor
Specification for a cursor.
using UiCaches = struct UiCaches
Caches.
using UiCursorState = enum UiCursorState
Various cursor states to be shared.
using UiOverlayAction = enum UiOverlayAction
Various overlay actions to be shared.
using UiDragMode = enum UiDragMode
Dragging modes for widgets that have click&drag.
using ZrythmObject = struct ZrythmObject
Base object for debugging.

Functions

auto supported_file_new_from_path(const char* path) -> SupportedFile*
Creates a new SupportedFile from the given absolute path.
auto supported_file_type_get_description(ZFileType type) -> char*
Returns a human readable description of the given file type.
auto supported_file_clone(SupportedFile* src) -> SupportedFile*
Clones the given SupportedFile.
auto supported_file_type_is_supported(ZFileType type) -> int
Returns if the given type is supported.
auto supported_file_type_is_audio(ZFileType type) -> int
Returns if the SupportedFile is an audio file.
auto supported_file_type_is_midi(ZFileType type) -> int
Returns if the SupportedFile is a midi file.
auto supported_file_type_get_ext(ZFileType type) -> const char*
Returns the most common extension for the given filetype.
auto supported_file_get_type(const char* file) -> ZFileType
Returns the file type of the given file path.
auto supported_file_should_autoplay(const SupportedFile* self) -> NONNULL bool
Returns whether the given file should auto-play (shorter than 1 min).
auto supported_file_get_info_text_for_label(const SupportedFile* self) -> NONNULL char*
Returns a pango markup to be used in GTK labels.
void supported_file_free(SupportedFile* self)
Frees the instance and all its members.
auto audio_write_raw_file(float* buff, long frames_already_written, long nframes, uint32_t samplerate, bool flac, BitDepth bit_depth, unsigned int channels, const char* filename) -> int
Writes the buffer as a raw file to the given path.
auto audio_get_num_frames(const char* filepath) -> long
Returns the number of frames in the given audio file.
auto audio_frames_equal(float* src1, float* src2, size_t num_frames, float epsilon) -> bool
Returns whether the frame buffers are equal.
auto audio_frames_empty(float* src, size_t num_frames) -> bool
Returns whether the frame buffer is empty (zero).
auto audio_get_num_cores(void) -> int
Returns the number of CPU cores.
auto _backtrace_get(const char* exe_path, const char* prefix, int max_lines, bool with_lines, bool write_to_file) -> char*
Returns the backtrace with max_lines number of lines and a string prefix.
static void z_cairo_rounded_rectangle(cairo_t* cr, double x, double y, double width, double height, double aspect, double corner_radius)
void _z_cairo_get_text_extents_for_widget(GtkWidget* widget, PangoLayout* layout, const char* text, int* width, int* height)
Gets the width of the given text in pixels for the given widget.
void z_cairo_draw_text_full(cairo_t* cr, GtkWidget* widget, PangoLayout* layout, const char* text, int start_x, int start_y)
Draws the given text using the given font starting at the given position.
static void z_cairo_diamond(cairo_t* cr, double x, double y, double width, double height)
Draws a diamond shape.
auto z_cairo_get_surface_from_icon_name(const char* icon_name, int size, int scale) -> cairo_surface_t*
Returns a surface for the icon name.
auto z_cairo_create_pango_layout_from_string(GtkWidget* widget, const char* font, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding) -> PangoLayout*
Creates a PangoLayout to be cached in widgets based on the given settings.
auto z_cairo_create_pango_layout_from_description(GtkWidget* widget, PangoFontDescription* descr, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding) -> PangoLayout*
Creates a PangoLayout to be cached in widgets based on the given settings.
auto z_cairo_create_default_pango_layout(GtkWidget* widget) -> PangoLayout*
Creates a PangoLayout with default settings.
void z_cairo_reset_caches(cairo_t** cr_cache, cairo_surface_t** surface_cache, int width, int height, cairo_t* new_cr)
Resets a surface and cairo_t with a new surface and cairo_t based on the given rectangle and cairo_t.
void color_brighten(GdkRGBA* src, double val)
Brightens the color by the given amount.
void color_brighten_default(GdkRGBA* src)
Brightens the color by the default amount.
void color_darken(GdkRGBA* src, double val)
Darkens the color by the given amount.
void color_darken_default(GdkRGBA* src)
Darkens the color by the default amount.
auto color_is_same(GdkRGBA* src, GdkRGBA* dest) -> bool
Returns whether the color is the same.
auto color_is_bright(GdkRGBA* src) -> bool
Returns if the color is bright or not.
auto color_is_very_bright(GdkRGBA* src) -> bool
Returns if the color is very bright or not.
auto color_is_very_very_bright(GdkRGBA* src) -> bool
Returns if the color is very very bright or not.
auto color_is_very_dark(GdkRGBA* src) -> bool
Returns if the color is very dark or not.
auto color_is_very_very_dark(GdkRGBA* src) -> bool
Returns if the color is very very dark or not.
void color_morph(GdkRGBA* a, GdkRGBA* b, double amt, GdkRGBA* result)
Morphs from a to b, depending on the given amount.
auto z_curl_get_page_contents(const char* url, int timeout) -> char*
Returns the contents of the page in a newly allocated string.
auto z_curl_get_page_contents_default(const char* url) -> char*
Returns the contents of the page in a newly allocated string.
auto z_curl_post_json_no_auth(const char* url, const char* data, int timeout, GError** error, ...) G_GNUC_NULL_TERMINATED -> int
Posts the given JSON to the URL without any authentication.
auto datetime_get_current_as_string(void) -> char*
Returns the current datetime as a string.
auto datetime_get_for_filename(void) -> char*
Get the current datetime to be used in filenames, eg, for the log file.
auto env_get_string(const char* key, const char* def) -> char*
Returns a newly allocated string.
auto env_get_int(const char* key, int def) -> int
Returns an int for the given environment variable if it exists and is valid, otherwise returns the default int.
auto file_reflink(const char* dest, const char* src) -> int
Do cp –reflink from src to dest.
auto utils_get_uint_from_bitfield_val(unsigned int bitfield) -> unsigned int
From https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightLinear.
void z_gtk_container_remove_all_children(GtkContainer* container)
auto z_gtk_message_dialog_get_label(GtkMessageDialog* self, const int secondary) -> GtkLabel*
Returns the primary or secondary label of the given GtkMessageDialog.
void z_gtk_configure_simple_combo_box(GtkComboBox* cb, GtkTreeModel* model)
Configures a simple value-text combo box using the given model.
void z_gtk_button_set_icon_name(GtkButton* btn, const char* name)
Sets the icon name and optionally text.
void z_gtk_button_set_icon_name_and_text(GtkButton* btn, const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing)
Sets the icon name and optionally text.
auto z_gtk_button_new_with_icon(const char* name) -> GtkButton*
Creates a button with the given icon name.
auto z_gtk_toggle_button_new_with_icon(const char* name) -> GtkToggleButton*
Creates a toggle button with the given icon name.
auto z_gtk_toggle_button_new_with_icon_and_text(const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing) -> GtkToggleButton*
Creates a toggle button with the given icon name.
auto z_gtk_button_new_with_icon_and_text(const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing) -> GtkButton*
Creates a button with the given icon name and text.
auto z_gtk_button_new_with_resource(IconType icon_type, const char* name) -> GtkButton*
Creates a button with the given resource name as icon.
auto z_gtk_toggle_button_new_with_resource(IconType icon_type, const char* name) -> GtkToggleButton*
Creates a toggle button with the given resource name as icon.
auto z_gtk_create_menu_item_full(const gchar* label_name, const gchar* icon_name, IconType resource_icon_type, const gchar* resource, bool is_toggle, const char* action_name) -> GtkMenuItem*
Creates a menu item.
auto z_gtk_get_single_selection_pointer(GtkTreeView* tv, int column) -> void*
Returns a pointer stored at the given selection.
auto z_gtk_get_label_from_menu_item(GtkMenuItem* mi) -> GtkLabel*
Returns the label from a given GtkMenuItem.
auto z_gtk_get_tooltip_for_action(const char* detailed_action, const char* tooltip) -> char*
Gets the tooltip for the given action on the given widget.
void z_gtk_widget_set_tooltip_for_action(GtkWidget* widget, const char* detailed_action, const char* tooltip)
Sets the tooltip for the given action on the given widget.
void z_gtk_set_tooltip_for_actionable(GtkActionable* actionable, const char* tooltip)
Sets the tooltip and finds the accel keys and appends them to the tooltip in small text.
void z_gtk_tool_button_set_icon_size(GtkToolButton* toolbutton, GtkIconSize icon_size)
Changes the size of the icon inside tool buttons.
void z_gtk_widget_add_style_class(GtkWidget* widget, const gchar* class_name)
Adds the given style class to the widget.
void z_gtk_widget_remove_style_class(GtkWidget* widget, const gchar* class_name)
Removes the given style class from the widget.
static auto z_gtk_widget_get_device(GtkWidget* widget) -> GdkDevice*
Gets the GdkDevice for a GtkWidget.
static void z_gtk_warp_cursor_to(GtkWidget* widget, int x, int y)
Wraps the cursor to the given global coordinates.
static void z_gtk_widget_get_mask(GtkWidget* widget, GdkModifierType* mask)
Sets the GdkModifierType given for the widget.
static auto z_gtk_keyval_is_alt(const guint keyval) -> int
Returns if the keyval is an Alt key.
static auto z_gtk_keyval_is_ctrl(const guint keyval) -> int
Returns if the keyval is a Control key.
static auto z_gtk_keyval_is_arrow(const guint keyval) -> int
Returns if the keyval is an arrow key.
static auto z_gtk_keyval_is_shift(const guint keyval) -> int
Returns if the keyval is a Shift key.
static auto z_gtk_container_get_single_child(GtkContainer* container) -> GtkWidget*
Returns the single child of a container.
auto z_gtk_container_get_nth_child(GtkContainer* container, int index) -> GtkWidget*
Returns the nth child of a container.
void z_gtk_combo_box_set_ellipsize_mode(GtkComboBox* self, PangoEllipsizeMode ellipsize)
Sets the ellipsize mode of each text cell renderer in the combo box.
void z_gtk_button_set_emblem(GtkButton* btn, const char* emblem_icon)
Sets the given emblem to the button, or unsets the emblem if emblem_icon is NULL.
void z_gtk_setup_foldable_notebook(GtkNotebook* notebook)
Makes the given notebook foldable.
void z_gtk_widget_set_margin(GtkWidget* widget, int margin)
Sets the margin on all 4 sides on the widget.
auto z_gtk_activate_dir_link_func(GtkLabel* label, char* uri, void* data) -> bool
Callback to use for simple directory links.
void z_gtk_notebook_make_detachable(GtkNotebook* notebook, GtkWindow* parent_window)
Makes the given GtkNotebook detachable to a new window.
void z_gtk_message_dialog_wrap_message_area_in_scroll(GtkMessageDialog* dialog, int min_width, int min_height)
Wraps the message area in a scrolled window.
auto z_gtk_text_buffer_get_full_text(GtkTextBuffer* buffer) -> char*
Returns the full text contained in the text buffer.
void z_gtk_generate_screenshot_image(GtkWidget* widget, const char* type, char** option_keys, char** option_values, char** ret_dir, char** ret_path)
Generates a screenshot image for the given widget.
void z_gtk_actionable_set_action_from_setting(GtkActionable* actionable, GSettings* settings, const char* key)
Sets the action target of the given GtkActionable to be binded to the given setting.
auto io_get_dir(const char* filename) -> NONNULL char*
Gets directory part of filename.
auto io_mkdir(const char* dir) -> NONNULL void
Makes directory if doesn't exist.
auto io_touch_file(const char* filename) -> NONNULL FILE*
Creates the file if doesn't exist.
auto io_file_strip_ext(const char* filename) -> NONNULL char*
Strips extensions from given filename.
auto io_file_get_ext(const char* file) -> NONNULL const char*
Returns file extension or NULL.
auto io_path_get_basename_without_ext(const char* filename) -> NONNULL char*
Strips path from given filename.
auto io_remove(const char* path) -> NONNULL int
Removes the given file.
auto io_rmdir(const char* path, bool force) -> NONNULL int
Removes a dir, optionally forcing deletion.
auto io_get_files_in_dir_ending_in(const char* _dir, const int recursive, const char* end_string, bool allow_empty) -> char**
Returns a list of the files in the given directory.
void io_copy_dir(const char* destdir_str, const char* srcdir_str, bool follow_symlinks, bool recursive)
auto io_get_next_available_filepath(const char* filepath) -> NONNULL char*
Returns a newly allocated path that is either a copy of the original path if the path does not exist, or the original path appended with (n), where n is a number.
auto io_open_directory(const char* path) -> NONNULL void
Opens the given directory using the default program.
auto io_escape_dir_name(char* dest, const char* dir) -> NONNULL void
Returns a clone of the given string after removing forbidden characters.
auto log_init_writer_idle(Log* self, unsigned int secs) -> NONNULL void
Initializes logging to a file.
auto log_idle_cb(Log* self) -> NONNULL int
Idle callback.
auto log_get_last_n_lines(Log* self, int n) -> NONNULL char*
Returns the last n lines as a newly allocated string.
auto log_generate_compressed_file(Log* self, char** ret_dir, char** ret_path, GError** error) -> bool
Generates a compressed log file (for sending with bug reports).
void log_init_with_file(Log* self, const char* filepath)
Initializes logging to a file.
auto log_new(void) -> Log*
Creates the logger and sets the writer func.
auto log_free(Log* self) -> NONNULL void
Stops logging and frees any allocated memory.
static auto math_fast_log2(float val) -> CONST float
Fast log calculation to be used where precision is not required (like log curves).
static auto math_get_fader_val_from_amp(sample_t amp) -> CONST sample_t
Returns fader value 0.0 to 1.0 from amp value 0.0 to 2.0 (+6 dbFS).
static auto math_get_amp_val_from_fader(sample_t fader) -> CONST sample_t
Returns amp value 0.0 to 2.0 (+6 dbFS) from fader value 0.0 to 1.0.
static auto math_amp_to_dbfs(sample_t amp) -> CONST sample_t
Convert from amplitude 0.0 to 2.0 to dbFS.
auto math_calculate_max_amp(sample_t* buf, const nframes_t nframes) -> sample_t
Gets the digital peak of the given signal as amplitude (0-2).
auto math_calculate_rms_db(sample_t* buf, const nframes_t nframes) -> sample_t
Calculate db using RMS method.
static auto math_dbfs_to_amp(sample_t dbfs) -> CONST sample_t
Convert form dbFS to amplitude 0.0 to 2.0.
static auto math_dbfs_to_fader_val(sample_t dbfs) -> CONST sample_t
Convert form dbFS to fader val 0.0 to 1.0.
auto math_assert_nonnann(float x) -> bool
Asserts that the value is non-nan.
void _free_later(void* object, void(*)(void*) dfunc, const char* file, const char* func, int line)
Frees the object after a while.
auto object_utils_new(void) -> ObjectUtils*
Inits the subsystems for the object utils in this file.
auto resources_get_icon(IconType icon_type, const char* filename) -> GtkWidget*
Creates a GtkImage of from the given information and returns it as a GtkWidget.
void resources_set_class_template(GtkWidgetClass* klass, const char* filename)
Sets class template from resource.
auto resources_get_gl_shader_data(const char* path) -> GBytes*
Returns the bytes of the specified OpenGL shader in RESOURCES_GL_SHADERS_PATH.
auto sort_alphabetical_func(const void* a, const void* b) -> int
Alphabetical sort func.
auto stack_new(int length) -> Stack*
Creates a new stack of the given size.
auto stack_pop_last(Stack* s) -> void*
Pops the last element and moves everything back.
auto string_is_ascii(const char* string) -> int
Returns if the string is ASCII.
auto string_array_contains_substr(char** str_array, int num_str, const char* substr) -> char*
Returns the matched string if the string array contains the given substring.
auto string_contains_substr(const char* str, const char* substr) -> bool
Returns if the given string contains the given substring.
void string_to_upper(const char* in, char* out)
Converts the given string to uppercase in out.
void string_to_lower(const char* in, char* out)
Converts the given string to lowercase in out.
auto string_is_equal_ignore_case(const char* str1, const char* str2) -> bool
Returns if the two strings are equal ignoring case.
auto string_convert_to_filename(const char* str) -> char*
Returns a newly allocated string that is a filename version of the given string.
auto string_get_substr_before_suffix(const char* str, const char* suffix) -> char*
Removes the suffix starting from suffix from full_str and returns a newly allocated string.
auto string_remove_until_after_first_match(const char* str, const char* match) -> char*
Removes everything up to and including the first match of match from the start of the string and returns a newly allocated string.
void string_replace_regex(char** str, const char* regex, const char* replace_str)
Replaces src_str with replace_str in all instances matched by regex.
auto string_get_regex_group(const char* str, const char* regex, int group) -> char*
Gets the string in the given regex group.
auto string_get_regex_group_as_int(const char* str, const char* regex, int group, int def) -> int
Gets the string in the given regex group as an integer.
auto string_get_int_after_last_space(const char* str, char* str_without_num) -> int
Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found.
auto string_array_sort_and_remove_duplicates(char** str_arr) -> char**
TODO Sorts the given string array and removes duplicates.
void string_copy_w_realloc(char** dest, const char* src)
Copies the string src to the buffer in dest after reallocating the buffer in dest to the length of src.
auto string_symbolify(const char* in) -> char*
Returns a new string with only ASCII alphanumeric characters and replaces ther est with underscore.
auto system_run_cmd(const char* cmd, long ms_timer) -> int
Runs the given command in the background, waits for it to finish and returns its exit code.
auto system_get_cmd_output(char** argv, long ms_timer, bool always_wait) -> char*
Runs the command and returns the output, or NULL.
auto system_run_cmd_w_args(const char** args, int ms_to_wait, char** out_stdout, char** out_stderr, bool warn_if_fail) -> int
Runs the given command in the background, waits for it to finish and returns its exit code.
auto ui_get_state_mask(GtkGesture* gesture) -> GdkModifierType
Used in handlers to get the state mask.
void ui_set_cursor_from_icon_name(GtkWidget* widget, const char* name, int offset_x, int offset_y)
Sets cursor from icon name.
void ui_set_cursor_from_name(GtkWidget* widget, const char* name)
Sets cursor from standard cursor name.
void ui_show_message_full(GtkWindow* parent_window, GtkMessageType type, const char* format, ...) G_GNUC_PRINTF(3
Shows a popup message of the given type with the given message.
auto ui_is_point_in_rect_hit(GdkRectangle* rect, const bool check_x, const bool check_y, double x, double y, double x_padding, double y_padding) -> bool
Returns if rect is hit or not by the given coordinate.
auto ui_is_child_hit(GtkWidget* parent, GtkWidget* child, const int check_x, const int check_y, const double x, const double y, const double x_padding, const double y_padding) -> int
Returns if the child is hit or not by the coordinates in parent.
auto ui_get_hit_child(GtkContainer* parent, double x, double y, GType type) -> GtkWidget*
Returns the matching hit child, or NULL.
auto ui_px_to_pos_timeline(double px, Position* pos, int has_padding) -> NONNULL void
Converts from pixels to position.
auto ui_px_to_frames_timeline(double px, int has_padding) -> long
Converts from pixels to frames.
auto ui_px_to_frames_editor(double px, int has_padding) -> long
Converts from pixels to frames.
auto ui_pos_to_px_timeline(Position* pos, int use_padding) -> NONNULL int
Converts position to px, optionally adding the ruler padding.
auto ui_pos_to_px_editor(Position* pos, int use_padding) -> NONNULL int
Converts position to px, optionally adding the ruler padding.
auto ui_px_to_pos_editor(double px, Position* pos, int has_padding) -> NONNULL void
Converts from pixels to position.
void ui_rgb_to_hex(double red, double green, double blue, char* buf)
Converts RGB to hex string.
void ui_show_notification(const char* msg)
Shows a notification in the revealer.
auto ui_show_notification_idle_func(char* msg) -> int
Show notification from non-GTK threads.
void ui_get_modifier_type_from_gesture(GtkGestureSingle* gesture, GdkModifierType* state_mask)
Returns the modifier type (state mask) from the given gesture.
void ui_setup_language_combo_box(GtkComboBox* language)
Sets up a combo box to have a selection of languages.
void ui_setup_audio_backends_combo_box(GtkComboBox* cb)
Sets up an audio backends combo box.
void ui_setup_midi_backends_combo_box(GtkComboBox* cb)
Sets up a MIDI backends combo box.
void ui_setup_pan_algo_combo_box(GtkComboBox* cb)
Sets up a pan algorithm combo box.
void ui_setup_pan_law_combo_box(GtkComboBox* cb)
Sets up a pan law combo box.
void ui_setup_buffer_size_combo_box(GtkComboBox* cb)
Sets up a pan law combo box.
void ui_setup_samplerate_combo_box(GtkComboBox* cb)
Sets up a pan law combo box.
void ui_setup_device_name_combo_box(GtkComboBoxText* cb)
Sets up a pan law combo box.
void ui_setup_vst_paths_entry(GtkEntry* entry)
Sets up the VST paths entry.
void ui_update_vst_paths_from_entry(GtkEntry* entry)
Updates the the VST paths in the gsettings from the text in the entry.
auto ui_get_locale_not_available_string(LocalizationLanguage lang) -> char*
Returns the "a locale for the language you have selected..." text based on the given language.
void ui_get_contrast_color(GdkRGBA* src, GdkRGBA* dest)
Returns the contrasting color (variation of black or white) based on if the given color is dark enough or not.
void ui_get_mid_color(GdkRGBA* dest, const GdkRGBA* c1, const GdkRGBA* c2, const double transition)
Returns the color in-between two colors.
static auto ui_rectangle_overlap(const GdkRectangle*const rect1, const GdkRectangle*const rect2) -> NONNULL static PURE bool
Returns if the 2 rectangles overlay.
void ui_get_arranger_object_color(GdkRGBA* color, const bool is_hovered, const bool is_selected, const bool is_transient, const bool is_muted)
Gets the color the widget should be.
auto ui_get_normalized_draggable_value(double size, double cur_val, double start_px, double cur_px, double last_px, double multiplier, UiDragMode mode) -> double
Gets a draggable value as a normalized value between 0 and 1.
void ui_bind_midi_cc_item_activate_cb(GtkMenuItem* menuitem, Port* port)
All purpose menuitem callback for binding MIDI CC to a port.
void vamp_print_all(void)
Prints detected vamp plugins.
auto yaml_serialize(void* data, const cyaml_schema_value_t* schema) -> NONNULL char*
Serializes to YAML.
void yaml_cyaml_log_func(cyaml_log_t level, void* ctxt, const char* format, va_list args)
Custom logging function for libcyaml.

Variables

Log* zlog
Global variable, available to all files.
static const char* ui_overlay_strings
Various overlay actions to be shared.

Defines

#define STRIP_SIZE
Number of plugin slots per channel.
#define Z_CAIRO_FONT
Default font for drawing pango text.
#define Z_CAIRO_TEXT_PADDING
Padding to leave from the top/left edges when drawing text.
#define z_cairo_draw_text(cr, widget, layout, text)
Draw text with default padding.
#define file_exists(file)
Returns 1 if the file/dir exists.
#define io_get_files_in_dir(dir, allow_empty)
Returns a list of the files in the given directory.
#define MATH_RMS_FRAMES
Frames to skip when calculating the RMS.
#define MATH_TINY_NUMBER
Tiny number to be used for denormaml prevention (-140dB).
#define math_floats_equal_epsilon(a, b, e)
Checks if 2 doubles are equal.
#define math_floats_equal(a, b)
Checks if 2 doubles are equal.
#define math_round_double_to_type(x, type)
Rounds a double to an int.
#define math_round_double_to_int(x)
Rounds a double to an int.
#define math_round_double_to_size_t(x)
Rounds a double to a size_t.
#define math_round_double_to_long(x)
Rounds a double to a long.
#define math_round_float_to_type(x, type)
Rounds a float to a given type.
#define math_round_float_to_int(x)
Rounds a float to an int.
#define math_round_float_to_long(x)
Rounds a float to a long.
#define free_later(obj, func)
Calls _free_later after doing the casting so the caller doesn't have to.
#define object_new(type)
Allocates memory for an object of type type.
#define object_new_n_sizeof(n, sz)
Calloc equivalent.
#define object_new_n(n, type)
Calloc n blocks for type type.
#define object_realloc_n(obj, prev_n, n, type)
Reallocate memory for obj.
#define object_set_to_zero(ptr)
Zero's out the struct pointed to by ptr.
#define object_zero_and_free(ptr)
Zero's out a struct pointed to by ptr and frees the object.
#define object_free_w_func_and_null(_func, _obj)
Call the function _func to free _obj and set _obj to NULL.
#define g_object_unref_and_null(ptr)
Convenience wrapper.
#define g_free_and_null(ptr)
Convenience wrapper.
#define g_error_free_and_null(ptr)
Convenience wrapper.
#define object_free_w_func_and_null_cast(_func, _cast, _obj)
Convenience wrapper.
#define string_is_equal(str1, str2)
Returns if the two strings are exactly equal.
#define UI_RESIZE_CURSOR_SPACE
Space on the edges to show resize cursors.
#define TARGET_ENTRY_PLUGIN_DESCR
Plugin descriptor, used to instantiate plugins.
#define TARGET_ENTRY_SUPPORTED_FILE
For SupportedFile pointers.
#define TARGET_ENTRY_PLUGIN
Plugin ID, used to move/copy plugins.
#define TARGET_ENTRY_URI_LIST
URI list.
#define TARGET_ENTRY_TRACK
Track target entry.
#define TARGET_ENTRY_CHORD_DESCR
Chord descriptor target entry.
#define ui_show_notification_idle(msg)
Shows the notification when idle.
#define ui_show_error_message(win, msg)
Wrapper to show error message so that no casting of the window is needed on the caller side.
#define ui_show_message_printf(win, type, fmt, ...)
Type can be GTK_MESSAGE_ERROR, etc.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)
Mapping pointer to a struct.
#define YAML_FIELD_FIXED_SIZE_PTR_ARRAY_VAR_COUNT(owner, member, schema)
Fixed-width array of pointers with variable count.
#define YAML_FIELD_FIXED_SIZE_PTR_ARRAY(owner, member, schema, size)
Fixed-width array of pointers with fixed count.
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count.
#define YAML_FIELD_DYN_ARRAY_VAR_COUNT(owner, member, schema)
Dynamic-width (reallocated) array of structs with variable count.
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count, nullable.
#define YAML_FIELD_DYN_ARRAY_VAR_COUNT_PRIMITIVES(owner, member, schema)
Dynamic-width (reallocated) array of primitives with variable count.
#define YAML_FIELD_SEQUENCE_FIXED(owner, member, schema, size)
Fixed sequence of pointers.
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)
Schema to be used as a pointer that can be NULL.
#define YAML_VALUE_DEFAULT(cc, fields_schema)
Schema to be used for arrays of structs directly (not as pointers).

Enum documentation

enum BitDepth

Bit depth.

enum AudioValueFormat

Enumerators
AUDIO_VALUE_AMPLITUDE

0 to 2, amplitude.

AUDIO_VALUE_DBFS

dbFS.

AUDIO_VALUE_FADER

0 to 1, suitable for drawing.

enum UiCursorState
#include <utils/ui.h>

Various cursor states to be shared.

enum UiOverlayAction
#include <utils/ui.h>

Various overlay actions to be shared.

Enumerators
UI_OVERLAY_ACTION_NONE
UI_OVERLAY_ACTION_CREATING_RESIZING_R
UI_OVERLAY_ACTION_CREATING_MOVING
UI_OVERLAY_ACTION_RESIZING_L
UI_OVERLAY_ACTION_RESIZING_L_LOOP
UI_OVERLAY_ACTION_RESIZING_L_FADE
UI_OVERLAY_ACTION_RESIZING_R
UI_OVERLAY_ACTION_RESIZING_R_LOOP
UI_OVERLAY_ACTION_RESIZING_R_FADE
UI_OVERLAY_ACTION_RESIZING_UP
UI_OVERLAY_ACTION_RESIZING_UP_FADE_IN
UI_OVERLAY_ACTION_RESIZING_UP_FADE_OUT
UI_OVERLAY_ACTION_STRETCHING_L
UI_OVERLAY_ACTION_STRETCHING_R
UI_OVERLAY_ACTION_AUDITIONING
UI_OVERLAY_ACTION_AUTOFILLING

Auto-filling in edit mode.

UI_OVERLAY_ACTION_ERASING

Erasing.

UI_OVERLAY_ACTION_STARTING_ERASING
UI_OVERLAY_ACTION_STARTING_MOVING

To be set in drag_start.

UI_OVERLAY_ACTION_STARTING_MOVING_COPY
UI_OVERLAY_ACTION_STARTING_MOVING_LINK
UI_OVERLAY_ACTION_MOVING
UI_OVERLAY_ACTION_MOVING_COPY
UI_OVERLAY_ACTION_MOVING_LINK
UI_OVERLAY_ACTION_STARTING_CHANGING_CURVE
UI_OVERLAY_ACTION_CHANGING_CURVE
UI_OVERLAY_ACTION_STARTING_SELECTION

To be set in drag_start.

Useful to check if nothing was clicked.

UI_OVERLAY_ACTION_SELECTING
UI_OVERLAY_ACTION_STARTING_DELETE_SELECTION

Like selecting but it auto deletes whatever touches the selection.

UI_OVERLAY_ACTION_DELETE_SELECTING
UI_OVERLAY_ACTION_STARTING_RAMP
UI_OVERLAY_ACTION_RAMPING
UI_OVERLAY_ACTION_CUTTING
UI_OVERLAY_ACTION_RENAMING
NUM_UI_OVERLAY_ACTIONS

enum UiDragMode
#include <utils/ui.h>

Dragging modes for widgets that have click&drag.

Enumerators
UI_DRAG_MODE_CURSOR

Value is wherever the cursor is.

UI_DRAG_MODE_RELATIVE

Value is changed based on the offset.

UI_DRAG_MODE_RELATIVE_WITH_MULTIPLIER

Value is changed based on the offset, times a multiplier.

Typedef documentation

typedef enum ZFileType ZFileType

File type.

typedef struct SupportedFile SupportedFile

Metadata for a supported file.

typedef enum BitDepth BitDepth

Bit depth.

typedef struct CairoCaches CairoCaches

Caches for cairo.

typedef struct MPMCQueue MPMCQueue

Multiple Producer Multiple Consumer lock-free queue.

See https://gist.github.com/x42/9aa5e737a1479bafb7f1bb96f7c64dc0

typedef uint8_t midi_byte_t

MIDI byte.

typedef uint32_t nframes_t

Frame count.

typedef uint32_t sample_rate_t

Sample rate.

typedef uint32_t midi_time_t

MIDI time in global frames.

typedef unsigned int channels_t

Number of channels.

typedef float sample_t

The sample type.

typedef float bpm_t

The BPM type.

typedef float(*GenericFloatGetter)(void*object)

Getter prototype for float values.

typedef void(*GenericFloatSetter)(void*object, float val)

Setter prototype for float values.

typedef const char*(*GenericStringGetter)(void*object)

Getter prototype for strings.

typedef void(*GenericStringCopyGetter)(void*object, char*buf)

Getter prototype for strings to be saved in the given buffer.

typedef void(*GenericStringSetter)(void*object, const char*val)

Setter prototype for float values.

typedef void(*GenericCallback)(void*object)

Generic callback.

typedef int(*GenericCmpFunc)(const void*a, const void*b)

Generic comparator.

typedef bool(*GenericPredicateFunc)(const void*object, const void*user_data)

Predicate function prototype.

To be used to return whether the given pointer matches some condition.

typedef struct GenericProgressInfo GenericProgressInfo

Generic progress info.

typedef struct UiColors UiColors
#include <utils/ui.h>

Commonly used UI colors.

typedef struct UiCursor UiCursor
#include <utils/ui.h>

Specification for a cursor.

Used for caching.

typedef struct UiCaches UiCaches
#include <utils/ui.h>

Caches.

typedef enum UiCursorState UiCursorState
#include <utils/ui.h>

Various cursor states to be shared.

typedef enum UiOverlayAction UiOverlayAction
#include <utils/ui.h>

Various overlay actions to be shared.

typedef enum UiDragMode UiDragMode
#include <utils/ui.h>

Dragging modes for widgets that have click&drag.

Function documentation

SupportedFile* supported_file_new_from_path(const char* path)

Creates a new SupportedFile from the given absolute path.

char* supported_file_type_get_description(ZFileType type)

Returns a human readable description of the given file type.

Example: wav -> "Wave file".

int supported_file_type_is_supported(ZFileType type)

Returns if the given type is supported.

int supported_file_type_is_audio(ZFileType type)

Returns if the SupportedFile is an audio file.

int supported_file_type_is_midi(ZFileType type)

Returns if the SupportedFile is a midi file.

const char* supported_file_type_get_ext(ZFileType type)

Returns the most common extension for the given filetype.

ZFileType supported_file_get_type(const char* file)

Returns the file type of the given file path.

NONNULL bool supported_file_should_autoplay(const SupportedFile* self)

Returns whether the given file should auto-play (shorter than 1 min).

NONNULL char* supported_file_get_info_text_for_label(const SupportedFile* self)

Returns a pango markup to be used in GTK labels.

void supported_file_free(SupportedFile* self)

Frees the instance and all its members.

int audio_write_raw_file(float* buff, long frames_already_written, long nframes, uint32_t samplerate, bool flac, BitDepth bit_depth, unsigned int channels, const char* filename)

Writes the buffer as a raw file to the given path.

Parameters
buff
frames_already_written Frames (per channel)already written. If this is non-zero and the file exists, it will append to the existing file.
nframes
samplerate The samplerate of buff.
flac
bit_depth
channels
filename
Returns Non-zero if fail.

long audio_get_num_frames(const char* filepath)

Returns the number of frames in the given audio file.

bool audio_frames_equal(float* src1, float* src2, size_t num_frames, float epsilon)

Returns whether the frame buffers are equal.

bool audio_frames_empty(float* src, size_t num_frames)

Returns whether the frame buffer is empty (zero).

int audio_get_num_cores(void)

Returns the number of CPU cores.

char* _backtrace_get(const char* exe_path, const char* prefix, int max_lines, bool with_lines, bool write_to_file)

Returns the backtrace with max_lines number of lines and a string prefix.

Parameters
exe_path Executable path for running addr2line.
prefix
max_lines
with_lines Whether to show line numbers. This is very slow.
write_to_file

static void z_cairo_rounded_rectangle(cairo_t* cr, double x, double y, double width, double height, double aspect, double corner_radius)

Parameters
cr
x
y
width
height
aspect Aspect ratio.
corner_radius Corner curvature radius.

void _z_cairo_get_text_extents_for_widget(GtkWidget* widget, PangoLayout* layout, const char* text, int* width, int* height)

Gets the width of the given text in pixels for the given widget.

Parameters
widget The widget to derive a PangoLayout from.
layout
text The text to draw.
width The width to fill in.
height The height to fill in.

void z_cairo_draw_text_full(cairo_t* cr, GtkWidget* widget, PangoLayout* layout, const char* text, int start_x, int start_y)

Draws the given text using the given font starting at the given position.

static void z_cairo_diamond(cairo_t* cr, double x, double y, double width, double height)

Draws a diamond shape.

cairo_surface_t* z_cairo_get_surface_from_icon_name(const char* icon_name, int size, int scale)

Returns a surface for the icon name.

PangoLayout* z_cairo_create_pango_layout_from_string(GtkWidget* widget, const char* font, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding)

Creates a PangoLayout to be cached in widgets based on the given settings.

PangoLayout* z_cairo_create_pango_layout_from_description(GtkWidget* widget, PangoFontDescription* descr, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding)

Creates a PangoLayout to be cached in widgets based on the given settings.

PangoLayout* z_cairo_create_default_pango_layout(GtkWidget* widget)

Creates a PangoLayout with default settings.

void z_cairo_reset_caches(cairo_t** cr_cache, cairo_surface_t** surface_cache, int width, int height, cairo_t* new_cr)

Resets a surface and cairo_t with a new surface and cairo_t based on the given rectangle and cairo_t.

Parameters
cr_cache
surface_cache
width New surface width.
height New surface height.
new_cr

To be used inside draw calls of widgets that use caching.

void color_brighten(GdkRGBA* src, double val)

Brightens the color by the given amount.

void color_brighten_default(GdkRGBA* src)

Brightens the color by the default amount.

void color_darken(GdkRGBA* src, double val)

Darkens the color by the given amount.

void color_darken_default(GdkRGBA* src)

Darkens the color by the default amount.

bool color_is_same(GdkRGBA* src, GdkRGBA* dest)

Returns whether the color is the same.

bool color_is_bright(GdkRGBA* src)

Returns if the color is bright or not.

bool color_is_very_bright(GdkRGBA* src)

Returns if the color is very bright or not.

bool color_is_very_very_bright(GdkRGBA* src)

Returns if the color is very very bright or not.

bool color_is_very_dark(GdkRGBA* src)

Returns if the color is very dark or not.

bool color_is_very_very_dark(GdkRGBA* src)

Returns if the color is very very dark or not.

void color_morph(GdkRGBA* a, GdkRGBA* b, double amt, GdkRGBA* result)

Morphs from a to b, depending on the given amount.

Eg, if amt is 0, the resulting color will be a. If amt is 1, the resulting color will be .

char* z_curl_get_page_contents(const char* url, int timeout)

Returns the contents of the page in a newly allocated string.

Parameters
url
timeout Timeout in seconds.
Returns Newly allocated string or NULL if fail.

char* z_curl_get_page_contents_default(const char* url)

Returns the contents of the page in a newly allocated string.

Returns Newly allocated string or NULL if fail.

int z_curl_post_json_no_auth(const char* url, const char* data, int timeout, GError** error, ...) G_GNUC_NULL_TERMINATED

Posts the given JSON to the URL without any authentication.

Parameters
url
data
timeout Timeout, in seconds.
error
Returns Non-zero if error.

char* datetime_get_current_as_string(void)

Returns the current datetime as a string.

Must be free()'d by caller.

char* datetime_get_for_filename(void)

Get the current datetime to be used in filenames, eg, for the log file.

char* env_get_string(const char* key, const char* def)
#include <utils/env.h>

Returns a newly allocated string.

Parameters
key
def Default value to return if not found.

int env_get_int(const char* key, int def)
#include <utils/env.h>

Returns an int for the given environment variable if it exists and is valid, otherwise returns the default int.

Parameters
key
def Default value to return if not found.

int file_reflink(const char* dest, const char* src)

Do cp –reflink from src to dest.

Returns Non-zero on error.

void z_gtk_container_remove_all_children(GtkContainer* container)
#include <utils/gtk.h>

GtkLabel* z_gtk_message_dialog_get_label(GtkMessageDialog* self, const int secondary)
#include <utils/gtk.h>

Returns the primary or secondary label of the given GtkMessageDialog.

Parameters
self
secondary 0 for primary, 1 for secondary.

void z_gtk_configure_simple_combo_box(GtkComboBox* cb, GtkTreeModel* model)
#include <utils/gtk.h>

Configures a simple value-text combo box using the given model.

void z_gtk_button_set_icon_name(GtkButton* btn, const char* name)
#include <utils/gtk.h>

Sets the icon name and optionally text.

void z_gtk_button_set_icon_name_and_text(GtkButton* btn, const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing)
#include <utils/gtk.h>

Sets the icon name and optionally text.

GtkButton* z_gtk_button_new_with_icon(const char* name)
#include <utils/gtk.h>

Creates a button with the given icon name.

GtkToggleButton* z_gtk_toggle_button_new_with_icon(const char* name)
#include <utils/gtk.h>

Creates a toggle button with the given icon name.

GtkToggleButton* z_gtk_toggle_button_new_with_icon_and_text(const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing)
#include <utils/gtk.h>

Creates a toggle button with the given icon name.

GtkButton* z_gtk_button_new_with_icon_and_text(const char* name, const char* text, bool icon_first, GtkOrientation orientation, int spacing)
#include <utils/gtk.h>

Creates a button with the given icon name and text.

GtkButton* z_gtk_button_new_with_resource(IconType icon_type, const char* name)
#include <utils/gtk.h>

Creates a button with the given resource name as icon.

GtkToggleButton* z_gtk_toggle_button_new_with_resource(IconType icon_type, const char* name)
#include <utils/gtk.h>

Creates a toggle button with the given resource name as icon.

GtkMenuItem* z_gtk_create_menu_item_full(const gchar* label_name, const gchar* icon_name, IconType resource_icon_type, const gchar* resource, bool is_toggle, const char* action_name)
#include <utils/gtk.h>

Creates a menu item.

void* z_gtk_get_single_selection_pointer(GtkTreeView* tv, int column)
#include <utils/gtk.h>

Returns a pointer stored at the given selection.

GtkLabel* z_gtk_get_label_from_menu_item(GtkMenuItem* mi)
#include <utils/gtk.h>

Returns the label from a given GtkMenuItem.

The menu item must have a box with an optional icon and a label inside.

char* z_gtk_get_tooltip_for_action(const char* detailed_action, const char* tooltip)
#include <utils/gtk.h>

Gets the tooltip for the given action on the given widget.

Returns A new string that must be free'd with g_free().

If the action is valid, an orange text showing the accelerator will be added to the tooltip.

void z_gtk_widget_set_tooltip_for_action(GtkWidget* widget, const char* detailed_action, const char* tooltip)
#include <utils/gtk.h>

Sets the tooltip for the given action on the given widget.

If the action is valid, an orange text showing the accelerator will be added to the tooltip.

void z_gtk_set_tooltip_for_actionable(GtkActionable* actionable, const char* tooltip)
#include <utils/gtk.h>

Sets the tooltip and finds the accel keys and appends them to the tooltip in small text.

void z_gtk_tool_button_set_icon_size(GtkToolButton* toolbutton, GtkIconSize icon_size)
#include <utils/gtk.h>

Changes the size of the icon inside tool buttons.

void z_gtk_widget_add_style_class(GtkWidget* widget, const gchar* class_name)
#include <utils/gtk.h>

Adds the given style class to the widget.

void z_gtk_widget_remove_style_class(GtkWidget* widget, const gchar* class_name)
#include <utils/gtk.h>

Removes the given style class from the widget.

static GdkDevice* z_gtk_widget_get_device(GtkWidget* widget)
#include <utils/gtk.h>

Gets the GdkDevice for a GtkWidget.

static void z_gtk_warp_cursor_to(GtkWidget* widget, int x, int y)
#include <utils/gtk.h>

Wraps the cursor to the given global coordinates.

static void z_gtk_widget_get_mask(GtkWidget* widget, GdkModifierType* mask)
#include <utils/gtk.h>

Sets the GdkModifierType given for the widget.

Used in eg. drag_motion events to check if Ctrl is held.

static int z_gtk_keyval_is_alt(const guint keyval)
#include <utils/gtk.h>

Returns if the keyval is an Alt key.

static int z_gtk_keyval_is_ctrl(const guint keyval)
#include <utils/gtk.h>

Returns if the keyval is a Control key.

static int z_gtk_keyval_is_arrow(const guint keyval)
#include <utils/gtk.h>

Returns if the keyval is an arrow key.

static int z_gtk_keyval_is_shift(const guint keyval)
#include <utils/gtk.h>

Returns if the keyval is a Shift key.

static GtkWidget* z_gtk_container_get_single_child(GtkContainer* container)
#include <utils/gtk.h>

Returns the single child of a container.

GtkWidget* z_gtk_container_get_nth_child(GtkContainer* container, int index)
#include <utils/gtk.h>

Returns the nth child of a container.

void z_gtk_combo_box_set_ellipsize_mode(GtkComboBox* self, PangoEllipsizeMode ellipsize)
#include <utils/gtk.h>

Sets the ellipsize mode of each text cell renderer in the combo box.

void z_gtk_button_set_emblem(GtkButton* btn, const char* emblem_icon)
#include <utils/gtk.h>

Sets the given emblem to the button, or unsets the emblem if emblem_icon is NULL.

void z_gtk_setup_foldable_notebook(GtkNotebook* notebook)
#include <utils/gtk.h>

Makes the given notebook foldable.

The pages of the notebook must all be wrapped in GtkBox's.

void z_gtk_widget_set_margin(GtkWidget* widget, int margin)
#include <utils/gtk.h>

Sets the margin on all 4 sides on the widget.

bool z_gtk_activate_dir_link_func(GtkLabel* label, char* uri, void* data)
#include <utils/gtk.h>

Callback to use for simple directory links.

void z_gtk_notebook_make_detachable(GtkNotebook* notebook, GtkWindow* parent_window)
#include <utils/gtk.h>

Makes the given GtkNotebook detachable to a new window.

void z_gtk_message_dialog_wrap_message_area_in_scroll(GtkMessageDialog* dialog, int min_width, int min_height)
#include <utils/gtk.h>

Wraps the message area in a scrolled window.

char* z_gtk_text_buffer_get_full_text(GtkTextBuffer* buffer)
#include <utils/gtk.h>

Returns the full text contained in the text buffer.

Must be free'd using g_free().

void z_gtk_generate_screenshot_image(GtkWidget* widget, const char* type, char** option_keys, char** option_values, char** ret_dir, char** ret_path)
#include <utils/gtk.h>

Generates a screenshot image for the given widget.

Parameters
widget
type
option_keys
option_values
ret_dir out Placeholder for directory to be deleted after using the screenshot.
ret_path out Placeholder for absolute path to the screenshot.

See gdk_pixbuf_savev() for the parameters.

void z_gtk_actionable_set_action_from_setting(GtkActionable* actionable, GSettings* settings, const char* key)
#include <utils/gtk.h>

Sets the action target of the given GtkActionable to be binded to the given setting.

Mainly used for binding GSettings keys to toggle buttons.

NONNULL char* io_get_dir(const char* filename)

Gets directory part of filename.

Parameters
filename Filename containing directory.

MUST be freed.

NONNULL char* io_path_get_basename_without_ext(const char* filename)

Strips path from given filename.

MUST be freed.

NONNULL int io_rmdir(const char* path, bool force)

Removes a dir, optionally forcing deletion.

For safety reasons, this only accepts an absolute path with length greater than 20 if forced.

char** io_get_files_in_dir_ending_in(const char* _dir, const int recursive, const char* end_string, bool allow_empty)

Returns a list of the files in the given directory.

Parameters
_dir
recursive
end_string
allow_empty Whether to allow returning an empty array that has only NULL, otherwise return NULL if empty.
Returns a NULL terminated array of strings that must be free'd with g_strfreev() or NULL.

void io_copy_dir(const char* destdir_str, const char* srcdir_str, bool follow_symlinks, bool recursive)

NONNULL char* io_get_next_available_filepath(const char* filepath)

Returns a newly allocated path that is either a copy of the original path if the path does not exist, or the original path appended with (n), where n is a number.

Example: "myfile" -> "myfile (1)"

NONNULL void log_init_writer_idle(Log* self, unsigned int secs)

Initializes logging to a file.

Parameters
self
secs Number of timeout seconds.

This must be called from the GTK thread.

NONNULL char* log_get_last_n_lines(Log* self, int n)

Returns the last n lines as a newly allocated string.

Parameters
self
n Number of lines.

bool log_generate_compressed_file(Log* self, char** ret_dir, char** ret_path, GError** error)

Generates a compressed log file (for sending with bug reports).

Returns Whether successful.

void log_init_with_file(Log* self, const char* filepath)

Initializes logging to a file.

Parameters
self
filepath If non-NULL, the given file will be used, otherwise the default file will be created.

This can be called from any thread.

Log* log_new(void)

Creates the logger and sets the writer func.

This can be called from any thread.

static CONST float math_fast_log2(float val)

Fast log calculation to be used where precision is not required (like log curves).

Taken from ardour from code in the public domain.

static CONST sample_t math_get_fader_val_from_amp(sample_t amp)

Returns fader value 0.0 to 1.0 from amp value 0.0 to 2.0 (+6 dbFS).

static CONST sample_t math_get_amp_val_from_fader(sample_t fader)

Returns amp value 0.0 to 2.0 (+6 dbFS) from fader value 0.0 to 1.0.

static CONST sample_t math_amp_to_dbfs(sample_t amp)

Convert from amplitude 0.0 to 2.0 to dbFS.

sample_t math_calculate_max_amp(sample_t* buf, const nframes_t nframes)

Gets the digital peak of the given signal as amplitude (0-2).

sample_t math_calculate_rms_db(sample_t* buf, const nframes_t nframes)

Calculate db using RMS method.

Parameters
buf Buffer containing the samples.
nframes Number of samples.

static CONST sample_t math_dbfs_to_amp(sample_t dbfs)

Convert form dbFS to amplitude 0.0 to 2.0.

static CONST sample_t math_dbfs_to_fader_val(sample_t dbfs)

Convert form dbFS to fader val 0.0 to 1.0.

bool math_assert_nonnann(float x)

Asserts that the value is non-nan.

Returns Whether the value is valid (nonnan).

Not real-time safe.

void _free_later(void* object, void(*)(void*) dfunc, const char* file, const char* func, int line)

Frees the object after a while.

This is useful when the object will be in use for a while, for example in the current processing cycle.

GtkWidget* resources_get_icon(IconType icon_type, const char* filename)

Creates a GtkImage of from the given information and returns it as a GtkWidget.

Returns a GtkImage.

void resources_set_class_template(GtkWidgetClass* klass, const char* filename)

Sets class template from resource.

Filename is part after .../ui/

GBytes* resources_get_gl_shader_data(const char* path)

Returns the bytes of the specified OpenGL shader in RESOURCES_GL_SHADERS_PATH.

Returns bytes or NULL if error.

Caller must free the bytes with g_bytes_unref ().

int sort_alphabetical_func(const void* a, const void* b)

Alphabetical sort func.

The arguments must be strings (char *).

Stack* stack_new(int length)

Creates a new stack of the given size.

Parameters
length Stack size. If -1, the stack will have unlimited size.

int string_is_ascii(const char* string)

Returns if the string is ASCII.

char* string_array_contains_substr(char** str_array, int num_str, const char* substr)

Returns the matched string if the string array contains the given substring.

bool string_contains_substr(const char* str, const char* substr)

Returns if the given string contains the given substring.

void string_to_upper(const char* in, char* out)

Converts the given string to uppercase in out.

Assumes out is already allocated to as many chars as in.

void string_to_lower(const char* in, char* out)

Converts the given string to lowercase in out.

Assumes out is already allocated to as many chars as in.

bool string_is_equal_ignore_case(const char* str1, const char* str2)

Returns if the two strings are equal ignoring case.

char* string_convert_to_filename(const char* str)

Returns a newly allocated string that is a filename version of the given string.

Example: "MIDI ZRegion #1" -> "MIDI_Region_1".

char* string_get_substr_before_suffix(const char* str, const char* suffix)

Removes the suffix starting from suffix from full_str and returns a newly allocated string.

char* string_remove_until_after_first_match(const char* str, const char* match)

Removes everything up to and including the first match of match from the start of the string and returns a newly allocated string.

void string_replace_regex(char** str, const char* regex, const char* replace_str)

Replaces src_str with replace_str in all instances matched by regex.

char* string_get_regex_group(const char* str, const char* regex, int group)

Gets the string in the given regex group.

Returns A newly allocated string or NULL.

int string_get_regex_group_as_int(const char* str, const char* regex, int group, int def)

Gets the string in the given regex group as an integer.

Parameters
str
regex
group
def Default.
Returns The int, or default.

int string_get_int_after_last_space(const char* str, char* str_without_num)

Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found.

Parameters
str
str_without_num A buffer to save the string without the number (including the space).

See https://www.debuggex.com/cheatsheet/regex/pcre for more info.

char** string_array_sort_and_remove_duplicates(char** str_arr)

TODO Sorts the given string array and removes duplicates.

Parameters
str_arr A NULL-terminated array of strings.
Returns A NULL-terminated array with the string addresses of the source array.

void string_copy_w_realloc(char** dest, const char* src)

Copies the string src to the buffer in dest after reallocating the buffer in dest to the length of src.

If src is NULL, the string at dest is free'd and the pointer is set to NULL.

char* string_symbolify(const char* in)

Returns a new string with only ASCII alphanumeric characters and replaces ther est with underscore.

int system_run_cmd(const char* cmd, long ms_timer)

Runs the given command in the background, waits for it to finish and returns its exit code.

Parameters
cmd
ms_timer A timer in ms to kill the process, or negative to not wait.

char* system_get_cmd_output(char** argv, long ms_timer, bool always_wait)

Runs the command and returns the output, or NULL.

Parameters
argv
ms_timer A timer in ms to kill the process, or negative to not wait.
always_wait

This assumes that the process will exit within a few milliseconds from when the first output is printed, unless always_wait is true, in which case the process will only be reaped after the waiting time.

int system_run_cmd_w_args(const char** args, int ms_to_wait, char** out_stdout, char** out_stderr, bool warn_if_fail)

Runs the given command in the background, waits for it to finish and returns its exit code.

Parameters
args NULL-terminated array of args.
ms_to_wait
out_stdout out A pointer to save the newly allocated stdout output (if non-NULL).
out_stderr out A pointer to save the newly allocated stderr output (if non-NULL).
warn_if_fail

GdkModifierType ui_get_state_mask(GtkGesture* gesture)
#include <utils/ui.h>

Used in handlers to get the state mask.

void ui_set_cursor_from_icon_name(GtkWidget* widget, const char* name, int offset_x, int offset_y)
#include <utils/ui.h>

Sets cursor from icon name.

void ui_set_cursor_from_name(GtkWidget* widget, const char* name)
#include <utils/ui.h>

Sets cursor from standard cursor name.

void ui_show_message_full(GtkWindow* parent_window, GtkMessageType type, const char* format, ...) G_GNUC_PRINTF(3
#include <utils/ui.h>

Shows a popup message of the given type with the given message.

bool ui_is_point_in_rect_hit(GdkRectangle* rect, const bool check_x, const bool check_y, double x, double y, double x_padding, double y_padding)
#include <utils/ui.h>

Returns if rect is hit or not by the given coordinate.

Parameters
rect
check_x Check x-axis for match.
check_y Check y-axis for match.
x x in parent space.
y y in parent space.
x_padding Padding to add to the x of the object when checking if hit. The bigger the padding the more space the child will have to get hit.
y_padding Padding to add to the y of the object when checking if hit. The bigger the padding the more space the child will have to get hit.

int ui_is_child_hit(GtkWidget* parent, GtkWidget* child, const int check_x, const int check_y, const double x, const double y, const double x_padding, const double y_padding)
#include <utils/ui.h>

Returns if the child is hit or not by the coordinates in parent.

Parameters
parent
child
check_x Check x-axis for match.
check_y Check y-axis for match.
x x in parent space.
y y in parent space.
x_padding Padding to add to the x of the object when checking if hit. The bigger the padding the more space the child will have to get hit.
y_padding Padding to add to the y of the object when checking if hit. The bigger the padding the more space the child will have to get hit.

GtkWidget* ui_get_hit_child(GtkContainer* parent, double x, double y, GType type)
#include <utils/ui.h>

Returns the matching hit child, or NULL.

type to look for

NONNULL void ui_px_to_pos_timeline(double px, Position* pos, int has_padding)
#include <utils/ui.h>

Converts from pixels to position.

Parameters
px
pos
has_padding Whether px contains padding.

Only works with positive numbers. Negatives will be clamped at 0. If a negative is needed, pass the abs to this function and then change the sign.

long ui_px_to_frames_timeline(double px, int has_padding)
#include <utils/ui.h>

Converts from pixels to frames.

Parameters
px
has_padding Whether then given px contains padding.

Returns the frames.

long ui_px_to_frames_editor(double px, int has_padding)
#include <utils/ui.h>

Converts from pixels to frames.

Parameters
px
has_padding Whether then given px contains padding.

Returns the frames.

NONNULL int ui_pos_to_px_timeline(Position* pos, int use_padding)
#include <utils/ui.h>

Converts position to px, optionally adding the ruler padding.

NONNULL int ui_pos_to_px_editor(Position* pos, int use_padding)
#include <utils/ui.h>

Converts position to px, optionally adding the ruler padding.

NONNULL void ui_px_to_pos_editor(double px, Position* pos, int has_padding)
#include <utils/ui.h>

Converts from pixels to position.

Parameters
px
pos
has_padding Whether px contains padding.

Only works with positive numbers. Negatives will be clamped at 0. If a negative is needed, pass the abs to this function and then change the sign.

void ui_rgb_to_hex(double red, double green, double blue, char* buf)
#include <utils/ui.h>

Converts RGB to hex string.

void ui_show_notification(const char* msg)
#include <utils/ui.h>

Shows a notification in the revealer.

int ui_show_notification_idle_func(char* msg)
#include <utils/ui.h>

Show notification from non-GTK threads.

This should be used internally. Use the ui_show_notification_idle macro instead.

void ui_get_modifier_type_from_gesture(GtkGestureSingle* gesture, GdkModifierType* state_mask)
#include <utils/ui.h>

Returns the modifier type (state mask) from the given gesture.

return value

void ui_setup_language_combo_box(GtkComboBox* language)
#include <utils/ui.h>

Sets up a combo box to have a selection of languages.

void ui_setup_audio_backends_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up an audio backends combo box.

void ui_setup_midi_backends_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up a MIDI backends combo box.

void ui_setup_pan_algo_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up a pan algorithm combo box.

void ui_setup_pan_law_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up a pan law combo box.

void ui_setup_buffer_size_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up a pan law combo box.

void ui_setup_samplerate_combo_box(GtkComboBox* cb)
#include <utils/ui.h>

Sets up a pan law combo box.

void ui_setup_device_name_combo_box(GtkComboBoxText* cb)
#include <utils/ui.h>

Sets up a pan law combo box.

void ui_setup_vst_paths_entry(GtkEntry* entry)
#include <utils/ui.h>

Sets up the VST paths entry.

void ui_update_vst_paths_from_entry(GtkEntry* entry)
#include <utils/ui.h>

Updates the the VST paths in the gsettings from the text in the entry.

char* ui_get_locale_not_available_string(LocalizationLanguage lang)
#include <utils/ui.h>

Returns the "a locale for the language you have selected..." text based on the given language.

Must be free'd by caller.

void ui_get_contrast_color(GdkRGBA* src, GdkRGBA* dest)
#include <utils/ui.h>

Returns the contrasting color (variation of black or white) based on if the given color is dark enough or not.

Parameters
src The source color.
dest The desination color to write to.

void ui_get_mid_color(GdkRGBA* dest, const GdkRGBA* c1, const GdkRGBA* c2, const double transition)
#include <utils/ui.h>

Returns the color in-between two colors.

Parameters
dest
c1
c2
transition How far to transition (0.5 for half).

static NONNULL static PURE bool ui_rectangle_overlap(const GdkRectangle*const rect1, const GdkRectangle*const rect2)
#include <utils/ui.h>

Returns if the 2 rectangles overlay.

void ui_get_arranger_object_color(GdkRGBA* color, const bool is_hovered, const bool is_selected, const bool is_transient, const bool is_muted)
#include <utils/ui.h>

Gets the color the widget should be.

Parameters
color The original color.
is_hovered
is_selected Whether the widget is supposed to be selected or not.
is_transient
is_muted

double ui_get_normalized_draggable_value(double size, double cur_val, double start_px, double cur_px, double last_px, double multiplier, UiDragMode mode)
#include <utils/ui.h>

Gets a draggable value as a normalized value between 0 and 1.

Parameters
size Widget size (either width or height).
cur_val
start_px Px at start of drag.
cur_px Current px.
last_px Px during last call.
multiplier
mode

void ui_bind_midi_cc_item_activate_cb(GtkMenuItem* menuitem, Port* port)
#include <utils/ui.h>

All purpose menuitem callback for binding MIDI CC to a port.

An action will be performed if bound.

void vamp_print_all(void)

Prints detected vamp plugins.

NONNULL char* yaml_serialize(void* data, const cyaml_schema_value_t* schema)

Serializes to YAML.

Returns Newly allocated YAML string, or NULL if error.

void yaml_cyaml_log_func(cyaml_log_t level, void* ctxt, const char* format, va_list args)

Custom logging function for libcyaml.

Variable documentation

static const char* ui_overlay_strings
#include <utils/ui.h>

Various overlay actions to be shared.

Define documentation

#define STRIP_SIZE

Number of plugin slots per channel.

#define Z_CAIRO_FONT

Default font for drawing pango text.

#define Z_CAIRO_TEXT_PADDING

Padding to leave from the top/left edges when drawing text.

#define z_cairo_draw_text(cr, widget, layout, text)

Draw text with default padding.

#define file_exists(file)

Returns 1 if the file/dir exists.

#define io_get_files_in_dir(dir, allow_empty)

Returns a list of the files in the given directory.

Returns a NULL terminated array of strings that must be free'd with g_strfreev(), or NULL if no files were found.

#define MATH_RMS_FRAMES

Frames to skip when calculating the RMS.

The lower the more CPU intensive.

#define MATH_TINY_NUMBER

Tiny number to be used for denormaml prevention (-140dB).

#define math_floats_equal_epsilon(a, b, e)

Checks if 2 doubles are equal.

#define math_floats_equal(a, b)

Checks if 2 doubles are equal.

#define math_round_double_to_type(x, type)

Rounds a double to an int.

#define math_round_double_to_int(x)

Rounds a double to an int.

#define math_round_double_to_size_t(x)

Rounds a double to a size_t.

#define math_round_double_to_long(x)

Rounds a double to a long.

#define math_round_float_to_type(x, type)

Rounds a float to a given type.

#define math_round_float_to_int(x)

Rounds a float to an int.

#define math_round_float_to_long(x)

Rounds a float to a long.

#define string_is_equal(str1, str2)

Returns if the two strings are exactly equal.

#define UI_RESIZE_CURSOR_SPACE
#include <utils/ui.h>

Space on the edges to show resize cursors.

#define TARGET_ENTRY_PLUGIN_DESCR
#include <utils/ui.h>

Plugin descriptor, used to instantiate plugins.

#define TARGET_ENTRY_SUPPORTED_FILE
#include <utils/ui.h>

For SupportedFile pointers.

#define TARGET_ENTRY_PLUGIN
#include <utils/ui.h>

Plugin ID, used to move/copy plugins.

#define TARGET_ENTRY_URI_LIST
#include <utils/ui.h>

URI list.

#define TARGET_ENTRY_TRACK
#include <utils/ui.h>

Track target entry.

This is just the identifier. The TracklistSelections will be used.

#define TARGET_ENTRY_CHORD_DESCR
#include <utils/ui.h>

Chord descriptor target entry.

#define ui_show_notification_idle(msg)
#include <utils/ui.h>

Shows the notification when idle.

This should be called from threads other than GTK main thread.

#define ui_show_error_message(win, msg)
#include <utils/ui.h>

Wrapper to show error message so that no casting of the window is needed on the caller side.

#define ui_show_message_printf(win, type, fmt, ...)
#include <utils/ui.h>

Type can be GTK_MESSAGE_ERROR, etc.

#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)

Mapping embedded inside the struct.

#define YAML_FIELD_MAPPING_PTR(owner, member, schema)

Mapping pointer to a struct.

#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)

Mapping pointer to a struct.

#define YAML_FIELD_FIXED_SIZE_PTR_ARRAY_VAR_COUNT(owner, member, schema)

Fixed-width array of pointers with variable count.

 @
MyStruct * my_structs[MAX_STRUCTS];
int        num_my_structs;

@

#define YAML_FIELD_FIXED_SIZE_PTR_ARRAY(owner, member, schema, size)

Fixed-width array of pointers with fixed count.

 @
MyStruct * my_structs[MAX_STRUCTS_CONST];

@

#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT(owner, member, schema)

Dynamic-width (reallocated) array of pointers with variable count.

 @
AutomationTrack ** ats;
int                num_ats;
int                ats_size;

@

#define YAML_FIELD_DYN_ARRAY_VAR_COUNT(owner, member, schema)

Dynamic-width (reallocated) array of structs with variable count.

 @
RegionIdentifier * ids;
int                num_ids;
int                ids_size;

@

#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema)

Dynamic-width (reallocated) array of pointers with variable count, nullable.

 @
AutomationTrack ** ats;
int                num_ats;
int                ats_size;

@

#define YAML_FIELD_DYN_ARRAY_VAR_COUNT_PRIMITIVES(owner, member, schema)

Dynamic-width (reallocated) array of primitives with variable count.

 @
int * ids;
int   num_ids;
int   ids_size;

@

#define YAML_FIELD_SEQUENCE_FIXED(owner, member, schema, size)

Fixed sequence of pointers.

#define YAML_VALUE_PTR(cc, fields_schema)

Schema to be used as a pointer.

#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)

Schema to be used as a pointer that can be NULL.

#define YAML_VALUE_DEFAULT(cc, fields_schema)

Schema to be used for arrays of structs directly (not as pointers).

For every other case, use the PTR above.