File: interpreter_dynamic_dsp_aux.cpp

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (207 lines) | stat: -rw-r--r-- 8,136 bytes parent folder | download
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
/************************************************************************
 ************************************************************************
    FAUST compiler
    Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ************************************************************************
 ************************************************************************/

#if defined(_WIN32)
#include "compatibility.hh"
#else  // !defined(_WIN32)
#include <libgen.h>
#endif  // defined(_WIN32)

#include "Text.hh"
#include "interpreter_dynamic_dsp_aux.hh"
#include "libfaust.h"
#include "lock_api.hh"

using namespace std;

LIBFAUST_API interpreter_dsp_factory* createInterpreterDSPFactoryFromFile(const string& filename,
                                                                          int           argc,
                                                                          const char*   argv[],
                                                                          string&       error_msg)
{
    string base = basename((char*)filename.c_str());
    size_t pos  = filename.find(".dsp");

    if (pos != string::npos) {
        return createInterpreterDSPFactoryFromString(base.substr(0, pos), pathToContent(filename),
                                                     argc, argv, error_msg);
    } else {
        error_msg = "File Extension is not the one expected (.dsp expected)\n";
        return nullptr;
    }
}

LIBFAUST_API interpreter_dsp_factory* createInterpreterDSPFactoryFromString(
    const string& name_app, const string& dsp_content, int argc, const char* argv[],
    string& error_msg)
{
    LOCK_API
    string expanded_dsp_content, sha_key;

    if ((expanded_dsp_content = sha1FromDSP(name_app, dsp_content, argc, argv, sha_key)) == "") {
        return nullptr;
    } else {
        dsp_factory_table<SDsp_factory>::factory_iterator it;
        if (gInterpreterFactoryTable.getFactory(sha_key, it)) {
            SDsp_factory sfactory = (*it).first;
            sfactory->addReference();
            return sfactory;
        } else {
            try {
                int         argc1 = 0;
                const char* argv1[64];
                argv1[argc1++] = "faust";
                argv1[argc1++] = "-lang";
                argv1[argc1++] = "interp";
                argv1[argc1++] = "-o";
                argv1[argc1++] = "string";
                // Copy arguments
                for (int i = 0; i < argc; i++) {
                    argv1[argc1++] = argv[i];
                }
                argv1[argc1] = nullptr;  // NULL terminated argv

                dsp_factory_base* dsp_factory_aux =
                    createFactory(name_app, dsp_content, argc1, argv1, error_msg, true);
                if (dsp_factory_aux) {
                    dsp_factory_aux->setName(name_app);
                    interpreter_dsp_factory* factory = new interpreter_dsp_factory(dsp_factory_aux);
                    gInterpreterFactoryTable.setFactory(factory);
                    factory->setSHAKey(sha_key);
                    factory->setDSPCode(expanded_dsp_content);
                    return factory;
                } else {
                    return nullptr;
                }
            } catch (faustexception& e) {
                error_msg = e.what();
                return nullptr;
            }
        }
    }
}

LIBFAUST_API interpreter_dsp_factory* createInterpreterDSPFactoryFromSignals(
    const std::string& name_app, tvec signals, int argc, const char* argv[], std::string& error_msg)
{
    LOCK_API
    try {
        int         argc1 = 0;
        const char* argv1[64];
        argv1[argc1++] = "faust";
        argv1[argc1++] = "-lang";
        argv1[argc1++] = "interp";
        argv1[argc1++] = "-o";
        argv1[argc1++] = "string";
        // Copy arguments
        for (int i = 0; i < argc; i++) {
            argv1[argc1++] = argv[i];
        }
        argv1[argc1] = nullptr;  // NULL terminated argv

        dsp_factory_base* dsp_factory_aux =
            createFactory(name_app, signals, argc1, argv1, error_msg);
        if (dsp_factory_aux) {
            dsp_factory_aux->setName(name_app);
            interpreter_dsp_factory* factory = new interpreter_dsp_factory(dsp_factory_aux);
            gInterpreterFactoryTable.setFactory(factory);
            return factory;
        } else {
            return nullptr;
        }
    } catch (faustexception& e) {
        error_msg = e.what();
        return nullptr;
    }
}

LIBFAUST_API interpreter_dsp_factory* createInterpreterDSPFactoryFromBoxes(
    const std::string& name_app, Tree box, int argc, const char* argv[], std::string& error_msg)
{
    LOCK_API
    try {
        tvec signals = boxesToSignalsAux(box);
        return createInterpreterDSPFactoryFromSignals(name_app, signals, argc, argv, error_msg);
    } catch (faustexception& e) {
        error_msg = e.Message();
        return nullptr;
    }
}

// Public C interface : lock management is done by called C++ API

#ifdef __cplusplus
extern "C" {
#endif

LIBFAUST_API interpreter_dsp_factory* createCInterpreterDSPFactoryFromFile(const char* filename,
                                                                           int         argc,
                                                                           const char* argv[],
                                                                           char*       error_msg)
{
    string                   error_msg_aux;
    interpreter_dsp_factory* factory =
        createInterpreterDSPFactoryFromFile(filename, argc, argv, error_msg_aux);
    strncpy(error_msg, error_msg_aux.c_str(), 4096);
    return factory;
}

LIBFAUST_API interpreter_dsp_factory* createCInterpreterDSPFactoryFromString(
    const char* name_app, const char* dsp_content, int argc, const char* argv[], char* error_msg)
{
    string                   error_msg_aux;
    interpreter_dsp_factory* factory =
        createInterpreterDSPFactoryFromString(name_app, dsp_content, argc, argv, error_msg_aux);
    strncpy(error_msg, error_msg_aux.c_str(), 4096);
    return factory;
}

LIBFAUST_API interpreter_dsp_factory* createCInterpreterDSPFactoryFromSignals(
    const char* name_app, Signal* signals_aux, int argc, const char* argv[], char* error_msg)
{
    string error_msg_aux;
    tvec   signals;
    int    i = 0;
    while (signals_aux[i]) {
        signals.push_back(signals_aux[i]);
        i++;
    }
    interpreter_dsp_factory* factory =
        createInterpreterDSPFactoryFromSignals(name_app, signals, argc, argv, error_msg_aux);
    strncpy(error_msg, error_msg_aux.c_str(), 4096);
    return factory;
}

LIBFAUST_API interpreter_dsp_factory* createCInterpreterDSPFactoryFromBoxes(const char* name_app,
                                                                            Tree box, int argc,
                                                                            const char* argv[],
                                                                            char*       error_msg)
{
    string                   error_msg_aux;
    interpreter_dsp_factory* factory =
        createInterpreterDSPFactoryFromBoxes(name_app, box, argc, argv, error_msg_aux);
    strncpy(error_msg, error_msg_aux.c_str(), 4096);
    return factory;
}

#ifdef __cplusplus
}
#endif