Initial backend support for external export encoder
[ardour.git] / libs / ardour / vst_state.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2010 Paul Davis
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <string.h>
21 #include "ardour/vst_types.h"
22
23 void
24 vststate_init (VSTState* state) {
25         memset (state, 0, sizeof (VSTState));
26         pthread_mutex_init (&state->lock, 0);
27         pthread_mutex_init (&state->state_lock, 0);
28         pthread_cond_init (&state->window_status_change, 0);
29         pthread_cond_init (&state->plugin_dispatcher_called, 0);
30         pthread_cond_init (&state->window_created, 0);
31         state->want_program = -1;
32 }
33
34 /* This is to be called while handling VST UI events.
35  *
36  * Many plugins expect program dispatch from the GUI event-loop
37  * only  (VSTPlugin::load_plugin_preset/set_chunk is invoked by
38  * the user in ardour's main GUI thread, which on Windows and Linux
39  * may *not* the VST event loop).
40  */
41 void
42 vststate_maybe_set_program (VSTState* state)
43 {
44         if (state->want_program != -1) {
45                 if (state->vst_version >= 2) {
46                         state->plugin->dispatcher (state->plugin, effBeginSetProgram, 0, 0, NULL, 0);
47                 }
48
49                 state->plugin->dispatcher (state->plugin, effSetProgram, 0, state->want_program, NULL, 0);
50
51                 if (state->vst_version >= 2) {
52                         state->plugin->dispatcher (state->plugin, effEndSetProgram, 0, 0, NULL, 0);
53                 }
54                 state->want_program = -1;
55         }
56
57         if (state->want_chunk == 1) {
58                 pthread_mutex_lock (&state->state_lock);
59                 state->plugin->dispatcher (state->plugin, 24 /* effSetChunk */, 1, state->wanted_chunk_size, state->wanted_chunk, 0);
60                 state->want_chunk = 0;
61                 pthread_mutex_unlock (&state->state_lock);
62         }
63 }