Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
13#ifndef __PROJECT_H__
14#define __PROJECT_H__
15
17#include "dsp/engine.h"
18#include "dsp/midi_mapping.h"
19#include "dsp/midi_note.h"
20#include "dsp/port.h"
23#include "dsp/region.h"
25#include "dsp/tracklist.h"
34#include "gui/backend/tool.h"
35#include "plugins/plugin.h"
36#include "zrythm.h"
37
38#include <gtk/gtk.h>
39
40#include <zix/sem.h>
41
42typedef struct Timeline Timeline;
43typedef struct Transport Transport;
44typedef struct Tracklist Tracklist;
46
53#define PROJECT_SCHEMA_VERSION 5
54
55#define PROJECT ZRYTHM->project
56#define DEFAULT_PROJECT_NAME "Untitled Project"
57#define PROJECT_FILE "project.zpj"
58#define PROJECT_BACKUPS_DIR "backups"
59#define PROJECT_PLUGINS_DIR "plugins"
60#define PROJECT_PLUGIN_STATES_DIR "states"
61#define PROJECT_PLUGIN_EXT_COPIES_DIR "ext_file_copies"
62#define PROJECT_PLUGIN_EXT_LINKS_DIR "ext_file_links"
63#define PROJECT_EXPORTS_DIR "exports"
64#define PROJECT_STEMS_DIR "stems"
65#define PROJECT_POOL_DIR "pool"
66#define PROJECT_FINISHED_FILE "FINISHED"
67
68typedef enum ProjectPath
69{
70 PROJECT_PATH_PROJECT_FILE,
71 PROJECT_PATH_BACKUPS,
72
75
78
82
86
87 PROJECT_PATH_EXPORTS,
88
89 /* PROJECT_PATH_EXPORTS / "stems". */
90 PROJECT_PATH_EXPORTS_STEMS,
91
92 PROJECT_PATH_POOL,
93
94 PROJECT_PATH_FINISHED_FILE,
96
125
126static const cyaml_strval_t selection_type_strings[] = {
127 {"Tracklist", SELECTION_TYPE_TRACKLIST },
128 { "Timeline", SELECTION_TYPE_TIMELINE },
129 { "Insert", SELECTION_TYPE_INSERT },
130 { "MIDI FX", SELECTION_TYPE_MIDI_FX },
131 { "Instrument", SELECTION_TYPE_INSTRUMENT},
132 { "Modulator", SELECTION_TYPE_MODULATOR },
133 { "Editor", SELECTION_TYPE_EDITOR },
134};
135
141{
142 PROJECT_COMPRESS_FILE,
143 PROJECT_COMPRESS_DATA,
145
146#define PROJECT_DECOMPRESS_FILE PROJECT_COMPRESS_FILE
147#define PROJECT_DECOMPRESS_DATA PROJECT_COMPRESS_DATA
148
306
307static const cyaml_schema_field_t project_fields_schema[] = {
308 YAML_FIELD_INT (Project, schema_version),
309 YAML_FIELD_STRING_PTR (Project, title),
310 YAML_FIELD_STRING_PTR (Project, datetime_str),
311 YAML_FIELD_STRING_PTR (Project, version),
312 YAML_FIELD_MAPPING_PTR (Project, tracklist, tracklist_fields_schema),
313 YAML_FIELD_MAPPING_PTR (Project, clip_editor, clip_editor_fields_schema),
314 YAML_FIELD_MAPPING_PTR (Project, timeline, timeline_fields_schema),
315 YAML_FIELD_MAPPING_PTR (Project, snap_grid_timeline, snap_grid_fields_schema),
316 YAML_FIELD_MAPPING_PTR (Project, snap_grid_editor, snap_grid_fields_schema),
318 Project,
319 quantize_opts_timeline,
320 quantize_options_fields_schema),
322 Project,
323 quantize_opts_editor,
324 quantize_options_fields_schema),
325 YAML_FIELD_MAPPING_PTR (Project, audio_engine, engine_fields_schema),
327 Project,
328 mixer_selections,
329 mixer_selections_fields_schema),
331 Project,
332 timeline_selections,
333 timeline_selections_fields_schema),
335 Project,
336 midi_arranger_selections,
337 midi_arranger_selections_fields_schema),
339 Project,
340 chord_selections,
341 chord_selections_fields_schema),
343 Project,
344 automation_selections,
345 automation_selections_fields_schema),
347 Project,
348 audio_selections,
349 audio_selections_fields_schema),
351 Project,
352 tracklist_selections,
353 tracklist_selections_fields_schema),
355 Project,
356 region_link_group_manager,
357 region_link_group_manager_fields_schema),
359 Project,
360 port_connections_manager,
361 port_connections_manager_fields_schema),
362 YAML_FIELD_MAPPING_PTR (Project, midi_mappings, midi_mappings_fields_schema),
364 Project,
365 undo_manager,
366 undo_manager_fields_schema),
367 YAML_FIELD_ENUM (Project, last_selection, selection_type_strings),
368
369 CYAML_FIELD_END
370};
371
372static const cyaml_schema_value_t project_schema = {
373 YAML_VALUE_PTR (Project, project_fields_schema),
374};
375
379typedef struct ProjectSaveData
380{
383
386
387 bool is_backup;
388
391
392 bool show_notification;
393
396
397 ProgressInfo * progress_info;
399
401project_save_data_new (void);
402
403void
404project_save_data_free (ProjectSaveData * self);
405
409void
411
415bool
417
419project_get_arranger_selections_for_last_selection (Project * self);
420
421void
422project_init_common (Project * self);
423
436WARN_UNUSED_RESULT bool
438 Project * self,
439 const char * _dir,
440 const bool is_backup,
441 const bool show_notification,
442 const bool async,
443 GError ** error);
444
453int
455
456bool
457project_make_project_dirs (Project * self, bool is_backup, GError ** error);
458
466MALLOC
467NONNULL char *
468project_get_path (Project * self, ProjectPath path, bool backup);
469
476COLD void
478
495bool
497 bool compress,
498 char ** _dest,
499 size_t * _dest_size,
500 ProjectCompressionFlag dest_type,
501 const char * _src,
502 const size_t _src_size,
503 ProjectCompressionFlag src_type,
504 GError ** error);
505
506#define project_compress(a, b, c, d, e, f, error) \
507 _project_compress (true, a, b, c, d, e, f, error)
508
509#define project_decompress(a, b, c, d, e, f, error) \
510 _project_compress (false, a, b, c, d, e, f, error)
511
521char *
522project_get_existing_yaml (Project * self, bool backup, GError ** error);
523
527NONNULL bool
528project_has_unsaved_changes (const Project * self);
529
538NONNULL Project *
539project_clone (const Project * src, bool for_backup, GError ** error);
540
544COLD Project *
546
550void
552
557#endif
API for selections in the AudioArrangerWidget.
API for selections in the AutomationArrangerWidget.
The clip/region editor backend.
API for selections in the piano roll.
API for MIDI notes in the PianoRoll.
A region in the timeline.
Tracklist backend.
The audio engine.
Zrythm * zrythm
Global variable, should be available to all files.
bool project_fix_audio_regions(Project *self)
void project_free(Project *self)
Tears down the project.
NONNULL Project * project_clone(const Project *src, bool for_backup, GError **error)
Deep-clones the given project.
void project_validate(Project *self)
Checks that everything is okay with the project.
int project_autosave_cb(void *data)
Autosave callback.
bool _project_compress(bool compress, char **_dest, size_t *_dest_size, ProjectCompressionFlag dest_type, const char *_src, const size_t _src_size, ProjectCompressionFlag src_type, GError **error)
Compresses/decompress a project from a file/data to a file/data.
ProjectPath
Definition project.h:69
WARN_UNUSED_RESULT bool project_save(Project *self, const char *_dir, const bool is_backup, const bool show_notification, const bool async, GError **error)
Saves the project to a project file in the given dir.
char * project_get_existing_yaml(Project *self, bool backup, GError **error)
Returns the YAML representation of the saved project file.
COLD Project * project_new(Zrythm *zrythm)
Creates an empty project object.
COLD void project_init_selections(Project *self)
Initializes the selections in the project.
ProjectCompressionFlag
Flag to pass to project_compress() and project_decompress().
Definition project.h:141
SelectionType
Selection type, used for controlling which part of the interface is selected, for copy-paste,...
Definition project.h:103
MALLOC NONNULL char * project_get_path(Project *self, ProjectPath path, bool backup)
Returns the requested project path as a newly allocated string.
@ PROJECT_PATH_PLUGINS
Plugins path.
Definition project.h:74
@ PROJECT_PATH_PLUGIN_EXT_COPIES
External files for plugin states, under the STATES dir.
Definition project.h:81
@ PROJECT_PATH_PLUGIN_STATES
Path for state .ttl files.
Definition project.h:77
@ PROJECT_PATH_PLUGIN_EXT_LINKS
External files for plugin states, under the STATES dir.
Definition project.h:85
@ SELECTION_TYPE_INSERT
Insert selections in the mixer.
Definition project.h:111
@ SELECTION_TYPE_TRACKLIST
Track selection in tracklist or mixer.
Definition project.h:105
@ SELECTION_TYPE_MIDI_FX
MIDI FX selections in the mixer.
Definition project.h:114
@ SELECTION_TYPE_EDITOR
Editor arranger.
Definition project.h:123
@ SELECTION_TYPE_MODULATOR
Modulator slot.
Definition project.h:120
@ SELECTION_TYPE_TIMELINE
Timeline or pinned timeline.
Definition project.h:108
@ SELECTION_TYPE_INSTRUMENT
Instrument slot.
Definition project.h:117
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:37
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:202
#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:43
API for selections in the piano roll.
Mapping MIDI CC to controls.
Mixer selections.
Base plugin.
Ports that transfer audio/midi/other signals to one another.
Port connections manager.
Quantize options.
The audio engine.
Definition engine.h:363
Selections to be used for the AudioArrangerWidget's current selections, copying, undoing,...
Selections to be used for the AutomationArrangerWidget's current selections, copying,...
Selections to be used for the ChordArrangerWidget's current selections, copying, undoing,...
Clip editor serializable backend.
Definition clip_editor.h:41
A collection of selected MidiNote's.
All MIDI mappings in Zrythm.
Selections to be used for the timeline's current selections, copying, undoing, etc.
Port connections manager.
Project save data.
Definition project.h:380
bool has_error
Whether an error occurred during saving.
Definition project.h:395
Project * project
Project clone (with memcpy).
Definition project.h:382
char * project_file_path
Full path to save to.
Definition project.h:385
bool finished
To be set to true when the thread finishes.
Definition project.h:390
Contains all of the info that will be serialized into a project file.
Definition project.h:157
ChordSelections * chord_selections
Selected objects in the ChordObjectArrangerWidget.
Definition project.h:215
TimelineSelections * timeline_selections
Selected objects in the TimelineArrangerWidget.
Definition project.h:220
Timeline * timeline
Timeline widget backend.
Definition project.h:186
Tool tool
Currently selected tool (select - normal, select - stretch, edit, delete, ramp, audition)
Definition project.h:258
ZixSem save_sem
Semaphore used to block saving.
Definition project.h:290
char * dir
Path to save the project in.
Definition project.h:167
bool loaded
If a project is currently loaded or not.
Definition project.h:277
QuantizeOptions * quantize_opts_editor
Quantize info for the piano roll.
Definition project.h:198
SelectionType last_selection
The last thing selected in the GUI.
Definition project.h:284
SnapGrid * snap_grid_editor
Snap/Grid info for the editor.
Definition project.h:192
MidiArrangerSelections * midi_arranger_selections
Selected MidiNote's in the MidiArrangerWidget.
Definition project.h:225
UndoableAction * last_saved_action
Used to check if the project has unsaved changes.
Definition project.h:294
QuantizeOptions * quantize_opts_timeline
Quantize info for the timeline.
Definition project.h:195
SnapGrid * snap_grid_timeline
Snap/Grid info for the timeline.
Definition project.h:189
double timeline_zoom
Zoom levels.
Definition project.h:238
AudioEngine * audio_engine
The audio backend.
Definition project.h:249
AutomationSelections * automation_selections
Selected objects in the AutomationArrangerWidget.
Definition project.h:204
char * backup_dir
Backup dir to save the project during the current save call.
Definition project.h:176
MixerSelections * mixer_selections
Plugin selections in the Mixer.
Definition project.h:235
bool loading_from_backup
Whether the current is currently being loaded from a backup file.
Definition project.h:268
gint64 last_successful_autosave_time
Last successful autosave timestamp.
Definition project.h:297
RegionLinkGroupManager * region_link_group_manager
Manager for region link groups.
Definition project.h:242
UndoableAction * last_action_in_last_successful_autosave
Last undoable action in the previous successful autosave.
Definition project.h:304
char * title
Project title.
Definition project.h:161
char * datetime_str
Datetime string to add to the project file.
Definition project.h:164
ClipEditor * clip_editor
Backend for the widget.
Definition project.h:183
TracklistSelections * tracklist_selections
Selected Track's.
Definition project.h:230
AudioSelections * audio_selections
Selected objects in the audio editor.
Definition project.h:209
char * version
Zrythm version, for serialization.
Definition project.h:287
MidiMappings * midi_mappings
MIDI bindings.
Definition project.h:252
Manager of region link groups.
Selections to be used for the timeline's current selections, copying, undoing, etc.
Clip editor serializable backend.
Definition timeline.h:33
Selections to be used for the tracklist's current selections, copying, undoing, etc.
The Tracklist contains all the tracks in the Project.
Definition tracklist.h:63
The transport.
Definition transport.h:192
Undo manager.
Base struct to be inherited by implementing undoable actions.
To be used throughout the program.
Definition zrythm.h:188
Timeline backend.
Current TimelineArranger selections.
Undo manager.
The main Zrythm struct.