1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2020 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU 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  * GSequencer 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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __AGS_AUTOMATION_H__
21 #define __AGS_AUTOMATION_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 #include <libxml/tree.h>
27 
28 #include <ags/libags.h>
29 
30 #include <ags/audio/ags_acceleration.h>
31 
32 G_BEGIN_DECLS
33 
34 #define AGS_TYPE_AUTOMATION                (ags_automation_get_type())
35 #define AGS_AUTOMATION(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_AUTOMATION, AgsAutomation))
36 #define AGS_AUTOMATION_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_AUTOMATION, AgsAutomationClass))
37 #define AGS_IS_AUTOMATION(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_AUTOMATION))
38 #define AGS_IS_AUTOMATION_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_AUTOMATION))
39 #define AGS_AUTOMATION_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS (obj, AGS_TYPE_AUTOMATION, AgsAutomationClass))
40 
41 #define AGS_AUTOMATION_GET_OBJ_MUTEX(obj) (&(((AgsAutomation *) obj)->obj_mutex))
42 
43 #define AGS_AUTOMATION_DEFAULT_BPM (120.0)
44 
45 #define AGS_AUTOMATION_TICS_PER_BEAT (1.0)
46 #define AGS_AUTOMATION_MINIMUM_ACCELERATION_LENGTH (1.0 / 16.0 / 64.0)
47 #define AGS_AUTOMATION_MAXIMUM_ACCELERATION_LENGTH (16.0)
48 
49 #define AGS_AUTOMATION_DEFAULT_LENGTH (64 * 16 * 1200 / AGS_AUTOMATION_TICS_PER_BEAT)
50 #define AGS_AUTOMATION_DEFAULT_JIFFIE (60.0 / AGS_AUTOMATION_DEFAULT_BPM / AGS_AUTOMATION_TICS_PER_BEAT)
51 #define AGS_AUTOMATION_DEFAULT_DURATION (AGS_AUTOMATION_DEFAULT_LENGTH * AGS_AUTOMATION_DEFAULT_JIFFIE * AGS_USEC_PER_SEC)
52 #define AGS_AUTOMATION_DEFAULT_OFFSET (64 * (1 / AGS_AUTOMATION_MINIMUM_ACCELERATION_LENGTH))
53 
54 #define AGS_AUTOMATION_DEFAULT_PRECISION (8)
55 #define AGS_AUTOMATION_MAXIMUM_STEPS (128)
56 
57 #define AGS_AUTOMATION_CLIPBOARD_VERSION "1.3.0"
58 #define AGS_AUTOMATION_CLIPBOARD_TYPE "AgsAutomationClipboardXml"
59 #define AGS_AUTOMATION_CLIPBOARD_FORMAT "AgsAutomationNativeScale"
60 #define AGS_AUTOMATION_CLIPBOARD_LEGACY_FORMAT "AgsAutomationNativePiano"
61 
62 typedef struct _AgsAutomation AgsAutomation;
63 typedef struct _AgsAutomationClass AgsAutomationClass;
64 
65 /**
66  * AgsAutomationFlags:
67  * @AGS_AUTOMATION_BYPASS: ignore any automation data
68  *
69  * Enum values to control the behavior or indicate internal state of #AgsAutomation by
70  * enable/disable as flags.
71  */
72 typedef enum{
73   AGS_AUTOMATION_BYPASS               = 1,
74 }AgsAutomationFlags;
75 
76 struct _AgsAutomation
77 {
78   GObject gobject;
79 
80   guint flags;
81 
82   GRecMutex obj_mutex;
83 
84   GObject *audio;
85   GType channel_type;
86   guint line;
87 
88   AgsTimestamp *timestamp;
89 
90   gchar *control_name;
91 
92   guint steps;
93   gdouble upper;
94   gdouble lower;
95   gdouble default_value;
96 
97   AgsFunction *source_function;
98 
99   GObject *port;
100 
101   GList *acceleration;
102   GList *selection;
103 };
104 
105 struct _AgsAutomationClass
106 {
107   GObjectClass gobject;
108 };
109 
110 GType ags_automation_get_type(void);
111 GType ags_automation_flags_get_type(void);
112 
113 GRecMutex* ags_automation_get_obj_mutex(AgsAutomation *automation);
114 
115 gboolean ags_automation_test_flags(AgsAutomation *automation, guint flags);
116 void ags_automation_set_flags(AgsAutomation *automation, guint flags);
117 void ags_automation_unset_flags(AgsAutomation *automation, guint flags);
118 
119 GList* ags_automation_find_port(GList *automation,
120 				GObject *port);
121 
122 GList* ags_automation_find_near_timestamp(GList *automation, guint line,
123 					  AgsTimestamp *timestamp);
124 GList* ags_automation_find_near_timestamp_extended(GList *automation, guint line,
125 						   GType channel_type, gchar *control_name,
126 						   AgsTimestamp *timestamp);
127 
128 gint ags_automation_sort_func(gconstpointer a,
129 			      gconstpointer b);
130 
131 GList* ags_automation_add(GList *automation,
132 			  AgsAutomation *new_automation);
133 
134 GObject* ags_automation_get_audio(AgsAutomation *automation);
135 void ags_automation_set_audio(AgsAutomation *automation,
136 			      GObject *audio);
137 
138 GType ags_automation_get_channel_type(AgsAutomation *automation);
139 void ags_automation_set_channel_type(AgsAutomation *automation,
140 				     GType channel_type);
141 
142 guint ags_automation_get_line(AgsAutomation *automation);
143 void ags_automation_set_line(AgsAutomation *automation,
144 			     guint line);
145 
146 AgsTimestamp* ags_automation_get_timestamp(AgsAutomation *automation);
147 void ags_automation_set_timestamp(AgsAutomation *automation,
148 				  AgsTimestamp *timestamp);
149 
150 gchar* ags_automation_get_control_name(AgsAutomation *automation);
151 void ags_automation_set_control_name(AgsAutomation *automation,
152 				     gchar *control_name);
153 
154 guint ags_automation_get_steps(AgsAutomation *automation);
155 void ags_automation_set_steps(AgsAutomation *automation,
156 			      guint steps);
157 
158 gdouble ags_automation_get_upper(AgsAutomation *automation);
159 void ags_automation_set_upper(AgsAutomation *automation,
160 			      gdouble upper);
161 
162 gdouble ags_automation_get_lower(AgsAutomation *automation);
163 void ags_automation_set_lower(AgsAutomation *automation,
164 			      gdouble lower);
165 
166 gdouble ags_automation_get_default_value(AgsAutomation *automation);
167 void ags_automation_set_default_value(AgsAutomation *automation,
168 				      gdouble default_value);
169 
170 GObject* ags_automation_get_port(AgsAutomation *automation);
171 void ags_automation_set_port(AgsAutomation *automation,
172 			     GObject *port);
173 
174 GList* ags_automation_get_acceleration(AgsAutomation *automation);
175 void ags_automation_set_acceleration(AgsAutomation *automation,
176 				     GList *acceleration);
177 
178 void ags_automation_add_acceleration(AgsAutomation *automation,
179 				     AgsAcceleration *acceleration,
180 				     gboolean use_selection_list);
181 void ags_automation_remove_acceleration(AgsAutomation *automation,
182 					AgsAcceleration *acceleration,
183 					gboolean use_selection_list);
184 
185 gboolean ags_automation_remove_acceleration_at_position(AgsAutomation *automation,
186 							guint x, gdouble y);
187 
188 GList* ags_automation_get_selection(AgsAutomation *automation);
189 
190 gboolean ags_automation_is_acceleration_selected(AgsAutomation *automation, AgsAcceleration *acceleration);
191 
192 AgsAcceleration* ags_automation_find_point(AgsAutomation *automation,
193 					   guint x, gdouble y,
194 					   gboolean use_selection_list);
195 GList* ags_automation_find_region(AgsAutomation *automation,
196 				  guint x0, gdouble y0,
197 				  guint x1, gdouble y1,
198 				  gboolean use_selection_list);
199 
200 void ags_automation_free_selection(AgsAutomation *automation);
201 
202 void ags_automation_add_point_to_selection(AgsAutomation *automation,
203 					   guint x, gdouble y,
204 					   gboolean replace_current_selection);
205 void ags_automation_remove_point_from_selection(AgsAutomation *automation,
206 						guint x, gdouble y);
207 
208 void ags_automation_add_region_to_selection(AgsAutomation *automation,
209 					    guint x0, gdouble y0,
210 					    guint x1, gdouble y1,
211 					    gboolean replace_current_selection);
212 void ags_automation_remove_region_from_selection(AgsAutomation *automation,
213 						 guint x0, gdouble y0,
214 						 guint x1, gdouble y1);
215 
216 void ags_automation_add_all_to_selection(AgsAutomation *automation);
217 
218 xmlNode* ags_automation_copy_selection(AgsAutomation *automation);
219 xmlNode* ags_automation_cut_selection(AgsAutomation *automation);
220 
221 void ags_automation_insert_from_clipboard(AgsAutomation *automation,
222 					  xmlNode *automation_node,
223 					  gboolean reset_x_offset, guint x_offset,
224 					  gboolean reset_y_offset, gdouble y_offset);
225 
226 void ags_automation_insert_from_clipboard_extended(AgsAutomation *automation,
227 						   xmlNode *automation_node,
228 						   gboolean reset_x_offset, guint x_offset,
229 						   gboolean reset_y_offset, gdouble y_offset,
230 						   gboolean match_line, gboolean no_duplicates);
231 
232 gchar** ags_automation_get_specifier_unique(GList *automation);
233 gchar** ags_automation_get_specifier_unique_with_channel_type(GList *automation,
234 							      GType channel_type);
235 GList* ags_automation_find_specifier(GList *automation,
236 				     gchar *specifier);
237 GList* ags_automation_find_channel_type_with_control_name(GList *automation,
238 							  GType channel_type, gchar *specifier);
239 GList* ags_automation_find_specifier_with_type_and_line(GList *automation,
240 							gchar *specifier,
241 							GType channel_type,
242 							guint line);
243 
244 guint ags_automation_get_value(AgsAutomation *automation,
245 			       guint x, guint x_end,
246 			       gboolean use_prev_on_failure,
247 			       GValue *value);
248 
249 AgsAutomation* ags_automation_new(GObject *audio,
250 				  guint line,
251 				  GType channel_type,
252 				  gchar *control_name);
253 
254 G_END_DECLS
255 
256 #endif /*__AGS_AUTOMATION_H__*/
257