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