This file is indexed.

/usr/include/faust/audio/netjack-dsp.h is in faust-common 0.9.95~repack1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/************************************************************************

	IMPORTANT NOTE : this file contains two clearly delimited sections :
	the ARCHITECTURE section (in two parts) and the USER section. Each section
	is governed by its own copyright and license. Please check individually
	each section for license and copyright information.
*************************************************************************/

/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/

/************************************************************************
    FAUST Architecture File
	Copyright (C) 2003-2011 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.


 ************************************************************************
 ************************************************************************/

#ifndef __netjack_dsp__
#define __netjack_dsp__

#include <stdio.h>
#include "faust/audio/audio.h"
#include "faust/dsp/dsp.h"
#include "faust/gui/ControlUI.h"
#include "faust/midi/jack-midi.h"

#include <jack/net.h>
#include <string>
#include <assert.h>

class netjackaudio : public audio
{

    protected:
    
        dsp* fDSP;
        jack_net_slave_t* fNet;
        int fNetFormat;
        std::string fMasterIP;
        int fMasterPort;
        int fMTU;
        int fLatency;
        jack_master_t fResult;

    #ifdef RESTART_CB_API
        static int net_restart(void* arg) 
        {
            printf("Network failure, restart...\n");
            return static_cast<netjackaudio*>(arg)->restart_cb();
        }
    #else 
        static void net_shutdown(void* arg) 
        {
            printf("Network failure, shutdown...\n");
            static_cast<netjackaudio*>(arg)->shutdown_cb();
        }
    #endif
    
        static int net_sample_rate(jack_nframes_t nframes, void* arg) 
        {
            return static_cast<netjackaudio*>(arg)->set_sample_rate(nframes);
        }
        
        static int net_buffer_size(jack_nframes_t nframes, void* arg) 
        {
            return static_cast<netjackaudio*>(arg)->set_buffer_size(nframes);
        }
        
        static void net_error(int error_code, void* arg)
        {
            return static_cast<netjackaudio*>(arg)->error_cb(error_code);
        }
        
        static int net_process(jack_nframes_t buffer_size,
                               int,
                               float** audio_inputs,
                               int,
                               void** midi_inputs,
                               int,
                               float** audio_outputs,
                               int,
                               void** midi_outputs,
                               void* arg) 
        {
            static_cast<netjackaudio*>(arg)->process(buffer_size, audio_inputs, audio_outputs, midi_inputs, midi_outputs);
            return 0;
        }

        bool init_aux(const char* name, dsp* DSP, int audio_inputs, int audio_outputs, int midi_inputs, int midi_outputs) 
        {
            if (init_aux(name, audio_inputs, audio_outputs, midi_inputs, midi_outputs)) {
                set_dsp(DSP);
                return true;
            } else {
                return false;
            }
        }
    
        bool init_aux(const char* name, int audio_inputs, int audio_outputs, int midi_inputs, int midi_outputs) 
        {
            jack_slave_t request = {
                audio_inputs,
                audio_outputs,
                midi_inputs, 
                midi_outputs,
                fMTU,
                2,
                (fNetFormat > 0) ? JackOpusEncoder : ((fNetFormat == -1) ? JackFloatEncoder : JackIntEncoder),
                (fNetFormat > 0) ? fNetFormat : 0,
                fLatency
            };
      
            if ((fNet = jack_net_slave_open(fMasterIP.c_str(), fMasterPort, name, &request, &fResult)) == 0) {
                printf("JACK remote server not running ?\n");
                return false;
            }

            jack_set_net_slave_process_callback(fNet, net_process, this);
        #ifdef RESTART_CB_API
            jack_set_net_slave_restart_callback(fNet, net_restart, this);
        #else
            jack_set_net_slave_shutdown_callback(fNet, net_shutdown, this);
        #endif
            jack_set_net_slave_sample_rate_callback(fNet, net_sample_rate, this);
            
            jack_set_net_slave_buffer_size_callback(fNet, net_buffer_size, this);
            
            jack_set_net_slave_error_callback(fNet, net_error, this);

            return true;
        }
    
        // Possibly to be redefined by subclasses
        
        virtual int restart_cb()
        {
            return 0;
        }
       
        virtual void shutdown_cb()
        {}
        
        virtual void error_cb(int error_code)
        {}
       
        virtual int set_sample_rate(jack_nframes_t nframes)
        {
            return 0;
        }
        
        virtual int set_buffer_size(jack_nframes_t nframes)
        {
            return 0;
        }

        virtual void process(int count, float** audio_inputs, float** audio_outputs, void** midi_inputs, void** midi_outputs)
        {
             AVOIDDENORMALS;
             fDSP->compute(count, audio_inputs, audio_outputs);
        }

    public:

        netjackaudio(int net_format, const std::string& master_ip, int master_port, int mtu, int latency = 2)
            : fDSP(0), fNet(0), fNetFormat(net_format), fMasterIP(master_ip), fMasterPort(master_port), fMTU(mtu), fLatency(latency)
        {}
        
        virtual ~netjackaudio() 
        {
            if (fNet) {
                stop();
                jack_net_slave_close(fNet);
            }
        }

        virtual bool init(const char* name, dsp* DSP) 
        {
            return init_aux(name, DSP, DSP->getNumInputs(), DSP->getNumOutputs(), 0, 0);
        }

        virtual bool start() 
        {
            if (jack_net_slave_activate(fNet)) {
                printf("cannot activate net");
                return false;
            }
            return true;
        }

        virtual void stop() 
        {
            if (fNet) {
                jack_net_slave_deactivate(fNet);
            }
        }
        
        void set_dsp(dsp* DSP) 
        {
            fDSP = DSP;
            fDSP->init(fResult.sample_rate);
        }
        
        virtual int get_buffer_size() { return fResult.buffer_size; }
        virtual int get_sample_rate() { return fResult.sample_rate; }

};

/*
A special NetJack client that uses one more audio input/output to transmit control values.
*/

class netjackaudio_control : public netjackaudio, public ControlUI {  
        
    protected:
        
        virtual void process(int count, float** audio_inputs, float** audio_outputs, void** midi_inputs, void** midi_outputs)
        {
            AVOIDDENORMALS;
            
            float** inputs_tmp = (float**)alloca(fDSP->getNumInputs()*sizeof(float*));
            float** outputs_tmp = (float**)alloca(fDSP->getNumOutputs()*sizeof(float*));
            
            for (int i = 0; i < fDSP->getNumInputs(); i++) {
                inputs_tmp[i] = audio_inputs[i+1];
            }
            
            for (int i = 0; i < fDSP->getNumOutputs(); i++) {
                outputs_tmp[i] = audio_outputs[i+1];
            }
            
            // Control buffer always use buffer_size, even if uncomplete data buffer (count < buffer_size) is received
            decode_control(audio_inputs[0], fResult.buffer_size);
            
            // "count" may be less than buffer_size
            fDSP->compute(count, inputs_tmp, outputs_tmp);
            
            // Control buffer always use buffer_size, even if uncomplete data buffer (count < buffer_size) is received
            encode_control(audio_outputs[0], fResult.buffer_size);
        }
        
    public:
        
        netjackaudio_control(int net_format, const std::string& master_ip, int master_port, int mtu, int latency)
            :netjackaudio(net_format, master_ip, master_port, mtu, latency)
        {}
        
        virtual ~netjackaudio_control() 
        {}
        
        bool is_connexion_active()
        {
            return jack_net_slave_is_active(fNet);
        }
    
        virtual bool init(const char* name, dsp* dsp) 
        {
            dsp->buildUserInterface(this);
            return init_aux(name, dsp, dsp->getNumInputs() + 1, dsp->getNumOutputs() + 1, 0, 0); // One more audio port for control
        }
    
        virtual int restart_cb()
        {
            return -1;
        }
    
};

/*
A special NetJack client that uses MIDI input/output to transmit control values.
*/

class netjackaudio_midicontrol : public netjackaudio, public ControlUI, public jack_midi_handler {  
        
    protected:
        
        virtual void process(int count, float** audio_inputs, float** audio_outputs, void** midi_inputs, void** midi_outputs)
        {
            AVOIDDENORMALS;
            
            float** inputs_tmp = (float**)alloca(fDSP->getNumInputs()*sizeof(float*));
            float** outputs_tmp = (float**)alloca(fDSP->getNumOutputs()*sizeof(float*));
            
            for (int i = 0; i < fDSP->getNumInputs(); i++) {
                inputs_tmp[i] = audio_inputs[i];
            }
            
            for (int i = 0; i < fDSP->getNumOutputs(); i++) {
                outputs_tmp[i] = audio_outputs[i];
            }
            
            // Control buffer always use buffer_size, even if uncomplete data buffer (count < buffer_size) is received
            decode_midi_control(midi_inputs[0], fResult.buffer_size);
            
            // Decode MIDI messages
            processMidiInBuffer(midi_inputs[1]);
            
            // "count" may be less than buffer_size
            fDSP->compute(count, inputs_tmp, outputs_tmp);
            
            // Control buffer always use buffer_size, even if uncomplete data buffer (count < buffer_size) is received
            encode_midi_control(midi_outputs[0], fResult.buffer_size);
            
            // Encode MIDI messages
            processMidiOutBuffer(midi_outputs[1], true);
        }
        
    public:
        
        netjackaudio_midicontrol(int net_format, const std::string& master_ip, int master_port, int mtu, int latency)
            :netjackaudio(net_format, master_ip, master_port, mtu, latency)
        {}
        
        virtual ~netjackaudio_midicontrol() 
        {}
        
        bool is_connexion_active()
        {
            return jack_net_slave_is_active(fNet);
        }
    
        virtual bool init(const char* name, dsp* dsp) 
        {
            dsp->buildUserInterface(this);
            // One MIDI channel for control, and one MIDI channel for messages in both direction
            return init_aux(name, dsp, dsp->getNumInputs(), dsp->getNumOutputs(), 2, 2);
        }
    
        virtual int restart_cb()
        {
            return -1;
        }
    
};

#endif

/********************END ARCHITECTURE SECTION (part 2/2)****************/