Utilities module

Various utilities.

Files

file resources.h

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 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 ZGtkFill { Z_GTK_NO_FILL, Z_GTK_FILL }
For readability, instead of using 0s and 1s.
enum AudioValueFormat { AUDIO_VALUE_AMPLITUDE, AUDIO_VALUE_DBFS, AUDIO_VALUE_FADER }

Typedefs

using ZFileType = enum ZFileType
File type.
using SupportedFile = struct SupportedFile
Metadata for a supported file.
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 GenericStringSetter = void(*)(void*object, const char*val)
Setter prototype for float values.
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.
void supported_file_free(SupportedFile* self)
Frees the instance and all its members.
void audio_write_raw_file(float* buff, long nframes, uint32_t samplerate, unsigned int channels, const char* filename)
Writes the buffer as a raw file to the given path.
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) -> 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.
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 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.
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_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_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.
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 GtkWidget.
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_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.
auto io_get_dir(const char* filename) -> char*
Gets directory part of filename.
void io_mkdir(const char* dir)
Makes directory if doesn't exist.
auto io_touch_file(const char* filename) -> FILE*
Creates the file if doesn't exist.
auto io_file_strip_ext(const char* filename) -> char*
Strips extensions from given filename.
auto io_file_get_ext(const char* file) -> const char*
Returns file extension or NULL.
auto io_path_get_basename_without_ext(const char* filename) -> char*
Strips path from given filename.
auto io_remove(const char* path) -> int
Removes the given file.
auto io_rmdir(const char* path, int force) -> 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) -> char**
Returns a list of the files in the given directory.
auto io_get_next_available_filepath(const char* filepath) -> 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.
void io_open_directory(const char* path)
Opens the given directory using the default program.
void io_escape_dir_name(char* dest, const char* dir)
Returns a clone of the given string after removing forbidden characters.
static auto localization_get_string_code(LocalizationLanguage lang) -> const char*
Returns the character string code for the language (e.g.
auto localization_locale_exists(LocalizationLanguage lang) -> char*
Returns the first locale found matching the given language, or NULL if a locale for the given language does not exist.
auto localization_init(bool use_locale, bool print_debug_messages) -> bool
Sets the locale to the currently selected one and inits gettext.
void log_init_writer_idle(Log* self, unsigned int secs)
Initializes logging to a file.
auto log_idle_cb(Log* self) -> int
Idle callback.
auto log_get_last_n_lines(Log* self, int n) -> char*
Returns the last n lines as a newly allocated string.
void log_init_with_file(Log* self, bool use_file, int file)
Initializes logging to a file.
auto log_new(void) -> Log*
Creates the logger and sets the writer func.
void log_free(Log* self)
Stops logging and frees any allocated memory.
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 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, const bool accept_alternatives) -> bool
Returns if the given string contains the given substring.
auto string_is_equal(const char* str1, const char* str2) -> bool
Returns if the two strings are exactly equal.
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.
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.
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, bool get_stdout, char** output, bool warn_if_fail) -> int
Runs the given command in the background, waits for it to finish and returns its exit code.
void yaml_cyaml_log_func(cyaml_log_t level, void* ctxt, const char* format, va_list args)
Custom logging function for libcyaml.

Variables

const typedef char*(* GenericStringGetter
Getter prototype for strings.

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)
Returns a list of the files in the given directory.
#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_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 g_object_unref_and_null(ptr)
Frees memory, sets the pointer to NULL and zero's out the struct.
#define g_free_and_null(ptr)
Frees memory and sets the pointer to NULL.
#define object_free_w_func_and_null(_func, _obj)
Call the function _func to free _obj and set _obj to NULL.
#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).
#define SERIALIZE_INC(camelcase, lowercase)
Serializes to XML.

Enum documentation

enum ZGtkFill
#include <utils/gtk.h>

For readability, instead of using 0s and 1s.

enum AudioValueFormat

Enumerators
AUDIO_VALUE_AMPLITUDE

0 to 2, amplitude.

AUDIO_VALUE_DBFS

dbFS.

AUDIO_VALUE_FADER

0 to 1, suitable for drawing.

Typedef documentation

typedef enum ZFileType ZFileType

File type.

typedef struct SupportedFile SupportedFile

Metadata for a supported file.

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 struct Stack Stack

Stack implementation.

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 void(*GenericStringSetter)(void*object, const char*val)

Setter prototype for float values.

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.

void supported_file_free(SupportedFile* self)

Frees the instance and all its members.

void audio_write_raw_file(float* buff, long nframes, uint32_t samplerate, unsigned int channels, const char* filename)

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

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)

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.

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.

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

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.

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.

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.

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.

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.

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 GtkWidget.

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_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.

char* io_get_dir(const char* filename)

Gets directory part of filename.

Parameters
filename Filename containing directory.

MUST be freed.

char* io_path_get_basename_without_ext(const char* filename)

Strips path from given filename.

MUST be freed.

int io_rmdir(const char* path, int force)

Removes a dir, optionally forcing deletion.

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

char** io_get_files_in_dir_ending_in(const char* dir, const int recursive, const char* end_string)

Returns a list of the files in the given directory.

Parameters
dir The directory to look for.
recursive
end_string
Returns a NULL terminated array of strings that must be free'd with g_strfreev().

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)"

static const char* localization_get_string_code(LocalizationLanguage lang)

Returns the character string code for the language (e.g.

"fr").

char* localization_locale_exists(LocalizationLanguage lang)

Returns the first locale found matching the given language, or NULL if a locale for the given language does not exist.

Must be free'd with g_free().

bool localization_init(bool use_locale, bool print_debug_messages)

Sets the locale to the currently selected one and inits gettext.

Parameters
use_locale Use the user's local instead of the Zrythm settings.
print_debug_messages

Returns if a locale for the selected language exists on the system or not.

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.

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.

void log_init_with_file(Log* self, bool use_file, int file)

Initializes logging to a file.

Parameters
self
use_file Whether to use the given file or not.
file

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.

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/

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.

void* stack_pop_last(Stack* s)

Pops the last element and moves everything back.

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, const bool accept_alternatives)

Returns if the given string contains the given substring.

Parameters
str
substr
accept_alternatives Accept ASCII alternatives.

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

Returns if the two strings are exactly equal.

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.

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

Gets the string in the given regex group.

Returns The 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.

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, bool get_stdout, char** output, 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
get_stdout Whether to get the standard out (true) or stderr (false).
output out A pointer to save the newly allocated stdout or stderr output.
warn_if_fail

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

Custom logging function for libcyaml.

Variable documentation

const typedef char*(* GenericStringGetter

Getter prototype for strings.

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)

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().

#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.

#define SERIALIZE_INC(camelcase, lowercase)

Serializes to XML.

MUST be free'd.