remember tracklist width per project

This changes the project format from 1.7 to 1.8.

Implements #4091.
This commit is contained in:
Alexandros Theodotou 2023-12-24 15:19:36 +09:00
parent f1cdf686f0
commit 923a984467
No known key found for this signature in database
GPG Key ID: 022EAE42313D70F3
8 changed files with 32 additions and 23 deletions

View File

@ -118,6 +118,9 @@ typedef struct Tracklist
/** Pointer to owner project, if any. */
Project * project;
/** Width of track widgets. */
int width;
} Tracklist;
/**

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: © 2020 Alexandros Theodotou <alex@zrythm.org>
// SPDX-FileCopyrightText: © 2020, 2023 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
@ -11,7 +11,6 @@
#define __GUI_BACKEND_TIMELINE_H__
#include "gui/backend/editor_settings.h"
#include "utils/yaml.h"
/**
* @addtogroup gui_backend
@ -19,8 +18,6 @@
* @{
*/
#define TIMELINE_SCHEMA_VERSION 1
#define PRJ_TIMELINE (PROJECT->timeline)
/**
@ -31,26 +28,13 @@
*/
typedef struct Timeline
{
int schema_version;
/** Settings for the timeline. */
EditorSettings editor_settings;
/** Width of the left side of the timeline panel. */
int tracks_width;
} Timeline;
static const cyaml_schema_field_t timeline_fields_schema[] = {
YAML_FIELD_INT (Timeline, schema_version),
YAML_FIELD_MAPPING_EMBEDDED (
Timeline,
editor_settings,
editor_settings_fields_schema),
CYAML_FIELD_END
};
static const cyaml_schema_value_t timeline_schema = {
CYAML_VALUE_MAPPING (CYAML_FLAG_POINTER, Timeline, timeline_fields_schema),
};
/**
* Inits the Timeline after a Project is loaded.
*/

View File

@ -51,7 +51,7 @@ typedef struct TracklistSelections TracklistSelections;
*/
#define PROJECT_FORMAT_MAJOR 1
#define PROJECT_FORMAT_MINOR 7
#define PROJECT_FORMAT_MINOR 8
#define PROJECT ZRYTHM->project
#define DEFAULT_PROJECT_NAME "Untitled Project"

View File

@ -29,6 +29,7 @@
<object class="GtkBox" id="timelines_plus_ruler">
<property name="name">timelines-plus-ruler-box</property>
<property name="orientation">vertical</property>
<property name="width-request">64</property>
<child>
<object class="RulerWidget" id="ruler">
</object>

View File

@ -1030,6 +1030,8 @@ event_manager_process_event (EventManager * self, ZEvent * ev)
MW_RULER, ruler_widget_get_zoom_level (MW_RULER));
ruler_widget_set_zoom_level (
EDITOR_RULER, ruler_widget_get_zoom_level (EDITOR_RULER));
gtk_paned_set_position (
MW_TIMELINE_PANEL->tracklist_timeline, PRJ_TIMELINE->tracks_width);
break;
case ET_AUTOMATION_TRACKLIST_AT_REMOVED:
/* TODO */

View File

@ -25,9 +25,9 @@ Timeline *
timeline_clone (Timeline * src)
{
Timeline * self = object_new (Timeline);
self->schema_version = TIMELINE_SCHEMA_VERSION;
self->editor_settings = src->editor_settings;
self->tracks_width = src->tracks_width;
return self;
}
@ -39,7 +39,6 @@ Timeline *
timeline_new (void)
{
Timeline * self = object_new (Timeline);
self->schema_version = TIMELINE_SCHEMA_VERSION;
return self;
}

View File

@ -26,6 +26,16 @@
G_DEFINE_TYPE (TimelinePanelWidget, timeline_panel_widget, GTK_TYPE_BOX)
static void
on_vertical_divider_position_change (
GObject * gobject,
GParamSpec * pspec,
gpointer user_data)
{
GtkPaned * paned = GTK_PANED (gobject);
PRJ_TIMELINE->tracks_width = gtk_paned_get_position (paned);
}
void
timeline_panel_widget_setup (TimelinePanelWidget * self)
{
@ -118,6 +128,10 @@ timeline_panel_widget_init (TimelinePanelWidget * self)
GTK_WIDGET (self->timeline_divider_box), "timeline-divider-box");
gtk_widget_set_focus_on_click (GTK_WIDGET (self), false);
g_signal_connect (
G_OBJECT (self->tracklist_timeline), "notify::position",
G_CALLBACK (on_vertical_divider_position_change), NULL);
}
static void

View File

@ -146,6 +146,7 @@ timeline_serialize_to_json (
yyjson_mut_obj_add_obj (doc, t_obj, "editorSettings");
editor_settings_serialize_to_json (
doc, editor_settings_obj, &t->editor_settings, error);
yyjson_mut_obj_add_int (doc, t_obj, "tracksWidth", t->tracks_width);
return true;
}
@ -318,6 +319,11 @@ timeline_deserialize_from_json (
yyjson_val * editor_settings_obj = yyjson_obj_iter_get (&it, "editorSettings");
editor_settings_deserialize_from_json (
doc, editor_settings_obj, &t->editor_settings, error);
yyjson_val * tracks_width_obj = yyjson_obj_iter_get (&it, "tracksWidth");
if (tracks_width_obj) /* available after 1.8 */
{
t->tracks_width = yyjson_get_int (tracks_width_obj);
}
return true;
}