forked from falkTX/dssi-vst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremotevstclient.cpp
141 lines (108 loc) · 3.37 KB
/
remotevstclient.cpp
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
// -*- c-basic-offset: 4 -*-
/*
dssi-vst: a DSSI plugin wrapper for VST effects and instruments
Copyright 2004 Chris Cannam
*/
#include "remotevstclient.h"
#include <sys/un.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <iostream>
#include "rdwrops.h"
RemoteVSTClient::RemoteVSTClient(std::string dllName) :
RemotePluginClient()
{
pid_t child;
std::string arg = dllName + "," + getFileIdentifiers();
const char *argStr = arg.c_str();
std::cerr << "RemoteVSTClient: executing wine dssi-vst-server.exe.so " << argStr << std::endl;
if ((child = fork()) < 0) {
cleanup();
throw((std::string)"Fork failed");
} else if (child == 0) { // child process
if (execlp("wine", "wine", "dssi-vst-server.exe.so", argStr, 0)) {
perror("Exec failed");
exit(1);
}
}
syncStartup();
}
RemoteVSTClient::~RemoteVSTClient()
{
}
void
RemoteVSTClient::queryPlugins(std::vector<PluginRecord> &plugins)
{
char tmpFileBase[60];
sprintf(tmpFileBase, "/tmp/rplugin_qry_XXXXXX");
if (mkstemp(tmpFileBase) < 0) {
throw((std::string)"Failed to obtain temporary filename");
}
unlink(tmpFileBase);
if (mkfifo(tmpFileBase, 0666)) { //!!! what permission is correct here?
perror(tmpFileBase);
throw((std::string)"Failed to create FIFO");
}
pid_t child;
if ((child = fork()) < 0) {
unlink(tmpFileBase);
throw((std::string)"Fork failed");
} else if (child == 0) { // child process
if (execlp("wine", "wine", "dssi-vst-scanner.exe.so", tmpFileBase, 0)) {
perror("Exec failed");
exit(1);
}
}
//!!! again, should do this via nonblocking loop
int fd = -1;
if ((fd = open(tmpFileBase, O_RDONLY)) < 0) {
unlink(tmpFileBase);
throw((std::string)"Failed to open FIFO");
}
try {
unsigned long uniqueId;
char buffer[64];
while (1) {
try {
tryRead(fd, &uniqueId, sizeof(unsigned long));
} catch (RemotePluginClosedException) {
// This is acceptable here; it just means we're done
break;
}
PluginRecord rec;
rec.uniqueId = uniqueId;
tryRead(fd, buffer, 64);
rec.dllName = buffer;
tryRead(fd, buffer, 64);
rec.pluginName = buffer;
std::cerr << "Plugin " << rec.pluginName << std::endl;
tryRead(fd, buffer, 64);
rec.vendorName = buffer;
tryRead(fd, &rec.isSynth, sizeof(bool));
tryRead(fd, &rec.hasGUI, sizeof(bool));
tryRead(fd, &rec.inputs, sizeof(int));
tryRead(fd, &rec.outputs, sizeof(int));
tryRead(fd, &rec.parameters, sizeof(int));
std::cerr << rec.parameters << " parameters" << std::endl;
for (int i = 0; i < rec.parameters; ++i) {
tryRead(fd, buffer, 64);
rec.parameterNames.push_back(std::string(buffer));
std::cerr << "Parameter " << i << ": name " << buffer << std::endl;
}
tryRead(fd, &rec.programs, sizeof(int));
std::cerr << rec.programs << " programs" << std::endl;
for (int i = 0; i < rec.programs; ++i) {
tryRead(fd, buffer, 64);
rec.programNames.push_back(std::string(buffer));
std::cerr << "Program " << i << ": name " << buffer << std::endl;
}
plugins.push_back(rec);
}
} catch (std::string s) {
std::cerr << s << std::endl;
} catch (RemotePluginClosedException) {
std::cerr << "Plugin scanner exited unexpectedly." << std::endl;
}
close(fd);
unlink(tmpFileBase);
}