Settings.cpp 24.9 KB
Newer Older
jcaceres's avatar
jcaceres committed
1
2
//*****************************************************************
/*
jcaceres's avatar
jcaceres committed
3
  JackTrip: A System for High-Quality Audio Network Performance
jcaceres's avatar
jcaceres committed
4
5
6
7
  over the Internet

  Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe.
  SoundWIRE group at CCRMA, Stanford University.
8

jcaceres's avatar
jcaceres committed
9
10
11
12
13
14
15
16
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:
17

jcaceres's avatar
jcaceres committed
18
19
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
20

jcaceres's avatar
jcaceres committed
21
22
23
24
25
26
27
28
29
30
31
32
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/
//*****************************************************************

/**
33
 * \file Settings.cpp
jcaceres's avatar
jcaceres committed
34
35
36
37
38
 * \author Juan-Pablo Caceres
 * \date July 2008
 */

#include "Settings.h"
jcaceres's avatar
jcaceres committed
39
#include "LoopBack.h"
40
#include "NetKS.h"
Chris Chafe's avatar
src/  
Chris Chafe committed
41
42
43
44
45
46

#ifdef WAIR // wair
#include "ap8x2.dsp.h"
#include "Stk16.dsp.h"
#endif // endwhere

47
#include "UdpMasterListener.h"
48
#include "JackTripWorker.h"
49
#include "jacktrip_globals.h"
jcaceres's avatar
jcaceres committed
50
51
52

#include <iostream>
#include <getopt.h> // for command line parsing
jcacerec's avatar
jcacerec committed
53
#include <cstdlib>
jcaceres's avatar
jcaceres committed
54

55
56
#include "ThreadPoolTest.h"

jcaceres's avatar
jcaceres committed
57
58
using std::cout; using std::endl;

59
60
int gVerboseFlag = 0;

jcaceres's avatar
jcaceres committed
61

jcaceres's avatar
jcaceres committed
62
//*******************************************************************************
jcaceres's avatar
jcaceres committed
63
Settings::Settings() :
64
65
66
67
68
69
70
71
72
73
    mJackTrip(NULL),
    mJackTripMode(JackTrip::SERVER),
    mDataProtocol(JackTrip::UDP),
    mNumChans(2),
    mBufferQueueLength(gDefaultQueueLength),
    mAudioBitResolution(AudioInterface::BIT16),
    mBindPortNum(gDefaultPort), mPeerPortNum(gDefaultPort),
    mClientName(NULL),
    mUnderrrunZero(false),
    mLoopBack(false),
Chris Chafe's avatar
src/  
Chris Chafe committed
74
75
76
77
    #ifdef WAIR // WAIR
    mNumNetRevChans(0),
    mWAIR(false),
    #endif // endwhere
78
79
80
81
82
83
84
    mJamLink(false),
    mEmptyHeader(false),
    mJackTripServer(false),
    mLocalAddress(gDefaultLocalAddress),
    mRedundancy(1),
    mUseJack(true),
    mChanfeDefaultSR(false),
85
    mChanfeDefaultID(0),
86
    mChanfeDefaultBS(false),
Chris Chafe's avatar
Chris Chafe committed
87
    mHubConnectionMode(JackTrip::SERVERTOCLIENT),
88
    mConnectDefaultAudioPorts(true)
jcaceres's avatar
jcaceres committed
89
{}
jcaceres's avatar
jcaceres committed
90

91
92
93
//*******************************************************************************
Settings::~Settings()
{
94
95
    stopJackTrip();
    delete mJackTrip;
96
}
jcaceres's avatar
jcaceres committed
97

jcaceres's avatar
jcaceres committed
98
//*******************************************************************************
99
void Settings::parseInput(int argc, char** argv)
jcaceres's avatar
jcaceres committed
100
{
101
102
103
104
    // If no command arguments are given, print instructions
    if(argc == 1) {
        printUsage();
        std::exit(0);
jcaceres's avatar
jcaceres committed
105
106
    }

107
108
109
110
111
    // Usage example at:
    // http://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html#Getopt-Long-Option-Example
    // options descriptor
    //----------------------------------------------------------------------------
    static struct option longopts[] = {
Chris Chafe's avatar
src/  
Chris Chafe committed
112
        // These options don't set a flag.
113
    { "numchannels", required_argument, NULL, 'n' }, // Number of input and output channels
Chris Chafe's avatar
src/  
Chris Chafe committed
114
115
116
117
118
#ifdef WAIR // WAIR
    { "wair", no_argument, NULL, 'w' }, // Run in LAIR mode, sets numnetrevchannels
    { "addcombfilterlength", required_argument, NULL, 'N' }, // added comb filter length
    { "combfilterfeedback", required_argument, NULL, 'H' }, // comb filter feedback
#endif // endwhere
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    { "server", no_argument, NULL, 's' }, // Run in server mode
    { "client", required_argument, NULL, 'c' }, // Run in client mode, set server IP address
    { "localaddress", required_argument, NULL, 'L' }, // set local address e.g., 127.0.0.2 for second instance on same host
    { "jacktripserver", no_argument, NULL, 'S' }, // Run in JamLink mode
    { "pingtoserver", required_argument, NULL, 'C' }, // Run in ping to server mode, set server IP address
    { "portoffset", required_argument, NULL, 'o' }, // Port Offset from 4464
    { "bindport", required_argument, NULL, 'B' }, // Port Offset from 4464
    { "peerport", required_argument, NULL, 'P' }, // Port Offset from 4464
    { "queue", required_argument, NULL, 'q' }, // Queue Length
    { "redundancy", required_argument, NULL, 'r' }, // Redundancy
    { "bitres", required_argument, NULL, 'b' }, // Audio Bit Resolution
    { "zerounderrun", no_argument, NULL, 'z' }, // Use Underrun to Zeros Mode
    { "loopback", no_argument, NULL, 'l' }, // Run in loopback mode
    { "jamlink", no_argument, NULL, 'j' }, // Run in JamLink mode
    { "emptyheader", no_argument, NULL, 'e' }, // Run in JamLink mode
    { "clientname", required_argument, NULL, 'J' }, // Run in JamLink mode
    { "rtaudio", no_argument, NULL, 'R' }, // Run in JamLink mode
    { "srate", required_argument, NULL, 'T' }, // Set Sample Rate
    { "deviceid", required_argument, NULL, 'd' }, // Set RTAudio device id to use
    { "bufsize", required_argument, NULL, 'F' }, // Set buffer Size
    { "nojackportsconnect" , no_argument, NULL,  'D'}, // Don't connect default Audio Ports
    { "version", no_argument, NULL, 'v' }, // Version Number
Chris Chafe's avatar
src/  
Chris Chafe committed
141
    { "verbose", no_argument, NULL, 'V' }, // Verbose mode
Chris Chafe's avatar
Chris Chafe committed
142
    { "hubpatch", required_argument, NULL, 'p' }, // Set hubConnectionMode for auto patch in Jack
143
144
145
    { "help", no_argument, NULL, 'h' }, // Print Help
    { NULL, 0, NULL, 0 }
};
146
147
148
149
150
151

    // Parse Command Line Arguments
    //----------------------------------------------------------------------------
    /// \todo Specify mandatory arguments
    int ch;
    while ( (ch = getopt_long(argc, argv,
152
                              "n:N:H:sc:SC:o:B:P:q:r:b:zlwjeJ:RTd:F:p:DvVh", longopts, NULL)) != -1 )
153
154
155
156
157
158
        switch (ch) {

        case 'n': // Number of input and output channels
            //-------------------------------------------------------
            mNumChans = atoi(optarg);
            break;
Chris Chafe's avatar
src/  
Chris Chafe committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifdef WAIR
        case 'w':
            //-------------------------------------------------------
            mWAIR = true;
            mNumNetRevChans = gDefaultNumNetRevChannels; // fixed amount sets number of network channels and comb filters for WAIR
            break;
        case 'N':
            //-------------------------------------------------------
            mClientAddCombLen = atoi(optarg); // cmd line comb length adjustment
            break;
        case 'H': // comb feedback adjustment
            //-------------------------------------------------------
            mClientRoomSize = atof(optarg); // cmd line comb feedback adjustment
            break;
#endif // endwhere
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
        case 's': // Run in server mode
            //-------------------------------------------------------
            mJackTripMode = JackTrip::SERVER;
            break;
        case 'S': // Run in jacktripserver mode
            //-------------------------------------------------------
            mJackTripServer = true;
            break;
        case 'c': // Client mode
            //-------------------------------------------------------
            mJackTripMode = JackTrip::CLIENT;
            mPeerAddress = optarg;
            break;
        case 'L': // set optional local host address
            //-------------------------------------------------------
            mLocalAddress = optarg;
            break;
        case 'C': // Ping to server
            //-------------------------------------------------------
            mJackTripMode = JackTrip::CLIENTTOPINGSERVER;
            mPeerAddress = optarg;
            break;
        case 'o': // Port Offset
            //-------------------------------------------------------
            mBindPortNum += atoi(optarg);
            mPeerPortNum += atoi(optarg);
            break;
        case 'B': // Bind Port
            //-------------------------------------------------------
            mBindPortNum = atoi(optarg);
            break;
        case 'P': // Peer Port
            //-------------------------------------------------------
            mPeerPortNum = atoi(optarg);
            break;
        case 'b':
            //-------------------------------------------------------
            if      ( atoi(optarg) == 8 ) {
                mAudioBitResolution = AudioInterface::BIT8; }
            else if ( atoi(optarg) == 16 ) {
                mAudioBitResolution = AudioInterface::BIT16; }
            else if ( atoi(optarg) == 24 ) {
                mAudioBitResolution = AudioInterface::BIT24; }
            else if ( atoi(optarg) == 32 ) {
                mAudioBitResolution = AudioInterface::BIT32; }
            else {
220
                std::cerr << "--bitres ERROR: Wrong bit resolution: "
221
222
223
224
225
226
227
                          << atoi(optarg) << " is not supported." << endl;
                printUsage();
                std::exit(1); }
            break;
        case 'q':
            //-------------------------------------------------------
            if ( atoi(optarg) <= 0 ) {
228
                std::cerr << "--queue ERROR: The queue has to be equal or greater than 2" << endl;
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
                printUsage();
                std::exit(1); }
            else {
                mBufferQueueLength = atoi(optarg);
            }
            break;
        case 'r':
            //-------------------------------------------------------
            if ( atoi(optarg) <= 0 ) {
                std::cerr << "--redundancy ERROR: The reduncancy has to be a positive integer" << endl;
                printUsage();
                std::exit(1); }
            else {
                mRedundancy = atoi(optarg);
            }
            break;
        case 'z': // underrun to zero
            //-------------------------------------------------------
            mUnderrrunZero = true;
            break;
        case 'l': // loopback
            //-------------------------------------------------------
            mLoopBack = true;
            break;
        case 'e': // jamlink
            //-------------------------------------------------------
            mEmptyHeader = true;
            break;
        case 'j': // jamlink
            //-------------------------------------------------------
            mJamLink = true;
            break;
        case 'J': // Set client Name
            //-------------------------------------------------------
            mClientName = optarg;
            break;
        case 'R': // RtAudio
            //-------------------------------------------------------
            mUseJack = false;
            break;
        case 'T': // Sampling Rate
            //-------------------------------------------------------
            mChanfeDefaultSR = true;
            mSampleRate = atoi(optarg);
            break;
274
275
276
277
278
        case 'd': // RTAudio device id
            //-------------------------------------------------------
            mChanfeDefaultID = true;
            mDeviceID = atoi(optarg);
            break;
279
280
281
282
283
        case 'F': // Buffer Size
            //-------------------------------------------------------
            mChanfeDefaultBS = true;
            mAudioBufferSize = atoi(optarg);
            break;
284
285
286
287
        case 'D':
            //-------------------------------------------------------
            mConnectDefaultAudioPorts = false;
            break;
288
289
290
        case 'v':
            //-------------------------------------------------------
            cout << "JackTrip VERSION: " << gVersion << endl;
Chris Chafe's avatar
src/  
Chris Chafe committed
291
            cout << "Copyright (c) 2008-2018 Juan-Pablo Caceres, Chris Chafe." << endl;
292
293
294
295
            cout << "SoundWIRE group at CCRMA, Stanford University" << endl;
            cout << "" << endl;
            std::exit(0);
            break;
Chris Chafe's avatar
src/  
Chris Chafe committed
296
297
298
299
300
        case 'V':
            //-------------------------------------------------------
            gVerboseFlag = true;
            if (gVerboseFlag) std::cout << "Verbose mode" << std::endl;
            break;
Chris Chafe's avatar
Chris Chafe committed
301
302
303
        case 'p':
            //-------------------------------------------------------
            if      ( atoi(optarg) == 0 ) {
304
                mHubConnectionMode = JackTrip::SERVERTOCLIENT; }
305
            else if ( atoi(optarg) == 1 ) {
Chris Chafe's avatar
Chris Chafe committed
306
                mHubConnectionMode = JackTrip::CLIENTECHO; }
307
            else if ( atoi(optarg) == 2 ) {
Chris Chafe's avatar
Chris Chafe committed
308
                mHubConnectionMode = JackTrip::CLIENTFOFI; }
Chris Chafe's avatar
Chris Chafe committed
309
310
            else if ( atoi(optarg) == 3 ) {
                mHubConnectionMode = JackTrip::RESERVEDMATRIX; }
311
312
            else if ( atoi(optarg) == 4 ) {
                mHubConnectionMode = JackTrip::FULLMIX; }
Chris Chafe's avatar
Chris Chafe committed
313
            else {
314
                std::cerr << "-p ERROR: Wrong HubConnectionMode: "
Chris Chafe's avatar
Chris Chafe committed
315
316
317
318
                          << atoi(optarg) << " is not supported." << endl;
                printUsage();
                std::exit(1); }
            break;
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
        case 'h':
            //-------------------------------------------------------
            printUsage();
            std::exit(0);
            break;
        default:
            //-------------------------------------------------------
            printUsage();
            std::exit(0);
            break;
        }

    // Warn user if undefined options where entered
    //----------------------------------------------------------------------------
    if (optind < argc) {
        cout << gPrintSeparator << endl;
335
        cout << "WARINING: The following entered options have no effect." << endl;
336
        cout << "          They will be ignored!" << endl;
337
        cout << "          Type 'jacktrip' to see options." << endl;
338
        for( ; optind < argc; optind++) {
339
            cout << "argument: " << argv[optind] << endl;
340
341
        }
        cout << gPrintSeparator << endl;
jcaceres's avatar
jcaceres committed
342
343
344
345
346
347
348
    }
}


//*******************************************************************************
void Settings::printUsage()
{
349
350
351
    cout << "" << endl;
    cout << "JackTrip: A System for High-Quality Audio Network Performance" << endl;
    cout << "over the Internet" << endl;
Chris Chafe's avatar
src/  
Chris Chafe committed
352
    cout << "Copyright (c) 2008-2018 Juan-Pablo Caceres, Chris Chafe." << endl;
353
354
355
356
357
358
359
360
    cout << "SoundWIRE group at CCRMA, Stanford University" << endl;
    cout << "VERSION: " << gVersion << endl;
    cout << "" << endl;
    cout << "Usage: jacktrip [-s|-c host] [options]" << endl;
    cout << "" << endl;
    cout << "Options: " << endl;
    cout << "REQUIRED ARGUMENTS: " << endl;
    cout << " -s, --server                             Run in Server Mode" << endl;
jcacerec's avatar
jcacerec committed
361
    cout << " -c, --client <peer_hostname_or_IP_num>   Run in Client Mode" << endl;
Aaron Wyatt's avatar
Aaron Wyatt committed
362
363
    cout << " -S, --jacktripserver                     Run in Hub Server Mode" << endl;
    cout << " -C, --pingtoserver <peer_name_or_IP>     Run in Hub Client Mode" << endl;
364
365
    cout << endl;
    cout << "OPTIONAL ARGUMENTS: " << endl;
366
    cout << " -n, --numchannels #                      Number of Input and Output Channels (default: "
367
         << 2 << ")" << endl;
Chris Chafe's avatar
src/  
Chris Chafe committed
368
369
370
371
372
373
374
#ifdef WAIR // WAIR
    cout << " -w, --wair                               Run in WAIR Mode" << endl;
    cout << " -N, --addcombfilterlength #              comb length adjustment for WAIR (default "
         << gDefaultAddCombFilterLength << ")" << endl;
    cout << " -H, --combfilterfeedback #               comb feedback adjustment for WAIR (default "
         << gDefaultCombFilterFeedback << ")" << endl;
#endif // endwhere
375
    cout << " -q, --queue       # (2 or more)          Queue Buffer Length, in Packet Size (default: "
376
         << gDefaultQueueLength << ")" << endl;
377
    cout << " -r, --redundancy  # (1 or more)          Packet Redundancy to avoid glitches with packet losses (default: 1)"
378
379
         << endl;
    cout << " -o, --portoffset  #                      Receiving port offset from base port " << gDefaultPort << endl;
380
381
382
    cout << " --bindport        #                      Set only the bind port number (default: 4464)" << endl;
    cout << " --peerport        #                      Set only the Peer port number (default: 4464)" << endl;
    cout << " -b, --bitres      # (8, 16, 24, 32)      Audio Bit Rate Resolutions (default: 16)" << endl;
Aaron Wyatt's avatar
Aaron Wyatt committed
383
    cout << " -p, --hubpatch    # (0, 1, 2, 3, 4)      Hub auto audio patch, only has effect if running HUB SERVER mode, 0=server-to-clients, 1=client loopback, 2=client fan out/in but not loopback, 3=reserved for TUB, 4=full mix (default: 0)" << endl;
384
    cout << " -z, --zerounderrun                       Set buffer to zeros when underrun occurs (default: wavetable)" << endl;
385
386
    cout << " -l, --loopback                           Run in Loop-Back Mode" << endl;
    cout << " -j, --jamlink                            Run in JamLink Mode (Connect to a JamLink Box)" << endl;
387
388
    cout << " --clientname                             Change default client name (default: JackTrip)" << endl;
    cout << " --localaddress                           Change default local host IP address (default: 127.0.0.1)" << endl;
389
    cout << " --nojackportsconnect                     Don't connect default audio ports in jack" << endl;
390
    cout << endl;
391
392
393
394
    cout << "ARGUMENTS TO USE JACKTRIP WITHOUT JACK:" << endl;
    cout << " --rtaudio                                Use system's default sound system instead of Jack" << endl;
    cout << "   --srate         #                      Set the sampling rate, works on --rtaudio mode only (default: 48000)" << endl;
    cout << "   --bufsize       #                      Set the buffer size, works on --rtaudio mode only (default: 128)" << endl;
395
    cout << "   --deviceid      #                      The rtaudio device id --rtaudio mode only (default: 0)" << endl;
396
397
398
    cout << endl;
    cout << "HELP ARGUMENTS: " << endl;
    cout << " -v, --version                            Prints Version Number" << endl;
399
    cout << " -V, --verbose                            Verbose mode, prints debug messages" << endl;
400
401
    cout << " -h, --help                               Prints this Help" << endl;
    cout << "" << endl;
jcaceres's avatar
jcaceres committed
402
}
jcaceres's avatar
jcaceres committed
403
404
405
406
407


//*******************************************************************************
void Settings::startJackTrip()
{
408

409
410
411
    /// \todo Change this, just here to test
    if ( mJackTripServer ) {
        UdpMasterListener* udpmaster = new UdpMasterListener;
Chris Chafe's avatar
src/  
Chris Chafe committed
412
413
414
#ifdef WAIR // WAIR
        udpmaster->setWAIR(mWAIR);
#endif // endwhere
415
        udpmaster->setHubPatch(mHubConnectionMode);
416
        udpmaster->setConnectDefaultAudioPorts(mConnectDefaultAudioPorts);
Chris Chafe's avatar
src/  
Chris Chafe committed
417
        if (gVerboseFlag) std::cout << "Settings:startJackTrip before udpmaster->start" << std::endl;
Aaron Wyatt's avatar
Aaron Wyatt committed
418
419
420
421
422
423
        // Set buffers to zero when underrun
        if ( mUnderrrunZero ) {
            cout << "Setting buffers to zero when underrun..." << endl;
            cout << gPrintSeparator << std::endl;
            udpmaster->setUnderRunMode(JackTrip::ZEROS);
        }
Aaron Wyatt's avatar
Aaron Wyatt committed
424
        udpmaster->setBufferQueueLength(mBufferQueueLength);
425
426
427
428
        udpmaster->start();

        //---Thread Pool Test--------------------------------------------
        /*
429
430
431
432
    cout << "BEFORE START" << endl;
    ThreadPoolTest* thtest = new ThreadPoolTest();
    // QThreadPool takes ownership and deletes 'hello' automatically
    QThreadPool::globalInstance()->start(thtest);
433

434
435
436
437
    cout << "AFTER START" << endl;
    sleep(2);
    thtest->stop();
    QThreadPool::globalInstance()->waitForDone();
438
    */
439
        //---------------------------------------------------------------
440
441
    }

442
443
444
445
    else {

        //JackTrip jacktrip(mJackTripMode, mDataProtocol, mNumChans,
        //	    mBufferQueueLength, mAudioBitResolution);
Chris Chafe's avatar
src/  
Chris Chafe committed
446
447
448
449
#ifdef WAIR // WAIR
        if (gVerboseFlag) std::cout << "Settings:startJackTrip mNumNetRevChans = " << mNumNetRevChans << std::endl;
#endif // endwhere
        if (gVerboseFlag) std::cout << "Settings:startJackTrip before new JackTrip" << std::endl;
450
        mJackTrip = new JackTrip(mJackTripMode, mDataProtocol, mNumChans,
Chris Chafe's avatar
src/  
Chris Chafe committed
451
452
453
                         #ifdef WAIR // wair
                                 mNumNetRevChans,
                         #endif // endwhere
454
455
                                 mBufferQueueLength, mRedundancy, mAudioBitResolution);

456
457
458
        // Set connect or not default audio ports. Only work for jack
        mJackTrip->setConnectDefaultAudioPorts(mConnectDefaultAudioPorts);

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
        // Connect Signals and Slots
        QObject::connect(mJackTrip, SIGNAL( signalProcessesStopped() ),
                         this, SLOT( slotExitProgram() ));

        // Change client name if different from default
        if (mClientName != NULL) {
            mJackTrip->setClientName(mClientName);
        }

        // Set buffers to zero when underrun
        if ( mUnderrrunZero ) {
            cout << "Setting buffers to zero when underrun..." << endl;
            cout << gPrintSeparator << std::endl;
            mJackTrip->setUnderRunMode(JackTrip::ZEROS);
        }

        // Set peer address in server mode
        if ( mJackTripMode == JackTrip::CLIENT || mJackTripMode == JackTrip::CLIENTTOPINGSERVER ) {
            mJackTrip->setPeerAddress(mPeerAddress.toLatin1().data()); }

479
480
481
482
        //        if(mLocalAddress!=QString()) // default
        //            mJackTrip->setLocalAddress(QHostAddress(mLocalAddress.toLatin1().data()));
        //        else
        //            mJackTrip->setLocalAddress(QHostAddress::Any);
483
484
485

        // Set Ports
        //cout << "SETTING ALL PORTS" << endl;
Chris Chafe's avatar
src/  
Chris Chafe committed
486
        if (gVerboseFlag) std::cout << "Settings:startJackTrip before mJackTrip->setBindPorts" << std::endl;
487
        mJackTrip->setBindPorts(mBindPortNum);
Chris Chafe's avatar
src/  
Chris Chafe committed
488
        if (gVerboseFlag) std::cout << "Settings:startJackTrip before mJackTrip->setPeerPorts" << std::endl;
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
        mJackTrip->setPeerPorts(mPeerPortNum);

        // Set in JamLink Mode
        if ( mJamLink ) {
            cout << "Running in JamLink Mode..." << endl;
            cout << gPrintSeparator << std::endl;
            mJackTrip->setPacketHeaderType(DataProtocol::JAMLINK);
        }

        // Set in EmptyHeader Mode
        if ( mEmptyHeader ) {
            cout << "Running in EmptyHeader Mode..." << endl;
            cout << gPrintSeparator << std::endl;
            mJackTrip->setPacketHeaderType(DataProtocol::EMPTY);
        }

        // Set RtAudio
506
#ifdef __RT_AUDIO__
507
508
509
        if (!mUseJack) {
            mJackTrip->setAudiointerfaceMode(JackTrip::RTAUDIO);
        }
510
#endif
jcacerec's avatar
jcacerec committed
511

512
513
514
515
        // Chanfe default Sampling Rate
        if (mChanfeDefaultSR) {
            mJackTrip->setSampleRate(mSampleRate);
        }
516

517
518
519
520
        // Chanfe defualt device ID
        if (mChanfeDefaultID) {
            mJackTrip->setDeviceID(mDeviceID);
        }
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546

        // Chanfe default Buffer Size
        if (mChanfeDefaultBS) {
            mJackTrip->setAudioBufferSizeInSamples(mAudioBufferSize);
        }

        // Add Plugins
        if ( mLoopBack ) {
            cout << "Running in Loop-Back Mode..." << endl;
            cout << gPrintSeparator << std::endl;
            //std::tr1::shared_ptr<LoopBack> loopback(new LoopBack(mNumChans));
            //mJackTrip->appendProcessPlugin(loopback.get());

            LoopBack* loopback = new LoopBack(mNumChans);
            mJackTrip->appendProcessPlugin(loopback);

            // ----- Test Karplus Strong -----------------------------------
            //std::tr1::shared_ptr<NetKS> loopback(new NetKS());
            //mJackTrip->appendProcessPlugin(loopback);
            //loopback->play();
            //NetKS* netks = new NetKS;
            //mJackTrip->appendProcessPlugin(netks);
            //netks->play();
            // -------------------------------------------------------------
        }

Chris Chafe's avatar
src/  
Chris Chafe committed
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#ifdef WAIR // WAIR
        if ( mWAIR ) {
            cout << "Running in WAIR Mode..." << endl;
            cout << gPrintSeparator << std::endl;
            switch ( mNumNetRevChans )
            {
            case 16 :
            {
                mJackTrip->appendProcessPlugin(new ap8x2(mNumChans)); // plugin slot 0
                /////////////////////////////////////////////////////////
                Stk16* plugin = new Stk16(mNumNetRevChans);
                plugin->Stk16::initCombClient(mClientAddCombLen, mClientRoomSize);
                mJackTrip->appendProcessPlugin(plugin); // plugin slot 1
            }
                break;
            default:
                throw std::invalid_argument("Settings: mNumNetRevChans doesn't correspond to Faust plugin");
                break;
            }
        }
#endif // endwhere

569
        // Start JackTrip
Chris Chafe's avatar
src/  
Chris Chafe committed
570
571
        if (gVerboseFlag) std::cout << "Settings:startJackTrip before mJackTrip->startProcess" << std::endl;
        mJackTrip->startProcess(
Chris Chafe's avatar
Chris Chafe committed
572
            #ifdef WAIRTOMASTER // WAIR
Chris Chafe's avatar
src/  
Chris Chafe committed
573
574
575
576
577
578
                    0 // for WAIR compatibility, ID in jack client name
            #endif // endwhere
                    );
        //        if (gVerboseFlag) std::cout << "Settings:startJackTrip before mJackTrip->start" << std::endl;
        // this is a noop
        //        mJackTrip->start();
579
580

        /*
581
582
583
584
       sleep(10);
       cout << "Stoping JackTrip..." << endl;
       mJackTrip->stop();
    */
585
    }
jcaceres's avatar
jcaceres committed
586
}
587
588
589
590
591


//*******************************************************************************
void Settings::stopJackTrip()
{
592
    mJackTrip->stop();
593
}