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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/************************************************************************
FAUST Architecture File
Copyright (C) 2016 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 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, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#include <libgen.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
/*
#ifndef FAUSTFLOAT
#define FAUSTFLOAT double
#endif
*/
#include "faust/dsp/dsp-optimizer.h"
#include "faust/audio/jack-dsp.h"
#include "faust/dsp/llvm-dsp.h"
#include "faust/dsp/interpreter-dsp.h"
#include "faust/dsp/dsp-adapter.h"
#include "faust/dsp/proxy-dsp.h"
#include "faust/dsp/poly-dsp.h"
#include "faust/gui/meta.h"
#include "faust/gui/FUI.h"
#include "faust/gui/faustgtk.h"
#include "faust/gui/MidiUI.h"
#include "faust/gui/httpdUI.h"
#include "faust/gui/OSCUI.h"
#include "faust/gui/SoundUI.h"
#include "faust/misc.h"
using namespace std;
list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;
struct malloc_memory_manager : public dsp_memory_manager {
void* allocate(size_t size)
{
void* res = malloc(size);
//cout << "malloc_manager : " << size << " " << res << endl;
return res;
}
virtual void destroy(void* ptr)
{
//cout << "free_manager : " << ptr << endl;
free(ptr);
}
};
static void printList(const vector<string>& list)
{
for (int i = 0; i < list.size(); i++) {
std::cout << "item: " << list[i] << "\n";
}
}
int main(int argc, char* argv[])
{
char name[256];
char filename[256];
char rcfilename[256];
char* home = getenv("HOME");
snprintf(name, 255, "%s", basename(argv[0]));
snprintf(filename, 255, "%s", basename(argv[argc-1]));
snprintf(rcfilename, 255, "%s/.%s-%src", home, name, filename);
bool is_llvm = isopt(argv, "-llvm");
bool is_interp = isopt(argv, "-interp");
bool is_midi = isopt(argv, "-midi");
bool is_osc = isopt(argv, "-osc");
bool is_httpd = isopt(argv, "-httpd");
int nvoices = lopt(argv, "-nvoices", -1);
malloc_memory_manager manager;
if (isopt(argv, "-h") || isopt(argv, "-help") || (!is_llvm && !is_interp)) {
cout << "dynamic-jack-gtk [-llvm/interp] [-nvoices <num>] [-midi] [-osc] [-httpd] [additional Faust options (-vec -vs 8...)] foo.dsp/foo.fbc" << endl;
cout << "Use '-llvm' to use LLVM backend\n";
cout << "Use '-interp' to use Interpreter backend (using either .dsp or .fbc (Faust Byte Code) files\n";
cout << "Use '-nvoices <num>' to produce a polyphonic self-contained DSP with <num> voices, ready to be used with MIDI or OSC\n";
cout << "Use '-midi' to activate MIDI control\n";
cout << "Use '-osc' to activate OSC control\n";
cout << "Use '-httpd' to activate HTTP control\n";
exit(EXIT_FAILURE);
}
dsp_factory* factory = nullptr;
dsp* DSP = nullptr;
mydsp_poly* dsp_poly = nullptr;
MidiUI* midiinterface = nullptr;
httpdUI* httpdinterface = nullptr;
GUI* oscinterface = nullptr;
jackaudio_midi audio;
string error_msg;
cout << "Libfaust version : " << getCLibFaustVersion () << endl;
int argc1 = 0;
const char* argv1[64];
cout << "Compiled with additional options : ";
for (int i = 1; i < argc-1; i++) {
if ((string(argv[i]) == "-llvm")
|| (string(argv[i]) == "-interp")
|| (string(argv[i]) == "-midi")
|| (string(argv[i]) == "-osc")
|| (string(argv[i]) == "-httpd")) {
continue;
} else if (string(argv[i]) == "-nvoices") {
i++;
continue;
}
argv1[argc1++] = argv[i];
cout << argv[i] << " ";
}
cout << endl;
argv1[argc1] = 0; // NULL terminated argv
if (is_llvm) {
cout << "Using LLVM backend" << endl;
// argc : without the filename (last element);
factory = createDSPFactoryFromFile(argv[argc-1], argc1, argv1, "", error_msg, -1);
//cout << "getDSPMachineTarget " << getDSPMachineTarget() << endl;
/*
// Test Write/Read
string path_name = factory->getName();
cout << "Test writeDSPFactoryToBitcodeFile/readDSPFactoryFromBitcodeFile" << endl;
writeDSPFactoryToBitcodeFile(static_cast<llvm_dsp_factory*>(factory), path_name);
deleteDSPFactory(static_cast<llvm_dsp_factory*>(factory));
factory = readDSPFactoryFromBitcodeFile(path_name, "", -1);
cout << "getCompileOptions " << factory->getCompileOptions() << endl;
printList(factory->getLibraryList());
printList(factory->getIncludePathnames());
*/
} else {
cout << "Using interpreter backend" << endl;
// argc : without the filename (last element);
factory = createInterpreterDSPFactoryFromFile(argv[argc-1], argc1, argv1, error_msg);
if (!factory) {
cout << "createInterpreterDSPFactoryFromFile " << error_msg;
factory = readInterpreterDSPFactoryFromBitcodeFile(argv[argc-1], error_msg);
}
}
if (!factory) {
cerr << "Cannot create factory : " << error_msg;
exit(EXIT_FAILURE);
}
cout << "getCompileOptions " << factory->getCompileOptions() << endl;
printList(factory->getLibraryList());
printList(factory->getIncludePathnames());
//factory->setMemoryManager(&manager); causes crash in -fm mode
DSP = factory->createDSPInstance();
/*
measure_dsp* mes = new measure_dsp(DSP->clone(), 512, 5.); // Buffer_size and duration in sec of measure
for (int i = 0; i < 2; i++) {
mes->measure();
cout << argv[argc-1] << " : " << mes->getStats() << " " << "(DSP CPU % : " << (mes->getCPULoad() * 100) << ")" << endl;
}
*/
// To test compiled block reuse
//DSP = factory->createDSPInstance();
if (!DSP) {
cerr << "Cannot create instance "<< endl;
exit(EXIT_FAILURE);
}
cout << "getName " << factory->getName() << endl;
cout << "getSHAKey " << factory->getSHAKey() << endl;
//exit(1);
if (nvoices > 0) {
cout << "Starting polyphonic mode nvoices : " << nvoices << endl;
DSP = dsp_poly = new mydsp_poly(DSP, nvoices, true, true);
}
if (isopt(argv, "-double")) {
cout << "Running in double..." << endl;
}
GUI* interface = new GTKUI(filename, &argc, &argv);
DSP->buildUserInterface(interface);
FUI* finterface = new FUI();
DSP->buildUserInterface(finterface);
SoundUI* soundinterface = new SoundUI();
// SoundUI has to be dispatched on all internal voices
if (dsp_poly) dsp_poly->setGroup(false);
DSP->buildUserInterface(soundinterface);
if (dsp_poly) dsp_poly->setGroup(true);
if (!audio.init(filename, DSP)) {
return 0;
}
// After audio.init that calls 'init'
finterface->recallState(rcfilename);
if (is_httpd) {
httpdinterface = new httpdUI(name, DSP->getNumInputs(), DSP->getNumOutputs(), argc, argv);
DSP->buildUserInterface(httpdinterface);
}
if (is_osc) {
oscinterface = new OSCUI(filename, argc, argv);
DSP->buildUserInterface(oscinterface);
}
if (is_midi) {
midiinterface = new MidiUI(&audio);
DSP->buildUserInterface(midiinterface);
}
if (nvoices > 0) {
audio.addMidiIn(dsp_poly);
}
audio.start();
if (is_httpd) {
httpdinterface->run();
}
if (is_osc) {
oscinterface->run();
}
if (is_midi) {
midiinterface->run();
}
interface->run();
audio.stop();
finterface->saveState(rcfilename);
delete DSP;
delete interface;
delete finterface;
delete midiinterface;
delete httpdinterface;
delete oscinterface;
delete soundinterface;
//delete mes;
if (is_llvm) {
deleteDSPFactory(static_cast<llvm_dsp_factory*>(factory));
} else {
deleteInterpreterDSPFactory(static_cast<interpreter_dsp_factory*>(factory));
}
return 0;
}
|