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_AUDIO_LOOP_H__
21 #define __AGS_AUDIO_LOOP_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 #include <math.h>
31 
32 G_BEGIN_DECLS
33 
34 #define AGS_TYPE_AUDIO_LOOP                (ags_audio_loop_get_type())
35 #define AGS_AUDIO_LOOP(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_AUDIO_LOOP, AgsAudioLoop))
36 #define AGS_AUDIO_LOOP_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST(class, AGS_TYPE_AUDIO_LOOP, AgsAudioLoopClass))
37 #define AGS_IS_AUDIO_LOOP(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_AUDIO_LOOP))
38 #define AGS_IS_AUDIO_LOOP_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_AUDIO_LOOP))
39 #define AGS_AUDIO_LOOP_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS(obj, AGS_TYPE_AUDIO_LOOP, AgsAudioLoopClass))
40 
41 #define AGS_AUDIO_LOOP_DEFAULT_JIFFIE (ceil(AGS_SOUNDCARD_DEFAULT_SAMPLERATE / AGS_SOUNDCARD_DEFAULT_BUFFER_SIZE) + AGS_SOUNDCARD_DEFAULT_OVERCLOCK)
42 
43 typedef struct _AgsAudioLoop AgsAudioLoop;
44 typedef struct _AgsAudioLoopClass AgsAudioLoopClass;
45 
46 /**
47  * AgsAudioLoopFlags:
48  * @AGS_AUDIO_LOOP_PLAY_CHANNEL: play channel
49  * @AGS_AUDIO_LOOP_PLAYING_CHANNEL: playing channnel
50  * @AGS_AUDIO_LOOP_PLAY_CHANNEL_TERMINATING: play channe terminating
51  * @AGS_AUDIO_LOOP_PLAY_AUDIO: play audio
52  * @AGS_AUDIO_LOOP_PLAYING_AUDIO: playing audio
53  * @AGS_AUDIO_LOOP_PLAY_AUDIO_TERMINATING: play audio terminating
54  *
55  * Enum values to control the behavior or indicate internal state of #AgsAudioLoop by
56  * enable/disable as flags.
57  */
58 typedef enum{
59   AGS_AUDIO_LOOP_PLAY_CHANNEL                   = 1,
60   AGS_AUDIO_LOOP_PLAYING_CHANNEL                = 1 << 1,
61   AGS_AUDIO_LOOP_PLAY_CHANNEL_TERMINATING       = 1 << 2,
62   AGS_AUDIO_LOOP_PLAY_AUDIO                     = 1 << 3,
63   AGS_AUDIO_LOOP_PLAYING_AUDIO                  = 1 << 4,
64   AGS_AUDIO_LOOP_PLAY_AUDIO_TERMINATING         = 1 << 5,
65 }AgsAudioLoopFlags;
66 
67 struct _AgsAudioLoop
68 {
69   AgsThread thread;
70 
71   guint flags;
72 
73   GRecMutex tree_lock;
74 
75   volatile gboolean is_syncing;
76 
77   volatile gboolean is_critical_region;
78   volatile guint critical_region_ref;
79 
80   guint play_channel_ref;
81   GList *play_channel; // play AgsChannel
82 
83   guint play_audio_ref;
84   GList *play_audio; // play AgsAudio
85 
86   GList *sync_thread;
87 
88   gboolean do_fx_staging;
89 
90   guint *staging_program;
91   guint staging_program_count;
92 };
93 
94 struct _AgsAudioLoopClass
95 {
96   AgsThreadClass thread;
97 };
98 
99 GType ags_audio_loop_get_type();
100 
101 /* flags */
102 gboolean ags_audio_loop_test_flags(AgsAudioLoop *audio_loop, guint flags);
103 void ags_audio_loop_set_flags(AgsAudioLoop *audio_loop, guint flags);
104 void ags_audio_loop_unset_flags(AgsAudioLoop *audio_loop, guint flags);
105 
106 /* runtime */
107 void ags_audio_loop_add_audio(AgsAudioLoop *audio_loop, GObject *audio);
108 void ags_audio_loop_remove_audio(AgsAudioLoop *audio_loop, GObject *audio);
109 
110 void ags_audio_loop_add_channel(AgsAudioLoop *audio_loop, GObject *channel);
111 void ags_audio_loop_remove_channel(AgsAudioLoop *audio_loop, GObject *channel);
112 
113 /* staging */
114 gboolean ags_audio_loop_get_do_fx_staging(AgsAudioLoop *audio_loop);
115 void ags_audio_loop_set_do_fx_staging(AgsAudioLoop *audio_loop, gboolean do_fx_staging);
116 
117 guint* ags_audio_loop_get_staging_program(AgsAudioLoop *audio_loop,
118 					  guint *staging_program_count);
119 void ags_audio_loop_set_staging_program(AgsAudioLoop *audio_loop,
120 					guint *staging_program,
121 					guint staging_program_count);
122 
123 /* instantiate */
124 AgsAudioLoop* ags_audio_loop_new();
125 
126 G_END_DECLS
127 
128 #endif /*__AGS_AUDIO_LOOP_H__*/
129