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_TIMESTAMP_H__
21 #define __AGS_TIMESTAMP_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 G_BEGIN_DECLS
27 
28 #define AGS_TYPE_TIMESTAMP                (ags_timestamp_get_type())
29 #define AGS_TYPE_TIMESTAMP_FLAGS          (ags_timestamp_flags_get_type())
30 #define AGS_TIMESTAMP(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_TIMESTAMP, AgsTimestamp))
31 #define AGS_TIMESTAMP_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_TIMESTAMP, AgsTimestampClass))
32 #define AGS_IS_TIMESTAMP(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_TIMESTAMP))
33 #define AGS_IS_TIMESTAMP_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_TIMESTAMP))
34 #define AGS_TIMESTAMP_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), AGS_TYPE_TIMESTAMP, AgsTimestampClass))
35 
36 #define AGS_TIMESTAMP_GET_OBJ_MUTEX(obj) (&(((AgsTimestamp *) obj)->obj_mutex))
37 
38 typedef struct _AgsTimestamp AgsTimestamp;
39 typedef struct _AgsTimestampClass AgsTimestampClass;
40 
41 /**
42  * AgsTimestampFlags:
43  * @AGS_TIMESTAMP_UNIX: unix timestamp is used
44  * @AGS_TIMESTAMP_OFFSET: internal offset is used
45  * @AGS_TIMESTAMP_OUTDATED: the timestamp is outdated
46  *
47  * Enum values to control the behavior or indicate internal state of #AgsTimestamp by
48  * enable/disable as sync_flags.
49  */
50 typedef enum{
51   AGS_TIMESTAMP_UNIX      = 1,
52   AGS_TIMESTAMP_OFFSET    = 1 <<  1,
53   AGS_TIMESTAMP_OUTDATED  = 1 <<  2,
54 }AgsTimestampFlags;
55 
56 struct _AgsTimestamp
57 {
58   GObject gobject;
59 
60   guint flags;
61 
62   GRecMutex obj_mutex;
63 
64   union{
65     struct _unix{
66       time_t time_val;
67     }unix_time;
68     struct _ags{
69       guint64 offset;
70     }ags_offset;
71   }timer;
72 
73   gdouble delay;
74   guint attack;
75 };
76 
77 struct _AgsTimestampClass
78 {
79   GObjectClass gobject;
80 };
81 
82 GType ags_timestamp_get_type(void);
83 GType ags_timestamp_flags_get_type(void);
84 
85 /* flags */
86 gboolean ags_timestamp_test_flags(AgsTimestamp *timestamp,
87 				  guint flags);
88 void ags_timestamp_set_flags(AgsTimestamp *timestamp,
89 			     guint flags);
90 void ags_timestamp_unset_flags(AgsTimestamp *timestamp,
91 			       guint flags);
92 
93 /* query */
94 time_t ags_timestamp_get_unix_time(AgsTimestamp *timestamp);
95 void ags_timestamp_set_unix_time(AgsTimestamp *timestamp,
96 				 time_t unix_time);
97 
98 guint64 ags_timestamp_get_ags_offset(AgsTimestamp *timestamp);
99 void ags_timestamp_set_ags_offset(AgsTimestamp *timestamp,
100 				  guint64 ags_offset);
101 
102 /* */
103 AgsTimestamp* ags_timestamp_new();
104 
105 G_END_DECLS
106 
107 #endif /*__AGS_TIMESTAMP_H__*/
108