Utils module

Files

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

Classes

struct CairoCaches
Caches for cairo.
struct MPMCQueue
Multiple Producer Multiple Consumer lock-free queue.

Enums

enum ZGtkFill { Z_GTK_NO_FILL, Z_GTK_FILL }
For readability, instead of using 0s and 1s.

Typedefs

using CairoCaches = struct CairoCaches
Caches for cairo.
using MPMCQueue = struct MPMCQueue
Multiple Producer Multiple Consumer lock-free queue.
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.

Functions

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.
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(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_default_pango_layout(GtkWidget* widget) -> PangoLayout*
Creates a PangoLayout with default settings.
auto datetime_get_current_as_string(void) -> char*
Returns the current datetime as a string.
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.
void z_gtk_container_remove_all_children(GtkContainer* container)
NOTE: bumps reference, must be decremented after calling.
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_create_menu_item(const gchar* label_name, const gchar* icon_name, IconType resource_icon_type, const gchar* resource, int is_toggle, const char* action_name) -> GtkMenuItem*
TODO add description.
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_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_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_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.
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.
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_get_home_dir(void) -> const char*
Gets home dir.
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) -> char*
Returns file extension or NULL.
auto io_path_get_basename(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.
auto localization_get_string_code(UiLanguage lang) -> char*
Returns the character string code for the language (e.g.
auto localization_locale_exists(UiLanguage 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(void) -> int
Sets the locale to the currently selected one and inits gettext.
void _free_later(void* object, void(*)(void*) dfunc)
Frees the object after a while.
void object_utils_init(void)
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_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 int accept_alternatives) -> int
Returns if the given string contains the given substring.
auto string_is_equal(const char* str1, const char* str2, int ignore_case) -> int
Returns if the two strings are equal.
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_backup_ext(const char* str) -> char*
Removes any bak, bak1 etc suffixes from the string and returns a newly allocated string.

Variables

Dictionary* icon_surface_dict
Icon surface dictionary: icon name: cairo_surface_t.

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 io_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 SERIALIZE_INC(camelcase, lowercase)
Serializes to XML.

Typedef documentation

typedef struct MPMCQueue MPMCQueue

Multiple Producer Multiple Consumer lock-free queue.

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

Function documentation

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.

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

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.

Assumes that the layout is already set on the widget.

char* datetime_get_current_as_string(void)

Returns the current datetime as a string.

Must be free()'d by caller.

char* env_get_string(const char* key, const char* def)

Returns a newly allocated string.

Parameters
key
def Default value to return if not found.

int env_get_int(const char* key, int def)

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.

GtkLabel* z_gtk_get_label_from_menu_item(GtkMenuItem* mi)

Returns the label from a given GtkMenuItem.

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

static void z_gtk_widget_get_mask(GtkWidget* widget, GdkModifierType* mask)

Sets the GdkModifierType given for the widget.

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

void z_gtk_setup_foldable_notebook(GtkNotebook* notebook)

Makes the given notebook foldable.

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

char* io_get_dir(const char* filename)

Gets directory part of filename.

Parameters
filename Filename containing directory.

MUST be freed.

MUST be freed.

const char* io_get_home_dir(void)

Gets home dir.

MUST be freed.

char* io_file_strip_ext(const char* filename)

Strips extensions from given filename.

MUST be freed.

char* io_path_get_basename(const char* filename)

Strips path from given filename.

MUST be freed.

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

char* localization_get_string_code(UiLanguage lang)

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

"fr").

char* localization_locale_exists(UiLanguage 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().

int localization_init(void)

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

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

void _free_later(void* object, void(*)(void*) dfunc)

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/

int string_contains_substr(const char* str, const char* substr, const int accept_alternatives)

Returns if the given string contains the given substring.

Parameters
str
substr
accept_alternatives Accept ASCII alternatives.

char* string_convert_to_filename(const char* str)

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

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

Define documentation

#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 SERIALIZE_INC(camelcase, lowercase)

Serializes to XML.

MUST be free'd.