Logo Search packages:      
Sourcecode: jacktrip version File versions  Download package

void Settings::parseInput ( int  argc,
char **  argv 
)

Parses command line input.

Todo:
Specify mandatory arguments

Definition at line 82 of file Settings.cpp.

References JackAudioInterface::BIT16, JackAudioInterface::BIT24, JackAudioInterface::BIT32, JackAudioInterface::BIT8, JackTrip::CLIENT, JackTrip::CLIENTTOPINGSERVER, gVerboseFlag, mBufferQueueLength, mEmptyHeader, mJackTripMode, mJackTripServer, mJamLink, mLoopBack, mNumChans, mPeerAddress, mPortNum, mRedundancy, mUnderrrunZero, printUsage(), and JackTrip::SERVER.

{
  // If no command arguments are given, print instructions
  if(argc == 1) {
    printUsage();
    std::exit(0);
  }

  // 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[] = {
    // These options set a flag, has to be sepcified as a long option --verbose
    { "verbose", no_argument, &gVerboseFlag, 1 },
    // These options don't set a flag.
    { "numchannels", required_argument, NULL, 'n' }, // Number of input and output channels
    { "server", no_argument, NULL, 's' }, // Run in server mode
    { "client", required_argument, NULL, 'c' }, // Run in client mode, set server IP address
    { "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
    { "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
    { "version", no_argument, NULL, 'v' }, // Version Number
    { "help", no_argument, NULL, 'h' }, // Print Help
    { NULL, 0, NULL, 0 }
  };

  // Parse Command Line Arguments
  //----------------------------------------------------------------------------
  /// \todo Specify mandatory arguments
  int ch;
  while ( (ch = getopt_long(argc, argv, "n:sc:SC:o:q:r:b:zljeJ:vh", longopts, NULL)) != -1 )
    switch (ch) {
      
    case 'n': // Number of input and output channels
      //-------------------------------------------------------
      mNumChans = atoi(optarg);
      break;
    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 'C': // Ping to server
      //-------------------------------------------------------
      mJackTripMode = JackTrip::CLIENTTOPINGSERVER;
      mPeerAddress = optarg;
      break;
    case 'o': // Port Offset
      //-------------------------------------------------------
      mPortNum += atoi(optarg);
      break;
    case 'b':
      //-------------------------------------------------------
      if      ( atoi(optarg) == 8 ) {
      mAudioBitResolution = JackAudioInterface::BIT8; }
      else if ( atoi(optarg) == 16 ) {
      mAudioBitResolution = JackAudioInterface::BIT16; }
      else if ( atoi(optarg) == 24 ) {
      mAudioBitResolution = JackAudioInterface::BIT24; }
      else if ( atoi(optarg) == 32 ) {
      mAudioBitResolution = JackAudioInterface::BIT32; }
      else {
      std::cerr << "--bitres ERROR: Wrong bit resolutions: " 
              << atoi(optarg) << " is not supported." << endl;
      printUsage();
      std::exit(1); }
      break;
    case 'q':
      //-------------------------------------------------------
      if ( atoi(optarg) <= 0 ) {
      std::cerr << "--queue ERROR: The queue has to be a positive integer" << endl;
      printUsage();
      std::exit(1); }
      else {
      mBufferQueueLength = atoi(optarg);
      }
      break;
    case 'r':
      //-------------------------------------------------------
      if ( atoi(optarg) <= 0 ) {
      std::cerr << "--queue ERROR: The queue 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':
      //-------------------------------------------------------
      mClientName = optarg;
      break;
    case 'v':
      //-------------------------------------------------------
      cout << "JackTrip VERSION: " << gVersion << endl;
      cout << "Copyright (c) 2008-2009 Juan-Pablo Caceres, Chris Chafe." << endl;
      cout << "SoundWIRE group at CCRMA, Stanford University" << endl;
      cout << "" << endl;
      std::exit(0);
      break;
    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;
    cout << "WARINING: The following entered options have no effect" << endl;
    cout << "          They will be ignored!" << endl;
    cout << "          Type jacktrip to see options." << endl;
    for( ; optind < argc; optind++) {
      printf("argument: %s\n", argv[optind]);
    }
    cout << gPrintSeparator << endl;
  }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index