File: interp-tracer.cpp

package info (click to toggle)
faust 2.14.4~repack2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 276,136 kB
  • sloc: cpp: 231,578; ansic: 15,403; sh: 10,871; java: 6,917; objc: 4,085; makefile: 3,002; cs: 1,077; ruby: 951; python: 885; xml: 550; yacc: 516; lex: 233; lisp: 201
file content (267 lines) | stat: -rw-r--r-- 10,283 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
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
/************************************************************************
    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 <vector>
#include <algorithm>

#include "faust/audio/dummy-audio.h"
#include "faust/dsp/interpreter-dsp.h"
#include "faust/gui/meta.h"
#include "faust/gui/DecoratorUI.h"
#include "faust/gui/MapUI.h"
#include "faust/gui/faustgtk.h"
#include "faust/misc.h"

using namespace std;

//----------------------------------------------------------------------------
// DSP control UI
//----------------------------------------------------------------------------

struct CheckControlUI : public MapUI {
    
    struct ZoneDesc {
        
        FAUSTFLOAT fInit;
        FAUSTFLOAT fMin;
        FAUSTFLOAT fMax;
        FAUSTFLOAT fStep;
        
        ZoneDesc(FAUSTFLOAT init,
                 FAUSTFLOAT min,
                 FAUSTFLOAT max,
                 FAUSTFLOAT step)
            :fInit(init), fMin(min), fMax(max), fStep(step)
        {}
    };
    
    vector<pair<FAUSTFLOAT*, ZoneDesc> > fControlZone;
    
    virtual void addButton(const char* label, FAUSTFLOAT* zone)
    {
        MapUI::addButton(label, zone);
        addItem(zone, FAUSTFLOAT(0), FAUSTFLOAT(0), FAUSTFLOAT(1), FAUSTFLOAT(0));
    }
    virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
    {
        MapUI::addCheckButton(label, zone);
        addItem(zone, FAUSTFLOAT(1), FAUSTFLOAT(1), FAUSTFLOAT(1), FAUSTFLOAT(0));
    }
    virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
    {
        MapUI::addVerticalSlider(label, zone, init, min, max, step);
        addItem(zone, init, min, max, step);
    }
    virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
    {
        MapUI::addHorizontalSlider(label, zone, init, min, max, step);
        addItem(zone, init, min, max, step);
    }
    virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
    {
        MapUI::addNumEntry(label, zone, init, min, max, step);
        addItem(zone, init, min, max, step);
    }
    
    void addItem(FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
    {
        // Reset to init
        *zone = init;
        fControlZone.push_back(make_pair(zone, ZoneDesc(init, min, max, step)));
    }

};

list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;

int main(int argc, char* argv[])
{
    char name[256];
    char filename[256];
    char* home = getenv("HOME");
    
    snprintf(name, 255, "%s", basename(argv[0]));
    snprintf(filename, 255, "%s", basename(argv[argc-1]));
    
    int trace_mode = lopt(argv, "-trace", 0);
    bool is_control = isopt(argv, "-control");
    
    if (isopt(argv, "-h") || isopt(argv, "-help") || trace_mode < 0 || trace_mode > 5) {
        cout << "interp-tracer -trace <1-5> -control [additional Faust options (-ftz xx)] foo.dsp" << endl;
        cout << "-control to activate min/max control check\n";
        cout << "-trace 1 to collect FP_SUBNORMAL only\n";
        cout << "-trace 2 to collect FP_SUBNORMAL, FP_INFINITE and FP_NAN\n";
        cout << "-trace 3 to collect FP_SUBNORMAL, FP_INFINITE, FP_NAN, INTEGER_OVERFLOW and DIV_BY_ZERO\n";
        cout << "-trace 4 to collect FP_SUBNORMAL, FP_INFINITE, FP_NAN, INTEGER_OVERFLOW, DIV_BY_ZERO, fails at first FP_INFINITE or FP_NAN\n";
        cout << "-trace 5 to collect FP_SUBNORMAL, FP_INFINITE, FP_NAN, INTEGER_OVERFLOW, DIV_BY_ZERO, continue after FP_INFINITE or FP_NAN\n";
        exit(EXIT_FAILURE);
    }
    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]) == "-trace" || string(argv[i]) == "-control") {
            i++;
            continue;
        }
        argv1[argc1++] = argv[i];
        cout << argv[i] << " ";
    }
    cout << endl;
    
    argv1[argc1] = 0;  // NULL terminated argv
    
    cout << "Using interpreter backend" << endl;
    if (trace_mode > 0) {
        char mode[8]; sprintf(mode, "%d", trace_mode);
        setenv("FAUST_INTERP_TRACE", mode, 1);
    }
    
    string error_msg;
    // argc : without the filename (last element);
    dsp_factory* factory = createInterpreterDSPFactoryFromFile(argv[argc-1], argc1, argv1, error_msg);
    
    if (!factory) {
        cerr << "Cannot create factory : " << error_msg;
        exit(EXIT_FAILURE);
    }
    
    dsp* DSP = factory->createDSPInstance();
    if (!DSP) {
        cerr << "Cannot create instance "<< endl;
        exit(EXIT_FAILURE);
    }
    
    cout << "getName " << factory->getName() << endl;
    
    dummyaudio audio(44100, 4, INT_MAX);
    if (!audio.init(filename, DSP)) {
        return 0;
    }
    
    GUI* interface = new GTKUI(filename, &argc, &argv);
    DSP->buildUserInterface(interface);
    
    if (is_control) {
        
        // Check by setting each control to min, the max, then reset to init before going to next one
        {
            CheckControlUI ctl;
            DSP->buildUserInterface(&ctl);
            
            cout << "------------------------------" << endl;
            cout << "Check control min/max for " << ctl.fControlZone.size() << " controls" << endl;
            for (int index = 0; index < ctl.fControlZone.size(); index++) {
                cout << "------------------------------" << endl;
                cout << "Control: " << ctl.getParamAddress(ctl.fControlZone[index].first) << endl;
                FAUSTFLOAT min = ctl.fControlZone[index].second.fMin;
                FAUSTFLOAT max = ctl.fControlZone[index].second.fMax;
                FAUSTFLOAT init = ctl.fControlZone[index].second.fInit;
                // Test min
                cout << "Min: " << min << endl;
                *ctl.fControlZone[index].first = min;
                audio.render();
                *ctl.fControlZone[index].first = init; // reset to init
                // Test max
                cout << "Max: " << max << endl;
                *ctl.fControlZone[index].first = max;
                audio.render();
                *ctl.fControlZone[index].first = init; // reset to init
            }
        }
        
        // Check by setting each control to max, then min, then keeping to min before going to next one
        {
            CheckControlUI ctl;
            DSP->buildUserInterface(&ctl);
            
            cout << "------------------------------" << endl;
            cout << "Check control min/max successively keeping min for " << ctl.fControlZone.size() << " controls" << endl;
            for (int index = 0; index < ctl.fControlZone.size(); index++) {
                cout << "------------------------------" << endl;
                cout << "Control: " << ctl.getParamAddress(ctl.fControlZone[index].first) << endl;
                FAUSTFLOAT min = ctl.fControlZone[index].second.fMin;
                FAUSTFLOAT max = ctl.fControlZone[index].second.fMax;
                FAUSTFLOAT init = ctl.fControlZone[index].second.fInit;
                // Test max
                cout << "Max: " << max << endl;
                *ctl.fControlZone[index].first = max;
                audio.render();
                // Test min
                cout << "Min: " << min << endl;
                *ctl.fControlZone[index].first = min;
                audio.render();
            }
        }
        
        // Check by setting each control to min, then max, then keeping to max before going to next one
        {
            CheckControlUI ctl;
            DSP->buildUserInterface(&ctl);
            
            cout << "------------------------------" << endl;
            cout << "Check control min/max successively, keeping max for " << ctl.fControlZone.size() << " controls" << endl;
            for (int index = 0; index < ctl.fControlZone.size(); index++) {
                cout << "------------------------------" << endl;
                cout << "Control: " << ctl.getParamAddress(ctl.fControlZone[index].first) << endl;
                FAUSTFLOAT min = ctl.fControlZone[index].second.fMin;
                FAUSTFLOAT max = ctl.fControlZone[index].second.fMax;
                FAUSTFLOAT init = ctl.fControlZone[index].second.fInit;
                // Test min
                cout << "Min: " << min << endl;
                *ctl.fControlZone[index].first = min;
                audio.render();
                // Test max
                cout << "Max: " << max << endl;
                *ctl.fControlZone[index].first = max;
                audio.render();
            }
        }

        goto end;
        
    } else {
        audio.start();
    }
   
    interface->run();
    audio.stop();
    
end:
    
    delete DSP;
    delete interface;
    
    deleteInterpreterDSPFactory(static_cast<interpreter_dsp_factory*>(factory));
    return 0;
}