Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm_app.h
1// SPDX-FileCopyrightText: © 2019-2024 Alexandros Theodotou <alex@zrythm.org>
2/* SPDX-License-Identifier: LicenseRef-ZrythmLicense */
3
4#ifndef __ZRYTHM_APP_H__
5#define __ZRYTHM_APP_H__
6
7#include "zrythm-config.h"
8
9#include <utility>
10
11#include "common/utils/types.h"
12#include "common/utils/ui.h"
14#include "gui/backend/gtk_widgets/gtk_wrapper.h"
15#include "gui/backend/gtk_widgets/libadwaita_wrapper.h"
16
17#define ZRYTHM_APP_IS_GTK_THREAD \
18 (zrythm_app && zrythm_app->gtk_thread_id_ == current_thread_id.get ())
19
20TYPEDEF_STRUCT_UNDERSCORED (MainWindowWidget);
21TYPEDEF_STRUCT_UNDERSCORED (BugReportDialogWidget);
22TYPEDEF_STRUCT_UNDERSCORED (GreeterWidget);
24
30
34struct ZrythmAppUiMessage
35{
36 ZrythmAppUiMessage (GtkMessageType type, std::string msg)
37 : type_ (type), msg_ (std::move (msg))
38 {
39 }
40 GtkMessageType type_;
41 std::string msg_;
42};
43
49class ZrythmApp final : public Gtk::Application
50{
51public:
60 ZrythmApp (int argc, const char ** argv);
61
62 void set_font_scale (double font_scale);
63
68
76
83
89
94 const std::string &primary,
95 const std::string &secondary,
96 const std::string &action_name);
97
101 std::string get_primary_accel_for_action (const std::string &action_name);
102
106 static void exit_response_callback (AdwDialog * dialog, gpointer user_data);
107
108 void on_plugin_scan_finished ();
109
110protected:
116 void on_startup () override;
117
118 /*
119 * Called after startup if no filename is passed on command line.
120 */
121 void on_activate () override;
122
128 void on_open (
129 const Gio::Application::type_vec_files &files,
130 const Glib::ustring &hint) override;
131
138 void on_shutdown () override;
139
140private:
150 void add_option_entries ();
151
152 int
153 on_handle_local_options (const Glib::RefPtr<Glib::VariantDict> &opts) override;
154
155 void lock_memory ();
156
157 void print_settings ();
158 void reset_to_factory ();
159
166 void on_setup_main_window ();
167
174 void on_prompt_for_project ();
175
181 void on_load_project ();
182
183public:
187 Glib::RefPtr<Gtk::Settings> default_settings_;
188
191
197 // GThread * gtk_thread;
198 unsigned int gtk_thread_id_ = std::numeric_limits<unsigned int>::max ();
199
200 std::unique_ptr<UiCaches> ui_caches_;
201
203 bool init_finished_ = false;
204
207
213 bool is_first_run_ = false;
214
215 bool have_svg_loader_ = false;
216
219 std::string audio_backend_;
220
223 std::string midi_backend_;
224
226 int buf_size_ = 0;
227
229 int samplerate_ = 0;
230
232 std::queue<std::string> startup_error_queue_;
233 std::mutex startup_error_queue_mutex_;
234
236 std::string output_file_;
237
239 bool pretty_print_ = false;
240
242 int argc_ = 0;
243 char ** argv_ = nullptr;
244
247
250
254 std::queue<ZrythmAppUiMessage> project_load_message_queue_;
255 std::mutex queue_mutex_;
256
258 BugReportDialogWidget * bug_report_dialog_ = nullptr;
259
260 std::unique_ptr<ProjectInitFlowManager> project_init_flow_mgr_;
261
262 guint project_autosave_source_id_ = 0;
263};
264
268extern Glib::RefPtr<ZrythmApp> zrythm_app;
269
273
274#endif /* __ZRYTHM_APP_H__ */
This can just be created on the stack as needed since it uses globally available information.
static void exit_response_callback(AdwDialog *dialog, gpointer user_data)
To be used to exit Zrythm using the "response" signal on a message dialog.
std::string appimage_runtime_path_
AppImage runtime path, if AppImage build.
Definition zrythm_app.h:246
void check_for_updates()
Handles the logic for checking for updates on startup.
MainWindowWidget * main_window_
Main window.
Definition zrythm_app.h:190
bool rt_priority_message_shown_
Flag used to only show the RT priority message once.
Definition zrythm_app.h:249
std::queue< std::string > startup_error_queue_
Messages to show when the main window is shown.
Definition zrythm_app.h:232
int samplerate_
Samplerate passed with –samplerate=, if any.
Definition zrythm_app.h:229
bool is_first_run_
True if this is the first time Zrythm is runh.
Definition zrythm_app.h:213
void on_open(const Gio::Application::type_vec_files &files, const Glib::ustring &hint) override
Called when a filename is passed to the command line instead of activate.
std::string output_file_
Output file passed with –output.
Definition zrythm_app.h:236
std::string midi_backend_
MIDI backend passed with –audio-backend=, if any.
Definition zrythm_app.h:223
std::string get_primary_accel_for_action(const std::string &action_name)
Get the primary accelerator for an action.
void init_recent_projects()
Initializes the array of recent projects in Zrythm app.
unsigned int gtk_thread_id_
The GTK thread where the main GUI loop runs.
Definition zrythm_app.h:198
void on_startup() override
First function that gets called afted CLI args are parsed and processed.
void install_action_accel(const std::string &primary, const std::string &secondary, const std::string &action_name)
Install accelerator for an action.
int argc_
CLI args.
Definition zrythm_app.h:242
int prompt_for_project_func()
Unlike the init thread, this will run in the main GTK thread.
Glib::RefPtr< Gtk::Settings > default_settings_
Default settings (got from gtk_settings_get_default()).
Definition zrythm_app.h:187
ZrythmApp(int argc, const char **argv)
Creates the application.
bool init_finished_
Flag to set when initialization has finished.
Definition zrythm_app.h:203
bool pretty_print_
Whether to pretty-print.
Definition zrythm_app.h:239
std::queue< ZrythmAppUiMessage > project_load_message_queue_
Queue for messages to be shown when the project loads.
Definition zrythm_app.h:254
int buf_size_
Buffer size passed with –buf-size=, if any.
Definition zrythm_app.h:226
void on_shutdown() override
Called immediately after the main GTK loop terminates.
bool check_and_show_trial_limit_error()
Shows the trial limitation error message.
std::string audio_backend_
Audio backend passed with –audio-backend=, if any.
Definition zrythm_app.h:219
GreeterWidget * greeter_
Greeter screen.
Definition zrythm_app.h:206
BugReportDialogWidget * bug_report_dialog_
Currently opened bug report dialog.
Definition zrythm_app.h:258
Glib::RefPtr< ZrythmApp > zrythm_app
Global variable, should be available to all files.
struct _GreeterWidget { AdwWindow parent_instance; GtkStack *stack; AdwCarousel * welcome_carousel; guint welcome_carousel_page_idx; GtkButton * welcome_carousel_prev_btn; GtkButton * welcome_carousel_next_btn; GtkButton * continue_to_config_btn; AdwStatusPage *read_manual_status_page; AdwStatusPage *donate_status_page; AdwStatusPage *about_flatpak_status_page; AdwNavigationView *nav_view; AdwNavigationPage *nav_config_page; AdwPreferencesPage * pref_page; AdwComboRow * language_dropdown; GtkLabel * lang_error_txt; IdeFileChooserEntry *fc_entry; GtkButton * config_ok_btn; GtkButton * config_reset_btn; AdwStatusPage *status_page; GtkProgressBar *progress_bar; std::binary_semaphore progress_status_lock; double progress; std::string title; std::string description; AdwNavigationView *open_prj_navigation_view; AdwPreferencesGroup * recent_projects_pref_group; std::vector< std::unique_ptr< ProjectInfo > > project_infos_arr; ItemFactoryPtrVector recent_projects_item_factories; GtkButton * create_new_project_btn; GtkButton * select_folder_btn; AdwNavigationPage * create_project_nav_page; AdwEntryRow * project_title_row; AdwActionRow * project_parent_dir_row; IdeFileChooserEntry * project_parent_dir_fc; AdwComboRow * templates_combo_row; CcListRowInfoButton * templates_info_button; std::vector< std::unique_ptr< ProjectInfo > > templates_arr; ItemFactoryPtrVector templates_item_factories; AdwPreferencesGroup * templates_pref_group; GtkButton * create_project_confirm_btn; char *template_; bool zrythm_already_running; guint tick_cb_id; std::unique_ptr< juce::Thread > init_thread;} GreeterWidget
This widget handles the UI part of the initialization of Zrythm and presents a project selector when ...
Definition greeter.h:34
struct _MainWindowWidget { AdwApplicationWindow parent_instance; PanelToggleButton *start_dock_switcher; AdwWindowTitle * window_title; PanelToggleButton *end_dock_switcher; ToolboxWidget *toolbox; AdwSplitButton *undo_btn; AdwSplitButton *redo_btn; GtkBox * header_start_box; GtkBox * header_end_box; GtkButton *z_icon; GtkBox * center_box; CenterDockWidget *center_dock; BotBarWidget * bot_bar; int is_fullscreen; int height; int width; AdwToastOverlay * toast_overlay; bool preferences_opened; bool log_has_pending_warnings; bool setup;} MainWindowWidget
The main window of Zrythm.
Definition main_window.h:44