aboutsummaryrefslogtreecommitdiff
path: root/pluginhost~/src/pluginhost~.h
blob: 48dff963e222d98c7c29cb5272e49de53771fac5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* dssi~ - A DSSI host for PD 
 * 
 * Copyright 2006 Jamie Bullock and others 
 *
 * This file incorporates code from the following sources:
 * 
 * jack-dssi-host (BSD-style license): Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton.
 *
 * Hexter (GPL license): Copyright (C) 2004 Sean Bolton and others.
 * 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>     /* for uint8_t      */
#include <stdlib.h>     /* for exit()       */
#include <sys/types.h>  /* for fork()       */
#include <signal.h>     /* for kill()       */
#include <sys/wait.h>   /* for wait()       */
#include <dirent.h>     /* for readdir()    */

#include "m_pd.h"
#include "dssi.h"

#define DX7_VOICE_SIZE_PACKED 	128 /*From hexter_types.h by Sean Bolton */
#define DX7_DUMP_SIZE_BULK 	4096+8

#define VERSION           0.99
#define MY_NAME           "pluginhost~"
#define EVENT_BUFSIZE     1024
#define OSC_BASE_MAX      1024
#define TYPE_STRING_SIZE  20
#define DIR_STRING_SIZE   1024
#define DEBUG_STRING_SIZE 1024
#define ASCII_n           110
#define ASCII_p           112
#define ASCII_c           99
#define ASCII_b           98
#define ASCII_t           116
#define ASCII_a           97

#define LOADGUI 0 /* FIX: deprecate this */
#ifdef DEBUG
#define CHECKSUM_PATCH_FILES_ON_LOAD 1
#endif

#define MIN(a,b) ((a)<(b)?(a):(b))

/*From dx7_voice.h by Sean Bolton */

typedef struct _dx7_patch_t {
    uint8_t data[128];
} dx7_patch_t;

typedef struct _ph_instance {

    unsigned int     plugin_ProgramCount;
    char            *ui_osc_control_path;
    char            *ui_osc_configure_path;
    char            *ui_osc_program_path;
    char            *ui_osc_show_path;
    char            *ui_osc_hide_path;
    char            *ui_osc_quit_path;
    char            *osc_url_path;
    long             currentBank;
    long             currentProgram;
    int              uiNeedsProgramUpdate;
    int              pendingProgramChange;
    int              pendingBankLSB;
    int              pendingBankMSB;
    int              ui_hidden;
    int              ui_show;

    int *plugin_PortControlInNumbers; /*not sure if this should go here?*/
    DSSI_Program_Descriptor *pluginPrograms;

} ph_instance;

typedef struct ph_configure_pair {

    struct ph_configure_pair *next;
    char   *value;
    char   *key;
    int    instance;

} ph_configure_pair;

//typedef struct ph_configure_pair t_ph_configure_pair;

typedef struct _port_info {

    t_atom lower_bound;
    t_atom upper_bound;
    t_atom data_type;
    t_atom p_default;
    t_atom type;
    t_atom name;

} ph_port_info;

typedef struct _ph_tilde {

    int sr;
    int blksize;
    int time_ref;
    int ports_in;
    int ports_out;
    int ports_controlIn;
    int ports_controlOut;
    int bufWriteIndex;
    int bufReadIndex;

    bool is_DSSI;
    bool dsp;
    bool dsp_loop;

    char *plugin_basename;
    char *plugin_label;
    char *plugin_full_path;
    char *project_dir;
    void *plugin_handle;
    char *osc_url_base;

    float f;
    float sr_inv;
    float **plugin_InputBuffers;
    float **plugin_OutputBuffers;
    float *plugin_ControlDataInput;
    float *plugin_ControlDataOutput;

    unsigned int n_instances;
    unsigned int plugin_ins;
    unsigned int plugin_outs;
    unsigned int plugin_controlIns;
    unsigned int plugin_controlOuts;
    unsigned long *instanceEventCounts;
    unsigned long *plugin_ControlInPortNumbers;
    unsigned char channelMap[128];

    DSSI_Descriptor_Function desc_func;
    DSSI_Descriptor *descriptor;
    LADSPA_Handle *instanceHandles;

    t_inlet  **inlets;
    t_outlet **outlets;
    t_outlet *control_outlet;
    t_canvas *x_canvas;
    t_object x_obj;

    ph_port_info *port_info;
    ph_instance *instances;
    ph_configure_pair *configure_buffer_head;

    snd_seq_event_t **instanceEventBuffers;
    snd_seq_event_t midiEventBuf[EVENT_BUFSIZE];

    pthread_mutex_t midiEventBufferMutex;

} ph_tilde;

static char *ph_tilde_send_configure(ph_tilde *x, char *key, char *value,
        int instance);
static void MIDIbuf(int type, unsigned int chan, int param, int val,
        ph_tilde *x);
static void ph_debug_post(const char *fmt, ...);
static LADSPA_Data get_port_default(ph_tilde *x, int port);