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_FX_LV2_AUDIO_H__
21 #define __AGS_FX_LV2_AUDIO_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 #include <ags/libags.h>
27 
28 #include <alsa/seq_event.h>
29 
30 #include <lv2.h>
31 
32 #include <ags/plugin/ags_lv2_plugin.h>
33 
34 #include <ags/audio/ags_port.h>
35 
36 #include <ags/audio/fx/ags_fx_notation_audio.h>
37 
38 G_BEGIN_DECLS
39 
40 #define AGS_TYPE_FX_LV2_AUDIO                (ags_fx_lv2_audio_get_type())
41 #define AGS_FX_LV2_AUDIO(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_FX_LV2_AUDIO, AgsFxLv2Audio))
42 #define AGS_FX_LV2_AUDIO_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_FX_LV2_AUDIO, AgsFxLv2AudioClass))
43 #define AGS_IS_FX_LV2_AUDIO(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_FX_LV2_AUDIO))
44 #define AGS_IS_FX_LV2_AUDIO_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_FX_LV2_AUDIO))
45 #define AGS_FX_LV2_AUDIO_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), AGS_TYPE_FX_LV2_AUDIO, AgsFxLv2AudioClass))
46 
47 #define AGS_FX_LV2_AUDIO_SCOPE_DATA(ptr) ((AgsFxLv2AudioScopeData *) (ptr))
48 #define AGS_FX_LV2_AUDIO_SCOPE_DATA_GET_STRCT_MUTEX(ptr) (&(((AgsFxLv2AudioScopeData *)(ptr))->strct_mutex))
49 
50 #define AGS_FX_LV2_AUDIO_CHANNEL_DATA(ptr) ((AgsFxLv2AudioChannelData *) (ptr))
51 #define AGS_FX_LV2_AUDIO_CHANNEL_DATA_GET_STRCT_MUTEX(ptr) (&(((AgsFxLv2AudioChannelData *)(ptr))->strct_mutex))
52 
53 #define AGS_FX_LV2_AUDIO_INPUT_DATA(ptr) ((AgsFxLv2AudioInputData *) (ptr))
54 #define AGS_FX_LV2_AUDIO_INPUT_DATA_GET_STRCT_MUTEX(ptr) (&(((AgsFxLv2AudioInputData *)(ptr))->strct_mutex))
55 
56 #define AGS_FX_LV2_AUDIO_DEFAULT_MIDI_LENGHT (8 * 256)
57 
58 typedef struct _AgsFxLv2Audio AgsFxLv2Audio;
59 typedef struct _AgsFxLv2AudioScopeData AgsFxLv2AudioScopeData;
60 typedef struct _AgsFxLv2AudioChannelData AgsFxLv2AudioChannelData;
61 typedef struct _AgsFxLv2AudioInputData AgsFxLv2AudioInputData;
62 typedef struct _AgsFxLv2AudioClass AgsFxLv2AudioClass;
63 
64 typedef enum{
65   AGS_FX_LV2_AUDIO_LIVE_INSTRUMENT     = 1,
66 }AgsFxLv2AudioFlags;
67 
68 struct _AgsFxLv2Audio
69 {
70   AgsFxNotationAudio fx_notation_audio;
71 
72   guint flags;
73 
74   guint output_port_count;
75   guint *output_port;
76 
77   guint input_port_count;
78   guint *input_port;
79 
80   gboolean has_event_port;
81   guint event_port;
82 
83   gboolean has_atom_port;
84   guint atom_port;
85 
86   guint bank;
87   guint program;
88 
89   AgsFxLv2AudioScopeData* scope_data[AGS_SOUND_SCOPE_LAST];
90 
91   AgsLv2Plugin *lv2_plugin;
92 
93   AgsPort **lv2_port;
94 };
95 
96 struct _AgsFxLv2AudioClass
97 {
98   AgsFxNotationAudioClass fx_notation_audio;
99 };
100 
101 struct _AgsFxLv2AudioScopeData
102 {
103   GRecMutex strct_mutex;
104 
105   gpointer parent;
106 
107   guint audio_channels;
108 
109   AgsFxLv2AudioChannelData **channel_data;
110 };
111 
112 struct _AgsFxLv2AudioChannelData
113 {
114   GRecMutex strct_mutex;
115 
116   gpointer parent;
117 
118   guint event_count;
119 
120   float *output;
121   float *input;
122 
123   gpointer event_port;
124   gpointer atom_port;
125 
126   LV2_Handle *lv2_handle;
127 
128   AgsFxLv2AudioInputData* input_data[AGS_SEQUENCER_MAX_MIDI_KEYS];
129 };
130 
131 struct _AgsFxLv2AudioInputData
132 {
133   GRecMutex strct_mutex;
134 
135   gpointer parent;
136 
137   float *output;
138   float *input;
139 
140   gpointer event_port;
141   gpointer atom_port;
142 
143   LV2_Handle *lv2_handle;
144 
145   snd_seq_event_t *event_buffer;
146   guint key_on;
147 };
148 
149 GType ags_fx_lv2_audio_get_type();
150 
151 /* runtime */
152 AgsFxLv2AudioScopeData* ags_fx_lv2_audio_scope_data_alloc();
153 void ags_fx_lv2_audio_scope_data_free(AgsFxLv2AudioScopeData *scope_data);
154 
155 AgsFxLv2AudioChannelData* ags_fx_lv2_audio_channel_data_alloc();
156 void ags_fx_lv2_audio_channel_data_free(AgsFxLv2AudioChannelData *channel_data);
157 
158 AgsFxLv2AudioInputData* ags_fx_lv2_audio_input_data_alloc();
159 void ags_fx_lv2_audio_input_data_free(AgsFxLv2AudioInputData *input_data);
160 
161 /* flags */
162 gboolean ags_fx_lv2_audio_test_flags(AgsFxLv2Audio *fx_lv2_audio, guint flags);
163 void ags_fx_lv2_audio_set_flags(AgsFxLv2Audio *fx_lv2_audio, guint flags);
164 void ags_fx_lv2_audio_unset_flags(AgsFxLv2Audio *fx_lv2_audio, guint flags);
165 
166 /* load/unload */
167 void ags_fx_lv2_audio_load_plugin(AgsFxLv2Audio *fx_lv2_audio);
168 void ags_fx_lv2_audio_load_port(AgsFxLv2Audio *fx_lv2_audio);
169 
170 /* plugin */
171 void ags_fx_lv2_audio_change_program(AgsFxLv2Audio *fx_lv2_audio,
172 				     guint bank_index,
173 				     guint program_index);
174 
175 /* instantiate */
176 AgsFxLv2Audio* ags_fx_lv2_audio_new(AgsAudio *audio);
177 
178 G_END_DECLS
179 
180 #endif /*__AGS_FX_LV2_AUDIO_H__*/
181