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_CHANNEL_THREAD_H__
21 #define __AGS_CHANNEL_THREAD_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 #include <ags/libags.h>
27 
28 #include <ags/audio/ags_sound_enums.h>
29 
30 G_BEGIN_DECLS
31 
32 #define AGS_TYPE_CHANNEL_THREAD                (ags_channel_thread_get_type())
33 #define AGS_CHANNEL_THREAD(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_CHANNEL_THREAD, AgsChannelThread))
34 #define AGS_CHANNEL_THREAD_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST(class, AGS_TYPE_CHANNEL_THREAD, AgsChannelThreadClass))
35 #define AGS_IS_CHANNEL_THREAD(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_CHANNEL_THREAD))
36 #define AGS_IS_CHANNEL_THREAD_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_CHANNEL_THREAD))
37 #define AGS_CHANNEL_THREAD_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS(obj, AGS_TYPE_CHANNEL_THREAD, AgsChannelThreadClass))
38 
39 #define AGS_CHANNEL_THREAD_DEFAULT_JIFFIE (ceil(AGS_SOUNDCARD_DEFAULT_SAMPLERATE / AGS_SOUNDCARD_DEFAULT_BUFFER_SIZE) + AGS_SOUNDCARD_DEFAULT_OVERCLOCK)
40 
41 typedef struct _AgsChannelThread AgsChannelThread;
42 typedef struct _AgsChannelThreadClass AgsChannelThreadClass;
43 
44 /**
45  * AgsChannelThreadFlags:
46  * @AGS_CHANNEL_THREAD_STATUS_DONE: sync done parent thread, initial wait during #AgsThread::run()
47  * @AGS_CHANNEL_THREAD_STATUS_WAIT: sync wait parent thread, initial wait during #AgsThread::run()
48  * @AGS_CHANNEL_THREAD_STATUS_DONE_SYNC: sync done parent thread, signal completed during #AgsThread::run()
49  * @AGS_CHANNEL_THREAD_STATUS_WAIT_SYNC: sync wait parent thread, signal completed during #AgsThread::run()
50  *
51  * Enum values to control the behavior or indicate internal state of #AgsChannelThread by
52  * enable/disable as flags.
53  */
54 typedef enum{
55   AGS_CHANNEL_THREAD_STATUS_DONE            = 1,
56   AGS_CHANNEL_THREAD_STATUS_WAIT            = 1 <<  1,
57   AGS_CHANNEL_THREAD_STATUS_DONE_SYNC       = 1 <<  2,
58   AGS_CHANNEL_THREAD_STATUS_WAIT_SYNC       = 1 <<  3,
59 }AgsChannelThreadFlags;
60 
61 struct _AgsChannelThread
62 {
63   AgsThread thread;
64 
65   volatile guint status_flags;
66 
67   GObject *default_output_soundcard;
68 
69   GMutex wakeup_mutex;
70   GCond wakeup_cond;
71 
72   GMutex done_mutex;
73   GCond done_cond;
74 
75   GObject *channel;
76 
77   gint sound_scope;
78 
79   gboolean do_fx_staging;
80 
81   guint *staging_program;
82   guint staging_program_count;
83 };
84 
85 struct _AgsChannelThreadClass
86 {
87   AgsThreadClass thread;
88 };
89 
90 GType ags_channel_thread_get_type();
91 
92 /* flags */
93 gboolean ags_channel_thread_test_status_flags(AgsChannelThread *channel_thread, guint status_flags);
94 void ags_channel_thread_set_status_flags(AgsChannelThread *channel_thread, guint status_flags);
95 void ags_channel_thread_unset_status_flags(AgsChannelThread *channel_thread, guint status_flags);
96 
97 void ags_channel_thread_set_sound_scope(AgsChannelThread *channel_thread,
98 					gint sound_scope);
99 
100 /* staging */
101 gboolean ags_channel_thread_get_do_fx_staging(AgsChannelThread *channel_thread);
102 void ags_channel_thread_set_do_fx_staging(AgsChannelThread *channel_thread, gboolean do_fx_staging);
103 
104 guint* ags_channel_thread_get_staging_program(AgsChannelThread *channel_thread,
105 					      guint *staging_program_count);
106 void ags_channel_thread_set_staging_program(AgsChannelThread *channel_thread,
107 					    guint *staging_program,
108 					    guint staging_program_count);
109 
110 /* instantiate */
111 AgsChannelThread* ags_channel_thread_new(GObject *default_output_soundcard,
112 					 GObject *channel);
113 
114 G_END_DECLS
115 
116 #endif /*__AGS_CHANNEL_THREAD_H__*/
117