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),
313 Project,
314 tracklist,
315 tracklist_fields_schema),
317 Project,
318 clip_editor,
319 clip_editor_fields_schema),
321 Project,
322 timeline,
323 timeline_fields_schema),
325 Project,
326 snap_grid_timeline,
327 snap_grid_fields_schema),
329 Project,
330 snap_grid_editor,
331 snap_grid_fields_schema),
333 Project,
334 quantize_opts_timeline,
335 quantize_options_fields_schema),
337 Project,
338 quantize_opts_editor,
339 quantize_options_fields_schema),
341 Project,
342 audio_engine,
343 engine_fields_schema),
345 Project,
346 mixer_selections,
347 mixer_selections_fields_schema),
349 Project,
350 timeline_selections,
351 timeline_selections_fields_schema),
353 Project,
354 midi_arranger_selections,
355 midi_arranger_selections_fields_schema),
357 Project,
358 chord_selections,
359 chord_selections_fields_schema),
361 Project,
362 automation_selections,
363 automation_selections_fields_schema),
365 Project,
366 audio_selections,
367 audio_selections_fields_schema),
369 Project,
370 tracklist_selections,
371 tracklist_selections_fields_schema),
373 Project,
374 region_link_group_manager,
375 region_link_group_manager_fields_schema),
377 Project,
378 port_connections_manager,
379 port_connections_manager_fields_schema),
381 Project,
382 midi_mappings,
383 midi_mappings_fields_schema),
385 Project,
386 undo_manager,
387 undo_manager_fields_schema),
388 YAML_FIELD_ENUM (
389 Project,
390 last_selection,
391 selection_type_strings),
392
393 CYAML_FIELD_END
394};
395
396static const cyaml_schema_value_t project_schema = {
397 YAML_VALUE_PTR (Project, project_fields_schema),
398};
399
403typedef struct ProjectSaveData
404{
407
410
411 bool is_backup;
412
415
416 bool show_notification;
417
420
421 ProgressInfo * progress_info;
423
425project_save_data_new (void);
426
427void
428project_save_data_free (ProjectSaveData * self);
429
433void
435
439bool
441
443project_get_arranger_selections_for_last_selection (
444 Project * self);
445
459COLD WARN_UNUSED_RESULT Project *
461 Project * self,
462 const char * prj_dir,
463 bool headless,
464 bool with_engine,
465 GError ** error);
466
476WARN_UNUSED_RESULT COLD bool
478 const char * filename,
479 const bool is_template,
480 GError ** error);
481
495WARN_UNUSED_RESULT bool
497 Project * self,
498 const char * _dir,
499 const bool is_backup,
500 const bool show_notification,
501 const bool async,
502 GError ** error);
503
512int
514
522MALLOC
523NONNULL char *
524project_get_path (Project * self, ProjectPath path, bool backup);
525
532COLD void
534
551bool
553 bool compress,
554 char ** _dest,
555 size_t * _dest_size,
556 ProjectCompressionFlag dest_type,
557 const char * _src,
558 const size_t _src_size,
559 ProjectCompressionFlag src_type,
560 GError ** error);
561
562#define project_compress(a, b, c, d, e, f, error) \
563 _project_compress (true, a, b, c, d, e, f, error)
564
565#define project_decompress(a, b, c, d, e, f, error) \
566 _project_compress (false, a, b, c, d, e, f, error)
567
577char *
579 Project * self,
580 bool backup,
581 GError ** error);
582
591NONNULL Project *
593 const Project * src,
594 bool for_backup,
595 GError ** error);
596
600COLD Project *
602
606void
608
613#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.
COLD WARN_UNUSED_RESULT Project * project_create_default(Project *self, const char *prj_dir, bool headless, bool with_engine, GError **error)
Creates a default project.
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.
WARN_UNUSED_RESULT COLD bool project_load(const char *filename, const bool is_template, GError **error)
If project has a filename set, it loads that.
@ 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:39
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:221
#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:46
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:375
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:404
bool has_error
Whether an error occurred during saving.
Definition project.h:419
Project * project
Project clone (with memcpy).
Definition project.h:406
char * project_file_path
Full path to save to.
Definition project.h:409
bool finished
To be set to true when the thread finishes.
Definition project.h:414
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:68
The transport.
Definition transport.h:195
Undo manager.
Base struct to be inherited by implementing undoable actions.
To be used throughout the program.
Definition zrythm.h:190
Timeline backend.
Current TimelineArranger selections.
Undo manager.
The main Zrythm struct.