1 /*
2  * Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
3  *
4  * This file is part of Zrythm
5  *
6  * Zrythm is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Zrythm is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "audio/channel.h"
21 #include "audio/region.h"
22 #include "audio/track.h"
23 #include "gui/widgets/arranger.h"
24 #include "gui/widgets/audio_editor_space.h"
25 #include "gui/widgets/bot_dock_edge.h"
26 #include "gui/widgets/center_dock.h"
27 #include "gui/widgets/clip_editor.h"
28 #include "gui/widgets/clip_editor_inner.h"
29 #include "gui/widgets/color_area.h"
30 #include "gui/widgets/main_window.h"
31 #include "gui/widgets/audio_arranger.h"
32 #include "gui/widgets/editor_ruler.h"
33 #include "gui/widgets/ruler.h"
34 #include "project.h"
35 #include "utils/gtk.h"
36 #include "utils/resources.h"
audio_arranger_widget_snap_range_r(ArrangerWidget * self,Position * pos)37 #include "zrythm_app.h"
38 
39 #include <glib/gi18n.h>
40 
41 G_DEFINE_TYPE (
42   AudioEditorSpaceWidget,
43   audio_editor_space_widget,
44   GTK_TYPE_BOX)
45 
46 /**
47  * Links scroll windows after all widgets have been
48  * initialized.
49  */
50 static void
51 link_scrolls (
52   AudioEditorSpaceWidget * self)
53 {
54   /* link ruler h scroll to arranger h scroll */
55   if (MW_CLIP_EDITOR_INNER->ruler_scroll)
56     {
57       g_return_if_fail (
58         GTK_IS_WIDGET (
59           MW_CLIP_EDITOR_INNER->ruler_scroll));
60       gtk_scrolled_window_set_hadjustment (
61         MW_CLIP_EDITOR_INNER->ruler_scroll,
62         gtk_scrolled_window_get_hadjustment (
63           GTK_SCROLLED_WINDOW (
64             self->arranger_scroll)));
65     }
66 }
67 
68 /**
69  * See CLIP_EDITOR_INNER_WIDGET_ADD_TO_SIZEGROUP.
70  */
71 void
72 audio_editor_space_widget_update_size_group (
73   AudioEditorSpaceWidget * self,
74   int                     visible)
75 {
76   clip_editor_inner_widget_add_to_left_of_ruler_sizegroup (
77     MW_CLIP_EDITOR_INNER,
78     GTK_WIDGET (self->left_box),
79     visible);
80 }
81 
82 void
83 audio_editor_space_widget_refresh (
84   AudioEditorSpaceWidget * self)
audio_arranger_widget_is_cursor_in_fade(ArrangerWidget * self,double x,double y,bool fade_in,bool resize)85 {
86   link_scrolls (self);
87 }
88 
89 void
90 audio_editor_space_widget_setup (
91   AudioEditorSpaceWidget * self)
92 {
93   if (self->arranger)
94     {
95       arranger_widget_setup (
96         Z_ARRANGER_WIDGET (self->arranger),
97         ARRANGER_WIDGET_TYPE_AUDIO,
98         SNAP_GRID_EDITOR);
99       gtk_widget_show_all (
100         GTK_WIDGET (self->arranger));
101     }
102 
103   audio_editor_space_widget_refresh (self);
104 }
105 
106 static void
107 audio_editor_space_widget_init (
108   AudioEditorSpaceWidget * self)
109 {
110   gtk_widget_init_template (GTK_WIDGET (self));
111 
112   self->arranger->type =
113     ARRANGER_WIDGET_TYPE_AUDIO;
114 }
115 
116 static void
117 audio_editor_space_widget_class_init (
118   AudioEditorSpaceWidgetClass * _klass)
119 {
120   GtkWidgetClass * klass = GTK_WIDGET_CLASS (_klass);
121   resources_set_class_template (
122     klass,
123     "audio_editor_space.ui");
124 
125 #define BIND_CHILD(x) \
126   gtk_widget_class_bind_template_child ( \
127     klass, AudioEditorSpaceWidget, x)
128 
129   BIND_CHILD (arranger_scroll);
130   BIND_CHILD (left_box);
131   BIND_CHILD (arranger_viewport);
132   BIND_CHILD (arranger);
133 }
134